-
Notifications
You must be signed in to change notification settings - Fork 789
[SYCL] Don't include <complex> from <sycl/sycl.hpp> #11196
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
Conversation
This addresses a part of a bigger issue of polluting the global namespace with math functions by implicitly including <cmath> from sycl headers. Internally, <complex> includes <cmath> so we shouldn't be including it as well, which this patch implements. I'm doing it by providing our own version of <complex> that does `#include_next <complex>` and also provides needed functions/template specializations to support `std::complex`-related functionality whenever user program includes <complex> on its own. System include path for this is only provided in SYCL mode so non-SYCL compilation flow is unaffected.
f3556d8
to
76775da
Compare
76775da
to
d6e66a7
Compare
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"{{.*}} | ||
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-device" | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT:[^"]*]]bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" | ||
// CHECK-HEADER-DIR-NOT: -internal-isystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous version didn't catch cases where we had extra includes between the ones we match (due to {{.*}}bin
greedy regex). This update is both catching that and doesn't require extra long lines making it more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK for driver
@cperkinsintel , @intel/llvm-reviewers-runtime ping. |
So if a user wants to use complex numbers, they need to |
Both before/after would work - see https://github.com/intel/llvm/pull/11196/files#diff-d8871abe2a3a33ba61392bd95ccf6f1caab18118964cd0814868b73afeae4af0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ship it
@mdtoguchi , there was small driver change after your approval to support |
This follows intel#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 intel#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 intel#11196).
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).
…RMANT_APIS intel#11274 and intel#11196 could break customers code that relied on implicit inclusion of those headers. Don't break it before the next ABI breaking window.
This addresses a part of a bigger issue of polluting the global namespace with math functions by implicitly including
<cmath>
from sycl headers. Internally,<complex>
includes<cmath>
so we shouldn't be including it as well, which this patch implements.I'm doing it by providing our own version of that does
#include_next <complex>
and also provides needed functions/template specializations to supportstd::complex
-related functionality whenever user program includes on its own. System include path for this is only provided in SYCL mode, so non-SYCL compilation flow is unaffected.Unfortunately, MSVC doesn't have have
#include_next
so we use a hack to emulate it - via#include <../include/complex>
.