Get
Supported Products
Product |
Supported/Unsupported |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
√ |
Function Usage
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
Field |
Meaning |
|---|---|
T |
Data type of the tensor to be obtained. |
Parameter |
Input/Output |
Meaning |
|---|---|---|
len |
Input |
Number of tensor elements 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
The obtained LocalTensor is returned.
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); |
If the Get interface is called consecutively for the same TBuf object, the obtained tensors have the same start address, and the address is not shifted backward in sequence. To obtain the tensor after the 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 2048-byte continuous space. uint32_t byteLen = 2048; pipe.InitBuffer(calcBuf, byteLen); // Obtain tensor1 from calcBuf. The size of all memory allocated to the pipe is 2048 bytes. AscendC::LocalTensor<int32_t> tensor1 = calcBuf.Get<int32_t>(); // The 256th int32_t offset position of tensor1 is specified 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 x sizeof(int32_t) bytes. auto tensor2 = tensor1[256];