DeQue

Supported Products

Product

Supported/Unsupported

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 Usage

Extracts tensors from the queue for subsequent processing.

Prototype

  • The source and destination locations do not need to be specified.
    • Non-inplace API: Fetches the address of the enqueued LocalTensor from the queue, assigns the address to the newly created tensor, and returns the tensor.
      1
      2
      template <typename T>
      __aicore__ inline LocalTensor<T> DeQue()
      
    • Inplace API: Returns the tensor by using the output parameter, which can reduce the overhead of repeatedly creating tensors. For details about how to use the API, see How Do I Use Tensor In-place Operations to Improve Operator Performance?.
      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 Parameters in the template

Parameter

Description

T

Tensor data type,

srcUserPos

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

dstUserPos

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

Table 2 Parameters

Parameter

Input/Output

Meaning

tensor

Output

The inplace API returns the tensor by using the output parameter.

Restrictions

  • DeQueuing an empty queue is an abnormal operation, and an error will be reported during CPU debugging.
  • For the non-inplace interface and the interface that specifies the source and destination positions, the depth template parameter of TQueBind must be set to a non-zero value. For the inplace interface, the depth template parameter of TQueBind must be set to 0.

Returns

The return value of the non-inplace interface and the interface that specifies the source and destination positions is the LocalTensor obtained from the queue. The inplace interface does not return any 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 interface
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); // Moves the tensor out of the VECOUT queue.
que.FreeTensor<half>(tensor1);