Get

Product Support

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference product's AI Core

Atlas inference product's Vector Core

x

Atlas training products

Function

Obtains tensors of a specified length or all lengths from TBuf.

Prototype

  • Obtains tensors of all lengths.
    1
    2
    template <typename T>
    __aicore__ inline LocalTensor<T> Get()
    
  • Obtains tensors of a specified length.
    1
    2
    template <typename T>
    __aicore__ inline LocalTensor<T> Get(uint32_t len)
    

Parameters

Table 1 Template parameters

Parameter

Meaning

T

Data type of the tensor to be obtained.

Table 2 Parameters

Parameter

Input/Output

Meaning

len

Input

Number of elements in the tensor to be obtained.

Restrictions

The value of len is the number of elements in the tensor. The value of len x sizeof(T) cannot exceed the length during TBuf initialization.

Returns

Obtained LocalTensor.

Example

1
2
3
4
5
6
7
8
9
// Allocate buffer for TBuf initialization. The length of the allocated buffer is 1024 bytes.
AscendC::TPipe pipe;
AscendC::TBuf<AscendC::TPosition::VECCALC> calcBuf; // The template parameter is the VECCALC type in TPosition.
uint32_t byteLen = 1024;
pipe.InitBuffer(calcBuf, byteLen);
// Obtain a tensor from calcBuf. The tensor is the size of all memory allocated by the pipe (1024 bytes).
AscendC::LocalTensor<int32_t> tempTensor1 = calcBuf.Get<int32_t>();
// Obtain a tensor from calcBuf. The tensor is the memory size (512 bytes) of 128 int32_t elements.
AscendC::LocalTensor<int32_t> tempTensor2 = calcBuf.Get<int32_t>(128);

When the Get API is called consecutively for the same TBuf object, the start addresses of the obtained tensors are the same and do not offset backwards in sequence. To obtain the tensor after offset, use the following method:

AscendC::TPipe pipe;
// The template parameter is of the VECCALC type in TPosition.
AscendC::TBuf<AscendC::TPosition::VECCALC> calcBuf; 
// Allocate a continuous space of 2048 bytes.
uint32_t byteLen = 2048;
pipe.InitBuffer(calcBuf, byteLen);
// Obtain tensor 1 from calcBuf. tensor 1 is of the total memory size allocated by the pipe, which is 2048 bytes.
AscendC::LocalTensor<int32_t> tensor1 = calcBuf.Get<int32_t>();
// Set the offset position of the 256th int32_t of tensor1 as the start address of tensor2. Actually, the memory size that can be used by tensor2 is 1024 bytes, and the difference between the start addresses of the two tensors is 256 × sizeof(int32_t) bytes.
auto tensor2 = tensor1[256];