Function Description
Overview
This section describes how to collect and flush profile data by using profiling pyACL APIs. The purpose is to write the collected profile data to a file, which is then parsed and displayed by the Profiling tool. For details, see "Data Parsing and Export" in Profiling Instructions.
- Call the following APIs: acl.prof.init, acl.prof.start, acl.prof.stop, and acl.prof.finalize. You can obtain the pyACL API profile data, time taken to execute AI Core operators, as well as AI Core metrics. Currently, the preceding APIs perform process-level control. That is, if the APIs are called in any thread in the process, the calls also take effect in other threads in the same process.
These APIs can be called repeatedly in a process, allowing for varied profiling configurations with each call.
- Call acl.init. During pyACL initialization, the profiling configuration is passed as a JSON configuration file. You can obtain the pyACL API profile data, time taken to execute AI Core operators, as well as AI Core metrics.
acl.init can be called only once per process. To modify the profiling configuration, modify the JSON configuration file. For details, see the description of the acl.init API.
General Restrictions
The APIs in this section cannot be called with Profiling pyACL APIs for Subscription (Subscribing to Operator Information) together. acl.prof.model_subscribe, aclprofGet*, and acl.prof.model_unsubscribe cannot be called between acl.prof.init and acl.prof.finalize.
API Constraints
- API requirements
- acl.prof.init must be called after acl.init and before model loading.
If profiling information has been configured by calling acl.init, an error is returned when acl.prof.init, acl.prof.start, acl.prof.stop, or acl.prof.finalize is called.
If acl.prof.init has not been called, an error is returned when acl.prof.start, acl.prof.stop, or acl.prof.finalize is called.
- Call acl.prof.start before the model is executed. If acl.prof.start is called during model execution, only profile data after the acl.prof.start call is collected, which may be incomplete.
When calling acl.prof.start, you can specify one or more devices to profile.
In a user app process, an error is returned if acl.prof.start is called repeatedly and the specified profiling configuration or device is duplicate.
- In the lifetime of a user app process, do not call the acl.prof.init and acl.prof.finalize pair more than once. Otherwise, the path for storing profile data files may be changed.
- acl.prof.start needs to be called in conjunction with acl.prof.stop.
- The APIs related to the profiling msproftx function must be called between acl.prof.start and acl.prof.stop. The following APIs are used in pairs: acl.prof.create_stamp/acl.prof.destroy_stamp, acl.prof.push/acl.prof.pop, and acl.prof.range_start/acl.prof.range_stop.
- After acl.finalize is called and a normal exit code is received, the execution is complete. Otherwise, the execution is abnormal. Due to the lack of support for multi-process concurrent execution in profile data collection, to ensure that the driver can be properly stopped, it is necessary to wait until the previous profile data collection test case is fully executed before starting the next round of collection. You are advised to add exception handling operations to the return value of acl.finalize to facilitate execution status display and exception localization.
- acl.prof.init must be called after acl.init and before model loading.
- API call sequence
- The recommended API call sequence is as follows. In this example, two models are executed in a single user app process:
acl.init --> acl.prof.init --> acl.prof.start (specify Device 0 and Device 1) --> Load model 1 --> Execute model 1 --> acl.prof.stop (consistent with the aclprofConfig data of acl.prof.start) --> acl.prof.start (specify Device 1 and Device 2) --> Load model 2 --> Execute model 2 --> acl.prof.stop (consistent with the aclprofConfig data of acl.prof.start) --> acl.prof.finalize --> Execute other tasks --> Unload the model --> acl.finalize
- The following is an example of an incorrect call sequence. In this example, acl.prof.start is called repeatedly and duplicated devices are specified in a single app process:
acl.init --> acl.prof.init --> acl.prof.start (specify Device 0 and Device 1) --> acl.prof.start (specify Device 1 and Device 2) --> Load model 1 --> Execute model 1 --> Load model 2 --> Execute model 2 --> acl.prof.stop --> acl.prof.stop --> acl.prof.finalize --> Execute other tasks --> Unload the model --> acl.finalize
- The recommended API call sequence is as follows. In this example, two models are executed in a single user app process: