Function: infer_shape

Applicability

Product

Supported (√/x)

Atlas A3 training products / Atlas A3 inference products

Atlas A2 training products / Atlas A2 inference products

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

Function Usage

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

Prototype

  • C Prototype
    1
    aclError aclopInferShape(const char *opType, int numInputs, aclTensorDesc *inputDesc[], aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[], aclopAttr *attr)
    
  • Python Function
    1
    ret = acl.op.infer_shape(op_type, in_desc_list, in_list, num_outputs, out_desc_list, attr)
    

Parameter Description

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 the memory allocation API, 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 Value Description

Return Value

Description

ret

Int, error code: 0 on success; else, failure.

Restrictions

  • 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 calling acl.op.infer_shape to infer the output shape of a dynamic-input or dynamic-output operator, call set_tensor_desc_name first to set the names of all input and output tensor descriptions as follows. For details about the input and output names defined in the operator IR prototypes, see "Ascend IR Operator Specifications" in Operator Library API Reference.
    • 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(input_tensor_desc[0], "z");