Function: infer_shape

Applicable Products

  • Ascend 950PR&950DT products: Not supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Function

Infers the output shape of an operator based on the input shape and other necessary arguments.

Prototype

  • C Prototype

    aclError aclopInferShape(const char *opType, int numInputs, aclTensorDesc *inputDesc[], aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[], aclopAttr *attr)
    
  • Python Function

    ret = acl.op.infer_shape(op_type, in_desc_list, in_list, num_outputs, out_desc_list, attr)
    

Parameters

Parameter Description
op_type Int, operator type.
in_desc_list List, input tensor description. Call acl.create_tensor_desc to create data of the aclTensorDesc type in advance.
in_list List, input tensors. Determine the allocation of memory for storing the input tensor data of the operator. If the app runs on the host, allocate host memory. If the app runs on the device, allocate device memory. For details about memory allocation APIs, see Memory Management.
num_outputs Int, number of operator output tensors.
out_desc_list List, output tensor description. Call acl.create_tensor_desc to create data of the aclTensorDesc type in advance. The number of elements in the out_desc_list list must be the same as the value of num_outputs.
attr Int, attribute address object of the operator.

Return Values

Return Value Description
ret Int, error code: 0 on success; else, failure.

Constraints

  • Consider the following possibilities:

    • If the accurate output shape of the operator can be inferred, the accurate output shape is returned.
    • If the accurate output shape of the operator cannot be inferred, but the range of the output shape can be obtained, the dynamic dimension in the tensor description is set to –1 in the output parameter out_desc_list. In this scenario, you can call get_tensor_desc_dim_range to obtain the size range of the specified dimension from the tensor description.
    • (Reserved) If the accurate output shape and shape range cannot be obtained, the dynamic dimension in the tensor description is set to –2 in the output parameter out_desc_list.
  • Before this API is called to infer the output shape of a dynamic-input or dynamic-output operator, set_tensor_desc_name must be called to set the names of all input and output tensors as follows. For details about the input and output names defined in the operator IR prototypes, see "Ascend IR Operator Specifications" in the Operator Specifications.

    • For a required input, optional input, or required output, use the exact name defined in the operator IR prototypes.
    • For a dynamic input or dynamic output, use the exact name defined in the operator IR prototypes with a sequence number suffix. Dynamic inputs/outputs are indexed starting at 0.

    For example, if an operator has two inputs (the first one is required input x, the second one is dynamic input y, including two inputs) and one required output z, the code for calling the set_tensor_desc_name API is as follows.

    acl.set_tensor_desc_name(input_tensor_desc[0], "x");
    acl.set_tensor_desc_name(input_tensor_desc[1], "y0");
    acl.set_tensor_desc_name(input_tensor_desc[2], "y1");
    acl.set_tensor_desc_name(output_tensor_desc[0], "z");