SetAtomicType
产品支持情况
产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
x |
功能说明
通过设置模板参数来设定原子操作不同的数据类型。
函数原型
1 2 | template <typename T> __aicore__ inline void SetAtomicType() |
参数说明
参数名 |
描述 |
|---|---|
T |
设定不同的数据类型。 Ascend 950PR/Ascend 950DT, 支持int8_t/int16_t/half/bfloat16_t/int32_t/float |
返回值说明
无
约束说明
- SetAtomicAdd、SetAtomicMax、SetAtomicMin内部已集成与SetAtomicType相同的功能。建议调用上述接口时,通过设置模板参数显式指定原子操作的数据类型,无需额外调用SetAtomicType接口。
- 使用完成后,建议使用DisableDmaAtomic清空原子操作的状态,以免影响后续相关指令功能。
调用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 本演示示例使用DataCopy从VECOUT搬出到外部dstGlobal时进行原子最小,并调用SetAtomicType修改原子最小的数据类型。 #include "kernel_operator.h" // 初始化dst0Local与dst1Local AscendC::LocalTensor<T> dst0Local = queueDst0.DeQue<T>(); AscendC::LocalTensor<T> dst1Local = queueDst1.DeQue<T>(); // VECOUT dst1Local搬出到外部dstGlobal AscendC::DataCopy(dstGlobal, dst1Local, size); AscendC::PipeBarrier<PIPE_MTE3>(); // 设置后续传输时原子比较,将待拷贝的内容和GM已有内容进行比较,将最小值写入GM。 AscendC::SetAtomicMin<int8_t>(); // 此处设置的类型可随意,此例中以int8_t为例 AscendC::SetAtomicType<T>(); // 此处设置真实的数据类型 // VECOUT dst0Local原子比较搬出到外部dstGlobal AscendC::DataCopy(dstGlobal, dst0Local, size); queueDst0.FreeTensor(dst0Local); queueDst1.FreeTensor(dst1Local); // 清空原子操作的状态 AscendC::DisableDmaAtomic(); |
每个核的输入数据为: Src0: [1,1,1,1,1,...,1] // 256个1 Src1: [2,2,2,2,2,...,2] // 256个2 最终输出数据: [1,1,1,1,1,...,1] // 256个1
父主题: 原子操作