Lock
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Obtains the mutex based on MutexID and blocks the current pipeline instruction queue until the corresponding mutex ID is unlocked.
Prototype
1 2 | template <pipe_t pipe> static __aicore__ inline void Lock(MutexID id) |
Parameters
Parameter |
Description |
|---|---|
pipe |
Template parameter, indicating the type of a pipeline. For details about supported pipelines, see Pipelines. |
Parameter |
Input/Output |
Description |
|---|---|---|
id |
Input |
Mutex ID for pipeline synchronization management. The ID can be custom (ranging from 0 to 27) or released using AllocMutexID/ReleaseMutexID. |
Returns
None
Constraints
- When using lock and unlock operations and using custom mutex ID, do not use related APIs in TQue, TQueBind, and TBufPool at the same time.
- For the same mutex ID, the lock and unlock operations must be used together, and the specified pipes must be the same. This means operations on other pipelines can be performed only after the lock and unlock operations on a pipeline are complete.
- In scenarios where data dependency exists between the same pipelines, you are advised to use the PipeBarrier API.
Example
1 2 3 4 5 6 7 8 9 10 11 12 | // Lock the MTE2 pipeline mutex to ensure that the current thread exclusively occupies the MTE2 resources for data movement. AscendC::Mutex::Lock<PIPE_MTE2>(mutexId); AscendC::DataCopy(xLocal, src0Global[TILE_LENGTH * progress], TILE_LENGTH); AscendC::DataCopy(yLocal, src1Global[TILE_LENGTH * progress], TILE_LENGTH); // Unlock the MTE2 pipeline to allow other threads to use MTE2. AscendC::Mutex::Unlock<PIPE_MTE2>(mutexId); // Lock the vector pipeline mutex to ensure that the current thread exclusively occupies vector compute resources. AscendC::Mutex::Lock<PIPE_V>(mutexId); AscendC::Add(zLocal, xLocal, yLocal, TILE_LENGTH); // Unlock the vector pipeline to release compute resources for other threads. AscendC::Mutex::Unlock<PIPE_V>(mutexId); |
Parent topic: Mutex (ISASI)