InitBufPool
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
√ |
Function Usage
TPipe::InitBufPool obtains a TbufPool resource block, which can be further divided into small resource blocks by TBufPool::InitBufPool.
Prototype
- Non-sharing mode
1 2
template <class T> __aicore__ inline bool InitBufPool(T& bufPool, uint32_t len)
- Sharing mode
1 2
template <class T, class U> __aicore__ inline bool InitBufPool(T& bufPool, uint32_t len, U& shareBuf)
Parameters
Parameter |
Description |
|---|---|
T |
Type of the bufPool parameter. |
U |
shareBuf type. |
Parameter |
Input/Output |
Meaning |
|---|---|---|
bufPool |
Input |
New resource pool. The type is TBufPool. |
len |
Input |
Length of the new resource pool, in bytes. If the length is not 32-byte aligned, it is automatically padded up to 32-byte aligned. |
Parameter |
Input/Output |
Meaning |
|---|---|---|
bufPool |
Input |
New resource pool. The type is TBufPool. |
len |
Input |
Length of the new resource pool, in bytes. If the length is not 32-byte aligned, it is automatically padded up to 32-byte aligned. |
shareBuf |
Input |
Reused resource pool of the TBufPool type. The new resource pool shares the start address and length with the reused resource pool. |
Constraints
- The physical memory of the new resource pool must be the same as that of the reused resource pool. The two resource pools share the start address and length.
- The entered length must be less than or equal to the length of the reused resource pool.
- For details about other restrictions, see TBufPool.
Returns
None
Example
When the data volume is large and the memory is limited, data movement cannot be completed at a time. In this case, the data movement needs to be split into multiple phases. Each phase uses a part of the data. The TBufPool resource pool can be used for memory address reuse. In this example, the resource pool TBufPool0 is allocated from the TPipe. After TBufPool0 allocates space to src0Gm, TBufPool1 is allocated. TBufPool1 and TBufPool2 are reused and used for the first and second rounds of computation, respectively. In this case, TBufPool1 and TBufPool2 share the start address and length.
AscendC::TPipe pipe; AscendC::TBufPool<AscendC::TPosition::VECCALC> tbufPool0, tbufPool1, tbufPool2; // srcQue0, srcQue1, and srcQue2 are TQue instances on VECIN, and dstQue0 and dstQue1 are TQue instances on VECOUT. // Divide tbufPool0 from Tpipe. pipe.InitBufPool(tbufPool0, 131072); // Allocate space to srcQue0. tbufPool0.InitBuffer(srcQue0, 1, 65536); // Total src0 // Allocate space to tbufPool1 through tbufPool0, and specify that tbufPool1 and tbufPool2 share the same space. tbufPool0.InitBufPool(tbufPool1, 65536); tbufPool0.InitBufPool(tbufPool2, 65536, tbufPool1); // Allocate space to srcQue1 and dstQue0 through tbufPool1. tbufPool1.InitBuffer(srcQue1, 1, 32768); tbufPool1.InitBuffer(dstQue0, 1, 32768); // Switch the resource pool to tbufPool2 and allocate space to srcQue2 and dstQue1 through tbufPool2. tbufPool1.Reset(); tbufPool2.InitBuffer(srcQue2, 1, 32768); tbufPool2.InitBuffer(dstQue1, 1, 32768); tbufPool2.Reset(); tbufPool0.Reset(); pipe.Reset();