Operator Information of pyACL APIs for Subscription
Call the Profiling pyACL APIs for Subscription to parse the collected profile data and write it to the pipeline. Then, read the data to the memory and call the pyACL API to obtain the result data. The profile data of each operator in the network model can be obtained, including the operator name, operator type name, and operator execution time.
Profiling pyACL API for Subscription
API |
Description |
|---|---|
acl.prof.create_subscribe_config |
Creates the data of the aclprofSubscribeConfig type as a subscription configuration. |
acl.prof.model_subscribe |
Subscribes to a model for basic information of each operator in the model, including the operator name, operator type, and operator execution time. This API is synchronous. This API is used together with aclprofModelUnSubscribe. |
acl.prof.get_* |
Obtains the basic information about operators. The * includes: op_desc_size: size of the operator data structure. op_num: number of operators. op_type_len: character string length of the operator type. op_type: operator type op_type_v2: operator type acl.prof.get_op_type_v2 delivers the same function as acl.prof.get_op_type. However, the acl.prof.get_op_type_v2 API is used to obtain the length of the operator type and allocate the corresponding space. You do not need to pass arguments to specify the space required by the operator type. You are advised to use the acl.prof.get_op_type_v2 API first. op_name_len: character string length of the operator name. op_name: operator name op_name_v2: operator name acl.prof.get_op_name_v2 delivers the same function as acl.prof.get_op_name. However, the acl.prof.get_op_name_v2 API is used to obtain the length of the operator type and allocate the corresponding space. You do not need to pass arguments to specify the space required by the operator type. You are advised to use the acl.prof.get_op_name_v2 API first. op_start: operator execution start time. op_end: operator execution end time. op_duration: operator execution duration. model_id: ID of the model where the operators are located. The preceding information is displayed on the screen by the INFO_LOG call. |
acl.prof.model_un_subscribe |
Unsubscribes from basic operator information, including the operator name, operator type, and operator execution duration. This API is synchronous. This API must be used in pair with aclprofModelSubscribe. |
acl.prof.destroy_subscribe_config |
Destroys data of the aclprofSubscribeConfig type created by calling acl.prof.create_subscribe_config. |
Calling Example of Profiling pyACL APIs for Subscription
Sample code for a Profiling pyACL API for Subscription call
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import acl import numpy as np # ...... # 1. Allocate runtime resources, including setting the compute device, creating a context, and creating a stream. # ...... # 2. Load a model. After the model is successfully loaded, model_id that identifies the model is returned. # ...... # 3. Create data of type aclmdlDataset to describe the inputs and outputs of the model. # ...... # 4. Create a pipeline to read and write the model subscription data. r, w = os.pipe() # 5. Create a model subscription configuration and subscribe to the model. ACL_AICORE_NONE = 0xFF subscribe_config = acl.prof.create_subscribe_config(1, ACL_AICORE_NONE, w) # Pass model_id of the model for subscription. ret = acl.prof.model_subscribe(model_id, subscribe_config) # 6. Enable the pipeline to read subscription data. # 6.1 Customize a function to read subscription data from the user memory. def get_model_info(data, data_len): # Obtain the number of operators. op_number, ret = acl.prof.get_op_num(data, data_len) # Iterate over the operator information in the user memory. for i in range(op_number): # Obtain the model_id of the operator. model_id = acl.prof.get_model_id(data, data_len, i) # Obtain the operator type. op_type, ret = acl.prof.get_op_type(data, data_len, i, 65) # Obtain the operator name. op_name, ret = acl.prof.get_op_name(data, data_len, i, 275) # Obtain the execution start time of the operator. op_start = acl.prof.get_op_start(data, data_len, i) # Obtain the execution end time of the operator. op_end = acl.prof.get_op_end(data, data_len, i) # Obtain the time required for executing the operator. op_duration = acl.prof.get_op_duration(data, data_len, i) # 6.2 Customize a function to read data from the pipeline to the user memory. def prof_data_read(args): fd, ctx = args ret = acl.rt.set_context(ctx) # Obtain the operator information buffer size (in bytes) per operator. buffer_size, ret = acl.prof.get_op_desc_size() # Set the number of operators read from the pipeline each time. N = 10 # Calculate the total operator information buffer size. data_len = buffer_size * N # Read data from the pipeline to the allocated memory. The actual size of the read data may be less than buffer_size x N. # If there is no data in the pipeline, the process is blocked until data is read. while True: data = os.read(fd, data_len) if len(data) == 0: break np_data = np.array(data) np_data_ptr = acl.util.numpy_to_ptr(np_data) size = np_data.itemsize * np_data.size # Call the function implemented in 6.1 to parse data in the memory. get_model_info(np_data_ptr, size) # 7. Start the thread to read and parse the pipeline data. thr_id, ret = acl.util.start_thread(prof_data_read, [r, context]) # 8. Execute the model. ret = acl.mdl.execute(model_id, input, output) # 9. Process the model inference result. # ...... # 10. Destroy allocations such as the model inputs and outputs, free memory, and unload the model. # ...... # 11. Unsubscribe from the model and destroy the subscription-related resources. ret = acl.prof.model_un_subscribe(model_id) ret = acl.util.stop_thread(thr_id) os.close(r) ret = acl.prof.destroy_subscribe_config(subscribe_config) # 12. Destroy runtime allocations. # ...... |