InitBufHandle
Function Usage
Allocates memory for the memory blocks of the TQue and Tbuf objects, including setting the size and pointed address of the memory blocks.
Prototype
1 2 | template <typename T> __aicore__ inline void InitBufHandle(T* bufPool, uint32_t index, TBufHandle bufhandle, uint32_t curPoolAddr, uint32_t len) |
Parameters
Parameter |
Input/Output |
Meaning |
|---|---|---|
bufPool |
Input |
Customized TBufPool object. |
index |
Input |
Offset index value of the memory block to be set. The first block is 0, the second block is 1, and the same rule applies to the rest. |
bufhandle |
Input |
Pointer to the memory block to be set. The type is TBufHandle (actually uint8_t*). |
curPoolAddr |
Input |
Address of the memory block to be set. |
len |
Input |
Size of the memory block to be set. The unit is byte. |
Availability
Precautions
- The TQue and TBuf classes are inherited from the TQueBind class. Therefore, the TQue and TBuf objects can also use this API.
- Currently, this API is provided only for Customized TBufPool to initialize the TQue and TBuf memory blocks.
Returns
None
Example
For details about the complete example, see Example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // Assume that the customized tbufpool class is MyBufPool. // Customize the InitBuffer function for initializing the TQue in the tbufpool class: template<class T> __aicore__ inline bool MyBufPool::InitBuffer(T& que, uint8_t num, uint32_t len) { ... // Initialize the memory block of the TQue. uint32_t curPoolAddr = 0; // Start address of the memory block. auto bufhandle = xxx; // Specific memory block. This variable can be obtained from the customized tbufpool. srcQue0.InitStartBufHandle(bufhandle , num, len); for (uint8_t i = 0; i < num; i++) { que.InitBufHandle(this, i, bufhandle , curPoolAddr + i * len, len); } ... } // Customize the InitBuffer function for initializing the TBuf in the tbufpool class. template<class T> __aicore__ inline bool MyBufPool::InitBuffer(TBuf<bufPos>& buf, uint32_t len) { ... // Initialize the memory block of the TBuf. uint32_t curPoolAddr = 0; // Start address of the memory block. auto bufhandle = xxx; // Specific memory block. This variable can be obtained from the customized tbufpool. srcBuf1.InitStartBufHandle(bufhandle, 1, len); srcBuf1.InitBufHandle(this, 0, bufhandle , curPoolAddr, len); ... } AscendC::TPipe pipe; AscendC::TQue<QuePosition::VECIN, 1> srcQue0; AscendC::TBuf<QuePosition::VECIN> srcBuf1; MyBufPool tbufPool; pipe.InitBufPool(tbufPool, 1024 * 2); tbufPool.InitBuffer(srcQue0, 1, 1024); tbufPool.InitBuffer(srcBuf1, 1024); |
Parent topic: TQueBind