Skip to content

Commit 4bc1029

Browse files
authored
[OpenCL] Add SPV_KHR_integer_dot_product support (#301)
* [OpenCL] Add SPV_KHR_integer_dot_product support This is backporting of https://reviews.llvm.org/D106434 Signed-off-by: haonanya <[email protected]> * Add missing tableGen definitions Signed-off-by: haonanya <[email protected]>
1 parent f61a451 commit 4bc1029

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
From 54802abece1e4742050795162e3a773f0e143aa3 Mon Sep 17 00:00:00 2001
2+
From: haonanya <[email protected]>
3+
Date: Fri, 24 Dec 2021 15:27:46 +0800
4+
Subject: [PATCH] [OpenCL] 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 d94d64372dbb..b55d9601a452 100644
22+
--- a/clang/lib/Headers/opencl-c-base.h
23+
+++ b/clang/lib/Headers/opencl-c-base.h
24+
@@ -40,6 +40,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(__SPIR__)
32+
#endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
33+
34+
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
35+
index 501a04f6e82b..50dcc03955cb 100644
36+
--- a/clang/lib/Headers/opencl-c.h
37+
+++ b/clang/lib/Headers/opencl-c.h
38+
@@ -16362,6 +16362,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 745363a6b43f..3c5f8821063d 100644
71+
--- a/clang/lib/Sema/OpenCLBuiltins.td
72+
+++ b/clang/lib/Sema/OpenCLBuiltins.td
73+
@@ -1482,6 +1482,31 @@ let Extension = FuncExtKhrSubgroups in {
74+
}
75+
}
76+
77+
+// Section 42.3 - cl_khr_integer_dot_product
78+
+let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
79+
+ def : Builtin<"dot", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>], Attr.Const>;
80+
+ def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<Char, 4>], Attr.Const>;
81+
+ def : Builtin<"dot", [Int, VectorType<UChar, 4>, VectorType<Char, 4>], Attr.Const>;
82+
+ def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<UChar, 4>], Attr.Const>;
83+
+
84+
+ def : Builtin<"dot_acc_sat", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt], Attr.Const>;
85+
+ def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int], Attr.Const>;
86+
+ def : Builtin<"dot_acc_sat", [Int, VectorType<UChar, 4>, VectorType<Char, 4>, Int], Attr.Const>;
87+
+ def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<UChar, 4>, Int], Attr.Const>;
88+
+}
89+
+
90+
+let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
91+
+ def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
92+
+ def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
93+
+ def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
94+
+ def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
95+
+
96+
+ def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>;
97+
+ def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>;
98+
+ def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>;
99+
+ def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>;
100+
+}
101+
+
102+
//--------------------------------------------------------------------
103+
// Arm extensions.
104+
let Extension = ArmIntegerDotProductInt8 in {
105+
diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl
106+
index 443f682c711a..184eefd9f9c3 100644
107+
--- a/clang/test/Headers/opencl-c-header.cl
108+
+++ b/clang/test/Headers/opencl-c-header.cl
109+
@@ -166,6 +166,15 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
110+
#if __opencl_c_ext_fp64_local_atomic_min_max != 1
111+
#error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
112+
#endif
113+
+#if cl_khr_integer_dot_product != 1
114+
+#error "Incorrectly defined cl_khr_integer_dot_product"
115+
+#endif
116+
+#if __opencl_c_integer_dot_product_input_4x8bit != 1
117+
+#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit"
118+
+#endif
119+
+#if __opencl_c_integer_dot_product_input_4x8bit_packed != 1
120+
+#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed"
121+
+#endif
122+
123+
#else
124+
125+
@@ -232,6 +241,15 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
126+
#ifdef __opencl_c_ext_fp64_local_atomic_min_max
127+
#error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
128+
#endif
129+
+#ifdef cl_khr_integer_dot_product
130+
+#error "Incorrect cl_khr_integer_dot_product define"
131+
+#endif
132+
+#ifdef __opencl_c_integer_dot_product_input_4x8bit
133+
+#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define"
134+
+#endif
135+
+#ifdef __opencl_c_integer_dot_product_input_4x8bit_packed
136+
+#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define"
137+
+#endif
138+
139+
#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
140+
141+
--
142+
2.17.1
143+

0 commit comments

Comments
 (0)