EXTERN_IMPL_BUFPOOL Macro
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
√ |
Function Usage
Developers can manually manage the physical memory of the Unified Buffer and L1 Buffer by using the TBufPool class.
The buffers split by the TBufPool class are continuous. Developers may have specific custom buffer allocation requirements, for example, discontinuous buffers and buffer sharing between different TQues. In this case, developers need to customize the implementation of a TBufPool.
To simplify customization, the EXTERN_IMPL_BUFPOOL macro is provided to help you customize TBufPool. When using the custom TBufPool function, pay attention to the following:
- Before customizing the TBufPool, initialize the TBufPool memory resource pool by calling TPipe::InitBufPool.
- To customize a TBufPool, developers need to allocate, initialize, and release TQue/TBuf buffers.
For details about Reset, Init, GetBufHandle, SetCurAddr, GetCurAddr, SetCurBufSize, and GetCurBufSize defined in the EXTERN_IMPL_BUFPOOL macro, see the subsequent sections. After this macro is used, the preceding APIs can be used to customize TBufPool.
The custom TBufPool APIs are for trial use and may be adjusted or improved in later versions. Compatibility is not guaranteed. Pay attention to updates in later versions.
Prototype
1 2 | // The macro definition is omitted. #define EXTERN_IMPL_BUFPOOL(EXT_BUFPOOL, POSITION, BUFID_SIZE) ... |
Parameters
Parameter |
Input/Output |
Meaning |
|---|---|---|
EXT_BUFPOOL |
Input |
Customized TBufPool class name. |
POSITION |
Input |
Logical location of custom TBufPool. The value can be VECIN, VECOUT, VECCALC, A1, B1, or C1. For details about TPosition, see TPosition. |
BUFID_SIZE |
Input |
Number of buffers allocated by the custom TBufPool. A value less than or equal to 16 is recommended. |
Constraints
None
Returns
None
Example
For details, see Custom TBufPool sample.
In the following example, the buffer of 65536 x 3 is allocated to TBufPool0, and InitBuffer of MyBufPool is customized to allocate the buffers for TQue and TBuf.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include "kernel_operator.h" class MyBufPool { public: __aicore__ inline MyBufPool() { Init(); } template<class T> __aicore__ inline bool InitBuffer(T& que, uint8_t num, uint32_t len) { } template<AscendC::TPosition bufPos> __aicore__ inline bool InitBuffer(AscendC::TBuf<bufPos>& buf, uint32_t len) { } // MyBufPool: custom TBufPool class name. Set the logical location of the custom TBufPool to VECCALC. // Set the number of buffer blocks allocated by the custom TBufPool to 16. EXTERN_IMPL_BUFPOOL(MyBufPool, AscendC::TPosition::VECCALC, 16); }; |