Function: create_and_get_op_desc

C Prototype

aclError 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

op_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)

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.

Input Description

device_id: int, device ID.

Call acl.rt.get_device_id_from_exception_info to obtain the device ID in the exception information.

stream_id: int, stream ID.

Call acl.rt.get_stream_id_from_exception_info to obtain the stream ID in the exception information.

task_id: int, task ID.

Call acl.rt.get_task_id_from_exception_info to obtain the task ID in the exception information.

op_name_len: int, character string length of the operator name.

If the specified length is shorter than the actual length of the operator name, an error is returned.

Return Value

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 input tensors.

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 output tensors.

ret: int, error code.

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.

The recommended API call sequence is as follows:
  1. 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:

    1. 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 fn to obtain the device ID, stream ID, and task ID, respectively.
    2. Call acl.mdl.create_and_get_op_desc in fn to obtain the operator description.
    3. Call acl.get_tensor_desc_by_index in fn to obtain the input/output tensor description of the operator.
    4. In fn, obtain the tensor description for further analysis.

      For example, call acl.get_tensor_desc_address to obtain the tensor data 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 tensor format, call acl.get_tensor_desc_num_dims to obtain the tensor dimension count, and call acl.get_tensor_desc_dim_v2 to obtain the size of a specified dimension.

  2. Call acl.rt.set_exception_info_callback to set the exception callback function.
  3. Perform model inference.

    If an AI Core error is reported, fn is triggered to obtain the operator information for further troubleshooting.

Reference

For details about the API call example, see AI Core Troubleshooting.