Skip to content

[SYCL] Support stdlib function div, ldiv, lldiv in device library #3262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libdevice/device_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
#define __LIBDEVICE_DEVICE_MATH_H__

#include "device.h"

#include <cstdlib>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this under __SPIR__ below.

#ifdef __SPIR__

DEVICE_EXTERN_C
div_t __devicelib_div(int x, int y);

DEVICE_EXTERN_C
ldiv_t __devicelib_ldiv(long int x, long int y);

DEVICE_EXTERN_C
lldiv_t __devicelib_lldiv(long long int x, long long int y);

DEVICE_EXTERN_C
double __devicelib_log(double x);

Expand Down
10 changes: 10 additions & 0 deletions libdevice/fallback-cmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
// or remove any item in this file.
// TODO: generate the DeviceLibFuncMap in sycl-post-link.cpp automatically
// during the build based on libdevice to avoid manually sync.

DEVICE_EXTERN_C
div_t div(int x, int y) { return {x / y, x % y}; }

DEVICE_EXTERN_C
ldiv_t ldiv(long int x, long int y) { return {x / y, x % y}; }

DEVICE_EXTERN_C
lldiv_t lldiv(long long int x, long long int y) { return {x / y, x % y}; }

DEVICE_EXTERN_C
float __devicelib_scalbnf(float x, int n) { return __spirv_ocl_ldexp(x, n); }

Expand Down
3 changes: 3 additions & 0 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ static std::unordered_map<std::string, DeviceLibExt> DeviceLibFuncMap = {
{"__devicelib_cbrtf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_cosf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_coshf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_div", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_erfcf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_erff", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_exp2f", DeviceLibExt::cl_intel_devicelib_math},
Expand All @@ -203,8 +204,10 @@ static std::unordered_map<std::string, DeviceLibExt> DeviceLibFuncMap = {
{"__devicelib_frexpf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_hypotf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_ilogbf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_ldiv", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_ldexpf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_lgammaf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_lldiv", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_log10f", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_log1pf", DeviceLibExt::cl_intel_devicelib_math},
{"__devicelib_log2f", DeviceLibExt::cl_intel_devicelib_math},
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,11 @@ detail::enable_if_t<detail::is_genfloatf<T>::value, T> tan(T x) __NOEXC {
} // __SYCL_INLINE_NAMESPACE(cl)

#ifdef __SYCL_DEVICE_ONLY__
extern "C" {
extern SYCL_EXTERNAL div_t div(int x, int y);
extern SYCL_EXTERNAL ldiv_t ldiv(long int x, long int y);
extern SYCL_EXTERNAL lldiv_t lldiv(long long int x, long long int y);
}
#ifdef __GLIBC__
extern "C" {
extern SYCL_EXTERNAL void __assert_fail(const char *expr, const char *file,
Expand Down