aclopInferShape
Description
Infers the output shape of an operator based on the input shape and other necessary arguments.
Restrictions
- 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.
- If the operator has dynamic input DYNAMIC_INPUT or dynamic output DYNAMIC_OUTPUT, call the aclSetTensorDescName API to set the names of all input and output tensor descriptions before calling aclopInferShape to deduce the output shape of the operator, the name must meet the following requirements (for details about the input/output names defined in the operator IR prototype, see CANN 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 aclSetTensorDescName API is as follows.
aclSetTensorDescName(inputTensorDesc[0], "x"); aclSetTensorDescName(inputTensorDesc[1], "y0"); aclSetTensorDescName(inputTensorDesc[2], "y1"); aclSetTensorDescName(outputTensorDesc[0], "z");
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 aclCreateDataBuffer to create data of the aclDataBuffer type in advance. Determine the memory allocation method based on the app run mode. 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. |
|
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
The value 0 indicates success, and other values indicate failure. For details, see aclError.