GetWithOffset

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

Starts from the base address TBuf, offsets by a specified length, uses the offset address as the starting address, and extracts a tensor of the specified length.

Prototype

1
2
template <typename T>
__aicore__ inline LocalTensor<T> GetWithOffset(uint32_t size, uint32_t bufOffset)

Parameters

Table 1 Template parameters

Parameter

Meaning

T

Data type of the tensor to be obtained.

Table 2 Parameters

Parameter

Input/Output

Meaning

size

Input

Number of tensor elements to be obtained.

bufOffset

Input

Offset length from the start position, in bytes. The value must be 32-byte aligned.

Restrictions

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

The value of bufOffset must be 32-byte aligned.

Returns

Obtained LocalTensor.

Example

1
2
3
4
5
6
7
// 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 using an offset of 64 bytes. The tensor is the buffer size of 128 elements of the int32_t type, which is 512 bytes.
AscendC::LocalTensor<int32_t> tempTensor1 = calcBuf.GetWithOffset<int32_t>(128, 64);