aclSetTensorAddr

Function Usage

After aclOpExecutor reuse is enabled by the aclSetAclOpExecutorRepeatable call, if the input or output device memory address changes, the device memory address recorded in the corresponding aclTensor needs to be updated.

Prototype

aclnnStatus aclSetTensorAddr(aclOpExecutor *executor, const size_t index, aclTensor *tensor, void *addr)

Parameters

Parameter

Input/Output

Description

executor

Input

aclOpExecutor that is set to the reusable state.

index

Input

Index of aclTensor to be updated. Value range: [0, total number of tensors – 1].

tensor

Input

aclTensor pointer to be updated.

addr

Input

Device storage address to be updated to the specified aclTensor.

Returns

0 on success; else, failure. For details about the return codes, see Common APIs and Return Codes.

Possible causes:

  • If error code 561103 is returned, executor or tensor is a null pointer.
  • If error code 161002 is returned, the index value is out of range.
  • If error code 161002 is returned, the aclTensor input is nullptr when the first-phase API aclxxXxxGetWorkspaceSize is called for the first time. The address cannot be updated.

Constraints

None

Examples

The following code examples are for reference only and are not intended for direct copying and execution:

 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
28
29
// 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;
aclSetTensorAddr(executor, 0, tensor1, addr); // Update the device address of the first aclTensor in the input tensorList.
aclSetTensorAddr(executor, 1, tensor2, addr); // Update the device address of the second aclTensor in the input tensor list.
aclSetTensorAddr(executor, 2, tensor3, addr); // Update the device address of the input aclTensor.
aclSetTensorAddr(executor, 3, output, addr); // Update the device address of the output aclTensor.
...
// Call the second-phase API.
aclnnAddCustom(workspace, workspaceSize, executor, stream);
// Clear the executor.
aclDestroyAclOpExecutor(executor);