[PATCH] D95523: [OpenCL] Add cl_khr_subgroup_ballot to TableGen BIFs

Sven van Haastregt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 28 07:01:24 PST 2021


svenvh updated this revision to Diff 319860.
svenvh added a comment.

Add test after rebasing on dependent commit (D95616 <https://reviews.llvm.org/D95616>).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95523/new/

https://reviews.llvm.org/D95523

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


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===================================================================
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -30,6 +30,11 @@
 typedef int int4 __attribute__((ext_vector_type(4)));
 typedef uint uint4 __attribute__((ext_vector_type(4)));
 typedef long long2 __attribute__((ext_vector_type(2)));
+
+// Enable extensions that are enabled in opencl-c-base.h.
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+#define cl_khr_subgroup_ballot 1
+#endif
 #endif
 
 kernel void test_pointers(volatile global void *global_p, global const int4 *a) {
@@ -132,6 +137,14 @@
 #endif
 }
 
+kernel void extended_subgroup(global uint4 *out) {
+  out[0] = get_sub_group_eq_mask();
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(__OPENCL_CPP_VERSION__)
+  // expected-error at -2{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}}
+  // expected-error at -3{{implicit conversion changes signedness}}
+#endif
+}
+
 kernel void basic_vector_data() {
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
   generic void *generic_p;
Index: clang/lib/Sema/OpenCLBuiltins.td
===================================================================
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -53,6 +53,7 @@
 // FunctionExtension definitions.
 def FuncExtNone                          : FunctionExtension<"">;
 def FuncExtKhrSubgroups                  : FunctionExtension<"cl_khr_subgroups">;
+def FuncExtKhrSubgroupBallot             : FunctionExtension<"cl_khr_subgroup_ballot">;
 def FuncExtKhrGlobalInt32BaseAtomics     : FunctionExtension<"cl_khr_global_int32_base_atomics">;
 def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
 def FuncExtKhrLocalInt32BaseAtomics      : FunctionExtension<"cl_khr_local_int32_base_atomics">;
@@ -344,6 +345,7 @@
 // GenType definitions for multiple base types (e.g. all floating point types,
 // or all integer types).
 // All types
+def AGenType1              : GenericType<"AGenType1", TLAll, Vec1>;
 def AGenTypeN              : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
 def AGenTypeNNoScalar      : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
 // All integer
@@ -1486,6 +1488,44 @@
   }
 }
 
+// OpenCL Extension v3.0 s38 - Extended Subgroup Functions
+
+// Section 38.4.1 - cl_khr_subgroup_extended_types
+// TODO
+
+// Section 38.5.1 - cl_khr_subgroup_non_uniform_vote
+// TODO
+
+// Section 38.6.1 - cl_khr_subgroup_ballot
+let Extension = FuncExtKhrSubgroupBallot in {
+  def : Builtin<"sub_group_non_uniform_broadcast", [AGenTypeN, AGenTypeN, UInt]>;
+  def : Builtin<"sub_group_broadcast_first", [AGenType1, AGenType1]>;
+  def : Builtin<"sub_group_ballot", [VectorType<UInt, 4>, Int]>;
+  def : Builtin<"sub_group_inverse_ballot", [Int, VectorType<UInt, 4>], Attr.Const>;
+  def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType<UInt, 4>, UInt], Attr.Const>;
+  def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType<UInt, 4>], Attr.Const>;
+  def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType<UInt, 4>]>;
+  def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType<UInt, 4>]>;
+  def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType<UInt, 4>]>;
+  def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType<UInt, 4>]>;
+
+  foreach op = ["eq", "ge", "gt", "le", "lt"] in {
+    def : Builtin<"get_sub_group_" # op # "_mask", [VectorType<UInt, 4>], Attr.Const>;
+  }
+}
+
+// Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic
+// TODO
+
+// Section 38.8.1 - cl_khr_subgroup_shuffle
+// TODO
+
+// Section 38.9.1 - cl_khr_subgroup_shuffle_relative
+// TODO
+
+// Section 38.10.1 - cl_khr_subgroup_clustered_reduce
+// TODO
+
 //--------------------------------------------------------------------
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95523.319860.patch
Type: text/x-patch
Size: 4011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210128/d4d3c8d9/attachment.bin>


More information about the cfe-commits mailing list