aclInit
Description
AscendCL initialization function.
Restrictions
- aclInit must be called before app development using AscendCL APIs. Otherwise, errors may occur during the initialization of internal resources, causing service exceptions.
- The aclInit API can be called only once in a process and is used together with the aclFinalize deinitialization API.
Prototype
aclError aclInit(const char *configPath)
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
configPath |
Input |
Pointer to the path (including the file name) of the configuration file. The configuration file is in .json format. A .json file allows up to 10 levels of curly brackets and square brackets, respectively. When initializing AscendCL, you can use this configuration file to enable or set the following functions. If the following default configurations meet the requirements, you do not need to modify them. You can pass NULL to aclInit or set the configuration file to an empty JSON string (that is, the configuration file contains only {}).
NOTE:
Dump configuration and profiling configuration are mutually exclusive. The dump operation could affect system performance, resulting in inaccurate profile data collected by Profiling. |
Returns
The value 0 indicates success, and other values indicate failure. For details, see aclError.
Configuration File Example (Model Dump and Single-Operator Dump)
Model dump configuration example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
{ "dump":{ "dump_list":[ { "model_name":"ResNet-101" }, { "model_name":"ResNet-50", "layer":[ "conv1conv1_relu", "res2a_branch2ares2a_branch2a_relu", "res2a_branch1", "pool1" ] } ], "dump_path":"$HOME/output", "dump_mode":"output", "dump_op_switch":"off", "dump_data":"tensor" } } |
The following is an example of dump configuration of the single-operator model execution mode in the single-operator dump scenario:
1 2 3 4 5 6 7 8 |
{ "dump":{ "dump_path":"output", "dump_list":[], "dump_op_switch":"on", "dump_data":"tensor" } } |
The following is an example of dump configuration of the single-operator API execution mode in the single-operator dump scenario:
1 2 3 4 5 6 7 |
{ "dump":{ "dump_path":"output", "dump_list":[], "dump_data":"tensor" } } |
Configuration File Example (Exception Operator Dump Configuration)
If dump_scene is set to lite_exception or lite_exception_with_shape, the dump function of abnormal operators is enabled. In addition, the ASCEND_WORK_PATH environment variable can be used to configure the dump path. Otherwise, the dump path is the current execution directory of the application.
Note:
- The dump configuration of the abnormal operator cannot be enabled together with the model dump configuration or single-operator dump configuration. Otherwise, the model dump or single-operator dump does not take effect.
- lite_exception_with_shape is a trial feature and may be changed in later versions. It cannot be used in commercial products. The difference between lite_exception_with_shape and lite_exception is that in the graph scenario, lite_exception_with_shape can be used to export a dump file with the operator shape information.
The following gives a configuration example:
{
"dump":{
"dump_scene":"lite_exception"
}
}
The collected dump files cannot be viewed using a text tool. To view the dump file content, 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 Files" " in Accuracy Debugging Tool Guide.
Configuration File Example (Overflow/Underflow Operator Dump Configuration)
- If dump_debug is set to on, the overflow/underflow operator configuration is enabled. If dump_debug is not set or set to off, the overflow/underflow operator configuration is disabled.
- If this configuration is enabled, dump_path, which is the directory for storing exported data files, must be set.
The path can be either absolute or relative.
- An absolute path starts with a slash (/), for example, /home.
- A relative path starts with a directory name, for example, output.
- The overflow/underflow operator configuration cannot be enabled if the model dump configuration or single-operator dump configuration is enabled. Otherwise, an error is returned.
- Only overflow/underflow data of AI Core operators can be collected.
{
"dump":{
"dump_path":"output",
"dump_debug":"on"
}
}
For details about how to parse the exported data file, see Overflow/Underflow Operator Data Collection and Analysis in Accuracy Debugging Tool Guide.
Configuration File Example (Configuration for Operator Dump Watch Mode)
Set dump_scene to watcher to enable the operator dump watch mode. The configuration description and restrictions 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. This mode does not take effect 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 an operator configured for layer and watcher_node is not in the static graph and static subgraph, the configuration does not take effect.
- If an operator name configured for layer and watcher_node is duplicate, or an operator configured for layer is a collective communication operator (the operator type starts with Hcom, for example, HcomAllReduce), no dump file will be exported.
- For a fusion operator, its name configured for watcher_node must be the name of the operator after fusion. If the name of an operator before fusion is configured, no dump file will 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 path can be either absolute or relative.
- 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.
The following is an example of the content in the configuration file. The configuration effect is as follows: After operators A and B are executed, the output of operators C and D is dumped, and the following four dump files are dumped to check whether operator A or B overwrites the output memory of operator C or D: opType.A_To_C.* (operator C), opType.A_To_D.* (operator D), opType.B_To_C.* (operator C), and opType.B_To_D.* (operator D).
{
"dump":{
"dump_list":[
{
"layer":["A", "B"],
"watcher_nodes":["C", "D"]
}
],
"dump_path":"/home/",
"dump_mode":"output",
"dump_scene":"watcher"
}
}
The collected dump files cannot be viewed using a text tool. To view the dump file content, 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 Files" in Accuracy Debugging Tool Guide.
Configuration File Example (Operator Cache Aging Configuration)
Note the following restrictions on the operator cache aging configuration:
- For an operator that is statically loaded, when aclopSetModelDir is called to load a single-operator model in the specified directory, or aclopLoad is called to load a single-operator model, the aging configuration is invalid. That is, the operator information is not aged.
- For online operator compilation, when the aclopCompile API is called to compile an operator or the aclopCompileAndExecute API is called to compile and execute an operator, the API call loads the single-operator model based on the passed arguments, and the aging configuration takes effect.
If an operator is compiled and executed by using aclopCompile and aclopExecuteV2, promptly execute the operator in case the operator information is aged. In this case, you will need to recompile the operator. You are advised to use aclopCompileAndExecuteV2 instead, which completes operator compilation and execution as one action.
- AscendCL maintains two mapping queues, one for static-shape and the other for dynamic-shape operators. However, their maximum lengths are both determined by the max_opqueue_num parameter.
- The value of max_opqueue_num is the sum of the number of single-operator models with statically loaded operators and the number of single-operator models with operators compiled online. Therefore, the value of max_opqueue_num must be greater than the number of single-operator models with statically loaded operators that are available in the current process; otherwise, the information about operators compiled online cannot be aged.
The following gives a configuration example.
{
"max_opqueue_num": "10000"
}
Configuration File Example (Configuration for Error Information Reporting Mode)
Value range of the err_msg_mode parameter: 0 is the default value, indicating that error information is obtained by thread. 1 indicates that error information is obtained by process.
The following gives a configuration example:
{
"err_msg_mode": "1"
}
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"
}
}
Related APIs
AscendCL provides more flexible APIs for enabling Dump or Profiling. Unlike aclInit, these APIs can be called repeatedly in a process, allowing varied Dump/Profiling configurations with each call.
- Obtains dump data: aclmdlInitDump, aclmdlSetDump, aclmdlFinalizeDump
- Obtains profile data: Profiling Data Collection