Function: execute_v2
Applicable Products
- Ascend 950PR&950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
Executes a specified operator. This is an asynchronous API.
As the inputs, outputs, and attributes of each operator are different, the app needs to organize operators in strict accordance with their inputs, outputs, and attributes. When acl.op.execute_v2 is called, it searches for the corresponding task based on the operator type, input tensor description, output tensor description, and attribute information, and delivers the task for execution.
Prototype
-
C Prototype
aclError aclopExecuteV2(const char *opType, int numInputs, aclTensorDesc *inputDesc[], aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[], aclDataBuffer *outputs[], aclopAttr *attr, aclrtStream stream) -
Python Function
ret = acl.op.execute_v2(op_type, input_desc, inputs, output_desc, outputs, attr, stream)
Parameters
| Parameter | Description |
|---|---|
| op_type | Str, operator type. |
| input_desc | Int list, description of the operator input tensor. It contains multiple ACL tensor description address objects. |
| inputs | Int list, input tensor of the operator. It contains multiple aclDataBuffer data address objects. |
| output_desc | Int list, description of the operator output tensor. It contains multiple ACL tensor description address objects. |
| outputs | Int list, output tensor of the operator. It contains multiple aclDataBuffer data address objects. |
| attr | Int, attribute address object of the operator. |
| stream | Int, stream object to be loaded by the operator. |
Return Values
| Return Value | Description |
|---|---|
| ret | Int, error code: 0 on success; else, failure. |
Constraints
-
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, if the output shape of the operator cannot be determined, call
acl.op.infer_shapeto 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 theacl.op.execute_v2call. In this scenario, theacl.op.execute_v2API 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,acl.rt.synchronize_stream) 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 theacl.op.execute_v2call. In this scenario, after callingacl.op.execute_v2to execute the operator, the system calculates the accurate output shape, as theoutputDescoutput ofacl.op.execute_v2. In this case,acl.op.execute_v2is a synchronous API. - (Reserved) If the accurate output shape and shape range cannot be obtained, you need to estimate a maximum shape to construct an
outputDescas one of the arguments passed to theacl.op.execute_v2call. In this scenario, after callingacl.op.execute_v2to execute the operator, the system calculates the accurate output shape, as theoutputDescoutput ofacl.op.execute_v2. In this case,acl.op.execute_v2is a synchronous API.
- If the accurate output shape can be obtained, use the obtained accurate output shape to construct an
-
If an operator with an unused optional input is executed:
- Create data of the
aclTensorDesctype by using the acl.create_tensor_desc(ACL_DT_UNDEFINED, 0, [], ACL_FORMAT_UNDEFINED)call, indicating that the data type isACL_DT_UNDEFINED, the format isACL_FORMAT_UNDEFINED, and the shape is[]. - Create data of the
aclDataBuffertype by using theacl.create_data_buffer([], 0)call, where theaclDataBufferdata does not need to be freed.
- Create data of the
-
Before executing an operator with constant input, call acl.set_tensor_const to set the constant input.
The constant input passed must be consistent with that in
aclopExecuteV2calls.If an operator has a constant input but acl.set_tensor_const has not been called to set the constant input, call acl.set_tensor_place_ment to set the placement attribute of
TensorDescand setmemTypeto 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). In this case, you do not need to manually transfer such tensor data from the host to the device. You only need to call acl.set_tensor_place_ment to set the placement attribute of the corresponding
TensorDescto the host memory to instruct it to transfer the tensor data from the host to the device at operator runtime.
Reference
For details about the API calling process and examples, see Single-Operator Calling.