产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
原子操作函数,设置后续从VECOUT传输到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,将最大值写入GM。
可通过设置模板参数来设定不同的数据类型。
1 2 | template <typename T> __aicore__ inline void SetAtomicMax() |
参数名 |
描述 |
|---|---|
T |
设定不同的数据类型。 Ascend 950PR/Ascend 950DT,支持int8_t/int16_t/half/bfloat16_t/int32_t/float |
无
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "kernel_operator.h" constexpr uint32_t SIZE = 256; __aicore__ inline void CopyIn() { AscendC::LocalTensor<T> srcLocal = queueSrc.AllocTensor<T>(); // 清空原子操作的状态 AscendC::DisableDmaAtomic(); AscendC::DataCopy(srcLocal, srcGlobal, SIZE); queueSrc.EnQue(srcLocal); // 核间同步 AscendC::SyncAll(); } __aicore__ inline void CopyOut() { AscendC::LocalTensor<T> srcLocal = queueSrc.DeQue<T>(); // 开启原子MAX模式,3个核取最大值 AscendC::SetAtomicMax<T>(); AscendC::DataCopy(dstGlobal, srcLocal, SIZE); // 关闭原子操作 AscendC::DisableDmaAtomic(); queueSrc.FreeTensor(srcLocal); } 每个核的输入数据为: Src0: [1,1,1,1,1,...,1] // 256个1 Src1: [2,2,2,2,2,...,2] // 256个2 最终输出数据: [2,2,2,2,2,...,2] // 256个2 |