HasIdleBuffer

Function Usage

Queries whether there are free memory blocks in the queue.

Prototype

1
__aicore__ inline bool HasIdleBuffer()

Parameters

None

Availability

Atlas Training Series Product

Precautions

None

Returns

  • true: indicates that idle buffer exists in the queue.
  • false: No idle buffer exists in the queue.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Four memory blocks have been allocated in the current queue.
AscendC::TPipe pipe;
AscendC::TQue<AscendC::TPosition::VECOUT, 1> que;
int num = 4;
int len = 1024;
pipe.InitBuffer(que, num, len);
bool ret = que.HasIdleBuffer(); // No AllocTensor operation is involved, and the return value is true.
AscendC::LocalTensor<half> tensor1 = que.AllocTensor<half>();
ret = que.HasIdleBuffer(); // One memory block is allocated by AllocTensor, and the return value is true.
AscendC::LocalTensor<half> tensor2 = que.AllocTensor<half>();
AscendC::LocalTensor<half> tensor3 = que.AllocTensor<half>();
AscendC::LocalTensor<half> tensor4 = que.AllocTensor<half>();
ret = que.HasIdleBuffer(); // Four memory blocks are allocated by AllocTensor. Currently, there is no idle buffer, and the return value is false. If you continue call AllocTensor, an error is reported.