InitBufHandle

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

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

Table 1 Template parameters

Parameter

Description

T

Data type of bufPool.

Table 2 Parameters

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, in bytes.

Constraints

  • 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.

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);