InitStartBufHandle

Function Usage

Sets the start memory block pointer, number of memory blocks, and size of each memory block of the TQue/TBuf.

Prototype

1
__aicore__ inline void InitStartBufHandle(TBufHandle startBufhandle, uint8_t num, uint32_t len)

Parameters

Table 1 Parameters

Parameter

Input/Output

Meaning

startBufhandle

Input

Pointer to the start memory block of the TQue/TBuf. The data type is TBufHandle (actually uint8_t*).

num

Input

Number of allocated memory blocks.

len

Input

Size of each memory block. The unit is byte.

Availability

Atlas Training Series Product

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.
  • When the TBuf object is used to call this API, the value of the input parameter num must be 1.

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(AscendC::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<AscendC::QuePosition::VECIN, 1> srcQue0;
AscendC::TBuf<AscendC::QuePosition::VECIN> srcBuf1;
MyBufPool tbufPool;
pipe.InitBufPool(tbufPool, 1024 * 2);
tbufPool.InitBuffer(srcQue0, 1, 1024);
tbufPool.InitBuffer(srcBuf1, 1024);