InitBufHandle
Product Support
Product |
Supported |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
√ |
Function
Allocates memory for the buffers of the TQue and TBuf objects, including setting the size and pointed address of the buffers.
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 |
Description |
|---|---|
T |
Data type of bufPool. |
Parameter |
Input/Output |
Meaning |
|---|---|---|
bufPool |
Input |
Customized TBufPool object. |
index |
Input |
Offset index value of the buffer to be set. The first buffer is 0, the second buffer is 1, and the same rule applies to the rest. |
bufhandle |
Input |
Pointer to the buffer to be set. The type is TBufHandle (actually uint8_t*). |
curPoolAddr |
Input |
Address of the buffer to be set. |
len |
Input |
Size of the buffer to be set. The unit is byte. |
Restrictions
- 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 buffers.
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 custom TBufPool class is MyBufPool. // InitBuffer for initializing the TQue in the custom TBufPool class: template<class T> __aicore__ inline bool MyBufPool::InitBuffer(T& que, uint8_t num, uint32_t len) { ... // Initialize the buffer of TQue. uint32_t curPoolAddr = 0; // Start address of the buffer. auto bufhandle = xxx; // Specific buffer. This variable can be obtained from the custom TBufPool. srcQue0.InitStartBufHandle(bufhandle , num, len); for (uint8_t i = 0; i < num; i++) { que.InitBufHandle(this, i, bufhandle , curPoolAddr + i * len, len); } ... } // InitBuffer for initializing the TBuf in the custom TBufPool class: template<class T> __aicore__ inline bool MyBufPool::InitBuffer(TBuf<bufPos>& buf, uint32_t len) { ... // Initialize the buffer of TBuf. uint32_t curPoolAddr = 0; // Start address of the buffer. auto bufhandle = xxx; // Specific buffer. This variable can be obtained from the custom TBufPool. srcBuf1.InitStartBufHandle(bufhandle, 1, len); srcBuf1.InitBufHandle(this, 0, bufhandle , curPoolAddr, len); ... } AscendC::TPipe pipe; AscendC::TQue<TPosition::VECIN, 1> srcQue0; AscendC::TBuf<TPosition::VECIN> srcBuf1; MyBufPool tbufPool; pipe.InitBufPool(tbufPool, 1024 * 2); tbufPool.InitBuffer(srcQue0, 1, 1024); tbufPool.InitBuffer(srcBuf1, 1024); |