Function: create_and_get_op_desc
Function Usage
Obtains the description of an operator, including the operator name, input tensor description, and output tensor description. If the specified operator cannot be found, an error is returned. This API does not support the dynamic shape scenario.
Prototype
- C Prototype
1aclError aclmdlCreateAndGetOpDesc(uint32_t deviceId, uint32_t streamId, uint32_t taskId, char *opName, size_t opNameLen, aclTensorDesc **inputDesc, size_t *numInputs, aclTensorDesc **outputDesc, size_t *numOutputs)
- Python Function
1op_name, input_desc, num_inputs, output_desc, num_outputs, ret = acl.mdl.create_and_get_op_desc(device_id, stream_id, task_id, op_name_len)
Parameters
Returns
|
Return Value |
Description |
|---|---|
|
op_name |
String, operator name string. |
|
input_desc |
Int, description of all input tensors of the operator, pointing to the start address of a contiguous memory space. |
|
num_inputs |
Int, number of inputs. |
|
output_desc |
Int, description of all output tensors of the operator, pointing to the start address of a contiguous memory space. |
|
num_outputs |
Int, number of outputs. |
|
ret |
Int, error code. 0 indicates success, and other values indicate failure. |
Restrictions
Application scenario: For example, if an AI Core error is reported during network inference (dynamic shape scenarios unsupported), you can call this API to obtain the description of the error operator and then perform further troubleshooting.
- Define and implement the exception callback function fn (of the aclrtExceptionInfoCallback type). For details about the callback function prototype, see acl.rt.set_exception_info_callback.
The key steps for implementing the callback function are as follows:
- Call acl.rt.get_device_id_from_exception_info, acl.rt.get_stream_id_from_exception_info, and acl.rt.get_task_id_from_exception_info in the exception callback function fn to obtain the device ID, stream ID, and task ID.
- Call acl.mdl.create_and_get_op_desc in the exception callback function fn to obtain the operator description.
- Call acl.get_tensor_desc_by_index in the exception callback function fn to obtain the input/output tensor description of the specified operator.
- In fn, obtain the tensor description for further analysis.
For example, call acl.get_tensor_desc_address to obtain the memory address of the tensor data (you can obtain the tensor data from the memory address), call acl.get_tensor_desc_type to obtain the data type in the tensor description, call acl.get_tensor_desc_format to obtain the format in the tensor description, call acl.get_tensor_desc_num_dims to obtain the number of shape dimensions in the tensor description, and call acl.get_tensor_desc_dim_v2 to obtain the size of a specified dimension in the shape.
- Call acl.rt.set_exception_info_callback to set the exception callback function.
- Run model inference.
If an AI Core error is reported, fn is triggered to obtain the operator information for further analysis.