Introduction to TQueBind
TQueBind binds the source and destination logical locations. Based on the source and destination locations, TQueBind determines the memory allocation location and inserts the corresponding synchronization event, helping developers solve problems such as memory allocation, management, and synchronization. TQue is a simplified mode of TQueBind. Generally, developers use TQue for programming. TQueBind provides memory management and synchronization control for some special data channels. When these channels are involved, TQueBind can be directly used.
As shown in the following figure, the red and blue lines can be expressed by using the TQueBind definition, and the blue line can be simplified by using the TQue.

|
Data Path |
Definition of TQueBind |
Definition of TQue |
|---|---|---|
|
GM->VECIN |
TQueBind<TPosition::GM, TPosition::VECIN, 1> |
TQue<TPosition::VECIN, 1> |
|
VECOUT->GM |
TQueBind<TPosition::VECOUT, TPosition::GM, 1> |
TQue<TPosition::VECOUT, 1> |
|
VECIN->VECOUT |
TQueBind<TPosition::VECIN, TPosition::VECOUT, 1> |
- |
|
GM->A1 |
TQueBind<TPosition::GM, TPosition::A1, 1> |
TQue<TPosition::A1, 1> |
|
GM->B1 |
TQueBind<TPosition::GM, TPosition::B1, 1> |
TQue<TPosition::B1, 1> |
|
GM->C1 |
TQueBind<TPosition::GM, TPosition::C1, 1> |
TQue<TPosition::C1, 1> |
|
A1->A2 |
TQueBind<TPosition::A1, TPosition::A2, 1> |
TQue<TPosition::A2, 1> |
|
B1->B2 |
TQueBind<TPosition::B1, TPosition::B2, 1> |
TQue<TPosition::B2, 1> |
|
C1->C2 |
TQueBind<TPosition::C1, TPosition::C2, 1> |
TQue<TPosition::C2, 1> |
|
CO1->CO2 |
TQueBind<TPosition::CO1, TPosition::CO2, 1> |
TQue<TPosition::CO1, 1> |
|
CO2->GM |
TQueBind<TPosition::CO2, TPosition::GM, 1> |
TQue<TPosition::CO2, 1> |
|
VECOUT->A1/B1/C1 |
TQueBind<TPosition::VECOUT, TPosition::A1, 1> TQueBind<TPosition::VECOUT, TPosition::B1, 1> TQueBind<TPosition::VECOUT, TPosition::C1, 1> |
- |
|
CO2->VECIN |
TQueBind<TPosition::CO2, TPosition::VECIN, 1> |
- |
It is recommended that Cube-related data paths in the preceding table be implemented using Cube high-level APIs (such as Matmul). Using TQueBind to control data paths is complex.
The following uses two examples to describe how to use TQueBind in vector programming scenarios:
- In the following programming paradigm example, the two queues in the figure are bound to GM VECIN and VECOUT GM, respectively.
- If vector computation is not required, for example, only format conversion along data movement is required, the preceding process can be optimized by binding VECIN and VECOUT. In this way, the same buffer can be used for the input and output, implementing double buffer.
Template parameter
1
|
template <TPosition src, TPosition dst, int32_t depth, auto mask = 0> class TQueBind {...}; |
|
Parameter |
Description |
|---|---|
|
src |
Source logical position. The supported TPosition can be VECIN, VECOUT, A1, A2, B1, B2, CO1, or CO2. For details about TPosition, see TPosition. For details about the supported combinations of src and dst, see Table 1. |
|
dst |
Destination logical position. The TPosition can be VECIN, VECOUT, A1, A2, B1, B2, CO1, or CO2. |
|
depth |
Depth of the TQue. Generally, the value is less than or equal to 4. |
|
mask |
If data needs to be converted during data movement on a queue, set this parameter to 0 or 1. Generally, you can skip this parameter configuration. The default value is 0. If this parameter is set to 0, the data format is converted from ND to NZ. Currently, TPosition can only be set to A1 or B1. |

