From b4d91c3698118befcde2b163c325941e933da7f7 Mon Sep 17 00:00:00 2001 From: roy1994 <32302164+MoveCloudROY@users.noreply.github.com> Date: Tue, 31 Dec 2024 02:43:58 +0800 Subject: [PATCH] [SYCL][HIP] add missing nearbyint and rint (#16373) Failed to compile OneDNN using DPCPP on AMD with sycl because the code [here](https://github.com/oneapi-src/oneDNN/blob/c852fdc60073a1ae298618c4faf26487b4144755/src/gpu/generic/sycl/eltwise_kernels.hpp#L137) that will run on the device actually calls `nearbyintf` [here](https://github.com/oneapi-src/oneDNN/blob/c852fdc60073a1ae298618c4faf26487b4144755/src/common/math_utils.hpp#L120-L131) , but `nearbyintf` lacks a symbolic definition. Same solution as https://github.com/intel/llvm/pull/11177 but go straight to the `__ocml` symbols --- libdevice/cmath_wrapper.cpp | 10 ++++++++++ libdevice/cmath_wrapper_fp64.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/libdevice/cmath_wrapper.cpp b/libdevice/cmath_wrapper.cpp index 27d705d5406b2..1a5cec90d28cd 100644 --- a/libdevice/cmath_wrapper.cpp +++ b/libdevice/cmath_wrapper.cpp @@ -200,4 +200,14 @@ DEVICE_EXTERN_C_INLINE float rintf(float x) { return __nv_rintf(x); } #endif // __NVPTX__ +#ifdef __AMDGCN__ +extern "C" SYCL_EXTERNAL float __ocml_nearbyint_f32(float); +DEVICE_EXTERN_C_INLINE +float nearbyintf(float x) { return __ocml_nearbyint_f32(x); } + +extern "C" SYCL_EXTERNAL float __ocml_rint_f32(float); +DEVICE_EXTERN_C_INLINE +float rintf(float x) { return __ocml_rint_f32(x); } +#endif // __AMDGCN__ + #endif // __SPIR__ || __SPIRV__ || __NVPTX__ || __AMDGCN__ diff --git a/libdevice/cmath_wrapper_fp64.cpp b/libdevice/cmath_wrapper_fp64.cpp index 7f78a38600e55..8d9c70ea0fe69 100644 --- a/libdevice/cmath_wrapper_fp64.cpp +++ b/libdevice/cmath_wrapper_fp64.cpp @@ -190,6 +190,16 @@ DEVICE_EXTERN_C_INLINE double rint(double x) { return __nv_rint(x); } #endif // __NVPTX__ +#ifdef __AMDGCN__ +extern "C" SYCL_EXTERNAL double __ocml_nearbyint_f64(double); +DEVICE_EXTERN_C_INLINE +double nearbyint(double x) { return __ocml_nearbyint_f64(x); } + +extern "C" SYCL_EXTERNAL double __ocml_rint_f64(double); +DEVICE_EXTERN_C_INLINE +double rint(double x) { return __ocml_rint_f64(x); } +#endif // __AMDGCN__ + #if defined(_MSC_VER) #include // FLOAT PROPERTIES