InitBufPool
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
√ |
Function Usage
Initializes the TBufPool buffer resource pool. This API applies to the scenario where you want to manually specify UB/L1 buffer resource reuse when buffer resources are limited. After initialization, a child resource pool is allocated from the overall buffer resources. The child resource pool TBufPool provides the following resource management modes:
- The reloading API of TPipe::InitBufPool is reused with other TBufPool child resource pools.
- TBufPool:: InitBufPool continues to divide child resource pools.
- TBufPool::InitBuffer allocates buffers.
For details about the TBufPool and resource allocation diagram, see TBufPool.
Prototype
1 2 3 4 | template <class T> __aicore__ inline bool InitBufPool(T& bufPool, uint32_t len) template <class T, class U> __aicore__ inline bool InitBufPool(T& bufPool, uint32_t len, U& shareBuf) |
Parameters
Parameter |
Description |
|---|---|
T |
bufPool type. |
U |
shareBuf type. |
Parameter |
Input/Output |
Description |
|---|---|---|
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 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 hardware attributes of the new resource pool must be the same as those 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
Due to the limited size of the physical buffer, you can specify buffer reuse to solve the problem of insufficient resources in the scenario where there is no data dependency during computation or the scenario where data dependency is in serial mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Declare a pointer to the TPipe object. AscendC::TPipe* pipe; // Define two sub-resource pool objects tbufPool1 and tbufPool2. AscendC::TBufPool<AscendC::TPosition::VECCALC> tbufPool1, tbufPool2; // Initialize the first sub-resource pool tbufPool1. pipe->InitBufPool(tbufPool1, BUF_SIZE * 3); // Initialize the second sub-resource pool tbufPool2 and specify the start address and length of tbufPool1 to be reused by tbufPool2. pipe->InitBufPool(tbufPool2, BUF_SIZE * 3, tbufPool1); // Computation is performed in serial mode, and no data corruption occurs. Buffer reuse and automatic synchronization are implemented. tbufPool1.InitBuffer(queSrc0, 1, BUF_SIZE); tbufPool1.InitBuffer(queSrc1, 1, BUF_SIZE); tbufPool1.InitBuffer(queDst0, 1, BUF_SIZE); CopyIn(); Compute(); CopyOut(); tbufPool1.Reset(); tbufPool2.InitBuffer(queSrc2, 1, BUF_SIZE); tbufPool2.InitBuffer(queSrc3, 1, BUF_SIZE); tbufPool2.InitBuffer(queDst1, 1, BUF_SIZE); CopyIn1(); Compute1(); CopyOut1(); tbufPool2.Reset(); |