From e0b0716ca97b48bb500fc3fa703eeb1b837c07cd Mon Sep 17 00:00:00 2001 From: Marya Sharf Date: Mon, 22 Jul 2024 00:46:03 +0100 Subject: [PATCH] last update --- libclc/generic/libspirv/math/lround.cl | 95 +++++++++++++++---- libdevice/fallback-cmath-fp64.cpp | 2 +- libdevice/fallback-cmath.cpp | 2 +- .../sycl/detail/builtins/math_functions.inc | 2 +- 4 files changed, 79 insertions(+), 22 deletions(-) diff --git a/libclc/generic/libspirv/math/lround.cl b/libclc/generic/libspirv/math/lround.cl index b50b918291ed4..8170926c84793 100644 --- a/libclc/generic/libspirv/math/lround.cl +++ b/libclc/generic/libspirv/math/lround.cl @@ -1,19 +1,76 @@ -//===----------------------------------------------------------------------===// - // - // 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 - #include - - // Map the llvm intrinsic to an OpenCL function. - #define __CLC_FUNCTION __clc___spirv_ocl_lround - #define __CLC_INTRINSIC "llvm.lround" - #include - - #undef __CLC_FUNCTION - #define __CLC_FUNCTION __spirv_ocl_lround - #include +#include "utils.h" +#include + +#ifndef __CLC_BUILTIN +#define __CLC_BUILTIN __CLC_XCONCAT(__clc_, __CLC_FUNCTION) +#endif + +#ifndef __CLC_BUILTIN_D +#define __CLC_BUILTIN_D __CLC_BUILTIN +#endif + +#ifndef __CLC_BUILTIN_F +#define __CLC_BUILTIN_F __CLC_BUILTIN +#endif + +#ifndef __CLC_BUILTIN_H +#define __CLC_BUILTIN_H __CLC_BUILTIN_F +#endif + +// Define the lround function for float type +#define _CLC_DEFINE_LROUND_BUILTIN(FUNC, BUILTIN, TYPE) \ +_CLC_OVERLOAD _CLC_DECL _CLC_CONSTFN long FUNC(TYPE x) { \ + return (long)BUILTIN(x); \ +} + +#define _CLC_DEFINE_LROUND_VECTOR_BUILTIN(FUNC, BUILTIN, VTYPE, RTYPE) \ +_CLC_OVERLOAD _CLC_DECL _CLC_CONSTFN RTYPE FUNC(VTYPE x) { \ + return (RTYPE)BUILTIN(x); \ +} + +#define __CLC_FUNCTION lround + +_CLC_DEFINE_LROUND_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, float) + +#ifndef __FLOAT_ONLY + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +_CLC_DEFINE_LROUND_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, double) +#endif + +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable +_CLC_DEFINE_LROUND_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, half) +#endif + +#endif // !__FLOAT_ONLY + +// Define lround for vector types of float +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec2_float, __clc_vec2_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec3_float, __clc_vec3_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec4_float, __clc_vec4_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec8_float, __clc_vec8_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec16_float, __clc_vec16_long) + +#ifdef cl_khr_fp64 +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec2_double, __clc_vec2_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec3_double, __clc_vec3_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec4_double, __clc_vec4_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec8_double, __clc_vec8_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec16_double, __clc_vec16_long) +#endif + +#ifdef cl_khr_fp16 +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec2_half, __clc_vec2_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec3_half, __clc_vec3_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec4_half, __clc_vec4_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec8_half, __clc_vec8_long) +_CLC_DEFINE_LROUND_VECTOR_BUILTIN(__spirv_ocl_lround, __spirv_ocl_rint, __clc_vec16_half, __clc_vec16_long) +#endif + +#undef __CLC_FUNCTION +#undef __CLC_BUILTIN +#undef __CLC_BUILTIN_D +#undef __CLC_BUILTIN_F +#undef __CLC_BUILTIN_H diff --git a/libdevice/fallback-cmath-fp64.cpp b/libdevice/fallback-cmath-fp64.cpp index 0fc4129e1b02b..e8de9ec6c918e 100644 --- a/libdevice/fallback-cmath-fp64.cpp +++ b/libdevice/fallback-cmath-fp64.cpp @@ -72,7 +72,7 @@ double __devicelib_modf(double x, double *intpart) { } DEVICE_EXTERN_C_INLINE -long int __devicelib_lround(double x) { return __spirv_ocl_lround(x); } +long int __devicelib_lround(double x) { return static_cast(__spirv_ocl_round(x)); }//__spirv_ocl_lround(x); } DEVICE_EXTERN_C_INLINE double __devicelib_round(double x) { return __spirv_ocl_round(x); } diff --git a/libdevice/fallback-cmath.cpp b/libdevice/fallback-cmath.cpp index 06f986b4cda16..89389e58f356d 100644 --- a/libdevice/fallback-cmath.cpp +++ b/libdevice/fallback-cmath.cpp @@ -37,7 +37,7 @@ float __devicelib_copysignf(float x, float y) { } DEVICE_EXTERN_C_INLINE -long int __devicelib_lroundf(float x) { return __spirv_ocl_lround(x); } +long int __devicelib_lroundf(float x) { return static_cast(__spirv_ocl_round(x)); }//__spirv_ocl_lround(x); } DEVICE_EXTERN_C_INLINE float __devicelib_cospif(float x) { return __spirv_ocl_cospi(x); } diff --git a/sycl/include/sycl/detail/builtins/math_functions.inc b/sycl/include/sycl/detail/builtins/math_functions.inc index 7a7610c0865f6..803f37d54a5ea 100644 --- a/sycl/include/sycl/detail/builtins/math_functions.inc +++ b/sycl/include/sycl/detail/builtins/math_functions.inc @@ -141,7 +141,7 @@ BUILTIN_GENF(ONE_ARG, floor) BUILTIN_GENF(ONE_ARG, lgamma) BUILTIN_GENF(ONE_ARG, log1p) BUILTIN_GENF(ONE_ARG, logb) -BUILTIN_GENF(ONE_ARG, lround) +//BUILTIN_GENF(ONE_ARG, lround) BUILTIN_GENF(ONE_ARG, rint) BUILTIN_GENF(ONE_ARG, round) BUILTIN_GENF(ONE_ARG, sinh)