|
| 1 | +From 9a1886d1b70b4bf452f201ff1268194e21bd686c Mon Sep 17 00:00:00 2001 |
| 2 | +From: haonanya < [email protected]> |
| 3 | +Date: Fri, 24 Dec 2021 10:12:19 +0800 |
| 4 | +Subject: [PATCH] Add cl_khr_integer_dot_product |
| 5 | + |
| 6 | +This is backporting of https://reviews.llvm.org/D106434 |
| 7 | +Add the builtins defined by Section 42 "Integer dot product" in the OpenCL |
| 8 | +Extension Specification. |
| 9 | + |
| 10 | +See https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_integer_dot_product |
| 11 | + |
| 12 | +Signed-off-by: haonanya < [email protected]> |
| 13 | +--- |
| 14 | + clang/lib/Headers/opencl-c-base.h | 3 +++ |
| 15 | + clang/lib/Headers/opencl-c.h | 24 ++++++++++++++++++++++++ |
| 16 | + clang/lib/Sema/OpenCLBuiltins.td | 25 +++++++++++++++++++++++++ |
| 17 | + clang/test/Headers/opencl-c-header.cl | 18 ++++++++++++++++++ |
| 18 | + 4 files changed, 70 insertions(+) |
| 19 | + |
| 20 | +diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h |
| 21 | +index 18d367de68ec..f612e85a1797 100644 |
| 22 | +--- a/clang/lib/Headers/opencl-c-base.h |
| 23 | ++++ b/clang/lib/Headers/opencl-c-base.h |
| 24 | +@@ -34,6 +34,9 @@ |
| 25 | + #define __opencl_c_ext_fp32_local_atomic_add 1 |
| 26 | + #define __opencl_c_ext_fp32_global_atomic_min_max 1 |
| 27 | + #define __opencl_c_ext_fp32_local_atomic_min_max 1 |
| 28 | ++#define cl_khr_integer_dot_product 1 |
| 29 | ++#define __opencl_c_integer_dot_product_input_4x8bit 1 |
| 30 | ++#define __opencl_c_integer_dot_product_input_4x8bit_packed 1 |
| 31 | + #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) |
| 32 | + |
| 33 | + // Define features for 2.0 for header backward compatibility |
| 34 | +diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h |
| 35 | +index 454469991d59..225d9a47abfe 100644 |
| 36 | +--- a/clang/lib/Headers/opencl-c.h |
| 37 | ++++ b/clang/lib/Headers/opencl-c.h |
| 38 | +@@ -18428,6 +18428,30 @@ double __ovld sub_group_clustered_reduce_max( double value, uint clustersize ); |
| 39 | + |
| 40 | + #endif // cl_khr_subgroup_clustered_reduce |
| 41 | + |
| 42 | ++#if defined(__opencl_c_integer_dot_product_input_4x8bit) |
| 43 | ++uint __ovld __cnfn dot(uchar4, uchar4); |
| 44 | ++int __ovld __cnfn dot(char4, char4); |
| 45 | ++int __ovld __cnfn dot(uchar4, char4); |
| 46 | ++int __ovld __cnfn dot(char4, uchar4); |
| 47 | ++ |
| 48 | ++uint __ovld __cnfn dot_acc_sat(uchar4, uchar4, uint); |
| 49 | ++int __ovld __cnfn dot_acc_sat(char4, char4, int); |
| 50 | ++int __ovld __cnfn dot_acc_sat(uchar4, char4, int); |
| 51 | ++int __ovld __cnfn dot_acc_sat(char4, uchar4, int); |
| 52 | ++#endif // __opencl_c_integer_dot_product_input_4x8bit |
| 53 | ++ |
| 54 | ++#if defined(__opencl_c_integer_dot_product_input_4x8bit_packed) |
| 55 | ++uint __ovld __cnfn dot_4x8packed_uu_uint(uint, uint); |
| 56 | ++int __ovld __cnfn dot_4x8packed_ss_int(uint, uint); |
| 57 | ++int __ovld __cnfn dot_4x8packed_us_int(uint, uint); |
| 58 | ++int __ovld __cnfn dot_4x8packed_su_int(uint, uint); |
| 59 | ++ |
| 60 | ++uint __ovld __cnfn dot_acc_sat_4x8packed_uu_uint(uint, uint, uint); |
| 61 | ++int __ovld __cnfn dot_acc_sat_4x8packed_ss_int(uint, uint, int); |
| 62 | ++int __ovld __cnfn dot_acc_sat_4x8packed_us_int(uint, uint, int); |
| 63 | ++int __ovld __cnfn dot_acc_sat_4x8packed_su_int(uint, uint, int); |
| 64 | ++#endif // __opencl_c_integer_dot_product_input_4x8bit_packed |
| 65 | ++ |
| 66 | + #if defined(cl_intel_subgroups) |
| 67 | + // Intel-Specific Sub Group Functions |
| 68 | + float __ovld __conv intel_sub_group_shuffle( float x, uint c ); |
| 69 | +diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td |
| 70 | +index d352d35f1e46..d2f8e0a407d4 100644 |
| 71 | +--- a/clang/lib/Sema/OpenCLBuiltins.td |
| 72 | ++++ b/clang/lib/Sema/OpenCLBuiltins.td |
| 73 | +@@ -1366,3 +1366,28 @@ let Extension = FuncExtKhrGlMsaaSharing in { |
| 74 | + def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>; |
| 75 | + } |
| 76 | + } |
| 77 | ++ |
| 78 | ++// Section 42.3 - cl_khr_integer_dot_product |
| 79 | ++let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in { |
| 80 | ++ def : Builtin<"dot", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>], Attr.Const>; |
| 81 | ++ def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<Char, 4>], Attr.Const>; |
| 82 | ++ def : Builtin<"dot", [Int, VectorType<UChar, 4>, VectorType<Char, 4>], Attr.Const>; |
| 83 | ++ def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<UChar, 4>], Attr.Const>; |
| 84 | ++ |
| 85 | ++ def : Builtin<"dot_acc_sat", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt], Attr.Const>; |
| 86 | ++ def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int], Attr.Const>; |
| 87 | ++ def : Builtin<"dot_acc_sat", [Int, VectorType<UChar, 4>, VectorType<Char, 4>, Int], Attr.Const>; |
| 88 | ++ def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<UChar, 4>, Int], Attr.Const>; |
| 89 | ++} |
| 90 | ++ |
| 91 | ++let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in { |
| 92 | ++ def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>; |
| 93 | ++ def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>; |
| 94 | ++ def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>; |
| 95 | ++ def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>; |
| 96 | ++ |
| 97 | ++ def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>; |
| 98 | ++ def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>; |
| 99 | ++ def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>; |
| 100 | ++ def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>; |
| 101 | ++} |
| 102 | +diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl |
| 103 | +index 7f720cf28142..f2771cd6c6ca 100644 |
| 104 | +--- a/clang/test/Headers/opencl-c-header.cl |
| 105 | ++++ b/clang/test/Headers/opencl-c-header.cl |
| 106 | +@@ -146,6 +146,15 @@ global atomic_int z = ATOMIC_VAR_INIT(99); |
| 107 | + #if __opencl_c_ext_fp64_local_atomic_min_max != 1 |
| 108 | + #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max" |
| 109 | + #endif |
| 110 | ++#if cl_khr_integer_dot_product != 1 |
| 111 | ++#error "Incorrectly defined cl_khr_integer_dot_product" |
| 112 | ++#endif |
| 113 | ++#if __opencl_c_integer_dot_product_input_4x8bit != 1 |
| 114 | ++#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit" |
| 115 | ++#endif |
| 116 | ++#if __opencl_c_integer_dot_product_input_4x8bit_packed != 1 |
| 117 | ++#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed" |
| 118 | ++#endif |
| 119 | + #else |
| 120 | + |
| 121 | + #ifdef __opencl_c_ext_fp16_global_atomic_load_store |
| 122 | +@@ -190,6 +199,15 @@ global atomic_int z = ATOMIC_VAR_INIT(99); |
| 123 | + #ifdef __opencl_c_ext_fp64_local_atomic_min_max |
| 124 | + #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined" |
| 125 | + #endif |
| 126 | ++#ifdef cl_khr_integer_dot_product |
| 127 | ++#error "Incorrect cl_khr_integer_dot_product define" |
| 128 | ++#endif |
| 129 | ++#ifdef __opencl_c_integer_dot_product_input_4x8bit |
| 130 | ++#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define" |
| 131 | ++#endif |
| 132 | ++#ifdef __opencl_c_integer_dot_product_input_4x8bit_packed |
| 133 | ++#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define" |
| 134 | ++#endif |
| 135 | + |
| 136 | + #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) |
| 137 | + |
| 138 | +-- |
| 139 | +2.17.1 |
| 140 | + |
0 commit comments