DeQue
Product Support
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function
Extracts tensors from the queue for subsequent processing.
Prototype
- 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)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Data type of the tensor. |
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
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, 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 is the LocalTensor obtained from the queue. The inplace API does not return any value.
Example
- Non-inplace API
1 2 3 4 5 6 7 8
AscendC::TPipe pipe; AscendC::TQueBind<AscendC::TPosition::VECOUT, AscendC::TPosition::GM, 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 the tensor out of the VECOUT queue.
- Inplace API
1 2 3 4 5 6 7 8 9 10
AscendC::TPipe pipe; AscendC::TQueBind<AscendC::TPosition::VECOUT, AscendC::TPosition::GM, 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);