Introduction to TBufPool

TPipe can manage global memory resources, while TBufPool can be used for manual management or reuse of the Unified Buffer/L1 Buffer physical memory. TBufPool is mainly used when the Unified Buffer/L1 Buffer physical memory is insufficient in multi-stage computing.

Functional Diagram

The following figure shows the resource pool division process.

  1. TPipe:: InitBuffer can allocate buffers and manage buffers by using queues.
  2. TPipe:: InitBufPool can divide the resource pool BufPool1.
  3. TPipe:: InitBufPool can specify the addresses and lengths of BufPool1 and BufPool3 for reuse.
  4. TBufPool:: InitBuffer and TBufPool:: InitBufPool divide BufPool1 and BufPool3 into buffer or TBufPool resource pools.
Figure 1 BufPool resource pool division

As shown in the preceding figure, the outer TBufPool (BufPool1 and BufPool3) needs to be allocated and initialized through TPipe::InitBufPool, and the inner TBufPool (BufPool2) can be allocated and initialized through TBufPool::InitBufPool.

Precautions

  1. TBufPool must be divided and initialized by calling TPipe::InitBufPool or TBufPool::InitBufPool. A resource pool can only be divided into parts, and parts cannot be combined as a whole.
  2. When different TBufPool resource pools are switched for computation, TBufPool::Reset() needs to be called to clear TBufPool that has been computed. The cleared TBufPool resource pool, allocated buffers, and data are invalid by default.
  3. Buffers allocated by different resource pools cannot be used together to avoid data overwrites.
  4. Alloc/Free and EnQue/DeQue must be used in pairs to split a TBufPool resource pool to ensure automatic synchronization.
  5. When the resource pool is switched, handwriting synchronization may cause Ascend C address read/write and reuse asynchronization. Therefore, handwriting synchronization is not recommended.