Introduction

Mutex is used for synchronization between asynchronous pipeline instructions in a core. Its function is similar to the lock mechanism in traditional CPUs. The synchronization dependency between pipelines is implemented by locking specified pipelines and then releasing them. Each lock has a fixed mutex ID, which can be custom (ranging from 0 to 27) or released using AllocMutexID/ReleaseMutexID. During custom configuration, the API performance is optimal. However, this API cannot be used together with APIs such as TQue. If you release the mutex using AllocMutexID/ReleaseMutexID, this API can be used together with framework APIs such as TQue.

  • Lock: Obtains the mutex based on MutexID and blocks the current pipeline instruction queue until the corresponding mutex ID is unlocked.
  • Unlock: Releases the mutex based on MutexID after the current pipeline instruction preceding the unlock exits.

Prototype Definition

1
2
3
4
5
6
7
using MutexID = uint8_t;
class Mutex {
template <pipe_t pipe>
static __aicore__ inline void Lock(MutexID id);
template <pipe_t pipe>
static __aicore__ inline void Unlock(MutexID id);
};