Operator Information of AscendCL APIs for Subscription
Call the Profiling AscendCL 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 AscendCL 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 AscendCL API for Subscription
API |
Description |
|---|---|
aclprofCreateSubscribeConfig |
Creates the data of the aclprofSubscribeConfig type as a subscription configuration. |
aclprofModelSubscribe |
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. |
aclprofGet* |
Obtains the basic information about operators. The * includes: OpDescSize: size of the operator data structure. OpNum: number of operators. OpTypeLen: character string length of the operator type. OpType: operator type. OpNameLen: character string length of the operator name. OpName: operator name. OpStart: operator execution start time. OpEnd: operator execution end time. OpDuration: operator execution duration. ModelId: ID of the model where the operators are located. The preceding information is displayed on the screen by the INFO_LOG call. |
aclprofModelUnSubscribe |
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. |
aclprofDestroySubscribeConfig |
Destroys data of the aclprofSubscribeConfig type created by the aclprofCreateSubscribeConfig call. This API is synchronous. |
Calling Example of Profiling AscendCL APIs for Subscription
Sample code for a Profiling AscendCL 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 85 86 87 88 89 90 91 92 93 94 | //1. Initialize AscendCL. //2. Allocate runtime resources, including setting the compute device and creating a context and a stream. //3. Load your model. After the model is successfully loaded, modelId that identifies the model is returned. //4. Create data of type aclmdlDataset to describe the inputs and outputs of your model. //5. Create a pipeline (on UNIX, you need the unistd.h header file of the C++ standard library) to read and write the model subscription data. int subFd[2]; //The read pipeline pointer points to subFd[0], and the write pipeline pointer points to subFd[1]. pipe(subFd); //6. Create a model subscription configuration and subscribe to the model. aclprofSubscribeConfig *config = aclprofCreateSubscribeConfig(1, ACL_AICORE_NONE, &subFd[1]); //Pass modelId of the model to subscribe. aclprofModelSubscribe(modelId, config); //7. Enable the pipeline to read subscription data. //7.1 Customize a function to read subscription data from the user memory. void getModelInfo(void *data, uint32_t len) { uint32_t opNumber = 0; uint32_t dataLen = 0; //Read the number of operators by using the AscendCL API call. aclprofGetOpNum(data, len, &opNumber); //Iterate over the operator information in the user memory. for (int32_t i = 0; i < opNumber; i++){ //Obtain the modelId of the operator. uint32_t modelId = aclprofGetModelId(data,len, i); //Obtain the length of the operator type name. size_t opTypeLen = 0; aclprofGetOpTypeLen(data, len, i, &opTypeLen); //Obtain the operator type name. char opType[opTypeLen]; aclprofGetOpType(data, len, i, opType, opTypeLen); //Obtain the length of the operator name. size_t opNameLen = 0; aclprofGetOpNameLen(data, len, i, &opNameLen); //Obtain the operator name. char opName[opNameLen]; aclprofGetOpName(data, len, i, opName, opNameLen); //Obtain the execution start time of the operator. uint64_t opStart = aclprofGetOpStart(data, len, i); //Obtain the execution end time of the operator. uint64_t opEnd = aclprofGetOpEnd(data, len, i); uint64_t opDuration = aclprofGetOpDuration(data, len, i); } } //7.2 Customize a function to read data from the pipeline to the user memory. void *profDataRead(void *fd) { //Set the maximum operator information (by specifying the number of operators) read from the pipeline each time. uint64_t N = 10; //Obtain the operator information buffer size (in bytes) per operator. uint64_t bufferSize = 0; aclprofGetOpDescSize(&bufferSize); //Calculate the total operator information buffer size and allocate buffer accordingly. uint64_t readbufLen = bufferSize * N; char *readbuf = new char[readbufLen]; //Read data from the pipeline to the allocated memory. The actual size of the read data (dataLen) may be less than bufferSize * N. If there is no data in the pipeline, the process is blocked until data is read. auto dataLen = read(*(int*)fd, readbuf, readbufLen); //The data is successfully read to the readbuf. while (dataLen > 0) { //Call the function implemented in 5.1 to parse data in the memory. getModelInfo(readbuf, dataLen); memset(readbuf, 0, bufferSize); dataLen = read(*(int*)fd, readbuf, readbufLen); } delete []readbuf; } //8. Start the thread to read and parse the pipeline data. pthread_t subTid = 0; pthread_create(&subTid, NULL, profDataRead, &subFd[0]); //9. Execute your model. ret = aclmdlExecute(modelId, input, output); //10. Process the model inference result. //11. Destroy the model input and output descriptions, free memory, and unload the model. //12. Cancel the model subscription and destroy the subscription-related resources. aclprofModelUnSubscribe(modelId); pthread_join(subTid, NULL); //Close the read pipeline pointer. close(subFd[0]); //Destroy the config pointer. aclprofDestroySubscribeConfig(config); //13. Destroy runtime allocations. //14. Deinitialize AscendCL. //...... |