Skip to content

Commit

Permalink
gpu: ocl: remove fallback atomic function path
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonsays095 authored and karturov committed Sep 19, 2023
1 parent 90451cc commit 5987a9b
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/gpu/ocl/ocl_math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,42 +355,24 @@ DECLARE_MMAD_EMU(mmad8x8_bf16, bf16_dot2, 8, 8, short8, int8, float8)
#endif

// Atomics
#if __OPENCL_C_VERSION__ >= 200
#define DECLARE_ATOMIC_OP(op, type) \
type __attribute__((overloadable)) CONCAT3(atomic_, op, _global)( \
volatile global CONCAT2(atomic_, type) * source, type operand) { \
return CONCAT3(atomic_fetch_, op, _explicit)( \
source, operand, memory_order_relaxed); \
}

#if defined(cl_intel_global_float_atomics) \
|| (defined(cl_ext_float_atomics) \
&& defined(__opencl_c_ext_fp32_global_atomic_add))
#if __OPENCL_C_VERSION__ >= 200
// Atomic operations require:
// 1. The cl_ext_float_atomics extension (for all float functions)
// 2. the __opencl_c_ext_fp32_global_atomic_add feature (for float add/sub)
// 3. the __opencl_c_ext_fp32_global_atomic_min_max feature (for float min/max)
// All intel GPUs should support these on up-to-date drivers, for all archs
// gen9 and later
DECLARE_ATOMIC_OP(add, float)
DECLARE_ATOMIC_OP(sub, float)
#else // float atomics
inline float atomic_add_global(
volatile __global atomic_float *source, float operand) {
float old_val = atomic_load_explicit(
source, memory_order_relaxed, memory_scope_device);
bool success = false;
do {
float new_val = old_val + operand;
success = atomic_compare_exchange_strong_explicit(source, &old_val,
new_val, memory_order_acq_rel, memory_order_relaxed,
memory_scope_device);
} while (!success);
return old_val;
}
#endif

#if defined(cl_intel_global_float_atomics) \
|| (defined(cl_ext_float_atomics) \
&& defined(__opencl_c_ext_fp32_global_atomic_min_max))
DECLARE_ATOMIC_OP(min, float)
DECLARE_ATOMIC_OP(max, float)
#endif

#endif

#endif
#endif

0 comments on commit 5987a9b

Please sign in to comment.