Function: init

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas training product

Atlas inference product

Atlas 200I/500 A2 inference product

Description

Performs initialization.

Prototype

  • C Prototype
    1
    aclError aclInit(const char *configPath)
    
  • Python Function
    1
    ret = acl.init(config_path)
    

Parameters

Parameter

Description

config_path

Path of the configuration file, including the file name.

The configuration file is in JSON format. A JSON file allows up to 10 levels of curly brackets and square brackets, respectively. To use the default configurations, directly call the acl.init interface without passing any parameter or set the configuration file to an empty JSON string (that is, only {} exists in the configuration file).

The configuration file is in JSON format. The following configurations are supported:

  • Dump configuration: includes the following configurations. (If the operator input or output contains sensitive user information, information leakage may occur.)
    • Model dump configuration (used to export the input and output data of each operator layer in a model) and single-operator dump configuration (used to export the input and output data of a single operator). The exported data is used to compare with a specified model or operator, which affects the positioning accuracy. For details about the configuration examples, description, and restrictions, see Examples of Model Dump Configuration and Single-Operator Dump Configuration. This dump configuration is disabled by default.
    • Dump configuration of the exception operator (used to export the input and output data, workspace information, and tiling information of the exception operator). The exported data is used to analyze AI Core errors. For details about the configuration example, see Example of Dump Configuration for Exception Operators. This dump configuration is disabled by default.
    • Dump configuration of the overflow/underflow operator (used to export the input and output data of the overflow/underflow operator in the model). The exported data is used to analyze overflow/underflow causes and locate model accuracy problems. For details about the configuration example, description, and restrictions, see Example of Overflow/Underflow Operator Dump Configuration. This dump configuration is disabled by default.
    • Operator Dump Watch mode configuration (enables the observation mode for the output data of a specified operator). If you suspect that the memory is overwritten by other operators after locating the accuracy issues of some operators and excluding the computation issues of the operators, you can enable the Dump Watch mode. For details about the configuration example and restrictions, see Dump Watch Configuration for Operators. The dump watch mode is disabled by default.
    • Operator kernel debugging information dump configuration is used to export the kernel debugging information of Ascend C operators to locate operator problems. This dump configuration is disabled by default.

      This configuration is only available for the following models:

      Atlas 350 Accelerator Card

      Atlas A3 Training Series Product

      Atlas A2 Training Series Product/Atlas 800I A2 Inference Product

      Atlas 200/500 A2 Inference Product

      Atlas Inference Series Product

  • Profiling configuration. For the configuration example, description, and restrictions, see Performance Tuning Tool. Profiling is disabled by default.
  • Operator cache aging configuration. To save memory and balance the calling performance, you can use the max_opqueue_num parameter to configure the maximum length of the "operator type and single-operator model" mapping queue. If the length of the mapping queue reaches the maximum, the least used mapping information and single-operator models in the cache are deleted before the most recent mapping information and the corresponding single-operator model are loaded. The default maximum length of the mapping queue is 20000. For details about the examples and restrictions, see Example of Operator Cache Aging Configuration.
  • Error information report mode configuration, which is used to control the acl.get_recent_err_msg API to obtain error information by process or thread level. By default, error information is obtained by thread level. For details about the example, see Example of Error Information Report Mode Configuration.
  • Default device configuration (used to configure the default computing device). For details about the configuration example and description, see Configuration example of the default device.

    If the device is specified through set_device, aclrtSetDevice has a high priority.

    If you want to explicitly create a context after enabling the default device configuration, you need to call set_device. Otherwise, service exceptions may occur.

  • AI Core stack size configuration, which is used to control the size of the stack space allocated to each AI Core during kernel execution in a process. The default value is 32 KB. For details about the configuration example and usage description, see Configuration Example of the AI Core Stack Space. When compiling AI Core operators, the configured AI Core stack size is valid only when the O0 switch is enabled. This restriction does not apply to the Atlas 350 Accelerator Card.

    This configuration is only available for the following models:

    Atlas 350 Accelerator Card

    Atlas A3 training product / Atlas A3 inference product

    Atlas A2 training product / Atlas A2 inference product

    Atlas 200I/500 A2 inference product

  • Single Instruction Multiple Thread (SIMT) stack size configuration, which is used to control the stack size of the SIMT operator and the branch (divergence) stack size of the SIMT operator in each thread. The unit is byte. Only the Atlas 350 Accelerator Card supports this configuration.
  • Single Instruction Multiple Thread (SIMT) Printf maintenance and test space size configuration, which is used to control the size of the space for the SIMT operator to print information. The unit is byte. Only the Atlas 350 Accelerator Card supports this configuration.
  • Single Instruction Multiple Data (SIMD) Printf maintenance and test space size configuration, which is used to control the size of the space for the SIMD operator to print information on each core. The unit is byte. This configuration is only available for the following models:

    Atlas 350 Accelerator Card

    Atlas A3 Training Series Product

    Atlas A2 Training Series Product/Atlas 800I A2 Inference Product

  • Event resource scheduling mode, which is used to control the event resource scheduling mode when a model running instance is built in capture mode. For details about the configuration example and usage description, see Example of Configuring the Event Resource Scheduling Mode.

    This configuration is only available for the following models:

    Atlas 350 Accelerator Card

    Atlas A3 training product / Atlas A3 inference product

    Atlas A2 training product / Atlas A2 inference product

NOTE:

Dump configuration and profiling configuration should not be both set. The dump operation could affect the system performance, resulting in inaccurate profile data collected by Profiling.

Return Value

Return Value

Description

ret

Int, error code. 0 on success; else, failure.

Restrictions

  • acl.init must be called before app development using pyacl APIs. Otherwise, an error may occur during the initialization of internal system resources, causing other service exceptions.

  • aclInit can be called multiple times in a process, but the aclFinalize or aclFinalizeReference API must be called for deinitialization.
    • The configuration must be consistent each time aclInit is called. Otherwise, only the configuration of the first call is valid. Calling the aclInit API again may cause errors.
    • To be compatible with earlier versions, if the aclInit API is called repeatedly, the error code ACL_ERROR_REPEAT_INITIALIZE will be returned. You can ignore this error and continue to process services.
    • The aclInit and aclFinalize APIs can be called repeatedly for initialization and deinitialization, respectively. Only sequential calls are available for the two APIs.
      aclInit --> Service processing --> aclFinalize --> aclInit --> Service processing --> aclFinalize

      After you call aclInit multiple times, you only need to call aclFinalize once to perform deinitialization. The aclInit reference count will be reset to 0.

    • If the aclInit and aclFinalizeReference APIs are called for initialization and deinitialization, respectively, the two APIs need to be called in pairs.

      aclFinalizeReference involves reference counting. Each time aclInit is called, the reference count increases by 1. Each time aclFinalizeReference is called, the reference count decreases by 1. Deinitialization is performed only when the reference count decreases to 0.

      Repeated initialization and deinitialization are supported. The APIs can be called in sequence or concurrently. The API call sequence is as follows:

      • The following figure shows the sequential call sequence.

      • The following figure shows the concurrent call sequence.

Example of Overflow/Underflow Operator Dump Configuration

Set dump_debug to on to enable the overflow/underflow operator configuration. The following is an example of the configuration file:
{
    "dump":{
        "dump_path":"output",
        "dump_debug":"on"
    }
}
The details are as follows:
  • If dump_debug is not set or set to off, the overflow/underflow operator configuration is disabled.
  • If the overflow/underflow operator configuration is enabled, dump_path must be set to specify the path for storing exported dump files.

    After obtaining the exported data files, parse the files by referring to Collecting and Analyzing Data of Overflow/Underflow Operators in Accuracy Analyzer.

    dump_path can be set to an absolute path or a relative path.
    • An absolute path starts with a slash (/), for example, /home.
    • A relative path starts with a directory name, for example, output.
  • This function cannot be enabled when model or single-operator dump configuration is enabled. Otherwise, an error is returned.
  • Only overflow/underflow data of AI Core operators can be collected.

Dump Watch Configuration for Operators

Set dump_scene to watcher to enable the operator dump watch mode. The following is an example of the configuration file: (1) After operators A and B are executed, the output of operators C and D is dumped. (2) After the C and D operators are executed, the output of the C and D operators is also dumped. Compare the dump files of operators C and D in (1) and (2) to check whether operators A and B overwrite the output memory of operators C and D.

{
    "dump":{
        "dump_list":[
            {
                "layer":["A", "B"],
                "watcher_nodes":["C", "D"]
            }
        ],
        "dump_path":"/home/",
        "dump_mode":"output",
        "dump_scene":"watcher"
    }
}

The details are as follows:

  • If the operator dump watch mode is enabled, the overflow/underflow operator dump (by configuring the dump_debug parameter) or the single-operator model dump (by configuring the dump_op_switch parameter) cannot be enabled. Otherwise, an error will be reported. Dump watch cannot be applied in the single-operator API dump scenario.
  • In dump_list, the layer parameter is used to configure the names of the operators that may overwrite the memory of other operators, and the watcher_nodes parameter is used to configure the names of the operators with accuracy issues possibly due to output memory being overwritten by other operators.
    • If layer is specified, the output of the operators configured for watcher_nodes is dumped after all operators that support dump in the model are executed.
    • If any operator in layer and watcher_nodes is not in a static graph or static subgraph, the configuration does not take effect.
    • If an operator is in both layer and watcher_nodes or an operator in layer is a collective communication operator (the operator type starts with Hcom, for example, HcomAllReduce), only the dump files of operators in watcher_nodes will be exported.
    • For a fused operator, use its name after fusion when you add it to watcher_nodes. Otherwise, dump files cannot be exported.
    • Currently, model_name cannot be configured in dump_list.
  • If the operator dump watch mode is enabled, dump_path, which is the path for storing the exported dump file, must be configured.

    The exported dump files cannot be viewed using a text tool. To view the content of a dump file, convert the dump file to a NumPy file and then view the NumPy file using Python. For details about the conversion procedure, see Viewing Dump Data Files in Accuracy Analyzer.

    dump_path can be set to an absolute path or a relative path.
    • An absolute path starts with a slash (/), for example, /home.
    • A relative path starts with a directory name, for example, output.
  • dump_mode is used to specify the data of the operators configured for watcher_nodes to be exported. Currently, only output can be configured.

Dump configuration of the operator kernel debugging information

Configure the dump_kernel_data parameter to enable the operator kernel debugging information dump function. The following is an example of the configuration file:

{
    "dump":{
        "dump_kernel_data":"printf,assert",
        "dump_path":"/home/"
    }
}

The details are as follows:

  • dump_kernel_data: specifies the type of data to be exported. Multiple types can be configured and separated by commas (,). If this field is not configured but the model dump configuration and single-operator dump configuration are enabled, the debugging information is exported based on all by default.
    Available environment variables are as follows:
    • all: Exports the output data of all the following types:
    • printf: exports the output data debugged by AscendC::printf.
    • tensor: exports the output data debugged by AscendC::DumpTensor.
    • assert: exports the output data debugged by assert/ascendc_assert.
    • timestamp: exports the output data debugged by AscendC::PrintTimeStamp.
  • dump_path: path for storing the exported dump file, which must be configured when the operator kernel debugging information dump function is enabled. The path can be an absolute path or a relative path.

    The priorities of the dump file storage paths are as follows: ASCEND_DUMP_PATH environment variable > ASCEND_WORK_PATH environment variable > dump_path in the configuration file. For details about the environment variables, see Environment Variables.

    The content of the exported dump file cannot be directly viewed using a text tool. To view the content, use the show_kernel_debug_data tool to parse the debugging information into a readable format. For details about how to use the tool, see show_kernel_debug_data Tool in Ascend C Operator Development.

Example (Default Device Configuration)

Set the device ID in default_device, which can be 0 or a decimal positive integer. You can call aclrtGetDeviceCount to obtain the number of available devices. The value range of the device ID is [0, (Number of available devices – 1)].

The following gives a configuration example:

{
    "defaultDevice":{
        "default_device":"0"
    }
}

Example of AI Core Stack Size Configuration

Use aicore_stack_size to set the stack size, in bytes. The value must meet the following requirements:

  • The value of aicore_stack_size must be an integer multiple of 16 KB. Otherwise, the value will be rounded up to meet this requirement.
  • The minimum value of aicore_stack_size is 32 KB. If the input value is smaller than that, the default value 32 KB will be used.
  • The maximum value of aicore_stack_size for each product is as follows:

    For the Atlas 350 Accelerator Card, the maximum value of aicore_stack_size is 128 KB.

    For the Atlas A3 training product / Atlas A3 inference product , the maximum value of aicore_stack_size is 192 KB.

    For the Atlas A2 training product / Atlas A2 inference product , the maximum value of aicore_stack_size is 192 KB.

    For the Atlas 200I/500 A2 inference product , the maximum value of aicore_stack_size is 7,680 KB.

The following gives a configuration example:

{
    "StackSize":{
        "aicore_stack_size":32768
    }
}

Configuration example of the SIMT operator stack size

simt_stack_size specifies the stack size of each thread of the SIMT operator. The unit is byte.

The simt_divergence_stack_size parameter is used to set the size of the branch (Divergence) stack space of the SIMT operator. The unit is byte.

The values of simt_stack_size and simt_divergence_stack_size must be an integer multiple of 128. If the input value is not a multiple of 128, the API automatically rounds up the value to ensure that it is a multiple of 128.

The following gives a configuration example:

{
  "StackSize": {      
    "simt_stack_size": 1024,            
    "simt_divergence_stack_size": 512   
  }
}

Example of configuring the size of the SIMT Printf maintenance and test space

The simt_printf_fifo_size parameter is used to set the size of the Printf maintenance and test space of the SIMT operator. The unit is byte. The value must be an integer multiple of 8. If the input value is not an integer multiple of 8, the API automatically rounds up the value to ensure that it is an integer multiple of 8.

The default value of simt_printf_fifo_size is 2 MB. The minimum value is 1 MB and the maximum value is 64 MB.

The following gives a configuration example:

{
  "simt_printf_fifo_size": 1048576
}

Example of configuring the size of the SIMD Printf maintenance and test space

The simd_printf_fifo_size_per_core parameter is used to set the size of the Printf maintenance and test space of the SIMD operator. The unit is byte. The value must be an integer multiple of 8. If the input value is not an integer multiple of 8, the API automatically rounds up the value to ensure that it is an integer multiple of 8.

The default value of simd_printf_fifo_size_per_core is 32 KB. The minimum value is 1 KB and the maximum value is 64 MB.

The following gives a configuration example:

{
  "simd_printf_fifo_size_per_core": 1048576
}

Example of Configuring the Event Resource Scheduling Mode

Value range of event_mode: 0 is the default value, indicating the memory mode, where the number of event resources is limited by the memory. 1 indicates the hardware acceleration mode, where the number of event resources is limited by hardware specifications, but the performance is better.

The following gives a configuration example:

{
    "acl_graph":{
        "event_mode":"0"
    }
}

Reference

For the API call example, see Initialization and Deinitialization.

More flexible APIs are provided for enabling dump or profiling. Unlike aclInit, these APIs can be called repeatedly in a process, allowing varied dump or profiling configurations with each call.