1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can 5 * be found in the LICENSE file. 6 * 7 */ 8 9 #ifndef SKC_ONCE_ATOMIC_CL 10 #define SKC_ONCE_ATOMIC_CL 11 12 // 13 // git cl upload is bleating about needing an #include before and #if 14 // so we're unneccesarily reloading the types and OpenCL header 15 // 16 17 #include "types.h" 18 19 #if (__OPENCL_C_VERSION__ <= 120 /*CL_VERSION_1_2*/) 20 21 #define SKC_ATOMIC_UINT uint 22 #define SKC_ATOMIC_INT int 23 24 #define SKC_ATOMIC_ADD_LOCAL_RELAXED_DEVICE(p,v) atomic_add(p,v) 25 #define SKC_ATOMIC_ADD_LOCAL_RELAXED_SUBGROUP(p,v) atomic_add(p,v) 26 27 #define SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE(p,v) atomic_add(p,v) 28 #define SKC_ATOMIC_ADD_GLOBAL_RELAXED_SUBGROUP(p,v) atomic_add(p,v) 29 30 #else // __OPENCL_C_VERSION__ > __CL_VERSION_1_2 31 32 // 33 // REMOVE THESE DEFINES ASAP -- ONLY HERE BECAUSE THE INTEL CODE 34 // BUILDER UTILITY DOESN'T SUPPORT CREATING AN ATOMIC TYPE BUFFER 35 // 36 37 #ifdef SKC_SUPPORT_BROKEN_INTEL_CODE_BUILDER 38 39 #define SKC_ATOMIC_UINT uint 40 #define SKC_ATOMIC_CAST_LOCAL(p) (__local atomic_uint volatile * restrict const)(p) 41 #define SKC_ATOMIC_CAST_GLOBAL(p) (__global atomic_uint volatile * restrict const)(p) 42 43 #else 44 45 #define SKC_ATOMIC_UINT atomic_uint 46 #define SKC_ATOMIC_CAST_LOCAL(p) (p) 47 #define SKC_ATOMIC_CAST_GLOBAL(p) (p) 48 49 #endif 50 51 52 #define SKC_ATOMIC_ADD_LOCAL_RELAXED_DEVICE(p,v) atomic_fetch_add_explicit(SKC_ATOMIC_CAST_LOCAL(p), \ 53 v,memory_order_relaxed,memory_scope_device) 54 #define SKC_ATOMIC_ADD_LOCAL_RELAXED_SUBGROUP(p,v) atomic_fetch_add_explicit(SKC_ATOMIC_CAST_LOCAL(p), \ 55 v,memory_order_relaxed,memory_scope_sub_group) 56 57 #define SKC_ATOMIC_ADD_GLOBAL_RELAXED_DEVICE(p,v) atomic_fetch_add_explicit(SKC_ATOMIC_CAST_GLOBAL(p), \ 58 v,memory_order_relaxed,memory_scope_device) 59 #define SKC_ATOMIC_ADD_GLOBAL_RELAXED_SUBGROUP(p,v) atomic_fetch_add_explicit(SKC_ATOMIC_CAST_GLOBAL(p), \ 60 v,memory_order_relaxed,memory_scope_sub_group) 61 62 #endif 63 64 // 65 // 66 // 67 68 #endif // SKC_ONCE_ATOMIC_CL 69 70 // 71 // 72 // 73