Skip to content

Commit

Permalink
last update
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryaSharf committed Jul 22, 2024
1 parent 434a061 commit e0b0716
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 22 deletions.
95 changes: 76 additions & 19 deletions libclc/generic/libspirv/math/lround.cl
Original file line number Diff line number Diff line change
@@ -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 <clcmacro.h>
#include <spirv/spirv.h>

// Map the llvm intrinsic to an OpenCL function.
#define __CLC_FUNCTION __clc___spirv_ocl_lround
#define __CLC_INTRINSIC "llvm.lround"
#include <math/unary_intrin.inc>

#undef __CLC_FUNCTION
#define __CLC_FUNCTION __spirv_ocl_lround
#include <math/lround_builtin.inc>
#include "utils.h"
#include <clcmacro.h>

#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
2 changes: 1 addition & 1 deletion libdevice/fallback-cmath-fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long int>(__spirv_ocl_round(x)); }//__spirv_ocl_lround(x); }

DEVICE_EXTERN_C_INLINE
double __devicelib_round(double x) { return __spirv_ocl_round(x); }
Expand Down
2 changes: 1 addition & 1 deletion libdevice/fallback-cmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long int>(__spirv_ocl_round(x)); }//__spirv_ocl_lround(x); }

DEVICE_EXTERN_C_INLINE
float __devicelib_cospif(float x) { return __spirv_ocl_cospi(x); }
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/builtins/math_functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e0b0716

Please sign in to comment.