Collecting and Flushing Profile Data with AscendCL APIs

You can call AscendCL APIs to enable automatic collection of raw profile data. After the raw profile data is successfully collected, you can copy it to a development environment where the Ascend-CANN-Toolkit is installed to parse the data, and view the visualized parsing results.

Profiling AscendCL API

Table 1 Profiling AscendCL API

API

Description

aclprofCreateConfig

Creates a profiling configuration. This API is used together with aclprofDestroyConfig.

aclprofInit

Initializes profiling and sets the path for saving profile data files. This API is used together with aclprofFinalize.

aclprofSetConfig

Functions as an extended API of aclprofCreateConfig and is used to configure collection parameters.

aclprofStart

Starts profile data collection. This API is used together with aclprofStop.

aclprofStop

Stops profile data collection. This API is used together with aclprofStart.

aclprofFinalize

Finalizes profiling. This API is used together with aclprofInit.

aclprofDestroyConfig

Destroys data of the aclprofConfig type created by the aclprofCreateConfig API call. This API is used together with aclprofCreateConfig.

The user must have the read and write permissions on the profile data flush directory passed to the aclprofInit call.

Profiling AscendCL API Calling Example

The following is an example of calling the Profiling AscendCL API:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//1. Initialize AscendCL.

//2. Allocate runtime resources, including setting the compute device and creating a context and a stream.

//3. Initialize profiling.
//Set the data flush path.
const char *aclProfPath = "...";
aclprofInit(aclProfPath, strlen(aclProfPath));

//4. Configure profiling.
uint32_t deviceIdList[1] = {0}; //Set this parameter based on the device ID in the actual environment.
//Create a configuration struct.
aclprofConfig *config = aclprofCreateConfig(deviceIdList, 1, ACL_AICORE_ARITHMETIC_UTILIZATION, 
 nullptr,ACL_PROF_ACL_API | ACL_PROF_TASK_TIME);
const char *memFreq = "15";
ret = aclprofSetConfig(ACL_PROF_SYS_HARDWARE_MEM_FREQ, memFreq, strlen(memFreq));
aclprofStart(config);

//5. Load your model. After the model is successfully loaded, modelId that identifies the model is returned.

//6. Create data of type aclmdlDataset to describe the inputs and outputs of your model.

//7. Execute your model.
ret = aclmdlExecute(modelId, input, output);

//8. Process the model inference result.

//9. Destroy the model input and output descriptions, free memory, and unload the model.

//10. Stop profiling and destroy the configuration and related resources.
aclprofStop(config);
aclprofDestroyConfig(config);
aclprofFinalize();

//11. Destroy runtime allocations.

//12. Deinitialize AscendCL.
//......
The following lists the configuration parameter values of the Profiling AscendCL APIs called in the preceding example. Select required collection parameters based on the actual situation.
  • aclprofCreateConfig:
    1
    ACL_PROF_ACL_API | ACL_PROF_TASK_TIME | ACL_PROF_OP_ATTR | ACL_PROF_AICORE_METRICS | ACL_PROF_AICPU | ACL_PROF_L2CACHE | ACL_PROF_HCCL_TRACE | ACL_PROF_MSPROFTX | ACL_PROF_RUNTIME_API | ACL_PROF_TASK_MEMORY | ACL_PROF_TRAINING_TRACE
    

    For details about the parameters, see the dataTypeConfig description of the aclprofCreateConfig API.

  • aclprofSetConfig:
    1
    ACL_PROF_STORAGE_LIMIT | ACL_PROF_SYS_HARDWARE_MEM_FREQ | ACL_PROF_LLC_MODE | ACL_PROF_SYS_IO_FREQ | ACL_PROF_SYS_INTERCONNECTION_FREQ | ACL_PROF_DVPP_FREQ | ACL_PROF_HOST_SYS | ACL_PROF_HOST_SYS_USAGE | ACL_PROF_HOST_SYS_USAGE_FREQ
    

    For details about the parameters, see the dataTypeConfig description of the aclprofSetConfig API.