[libclc] 9160f49 - libclc: generic: add half implementation for erf/erfc (#66901)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 08:47:58 PST 2024


Author: Romaric Jodin
Date: 2024-01-09T16:47:53Z
New Revision: 9160f49e08af4267efdc870a1c9a434bfd155ae3

URL: https://github.com/llvm/llvm-project/commit/9160f49e08af4267efdc870a1c9a434bfd155ae3
DIFF: https://github.com/llvm/llvm-project/commit/9160f49e08af4267efdc870a1c9a434bfd155ae3.diff

LOG: libclc: generic: add half implementation for erf/erfc (#66901)

libclc does not have a half implementation for erf/erfc
Add one based on the float implementation by extending the input and
truncating the output.

Added: 
    

Modified: 
    libclc/generic/lib/math/erf.cl
    libclc/generic/lib/math/erfc.cl

Removed: 
    


################################################################################
diff  --git a/libclc/generic/lib/math/erf.cl b/libclc/generic/lib/math/erf.cl
index 3dc82d926e863a..2c395ce1a75267 100644
--- a/libclc/generic/lib/math/erf.cl
+++ b/libclc/generic/lib/math/erf.cl
@@ -399,4 +399,16 @@ _CLC_OVERLOAD _CLC_DEF double erf(double y) {
 
 _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, erf, double);
 
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half erf(half h) {
+    return (half)erf((float)h);
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, erf, half);
+
+#endif
+
 #endif

diff  --git a/libclc/generic/lib/math/erfc.cl b/libclc/generic/lib/math/erfc.cl
index c322f8691b3828..cd35ea8def7b6a 100644
--- a/libclc/generic/lib/math/erfc.cl
+++ b/libclc/generic/lib/math/erfc.cl
@@ -410,4 +410,16 @@ _CLC_OVERLOAD _CLC_DEF double erfc(double x) {
 
 _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, erfc, double);
 
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half erfc(half h) {
+    return (half)erfc((float)h);
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, erfc, half);
+
+#endif
+
 #endif


        


More information about the cfe-commits mailing list