Author: Wenju He Date: 2025-08-11T08:53:49+08:00 New Revision: 12cec437c664e1b671d85f38418c97f222340ce4
URL: https://github.com/llvm/llvm-project/commit/12cec437c664e1b671d85f38418c97f222340ce4 DIFF: https://github.com/llvm/llvm-project/commit/12cec437c664e1b671d85f38418c97f222340ce4.diff LOG: [libclc] Implement clc_log/sinpi/sqrt with __nv_* functions (#150174) This is to upstream implementations in https://github.com/intel/llvm/tree/sycl/libclc/clc/lib/ptx-nvidiacl/math Added: libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl libclc/clc/lib/ptx-nvidiacl/math/clc_rsqrt.cl libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl libclc/clc/lib/ptx-nvidiacl/relational/clc_isinf.cl Modified: libclc/clc/include/clc/math/gentype.inc libclc/clc/lib/ptx-nvidiacl/SOURCES Removed: ################################################################################ diff --git a/libclc/clc/include/clc/math/gentype.inc b/libclc/clc/include/clc/math/gentype.inc index d74a9932bd0a6..299ce6633cf0e 100644 --- a/libclc/clc/include/clc/math/gentype.inc +++ b/libclc/clc/include/clc/math/gentype.inc @@ -80,6 +80,7 @@ #define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE) #define __CLC_GENTYPE float +#define __CLC_BIT_INT int #define __CLC_BIT_INTN int #define __CLC_SCALAR #define __CLC_VECSIZE @@ -131,6 +132,7 @@ #include __CLC_BODY #undef __CLC_VECSIZE #undef __CLC_GENTYPE +#undef __CLC_BIT_INT #undef __CLC_BIT_INTN #undef __CLC_VECSIZE_OR_1 @@ -159,6 +161,7 @@ #define __CLC_VECSIZE #define __CLC_VECSIZE_OR_1 1 #define __CLC_GENTYPE double +#define __CLC_BIT_INT long #define __CLC_BIT_INTN long #include __CLC_BODY #undef __CLC_VECSIZE_OR_1 @@ -207,6 +210,7 @@ #include __CLC_BODY #undef __CLC_VECSIZE #undef __CLC_GENTYPE +#undef __CLC_BIT_INT #undef __CLC_BIT_INTN #undef __CLC_VECSIZE_OR_1 @@ -235,6 +239,7 @@ #define __CLC_VECSIZE #define __CLC_VECSIZE_OR_1 1 #define __CLC_GENTYPE half +#define __CLC_BIT_INT short #define __CLC_BIT_INTN short #include __CLC_BODY #undef __CLC_GENTYPE @@ -283,6 +288,7 @@ #include __CLC_BODY #undef __CLC_VECSIZE #undef __CLC_GENTYPE +#undef __CLC_BIT_INT #undef __CLC_BIT_INTN #undef __CLC_VECSIZE_OR_1 diff --git a/libclc/clc/lib/ptx-nvidiacl/SOURCES b/libclc/clc/lib/ptx-nvidiacl/SOURCES index b6f50654f89c5..cafd90943f22e 100644 --- a/libclc/clc/lib/ptx-nvidiacl/SOURCES +++ b/libclc/clc/lib/ptx-nvidiacl/SOURCES @@ -1,3 +1,7 @@ +math/clc_log.cl +math/clc_rsqrt.cl +math/clc_sinpi.cl +math/clc_sqrt.cl mem_fence/clc_mem_fence.cl synchronization/clc_work_group_barrier.cl workitem/clc_get_global_id.cl @@ -7,3 +11,4 @@ workitem/clc_get_local_size.cl workitem/clc_get_max_sub_group_size.cl workitem/clc_get_num_groups.cl workitem/clc_get_sub_group_local_id.cl +relational/clc_isinf.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_rsqrt.cl b/libclc/clc/lib/ptx-nvidiacl/math/clc_rsqrt.cl new file mode 100644 index 0000000000000..beea123180c5f --- /dev/null +++ b/libclc/clc/lib/ptx-nvidiacl/math/clc_rsqrt.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_rsqrt.h> + +float __nv_rsqrtf(float); +double __nv_rsqrt(double); + +_CLC_OVERLOAD _CLC_DEF float __clc_rsqrt(float x) { return __nv_rsqrtf(x); } + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +_CLC_OVERLOAD _CLC_DEF double __clc_rsqrt(double x) { return __nv_rsqrt(x); } + +#endif + +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable + +_CLC_OVERLOAD _CLC_DEF half __clc_rsqrt(half x) { + return (half)__clc_rsqrt((float)x); +} + +#endif + +#define FUNCTION __clc_rsqrt +#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> diff --git a/libclc/clc/lib/ptx-nvidiacl/relational/clc_isinf.cl b/libclc/clc/lib/ptx-nvidiacl/relational/clc_isinf.cl new file mode 100644 index 0000000000000..d518efad6a041 --- /dev/null +++ b/libclc/clc/lib/ptx-nvidiacl/relational/clc_isinf.cl @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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/relational/clc_isinf.h> + +int __nv_isinff(float); +int __nv_isinfd(double); + +_CLC_OVERLOAD _CLC_DEF int __clc_isinf(float x) { return __nv_isinff(x); } + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +_CLC_OVERLOAD _CLC_DEF int __clc_isinf(double x) { return __nv_isinfd(x); } + +#endif + +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable + +_CLC_OVERLOAD _CLC_DEF int __clc_isinf(half x) { return __clc_isinf((float)x); } + +#endif + +#define FUNCTION __clc_isinf +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#define __CLC_RET_TYPE __CLC_BIT_INT +#include <clc/math/gentype.inc> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits