Skip to content

Commit 9e0b2b6

Browse files
authored
[libclc] Don't rely on fp16 pragma guards in headers (llvm#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

0 commit comments

Comments
 (0)