AllocTensor

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Allocates tensors from TSCM. The size occupied by tensors is the length of each buffer configured when InitBuffer is used. Note that the allocated tensor content is not all 0s and may be random values.

Prototype

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

Parameters

None

Constraints

None

Returns

LocalTensor object.

Example

1
2
3
4
5
6
7
8
9
AscendC::TPipe pipe;
AscendC::TSCM<AscendC::TPosition::VECIN, 1> tscm;
int num = 4;
int len = 1024;
pipe.InitBuffer(tscm, 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.
que.EnQue(tensor1);
tensor1 = que.DeQue<half>();
que.FreeTensor(tensor1);