产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
根据MutexID获取Mutex,并阻塞当前流水指令队列,直到对应的MutexID被Unlock。
1 2 | template <pipe_t pipe> static __aicore__ inline void Lock(MutexID id) |
参数名 |
描述 |
|---|---|
pipe |
模板参数,表示流水类别。 支持的流水参考硬件流水类型。 |
参数名 |
输入/输出 |
描述 |
|---|---|---|
id |
输入 |
进行流水同步管理的MutexID。 该id可通过用户自定义(范围为0-27)或者通过AllocMutexID/ReleaseMutexID进行申请释放。 |
无
1 2 3 4 5 6 7 8 9 10 11 12 | // 锁定 MTE2 流水线互斥锁,确保当前线程独占 MTE2 资源进行数据搬运 AscendC::Mutex::Lock<PIPE_MTE2>(mutexId); AscendC::DataCopy(xLocal, src0Global[TILE_LENGTH * progress], TILE_LENGTH); AscendC::DataCopy(yLocal, src1Global[TILE_LENGTH * progress], TILE_LENGTH); // 解锁 MTE2 流水线,允许其他线程使用 MTE2 AscendC::Mutex::Unlock<PIPE_MTE2>(mutexId); // 锁定 Vector 流水线互斥锁,确保当前线程独占向量计算资源 AscendC::Mutex::Lock<PIPE_V>(mutexId); AscendC::Add(zLocal, xLocal, yLocal, TILE_LENGTH); // 解锁 Vector 流水线,释放计算资源供其他线程使用 AscendC::Mutex::Unlock<PIPE_V>(mutexId); |