Author: Sven van Haastregt Date: 2021-06-08T11:51:12+01:00 New Revision: d54e7b731e662e3ec19c590172c9827e3e184829
URL: https://github.com/llvm/llvm-project/commit/d54e7b731e662e3ec19c590172c9827e3e184829 DIFF: https://github.com/llvm/llvm-project/commit/d54e7b731e662e3ec19c590172c9827e3e184829.diff LOG: [OpenCL] Add memory_scope_all_devices Add the `memory_scope_all_devices` enum value, which is restricted to OpenCL 3.0 or newer and the `__opencl_c_atomic_scope_all_devices` feature. Also guard `memory_scope_all_svm_devices` accordingly, which is already available in OpenCL 2.0. The `__opencl_c_atomic_scope_all_devices` feature is header-only, so set its define to 1 in `opencl-c-base.h`. This is done unconditionally at the moment, as the mechanism for disabling header-only options hasn't been decided yet. This patch only adds a negative test for now. Ideally adding a CL3.0 run line to atomic-ops.cl should suffice as a positive test, but we cannot do that yet until (at least) generic address spaces and program scope variables are supported in OpenCL 3.0 mode. Differential Revision: https://reviews.llvm.org/D103241 Added: Modified: clang/lib/Headers/opencl-c-base.h clang/test/Headers/opencl-c-header.cl clang/test/SemaOpenCL/atomic-ops.cl Removed: ################################################################################ diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 72f8c2576ebd3..c9c1bda140384 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -39,6 +39,14 @@ #define __opencl_c_images 1 #endif +// Define header-only feature macros for OpenCL C 3.0. +#if (__OPENCL_C_VERSION__ == 300) +// For the SPIR target all features are supported. +#if defined(__SPIR__) +#define __opencl_c_atomic_scope_all_devices 1 +#endif // defined(__SPIR__) +#endif // (__OPENCL_C_VERSION__ == 300) + // built-in scalar data types: /** @@ -312,7 +320,12 @@ typedef enum memory_scope { memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM, memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP, memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE, +#if defined(__opencl_c_atomic_scope_all_devices) memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES, +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0) + memory_scope_all_devices = memory_scope_all_svm_devices, +#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#endif // defined(__opencl_c_atomic_scope_all_devices) #if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP #endif diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl index 2ab5c5af1facb..4e4545ef529d5 100644 --- a/clang/test/Headers/opencl-c-header.cl +++ b/clang/test/Headers/opencl-c-header.cl @@ -151,7 +151,13 @@ global atomic_int z = ATOMIC_VAR_INIT(99); #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) // OpenCL C features. -#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#if (__OPENCL_C_VERSION__ == 300) + +#if __opencl_c_atomic_scope_all_devices != 1 +#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices" +#endif + +#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) #ifndef __opencl_c_pipes #error "Feature macro __opencl_c_pipes should be defined" diff --git a/clang/test/SemaOpenCL/atomic-ops.cl b/clang/test/SemaOpenCL/atomic-ops.cl index 8d150d0fd9297..728c07540a4bd 100644 --- a/clang/test/SemaOpenCL/atomic-ops.cl +++ b/clang/test/SemaOpenCL/atomic-ops.cl @@ -2,6 +2,7 @@ // RUN: -fsyntax-only -triple=spir64 -fdeclare-opencl-builtins -finclude-default-header // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only \ // RUN: -triple=amdgcn-amd-amdhsa -fdeclare-opencl-builtins -finclude-default-header +// TODO: add -cl-std=CL3.0 line when generic and psv are supported. // Basic parsing/Sema tests for __opencl_atomic_* @@ -161,6 +162,11 @@ void synchscope_checks(atomic_int *Ap, int scope) { (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_work_group); (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_device); (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_all_svm_devices); + (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_all_devices); +#if __OPENCL_C_VERSION__ < CL_VERSION_3_0 + // expected-error@-2{{use of undeclared identifier 'memory_scope_all_devices'}} + // expected-note@* {{'memory_scope_all_svm_devices' declared here}} +#endif (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_sub_group); (void)__opencl_atomic_load(Ap, memory_order_relaxed, scope); (void)__opencl_atomic_load(Ap, memory_order_relaxed, 10); //expected-error{{synchronization scope argument to atomic operation is invalid}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits