目录

AllocTensor

Function Description

Allocates tensors from the queue. The size occupied by tensors is the length of each buffer configured when InitBuffer is used.

The allocated tensor content cannot all be 0. The content may be a random value.

Function Prototype

template <typename T> 
__aicore__ inline LocalTensor<T> AllocTensor()

Parameters

None

Supported Models

Kirin 9020 series processors

Kirin 9030 series processors

Kirin X90 series processors

Precautions

None

Return Value

LocalTensor object

Calling Example

// Use AllocTensor to allocate tensors.
AscendC::TPipe pipe;
AscendC::TQueBind<AscendC::TPosition::VECOUT, AscendC::TPosition::GM, 2> que;
int num = 4;
int len = 1024;
pipe.InitBuffer(que, num, len); // Four buffers are allocated by InitBuffer, and the size of each buffer is 1,024 bytes.
AscendC::LocalTensor<half> tensor1 = que.AllocTensor<half>(); // The length of the tensor allocated by AllocTensor is 1,024 bytes.