Skip to content

Commit a174ee0

Browse files
[SYCL] Don't include <cmath> from <sycl/sycl.hpp>
This follows #11196 that did the same with <complex> before. We still want to support `std::` math functions in user code (as part of `sycl/doc/extensions/supported/C-CXX-StandardLibrary.rst`). Also, often times STL implements math functions support somewhat like this: ``` extern "C" { extern double cos (double __x) noexcept (true); } extern "C++" { namespace std __attribute__ ((__visibility__ ("default"))) { using ::cos; } } ``` As such, we still want to let the compiler know which symbols in the global namespace are known (e.g. `::cos`) and which aren't and need an error ( `SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute`). One option to implement that is to recognize those functions as builtins in the front end (which #11014 tries to do). Another approach, taken in this PR, is to keep providing declaration in SYCL headers but only do so when customer included `<cmath>` explicitly (via `#include_next`, similarly to `<complex>` support added in #11196).
1 parent ee1c8e3 commit a174ee0

File tree

11 files changed

+222
-167
lines changed

11 files changed

+222
-167
lines changed

sycl/include/sycl/builtins.hpp

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -15,98 +15,8 @@
1515
#include <sycl/builtins_scalar_gen.hpp>
1616
#include <sycl/builtins_vector_gen.hpp>
1717

18-
// We don't use the same exception specifier as <cmath> so we get warnings if
19-
// our code is processed before STL's <cmath>.
20-
// TODO: We should remove this dependency alltogether in a subsequent patch.
21-
#include <cmath>
22-
2318
#ifdef __SYCL_DEVICE_ONLY__
2419
extern "C" {
25-
extern __DPCPP_SYCL_EXTERNAL int abs(int x);
26-
extern __DPCPP_SYCL_EXTERNAL long int labs(long int x);
27-
extern __DPCPP_SYCL_EXTERNAL long long int llabs(long long int x);
28-
29-
extern __DPCPP_SYCL_EXTERNAL div_t div(int x, int y);
30-
extern __DPCPP_SYCL_EXTERNAL ldiv_t ldiv(long int x, long int y);
31-
extern __DPCPP_SYCL_EXTERNAL lldiv_t lldiv(long long int x, long long int y);
32-
extern __DPCPP_SYCL_EXTERNAL float scalbnf(float x, int n);
33-
extern __DPCPP_SYCL_EXTERNAL double scalbn(double x, int n);
34-
extern __DPCPP_SYCL_EXTERNAL float logf(float x);
35-
extern __DPCPP_SYCL_EXTERNAL double log(double x);
36-
extern __DPCPP_SYCL_EXTERNAL float expf(float x);
37-
extern __DPCPP_SYCL_EXTERNAL double exp(double x);
38-
extern __DPCPP_SYCL_EXTERNAL float log10f(float x);
39-
extern __DPCPP_SYCL_EXTERNAL double log10(double x);
40-
extern __DPCPP_SYCL_EXTERNAL float modff(float x, float *intpart);
41-
extern __DPCPP_SYCL_EXTERNAL double modf(double x, double *intpart);
42-
extern __DPCPP_SYCL_EXTERNAL float exp2f(float x);
43-
extern __DPCPP_SYCL_EXTERNAL double exp2(double x);
44-
extern __DPCPP_SYCL_EXTERNAL float expm1f(float x);
45-
extern __DPCPP_SYCL_EXTERNAL double expm1(double x);
46-
extern __DPCPP_SYCL_EXTERNAL int ilogbf(float x);
47-
extern __DPCPP_SYCL_EXTERNAL int ilogb(double x);
48-
extern __DPCPP_SYCL_EXTERNAL float log1pf(float x);
49-
extern __DPCPP_SYCL_EXTERNAL double log1p(double x);
50-
extern __DPCPP_SYCL_EXTERNAL float log2f(float x);
51-
extern __DPCPP_SYCL_EXTERNAL double log2(double x);
52-
extern __DPCPP_SYCL_EXTERNAL float logbf(float x);
53-
extern __DPCPP_SYCL_EXTERNAL double logb(double x);
54-
extern __DPCPP_SYCL_EXTERNAL float sqrtf(float x);
55-
extern __DPCPP_SYCL_EXTERNAL double sqrt(double x);
56-
extern __DPCPP_SYCL_EXTERNAL float cbrtf(float x);
57-
extern __DPCPP_SYCL_EXTERNAL double cbrt(double x);
58-
extern __DPCPP_SYCL_EXTERNAL float erff(float x);
59-
extern __DPCPP_SYCL_EXTERNAL double erf(double x);
60-
extern __DPCPP_SYCL_EXTERNAL float erfcf(float x);
61-
extern __DPCPP_SYCL_EXTERNAL double erfc(double x);
62-
extern __DPCPP_SYCL_EXTERNAL float tgammaf(float x);
63-
extern __DPCPP_SYCL_EXTERNAL double tgamma(double x);
64-
extern __DPCPP_SYCL_EXTERNAL float lgammaf(float x);
65-
extern __DPCPP_SYCL_EXTERNAL double lgamma(double x);
66-
extern __DPCPP_SYCL_EXTERNAL float fmodf(float x, float y);
67-
extern __DPCPP_SYCL_EXTERNAL double fmod(double x, double y);
68-
extern __DPCPP_SYCL_EXTERNAL float remainderf(float x, float y);
69-
extern __DPCPP_SYCL_EXTERNAL double remainder(double x, double y);
70-
extern __DPCPP_SYCL_EXTERNAL float remquof(float x, float y, int *q);
71-
extern __DPCPP_SYCL_EXTERNAL double remquo(double x, double y, int *q);
72-
extern __DPCPP_SYCL_EXTERNAL float nextafterf(float x, float y);
73-
extern __DPCPP_SYCL_EXTERNAL double nextafter(double x, double y);
74-
extern __DPCPP_SYCL_EXTERNAL float fdimf(float x, float y);
75-
extern __DPCPP_SYCL_EXTERNAL double fdim(double x, double y);
76-
extern __DPCPP_SYCL_EXTERNAL float fmaf(float x, float y, float z);
77-
extern __DPCPP_SYCL_EXTERNAL double fma(double x, double y, double z);
78-
extern __DPCPP_SYCL_EXTERNAL float sinf(float x);
79-
extern __DPCPP_SYCL_EXTERNAL double sin(double x);
80-
extern __DPCPP_SYCL_EXTERNAL float cosf(float x);
81-
extern __DPCPP_SYCL_EXTERNAL double cos(double x);
82-
extern __DPCPP_SYCL_EXTERNAL float tanf(float x);
83-
extern __DPCPP_SYCL_EXTERNAL double tan(double x);
84-
extern __DPCPP_SYCL_EXTERNAL float asinf(float x);
85-
extern __DPCPP_SYCL_EXTERNAL double asin(double x);
86-
extern __DPCPP_SYCL_EXTERNAL float acosf(float x);
87-
extern __DPCPP_SYCL_EXTERNAL double acos(double x);
88-
extern __DPCPP_SYCL_EXTERNAL float atanf(float x);
89-
extern __DPCPP_SYCL_EXTERNAL double atan(double x);
90-
extern __DPCPP_SYCL_EXTERNAL float powf(float x, float y);
91-
extern __DPCPP_SYCL_EXTERNAL double pow(double x, double y);
92-
extern __DPCPP_SYCL_EXTERNAL float atan2f(float x, float y);
93-
extern __DPCPP_SYCL_EXTERNAL double atan2(double x, double y);
94-
95-
extern __DPCPP_SYCL_EXTERNAL float sinhf(float x);
96-
extern __DPCPP_SYCL_EXTERNAL double sinh(double x);
97-
extern __DPCPP_SYCL_EXTERNAL float coshf(float x);
98-
extern __DPCPP_SYCL_EXTERNAL double cosh(double x);
99-
extern __DPCPP_SYCL_EXTERNAL float tanhf(float x);
100-
extern __DPCPP_SYCL_EXTERNAL double tanh(double x);
101-
extern __DPCPP_SYCL_EXTERNAL float asinhf(float x);
102-
extern __DPCPP_SYCL_EXTERNAL double asinh(double x);
103-
extern __DPCPP_SYCL_EXTERNAL float acoshf(float x);
104-
extern __DPCPP_SYCL_EXTERNAL double acosh(double x);
105-
extern __DPCPP_SYCL_EXTERNAL float atanhf(float x);
106-
extern __DPCPP_SYCL_EXTERNAL double atanh(double x);
107-
extern __DPCPP_SYCL_EXTERNAL double frexp(double x, int *exp);
108-
extern __DPCPP_SYCL_EXTERNAL double ldexp(double x, int exp);
109-
extern __DPCPP_SYCL_EXTERNAL double hypot(double x, double y);
11020

11121
extern __DPCPP_SYCL_EXTERNAL void *memcpy(void *dest, const void *src,
11222
size_t n);
@@ -604,65 +514,6 @@ extern __DPCPP_SYCL_EXTERNAL void __assert_fail(const char *expr,
604514
const char *file,
605515
unsigned int line,
606516
const char *func);
607-
extern __DPCPP_SYCL_EXTERNAL float frexpf(float x, int *exp);
608-
extern __DPCPP_SYCL_EXTERNAL float ldexpf(float x, int exp);
609-
extern __DPCPP_SYCL_EXTERNAL float hypotf(float x, float y);
610-
611-
// MS UCRT supports most of the C standard library but <complex.h> is
612-
// an exception.
613-
extern __DPCPP_SYCL_EXTERNAL float cimagf(float __complex__ z);
614-
extern __DPCPP_SYCL_EXTERNAL double cimag(double __complex__ z);
615-
extern __DPCPP_SYCL_EXTERNAL float crealf(float __complex__ z);
616-
extern __DPCPP_SYCL_EXTERNAL double creal(double __complex__ z);
617-
extern __DPCPP_SYCL_EXTERNAL float cargf(float __complex__ z);
618-
extern __DPCPP_SYCL_EXTERNAL double carg(double __complex__ z);
619-
extern __DPCPP_SYCL_EXTERNAL float cabsf(float __complex__ z);
620-
extern __DPCPP_SYCL_EXTERNAL double cabs(double __complex__ z);
621-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cprojf(float __complex__ z);
622-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cproj(double __complex__ z);
623-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cexpf(float __complex__ z);
624-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cexp(double __complex__ z);
625-
extern __DPCPP_SYCL_EXTERNAL float __complex__ clogf(float __complex__ z);
626-
extern __DPCPP_SYCL_EXTERNAL double __complex__ clog(double __complex__ z);
627-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cpowf(float __complex__ z);
628-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cpow(double __complex__ z);
629-
extern __DPCPP_SYCL_EXTERNAL float __complex__ csqrtf(float __complex__ z);
630-
extern __DPCPP_SYCL_EXTERNAL double __complex__ csqrt(double __complex__ z);
631-
extern __DPCPP_SYCL_EXTERNAL float __complex__ csinhf(float __complex__ z);
632-
extern __DPCPP_SYCL_EXTERNAL double __complex__ csinh(double __complex__ z);
633-
extern __DPCPP_SYCL_EXTERNAL float __complex__ ccoshf(float __complex__ z);
634-
extern __DPCPP_SYCL_EXTERNAL double __complex__ ccosh(double __complex__ z);
635-
extern __DPCPP_SYCL_EXTERNAL float __complex__ ctanhf(float __complex__ z);
636-
extern __DPCPP_SYCL_EXTERNAL double __complex__ ctanh(double __complex__ z);
637-
extern __DPCPP_SYCL_EXTERNAL float __complex__ csinf(float __complex__ z);
638-
extern __DPCPP_SYCL_EXTERNAL double __complex__ csin(double __complex__ z);
639-
extern __DPCPP_SYCL_EXTERNAL float __complex__ ccosf(float __complex__ z);
640-
extern __DPCPP_SYCL_EXTERNAL double __complex__ ccos(double __complex__ z);
641-
extern __DPCPP_SYCL_EXTERNAL float __complex__ ctanf(float __complex__ z);
642-
extern __DPCPP_SYCL_EXTERNAL double __complex__ ctan(double __complex__ z);
643-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cacosf(float __complex__ z);
644-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cacos(double __complex__ z);
645-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cacoshf(float __complex__ z);
646-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cacosh(double __complex__ z);
647-
extern __DPCPP_SYCL_EXTERNAL float __complex__ casinf(float __complex__ z);
648-
extern __DPCPP_SYCL_EXTERNAL double __complex__ casin(double __complex__ z);
649-
extern __DPCPP_SYCL_EXTERNAL float __complex__ casinhf(float __complex__ z);
650-
extern __DPCPP_SYCL_EXTERNAL double __complex__ casinh(double __complex__ z);
651-
extern __DPCPP_SYCL_EXTERNAL float __complex__ catanf(float __complex__ z);
652-
extern __DPCPP_SYCL_EXTERNAL double __complex__ catan(double __complex__ z);
653-
extern __DPCPP_SYCL_EXTERNAL float __complex__ catanhf(float __complex__ z);
654-
extern __DPCPP_SYCL_EXTERNAL double __complex__ catanh(double __complex__ z);
655-
extern __DPCPP_SYCL_EXTERNAL float __complex__ cpolarf(float rho, float theta);
656-
extern __DPCPP_SYCL_EXTERNAL double __complex__ cpolar(double rho,
657-
double theta);
658-
extern __DPCPP_SYCL_EXTERNAL float __complex__ __mulsc3(float a, float b,
659-
float c, float d);
660-
extern __DPCPP_SYCL_EXTERNAL double __complex__ __muldc3(double a, double b,
661-
double c, double d);
662-
extern __DPCPP_SYCL_EXTERNAL float __complex__ __divsc3(float a, float b,
663-
float c, float d);
664-
extern __DPCPP_SYCL_EXTERNAL double __complex__ __divdc3(float a, float b,
665-
float c, float d);
666517
}
667518
#elif defined(_WIN32)
668519
extern "C" {
@@ -672,21 +523,6 @@ extern "C" {
672523
// APIs used by STL, such as _Cosh, are undocumented, even though
673524
// they are open-sourced. Recognizing them as builtins is not
674525
// straightforward currently.
675-
extern __DPCPP_SYCL_EXTERNAL double _Cosh(double x, double y);
676-
extern __DPCPP_SYCL_EXTERNAL int _dpcomp(double x, double y);
677-
extern __DPCPP_SYCL_EXTERNAL int _dsign(double x);
678-
extern __DPCPP_SYCL_EXTERNAL short _Dtest(double *px);
679-
extern __DPCPP_SYCL_EXTERNAL short _dtest(double *px);
680-
extern __DPCPP_SYCL_EXTERNAL short _Exp(double *px, double y, short eoff);
681-
extern __DPCPP_SYCL_EXTERNAL float _FCosh(float x, float y);
682-
extern __DPCPP_SYCL_EXTERNAL int _fdpcomp(float x, float y);
683-
extern __DPCPP_SYCL_EXTERNAL int _fdsign(float x);
684-
extern __DPCPP_SYCL_EXTERNAL short _FDtest(float *px);
685-
extern __DPCPP_SYCL_EXTERNAL short _fdtest(float *px);
686-
extern __DPCPP_SYCL_EXTERNAL short _FExp(float *px, float y, short eoff);
687-
extern __DPCPP_SYCL_EXTERNAL float _FSinh(float x, float y);
688-
extern __DPCPP_SYCL_EXTERNAL double _Sinh(double x, double y);
689-
extern __DPCPP_SYCL_EXTERNAL float _hypotf(float x, float y);
690526
extern __DPCPP_SYCL_EXTERNAL void _wassert(const wchar_t *wexpr,
691527
const wchar_t *wfile, unsigned line);
692528
}

0 commit comments

Comments
 (0)