DeQue

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

Extracts tensors from the queue for subsequent processing.

Prototype

  • The source and destination locations do not need to be specified.
    • Non-inplace API: obtains the enqueued LocalTensor address from the queue, assigns the address to the newly created tensor, and returns the address.
      1
      2
      template <typename T>
      __aicore__ inline LocalTensor<T> DeQue()
      
    • Inplace API: returns the result through output parameters, which reduces the overhead of repeatedly creating tensors. For details, see How to Improve Operator Performance Through Inplace Tensor Operations.
      1
      2
      template <typename T>
      __aicore__ inline void DeQue(LocalTensor<T>& tensor)
      
  • The source and destination locations need to be specified.

    Bind VECIN and VECOUT by using TQueBind to implement VECIN and VECOUT buffer reuse. The following API is used to implement buffer reuse for vector computation. The source and destination locations need to be specified during dequeuing. In the scenario where vector computation is not involved, call LocalTensor<T> DeQue().

    1
    2
    template <TPosition srcUserPos, TPosition dstUserPos, typename T>
    __aicore__ inline LocalTensor<T> DeQue()
    

Parameters

Table 1 Template parameters

Parameter

Description

T

Data type of the tensor.

srcUserPos

src position of the queue specified by the user. Supported path: GM->VECIN/VECOUT->GM

dstUserPos

dst position of the queue specified by the user. Supported path: GM->VECIN/VECOUT->GM

Table 2 Parameters

Parameter

Input/Output

Description

tensor

Output

The inplace API returns the tensor through output parameters.

Restrictions

  • Performing DeQue on an empty queue is abnormal behavior, and an error is reported during CPU debugging.
  • For the non-inplace API and the API that specifies the source and destination locations, the depth template parameter of TQueBind must be set to a non-zero value. For the inplace API, the depth template parameter of TQueBind must be set to 0.

Returns

The return value of the non-inplace API and the API that specifies the source and destination locations is the LocalTensor obtained from the queue. The inplace API has no return value.

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
// API: DeQue Tensor
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECOUT, 4> que;
int num = 4;
int len = 1024;
pipe.InitBuffer(que, num, len);
AscendC::LocalTensor<half> tensor1 = que.AllocTensor<half>();
que.EnQue(tensor1);
AscendC::LocalTensor<half> tensor2 = que.DeQue<half>(); // Move a tensor out of the VECOUT queue.
// API: DeQue Tensor, specifying a specific src/dst position
AscendC::TPipe pipe;
AscendC::TQueBind<AscendC::TPosition::VECIN, AscendC::TPosition::VECOUT, 1> que;
int num = 4;
int len = 1024;
pipe.InitBuffer(que, num, len);
AscendC::LocalTensor<half> tensor1 = que.AllocTensor<half>();
que.EnQue<AscendC::TPosition::GM, AscendC::TPosition::VECIN, half>(tensor1);
// Move a tensor out of the VECIN queue.
AscendC::LocalTensor<half> tensor2 = que.DeQue<AscendC::TPosition::GM, AscendC::TPosition::VECIN, half>(); 
// In-place API
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECOUT, 0> que;
int num = 2;
int len = 1024;
pipe.InitBuffer(que, num, len);
AscendC::LocalTensor<half> tensor1;
que.AllocTensor<half>(tensor1);
que.EnQue(tensor1);
que.DeQue<half>(tensor1); // Move the tensor out of the VECOUT queue.
que.FreeTensor<half>(tensor1);