aclopExecuteV2

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Function Usage

Executes a specified operator. This API is asynchronous.

The inputs, outputs, and attributes of operators are different from each other. This API searches for the corresponding task based on the optype, input tensor description, output tensor description, and attributes, and delivers the task for execution. Therefore, you need to organize operators in strict accordance with their inputs, outputs, and attributes when calling this API.

Prototype

1
2
3
4
5
6
7
8
9
aclError aclopExecuteV2(const char *opType,
int numInputs,
aclTensorDesc *inputDesc[],
aclDataBuffer *inputs[],
int numOutputs,
aclTensorDesc *outputDesc[],
aclDataBuffer *outputs[],
aclopAttr *attr,
aclrtStream stream)

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 operator input tensor description. For details about the type definition, see aclTensorDesc.

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

The array length must be consistent with numInputs. The elements in the inputs array must match those in the inputDesc array with ordering preserved.

inputs

Input

Pointer array of the operator input tensor. For details about the type definition, see aclDataBuffer.

Call aclCreateDataBuffer to create data of the aclDataBuffer type in advance.

The array length must be consistent with numInputs. The elements in the inputs array must match those in the inputDesc array with ordering preserved.

numOutputs

Input

Number of output tensors.

outputDesc

Input and output

Pointer array of the operator output tensor description. For details about the type definition, see aclTensorDesc.

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

The array length must be consistent with numOutputs. The elements in the outputs array must match those in the outputDesc array with ordering preserved.

outputs

Output

Pointer array of the operator output tensor. For details about the type definition, see aclDataBuffer.

Call aclCreateDataBuffer to create data of the aclDataBuffer type in advance.

The array length must be consistent with numOutputs. The elements in the outputs array must match those in the outputDesc array with ordering preserved.

attr

Input

Pointer to the operator attributes. For details about the type definition, see aclopAttr.

Call aclopCreateAttr to create data of the aclopAttr type in advance.

stream

Input

Target stream of the operator. For details about the type definition, see aclrtStream.

Returns

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

Restrictions

  • In multi-thread scenarios, this API cannot be called to specify the same stream or the default stream. Otherwise, exceptions may occur in task execution.
  • For an operator that supports dynamic shape, call aclopInferShape to obtain the output shape.
    • If the accurate output shape can be obtained, use the obtained accurate output shape to construct an outputDesc, as one of the arguments passed to the aclopExecuteV2 call. In this scenario, the aclopExecuteV2 API is an asynchronous API. For an asynchronous API, the API call delivers a task rather than executes a task. After this API is called, call the synchronization API (for example, aclrtSynchronizeStream) to ensure that the task is complete.
    • If the accurate output shape cannot be obtained and only the shape range can be obtained, the maximum value within the range is used to construct an outputDesc, as one of the arguments passed to the aclopExecuteV2 call. In this scenario, after aclopExecuteV2 is called to execute the operator, the system calculates the accurate output shape, as the outputDesc output of aclopExecuteV2. In this case, aclopExecuteV2 is a synchronous API.
    • (Reserved) If the accurate output shape and shape range cannot be obtained, estimate a maximum shape to construct an outputDesc as one of the arguments passed to the aclopExecuteV2 call. In this scenario, after aclopExecuteV2 is called to execute the operator, the system calculates the accurate output shape, as the outputDesc output of aclopExecuteV2. In this case, aclopExecuteV2 is a synchronous API.
  • If an operator with an unused optional input is executed:
    • Create data of the aclTensorDesc type by using the aclCreateTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED) call, indicating that the data type is ACL_DT_UNDEFINED, the format is ACL_FORMAT_UNDEFINED, and the shape is nullptr.
    • Create data of the aclDataBuffer type by using the aclCreateDataBuffer(nullptr, 0) call. aclDataBuffer does not need to be freed since it is a null pointer.
  • Before executing an operator with constant input, call aclSetTensorConst to set the constant input.

    The constant input passed to the aclopCompile and aclopExecuteV2 calls must be consistent.

    If an operator has a constant input but aclSetTensorConst has not been called to set the constant input, call aclSetTensorPlaceMent to set the placement attribute of TensorDesc and set memType to the host memory.

  • Typically, it is a best practice to store the input/output tensor data to feed for running a single-operator (for example, the add operator) in the device memory. Some operators, however, take not only tensor data in the device memory (such as the feature map and weights) but also tensor data in the host memory (such as tensor shape and learning rate) as inputs. In this case, you do not need to manually transfer such tensor data from the host to the device. You only need to call aclSetTensorPlaceMent to set the placement attribute of the corresponding TensorDesc to the host memory to instruct the API to transfer the tensor data from the host to the device at operator runtime.