asc_atomic_cas
产品支持情况
功能说明
对Unified Buffer或Global Memory上address的数值进行原子比较赋值操作,如果address上的数值等于指定数值compare,则对address赋值为指定数值val,否则address的数值不变。
函数原型
-
Unified Buffer数据的原子比较赋值操作
__simt_callee__ inline float asc_atomic_cas(__ubuf__ float *address, float compare, float val)__simt_callee__ inline int32_t asc_atomic_cas(__ubuf__ int32_t *address, int32_t compare, int32_t val)__simt_callee__ inline uint32_t asc_atomic_cas(__ubuf__ uint32_t *address, uint32_t compare, uint32_t val)__simt_callee__ inline half2 asc_atomic_cas(__ubuf__ half2 *address, half2 compare, half2 val)__simt_callee__ inline bfloat16x2_t asc_atomic_cas(__ubuf__ bfloat16x2_t *address, bfloat16x2_t compare, bfloat16x2_t val) -
Global Memory数据的原子比较赋值操作
__simt_callee__ inline float asc_atomic_cas(__gm__ float *address, float compare, float val)__simt_callee__ inline int32_t asc_atomic_cas(__gm__ int32_t *address, int32_t compare, int32_t val)__simt_callee__ inline uint32_t asc_atomic_cas(__gm__ uint32_t *address, uint32_t compare, uint32_t val)__simt_callee__ inline int64_t asc_atomic_cas(__gm__ int64_t *address, int64_t compare, int64_t val)__simt_callee__ inline uint64_t asc_atomic_cas(__gm__ uint64_t *address, uint64_t compare, uint64_t val)__simt_callee__ inline half2 asc_atomic_cas(__gm__ half2 *address, half2 compare, half2 val)__simt_callee__ inline bfloat16x2_t asc_atomic_cas(__gm__ bfloat16x2_t *address, bfloat16x2_t compare, bfloat16x2_t val)
参数说明
表 1 参数说明
返回值说明
Unified Buffer或Global Memory上的初始数据。
约束说明
无
需要包含的头文件
使用除half2、bfloat16x2_t类型之外的接口需要包含"simt_api/device_atomic_functions.h"头文件,使用half2类型接口需要包含"simt_api/asc_fp16.h"头文件,使用bfloat16x2_t类型接口需要包含"simt_api/asc_bf16.h"头文件。
#include "simt_api/device_atomic_functions.h"
#include "simt_api/asc_fp16.h"
#include "simt_api/asc_bf16.h"
调用示例
__simt_vf__ __launch_bounds__(1024) inline void KernelAtomicCas(__gm__ int32_t* dst, __gm__ int32_t* src0, __gm__ int32_t* src1)
{
int idx = threadIdx.x + blockIdx.x * blockDim.x;
asc_atomic_cas(dst + idx, src0[idx], src1[idx]);
}