InitBuffer
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Allocates buffer to TBuf and queues such as TQue.
Prototype
- Buffer allocation for queues such as TQue
1 2 3 4 5 6
template <class T> __aicore__ inline bool InitBuffer(T& que, uint8_t num, uint32_t len) // Allocate buffers to queues such as TQue. You can define buffer address information, including the start address and length. template <class T, class U, class V, class... Addrs> __aicore__ inline bool InitBuffer(T& que, const Std::tuple<U, V>& addr0, const Addrs&... addrs)
- Buffer allocation for TBuf
1 2
template <TPosition bufPos> __aicore__ inline bool InitBuffer(TBuf<bufPos>& buf, uint32_t len)
Parameters
|
Parameter |
Meaning |
|---|---|
|
T |
|
Parameter |
Meaning |
|---|---|
|
T |
|
|
U |
Start address type. The value is an integer. |
|
V |
Length type. The value is an integer. |
|
Addrs... |
Address information in tuple format, including the start address and length. |
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
que |
Input |
Objects such as TQue that require buffer allocation. |
|
addr0 |
Input |
Address information of the allocated memory block, including the start address and length. |
|
addrs |
Input |
Address information list in tuple format. The number of elements in a tuple must be 2, that is, the start address and length. |
|
Parameter |
Meaning |
|---|---|
|
bufPos |
Logical position of the TBuf, which is of the TPosition type. |
Constraints
- The buffer allocated by InitBuffer is automatically released through the destructor when the TPipe object is destroyed.
- If you need to reallocate the buffer allocated by InitBuffer, call Reset before calling InitBuffer.
- The total number of buffers used in a kernel cannot exceed 64.
- It is not recommended that the custom address allocation mode of InitBuffer be used together with the mode where no address is specified. Otherwise, buffer conflicts may occur.
Returns
Buffer initialization result.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Allocate two 128-byte buffers for TQue. AscendC::TPipe pipe; // TPipe object AscendC::TQue<AscendC::TPosition::VECOUT, 2> que; // Output queue management object, with TPosition set to VECOUT. uint8_t num = 2; uint32_t len = 128; pipe.InitBuffer(que, num, len); // Allocate buffers to TQue. The custom buffer addresses are [0, 1024], [2048, 4096], and [8192, 12288]. AscendC::TPipe pipe; // TPipe object AscendC::TQue<AscendC::TPosition::VECOUT, 1> que; // Output queue management object, with TPosition set to VECOUT. auto addr0 = Std::make_tuple(0, 1024); auto addr1 = Std::make_tuple(2048, 2048); auto addr2 = Std::make_tuple(8192, 4096); pipe.InitBuffer(que, addr0, addr1, addr2); // Allocate the 128-byte buffer for TBuf. AscendC::TPipe pipe; AscendC::TBuf<AscendC::TPosition::A1> buf; // Output management object, with TPosition set to A1. uint32_t len = 128; pipe.InitBuffer(buf, len); |