17 #ifndef __UTIL_ATOMIC_H__
18 #define __UTIL_ATOMIC_H__
20 #ifndef __KERNEL_GPU__
25 # define atomic_add_and_fetch_float(p, x) atomic_add_and_fetch_fl((p), (x))
26 # define atomic_compare_and_swap_float(p, old_val, new_val) \
27 atomic_cas_float((p), (old_val), (new_val))
29 # define atomic_fetch_and_inc_uint32(p) atomic_fetch_and_add_uint32((p), 1)
30 # define atomic_fetch_and_dec_uint32(p) atomic_fetch_and_add_uint32((p), -1)
32 # define CCL_LOCAL_MEM_FENCE 0
33 # define ccl_barrier(flags) ((void)0)
37 # ifdef __KERNEL_OPENCL__
46 unsigned int int_value;
50 unsigned int int_value;
54 prev_value.float_value = *source;
55 new_value.float_value = prev_value.float_value + operand;
56 }
while (atomic_cmpxchg((
volatile ccl_global unsigned int *)source,
58 new_value.int_value) != prev_value.int_value);
59 return new_value.float_value;
67 unsigned int int_value;
69 } new_value, prev_value,
result;
70 prev_value.float_value = old_val;
71 new_value.float_value = new_val;
72 result.int_value = atomic_cmpxchg(
73 (
volatile ccl_global unsigned int *)dest, prev_value.int_value, new_value.int_value);
77 # define atomic_fetch_and_add_uint32(p, x) atomic_add((p), (x))
78 # define atomic_fetch_and_inc_uint32(p) atomic_inc((p))
79 # define atomic_fetch_and_dec_uint32(p) atomic_dec((p))
80 # define atomic_fetch_and_or_uint32(p, x) atomic_or((p), (x))
82 # define CCL_LOCAL_MEM_FENCE CLK_LOCAL_MEM_FENCE
83 # define ccl_barrier(flags) barrier(flags)
87 # ifdef __KERNEL_CUDA__
89 # define atomic_add_and_fetch_float(p, x) (atomicAdd((float *)(p), (float)(x)) + (float)(x))
91 # define atomic_fetch_and_add_uint32(p, x) atomicAdd((unsigned int *)(p), (unsigned int)(x))
92 # define atomic_fetch_and_sub_uint32(p, x) atomicSub((unsigned int *)(p), (unsigned int)(x))
93 # define atomic_fetch_and_inc_uint32(p) atomic_fetch_and_add_uint32((p), 1)
94 # define atomic_fetch_and_dec_uint32(p) atomic_fetch_and_sub_uint32((p), 1)
95 # define atomic_fetch_and_or_uint32(p, x) atomicOr((unsigned int *)(p), (unsigned int)(x))
102 unsigned int int_value;
104 } new_value, prev_value,
result;
105 prev_value.float_value = old_val;
106 new_value.float_value = new_val;
107 result.int_value = atomicCAS((
unsigned int *)dest, prev_value.int_value, new_value.int_value);
108 return result.float_value;
111 # define CCL_LOCAL_MEM_FENCE
112 # define ccl_barrier(flags) __syncthreads()
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
#define ccl_device_inline
#define atomic_compare_and_swap_float(p, old_val, new_val)
#define atomic_add_and_fetch_float(p, x)