aclSetDynamicInputTensorAddr

Description

After aclOpExecutor reuse is enabled by calling aclSetAclOpExecutorRepeatable, if the input device memory address changes, the device memory address recorded in the input aclTensorList needs to be updated.

Prototype

aclnnStatus aclSetDynamicInputTensorAddr(aclOpExecutor *executor, size_t irIndex, const size_t relativeIndex, aclTensorList *tensors, void *addr)

Parameter Description

Parameter

Input/Output

Description

executor

Input

aclOpExecutor that is set to the reusable state.

irIndex

Input

Index of aclTensorList to be updated in the operator IR prototype definition, starting from 0.

relativeIndex

Input

Index of aclTensor to be updated in aclTensorList. If aclTensorList has N tensors, the value range is [0, N – 1].

tensors

Input

aclTensorList pointer to be updated.

addr

Input

Device storage address to be updated to the specified aclTensor. The address must be 32-byte aligned. Otherwise, an undefined error may occur.

Return Value

0 on success; otherwise, failure. For details about the return codes, see Common API Return Codes.

Possible causes:

  • Code 561103: executor or tensors is a null pointer.
  • Code 161002:
    • relativeIndex ≥ Number of tensors in tensors.
    • irIndex is greater than or equal to the number of input parameters for the operator prototype.
    • Ascend 950PR&950DT products: If PCIe through is enabled for the product model and the new device storage address and the original device storage address belong to different address spaces (e.g. writing a PCIe address to a non-PCIe space, or the other way round), the update will be intercepted.

Constraints

  • Ascend 950PR&950DT products: If PCIe through is enabled for the product model, the new device storage address and the original device storage address must belong to the same address space. That is, a PCIe address can only be updated to another PCIe address, and a non-PCIe address can only be updated to another non-PCIe address. Illegal cross-space overwrites will cause the API to intercept the operation and return error code 161002.
  • PCIe through is a hardware capability of Ascend NPUs. It allows device-side operators to directly access the host memory through the PCIe bus, eliminating the need for data copy between the host and device. This function is supported only by Ascend 950PR&950DT products.

Example

The following sample code is for reference only. Do not copy and run it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Create the input and output aclTensor and aclTensorList.
std::vector<int64_t> shape = {1, 2, 3};
aclTensor *tensor1 = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT,
nullptr, 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), nullptr);
aclTensor *tensor2 = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT,
nullptr, 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), nullptr);
aclTensor *tensor3 = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT,
nullptr, 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), nullptr);
aclTensor *output = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT,
nullptr, 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), nullptr);
aclTensor *list[] = {tensor1, tensor2};
auto tensorList = aclCreateTensorList(list, 2);
uint64_t workspaceSize = 0;
aclOpExecutor *executor;
// The AddCustom operator has two inputs (aclTensorList and aclTensor) and one output (aclTensor).
// Call the first-phase API.
aclnnAddCustomGetWorkspaceSize(tensorList, tensor3, output, &workspaceSize, &executor);
// Set the executor to be reusable.
aclSetAclOpExecutorRepeatable(executor);  
void *addr;
aclSetDynamicInputTensorAddr(executor, 0, 0, tensorList, addr);   // Update the device address of the first aclTensor in the input tensorList.
aclSetDynamicInputTensorAddr(executor, 0, 1, tensorList, addr);  // Update the device address of the second aclTensor in the input tensorList.
...
// Call the second-phase API.
aclnnAddCustom(workspace, workspaceSize, executor, stream);
// Clear the executor.
aclDestroyAclOpExecutor(executor);