Function: infer_shape

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)

Function Usage

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

Input Description

op_type: int, operator type name.

in_desc_list: list, description of the operator input tensor. Call acl.create_tensor_desc to create data of the aclTensorDesc type in advance.

in_list: list, input tensor of the operator.

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 output tensors of the operator.

attr: int, attribute address object of the operator.

Return Value

out_desc_list: list, description of the operator output tensor. 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.

ret: int, error code.

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 Operator Lists.
    • 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");