InitStartBufHandle

Product Support

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference product's AI Core

Atlas inference product's Vector Core

x

Atlas training products

Function

Sets the start buffer pointer, number of buffers, and size of each buffer of 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 buffer of TQue/TBuf. The data type is TBufHandle (actually uint8_t*).

num

Input

Number of allocated buffers.

len

Input

Size of each buffer. 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 buffers of TQue and TBuf.
  • When the TBuf object is used to call this API, the value of the passed-in 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 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(AscendC::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<AscendC::TPosition::VECIN, 1> srcQue0;
AscendC::TBuf<AscendC::TPosition::VECIN> srcBuf1;
MyBufPool tbufPool;
pipe.InitBufPool(tbufPool, 1024 * 2);
tbufPool.InitBuffer(srcQue0, 1, 1024);
tbufPool.InitBuffer(srcBuf1, 1024);