aclopInferShape

Applicability

Product

Supported

Atlas A3 training products / Atlas A3 inference products

Atlas A2 training products / Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

Description

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

Consider the following three 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 outputDesc. In this scenario, you can call aclGetTensorDescDimRange 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 runtime dimension in the tensor description is set to –2 in the output parameter outputDesc.

Prototype

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

Parameters

Parameter

Input/Output

Description

opType

Input

Pointer to the operator type name.

numInputs

Input

Number of input tensors.

inputDesc

Input

Pointer array of the input tensor description.

Call aclCreateTensorDesc to create data of the aclTensorDesc type in advance.

The array length is consistent with numInputs.

inputs

Input

Pointer array of the input tensors.

Call to create data of the aclDataBuffer type in advance.

In Ascend EP form, allocate host memory for storing the input tensor data of the operator.

In Ascend RC form, allocate device memory for storing the input tensor data of the operator.

In Open Ctrl CPU form form, allocate device memory for storing the input tensor data of the operator.

For details about the memory allocation API, see Memory Management.

numOutputs

Input

Number of output tensors.

outputDesc

Output

Pointer array of the output tensor description.

Call aclCreateTensorDesc to create data of the aclTensorDesc type in advance.

The array length is consistent with numOutputs.

attr

Input

Operator attributes.

Returns

0 on success; else, failure. For details, see aclError.

Restrictions

Before aclopInferShape is called to infer the output shape of a dynamic-input or dynamic-output operator, aclSetTensorDescName must be called to set the names of all input and output tensors. For details about the input and output names defined in the operator IR prototypes, see .
  • 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 aclSetTensorDescName API is as follows:

aclSetTensorDescName(inputTensorDesc[0], "x");
aclSetTensorDescName(inputTensorDesc[1], "y0");
aclSetTensorDescName(inputTensorDesc[2], "y1");
aclSetTensorDescName(outputTensorDesc[0], "z");

See Also

For the API call example, see Sample Code for Executing a Dynamic-Shape Operator.