-
Notifications
You must be signed in to change notification settings - Fork 768
[SYCL] Hide inline definitions of stdio functions #18174
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
base: sycl
Are you sure you want to change the base?
Conversation
MSVC's inline definitions of stdio functions such as printf() are only meant for host code; device code cannot call them. Device code can, however, call ext::oneapi::experimental::printf() which depending on the target is implemented as a call to the global printf(). The availability of a definition of the global host printf() makes it more difficult to handle in device code, so hide it.
This fixes at least one SYCL E2E test ( |
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.
I'm not aware of implications of always enabling this macro, @AaronBallman can you maybe weigh in?
@@ -1547,6 +1547,13 @@ static void InitializePredefinedMacros(const TargetInfo &TI, | |||
Builder.defineMacro("__ENABLE_USM_ADDR_SPACE__"); | |||
Builder.defineMacro("SYCL_DISABLE_FALLBACK_ASSERT"); | |||
} | |||
|
|||
// Despite the name, DeviceTriple is not necessarily the device triple. |
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.
That comment can break a brain, could you please explain the whole situation here instead?
Also, should that only happen for native cpu?
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.
Should we also consider enabling this macro in SYCL headers instead? It is our library implementation can't deal with this, not any SYCL.
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.
That comment can break a brain, could you please explain the whole situation here instead?
This relates to
llvm/clang/lib/Frontend/InitPreprocessor.cpp
Lines 1630 to 1639 in 6a8df7d
// FIXME: This will create multiple definitions for most of the predefined | |
// macros. This is not the right way to handle this. | |
if ((LangOpts.CUDA || LangOpts.OpenMPIsTargetDevice || | |
LangOpts.SYCLIsDevice) && | |
PP.getAuxTargetInfo()) | |
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, | |
PP.getPreprocessorOpts(), Builder); | |
InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, | |
PP.getPreprocessorOpts(), Builder); |
InitializePredefinedMacros
called is not exactly ideal. It gets called twice, once for the host, once for the device, and the macros from both are used.
Also, should that only happen for native cpu?
This can simplify handling for all SYCL targets, not just NativeCPU.
Should we also consider enabling this macro in SYCL headers instead? It is our library implementation can't deal with this, not any SYCL.
We cannot enable this macro in SYCL headers since the MSVC system headers may be included before any SYCL header is included, so the macro would be defined too late.
Do we support any SYCL library other than our own?
For the avoidance of confusion, this is inside a |
|
MSVC's inline definitions of stdio functions such as printf() are only meant for host code; device code cannot call them. Device code can, however, call ext::oneapi::experimental::printf() which depending on the target is implemented as a call to the global printf(). The availability of a definition of the global host printf() makes it more difficult to handle in device code, so hide it.