https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/150174

This is to upstream implementations in 
https://github.com/intel/llvm/tree/sycl/libclc/clc/lib/ptx-nvidiacl/math

>From d4fcaf56d63efe283240bfc582706e268e30c854 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju...@intel.com>
Date: Wed, 23 Jul 2025 08:47:17 +0200
Subject: [PATCH] [libclc] Implement clc_log/sinpi/sqrt with __nv_* functions

This is to upstream implementations in 
https://github.com/intel/llvm/tree/sycl/libclc/clc/lib/ptx-nvidiacl/math
---
 libclc/clc/lib/ptx-nvidiacl/SOURCES           |  3 ++
 libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl   | 34 +++++++++++++++++++
 libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl | 34 +++++++++++++++++++
 libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl  | 34 +++++++++++++++++++
 4 files changed, 105 insertions(+)
 create mode 100644 libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl
 create mode 100644 libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl
 create mode 100644 libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl

diff --git a/libclc/clc/lib/ptx-nvidiacl/SOURCES 
b/libclc/clc/lib/ptx-nvidiacl/SOURCES
index 05368c5e4d4e3..52e4fdd7d4bfa 100644
--- a/libclc/clc/lib/ptx-nvidiacl/SOURCES
+++ b/libclc/clc/lib/ptx-nvidiacl/SOURCES
@@ -1,3 +1,6 @@
+math/clc_log.cl
+math/clc_sinpi.cl
+math/clc_sqrt.cl
 workitem/clc_get_global_id.cl
 workitem/clc_get_group_id.cl
 workitem/clc_get_local_id.cl
diff --git a/libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl 
b/libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl
new file mode 100644
index 0000000000000..9c2778bfd1a7b
--- /dev/null
+++ b/libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/math/clc_log.h>
+
+float __nv_logf(float);
+double __nv_log(double);
+
+_CLC_OVERLOAD _CLC_DEF float __clc_log(float x) { return __nv_logf(x); }
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double __clc_log(double x) { return __nv_log(x); }
+
+#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half __clc_log(half x) {
+  return (half)__clc_log((float)x);
+}
+
+#endif
+
+#define FUNCTION __clc_log
+#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl 
b/libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl
new file mode 100644
index 0000000000000..40903ba58b840
--- /dev/null
+++ b/libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/math/clc_sinpi.h>
+
+float __nv_sinpif(float);
+double __nv_sinpi(double);
+
+_CLC_OVERLOAD _CLC_DEF float __clc_sinpi(float x) { return __nv_sinpif(x); }
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double __clc_sinpi(double x) { return __nv_sinpi(x); }
+
+#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half __clc_sinpi(half x) {
+  return (half)__clc_sinpi((float)x);
+}
+
+#endif
+
+#define FUNCTION __clc_sinpi
+#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl 
b/libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl
new file mode 100644
index 0000000000000..ea91894b9dcf7
--- /dev/null
+++ b/libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/math/clc_sqrt.h>
+
+float __nv_sqrtf(float);
+double __nv_sqrt(double);
+
+_CLC_OVERLOAD _CLC_DEF float __clc_sqrt(float x) { return __nv_sqrtf(x); }
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double __clc_sqrt(double x) { return __nv_sqrt(x); }
+
+#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half __clc_sqrt(half x) {
+  return (half)__clc_sqrt((float)x);
+}
+
+#endif
+
+#define FUNCTION __clc_sqrt
+#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
+#include <clc/math/gentype.inc>

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to