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

Parameters

Parameter

Description

device_id

Int, device ID.

Call acl.rt.get_device_id_from_exception_info to obtain the device ID in the exception information, which is used as the input of this API.

stream_id

Int, stream ID.

Call acl.rt.get_stream_id_from_exception_info to obtain the stream ID in the exception information, which is used as the input of this API.

task_id

Int, task ID.

Call acl.rt.get_task_id_from_exception_info to obtain the task ID in the exception information, which is used as the input of this API.

op_name_len

Int, length of the operator name string.

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

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.

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 the exception callback function fn to obtain the device ID, stream ID, and task ID.
    2. Call acl.mdl.create_and_get_op_desc in the exception callback function fn to obtain the operator description.
    3. Call acl.get_tensor_desc_by_index in the exception callback function fn to obtain the input/output tensor description of the specified operator.
    4. 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.

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

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