Skip to content

Commit 9e0b2b6

Browse files
authored
[libclc] Don't rely on fp16 pragma guards in headers (#122751)
Having the fp16 pragmas enabled in the header file is risky. The macros defined by that header don't (and can't) include the pragmas that make fp16 types themselves legal, and another header may disable the fp16 pragma before the macro's use. The safest thing to do is the use of pragmas surrounding each use of the macro in the implementation files. This pattern is also far more common across the codebase.
1 parent ef37c3d commit 9e0b2b6

File tree

23 files changed

+133
-0
lines changed

23 files changed

+133
-0
lines changed

libclc/clc/include/clc/clcmacro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@
227227
} \
228228
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, FUNCTION, half, half)
229229

230+
#pragma OPENCL EXTENSION cl_khr_fp16 : disable
231+
230232
#else
231233

232234
#define _CLC_DEFINE_UNARY_BUILTIN_FP16(FUNCTION)

libclc/generic/lib/math/acos.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, acos, double);
172172

173173
#endif // cl_khr_fp64
174174

175+
#ifdef cl_khr_fp16
176+
177+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
178+
175179
_CLC_DEFINE_UNARY_BUILTIN_FP16(acos)
180+
181+
#endif

libclc/generic/lib/math/acosh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, acosh, double)
126126

127127
#endif
128128

129+
#ifdef cl_khr_fp16
130+
131+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
132+
129133
_CLC_DEFINE_UNARY_BUILTIN_FP16(acosh)
134+
135+
#endif

libclc/generic/lib/math/acospi.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, acospi, double)
171171

172172
#endif
173173

174+
#ifdef cl_khr_fp16
175+
176+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
177+
174178
_CLC_DEFINE_UNARY_BUILTIN_FP16(acospi)
179+
180+
#endif

libclc/generic/lib/math/asinh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, asinh, double)
292292

293293
#endif
294294

295+
#ifdef cl_khr_fp16
296+
297+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
298+
295299
_CLC_DEFINE_UNARY_BUILTIN_FP16(asinh)
300+
301+
#endif

libclc/generic/lib/math/atan.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atan, double);
182182

183183
#endif // cl_khr_fp64
184184

185+
#ifdef cl_khr_fp16
186+
187+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
185188

186189
_CLC_DEFINE_UNARY_BUILTIN_FP16(atan)
190+
191+
#endif

libclc/generic/lib/math/atan2.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,10 @@ _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atan2, double, double);
236236

237237
#endif
238238

239+
#ifdef cl_khr_fp16
240+
241+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
242+
239243
_CLC_DEFINE_BINARY_BUILTIN_FP16(atan2)
244+
245+
#endif

libclc/generic/lib/math/atan2pi.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,10 @@ _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atan2pi, double, double)
220220

221221
#endif
222222

223+
#ifdef cl_khr_fp16
224+
225+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
226+
223227
_CLC_DEFINE_BINARY_BUILTIN_FP16(atan2pi)
228+
229+
#endif

libclc/generic/lib/math/atanh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atanh, double)
112112

113113
#endif
114114

115+
#ifdef cl_khr_fp16
116+
117+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
118+
115119
_CLC_DEFINE_UNARY_BUILTIN_FP16(atanh)
120+
121+
#endif

libclc/generic/lib/math/atanpi.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atanpi, double)
181181

182182
#endif
183183

184+
#ifdef cl_khr_fp16
185+
186+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
187+
184188
_CLC_DEFINE_UNARY_BUILTIN_FP16(atanpi)
189+
190+
#endif

libclc/generic/lib/math/cbrt.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, cbrt, double)
150150

151151
#endif
152152

153+
#ifdef cl_khr_fp16
154+
155+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
156+
153157
_CLC_DEFINE_UNARY_BUILTIN_FP16(cbrt)
158+
159+
#endif

libclc/generic/lib/math/cos.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, cos, double);
7676

7777
#endif
7878

79+
#ifdef cl_khr_fp16
80+
81+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
82+
7983
_CLC_DEFINE_UNARY_BUILTIN_FP16(cos)
84+
85+
#endif

libclc/generic/lib/math/cosh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, cosh, double)
191191

192192
#endif
193193

194+
#ifdef cl_khr_fp16
195+
196+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
197+
194198
_CLC_DEFINE_UNARY_BUILTIN_FP16(cosh)
199+
200+
#endif

libclc/generic/lib/math/cospi.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@ _CLC_OVERLOAD _CLC_DEF double cospi(double x) {
135135
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, cospi, double);
136136
#endif
137137

138+
#ifdef cl_khr_fp16
139+
140+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
141+
138142
_CLC_DEFINE_UNARY_BUILTIN_FP16(cospi)
143+
144+
#endif

libclc/generic/lib/math/exp.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, exp, double)
8989

9090
#endif
9191

92+
#ifdef cl_khr_fp16
93+
94+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
95+
9296
_CLC_DEFINE_UNARY_BUILTIN_FP16(exp)
97+
98+
#endif

libclc/generic/lib/math/expm1.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, expm1, double)
141141

142142
#endif
143143

144+
#ifdef cl_khr_fp16
145+
146+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
147+
144148
_CLC_DEFINE_UNARY_BUILTIN_FP16(expm1)
149+
150+
#endif

libclc/generic/lib/math/lgamma.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, lgamma, double)
4343

4444
#endif
4545

46+
#ifdef cl_khr_fp16
47+
48+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
49+
4650
_CLC_DEFINE_UNARY_BUILTIN_FP16(lgamma)
51+
52+
#endif

libclc/generic/lib/math/log1p.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, log1p, double);
176176

177177
#endif // cl_khr_fp64
178178

179+
#ifdef cl_khr_fp16
180+
181+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
182+
179183
_CLC_DEFINE_UNARY_BUILTIN_FP16(log1p)
184+
185+
#endif

libclc/generic/lib/math/logb.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ _CLC_OVERLOAD _CLC_DEF double logb(double x) {
3030
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, logb, double)
3131
#endif
3232

33+
#ifdef cl_khr_fp16
34+
35+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
36+
3337
_CLC_DEFINE_UNARY_BUILTIN_FP16(logb)
38+
39+
#endif

libclc/generic/lib/math/sin.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, sin, double);
7878

7979
#endif
8080

81+
#ifdef cl_khr_fp16
82+
83+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
84+
8185
_CLC_DEFINE_UNARY_BUILTIN_FP16(sin)
86+
87+
#endif

libclc/generic/lib/math/sinh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, sinh, double)
190190

191191
#endif
192192

193+
#ifdef cl_khr_fp16
194+
195+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
196+
193197
_CLC_DEFINE_UNARY_BUILTIN_FP16(sinh)
198+
199+
#endif

libclc/generic/lib/math/sinpi.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, sinpi, double)
130130

131131
#endif
132132

133+
#ifdef cl_khr_fp16
134+
135+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
136+
133137
_CLC_DEFINE_UNARY_BUILTIN_FP16(sinpi)
138+
139+
#endif

libclc/generic/lib/math/tanh.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,10 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, tanh, double);
145145

146146
#endif // cl_khr_fp64
147147

148+
#ifdef cl_khr_fp16
149+
150+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
151+
148152
_CLC_DEFINE_UNARY_BUILTIN_FP16(tanh)
153+
154+
#endif

0 commit comments

Comments
 (0)