[clang] 9da6a40 - [OpenCL] Add sub-group builtin functions

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 2 05:19:49 PDT 2020


Author: Sven van Haastregt
Date: 2020-04-02T13:18:56+01:00
New Revision: 9da6a40e0999523f8bdabfdab875890770eb9b3a

URL: https://github.com/llvm/llvm-project/commit/9da6a40e0999523f8bdabfdab875890770eb9b3a
DIFF: https://github.com/llvm/llvm-project/commit/9da6a40e0999523f8bdabfdab875890770eb9b3a.diff

LOG: [OpenCL] Add sub-group builtin functions

Add the sub-group builtin functions from the OpenCL Extension
specification.  This patch excludes the sub_group_barrier builtins
that take argument types not yet handled by the
`-fdeclare-opencl-builtins` machinery.

Co-authored-by: Pierre Gondois <pierre.gondois at arm.com>

Added: 
    

Modified: 
    clang/lib/Sema/OpenCLBuiltins.td
    clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 40798b744ced..745363a6b43f 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1273,15 +1273,6 @@ def : Builtin<"get_default_queue", [Queue]>;
 // TODO: ndrange functions
 
 
-// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
-let MinVersion = CL20 in {
-  let Extension = FuncExtKhrSubgroups in {
-    def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
-    def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
-    def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
-  }
-}
-
 //--------------------------------------------------------------------
 // End of the builtin functions defined in the OpenCL C specification.
 // Builtin functions defined in the OpenCL C Extension are below.
@@ -1456,6 +1447,41 @@ let Extension = FuncExtKhrGlMsaaSharing in {
   }
 }
 
+//--------------------------------------------------------------------
+// OpenCL Extension v2.0 s28 - Subgroups
+// --- Table 28.2.1 ---
+let Extension = FuncExtKhrSubgroups in {
+  foreach name = ["get_sub_group_size", "get_max_sub_group_size",
+                  "get_num_sub_groups", "get_sub_group_id",
+                  "get_sub_group_local_id"] in {
+    def : Builtin<name, [UInt]>;
+  }
+  let MinVersion = CL20 in {
+    foreach name = ["get_enqueued_num_sub_groups"] in {
+      def : Builtin<name, [UInt]>;
+    }
+  }
+}
+
+// --- Table 28.2.2 ---
+// TODO: sub_group_barrier
+
+// --- Table 28.2.4 ---
+let Extension = FuncExtKhrSubgroups in {
+  foreach name = ["sub_group_all", "sub_group_any"] in {
+    def : Builtin<name, [Int, Int], Attr.Convergent>;
+  }
+  foreach name = ["sub_group_broadcast"] in {
+    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, UInt], Attr.Convergent>;
+  }
+  foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
+                  "sub_group_scan_inclusive_"] in {
+    foreach op = ["add", "min", "max"] in {
+      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
+    }
+  }
+}
+
 //--------------------------------------------------------------------
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index e593b21ec459..d1dcdfe8cb35 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -140,14 +140,11 @@ kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_i
 
 kernel void basic_subgroup(global uint *out) {
   out[0] = get_sub_group_size();
-#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
-// expected-error at -2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
-// expected-error at -3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
-#elif defined(__OPENCL_CPP_VERSION__)
-// expected-error at -5{{no matching function for call to 'get_sub_group_size'}}
-// expected-note at -6{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}}
+#if defined(__OPENCL_CPP_VERSION__)
+  // expected-error at -2{{no matching function for call to 'get_sub_group_size'}}
+  // expected-note at -3{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}}
 #else
-// expected-error at -8{{use of declaration 'get_sub_group_size' requires cl_khr_subgroups extension to be enabled}}
+  // expected-error at -5{{use of declaration 'get_sub_group_size' requires cl_khr_subgroups extension to be enabled}}
 #endif
 }
 


        


More information about the cfe-commits mailing list