-
Notifications
You must be signed in to change notification settings - Fork 769
[Driver][SYCL] For SYCL compilations, force C++ source even with .c #2491
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
[Driver][SYCL] For SYCL compilations, force C++ source even with .c #2491
Conversation
When compiling for SYCL, we want to enforce C++ compilations. For all C source file types, enforce C++. Also move the -x c check to be in line with the other -x processing
What is the motivation for this or the use-case? |
@keryell, @Fznamznon is better suited to answer here. |
@premanandrao, @erichkeane, I didn't realize @Fznamznon was out - can you respond? There is bit of urgency for this one for MKL. |
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.
2 small things. I'm not the maintainer here, but otherwise this LGTM.
@@ -273,7 +273,7 @@ def err_drv_expecting_fopenmp_with_fopenmp_targets : Error< | |||
def err_drv_expecting_fsycl_with_sycl_opt : Error< | |||
"The option %0 must be used in conjunction with -fsycl to enable offloading.">; | |||
def err_drv_fsycl_with_c_type : Error< | |||
"The option %0%1 must not be used in conjunction with -fsycl which expects C++ source.">; | |||
"The option '%0' must not be used in conjunction with '-fsycl' which expects C++ source.">; |
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.
Nit: My reading would also add a comma after '-fsycl'
@@ -2443,9 +2441,21 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |||
if (const char *Ext = strrchr(Value, '.')) | |||
Ty = TC.LookupTypeForExtension(Ext + 1); | |||
|
|||
// For SYCL, convert C-type sources to C++-type sources. | |||
if (IsSYCL) { |
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 this be a switch instead? I would fear this getting unwieldy otherwise in pulldown/etc or if this got any more complicated.
- add comma to diagnostic - use switch statement instead of ifs
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.
The changes LGTM but I do not know the answer to @keryell's concerns i.e. the motivation for this and incompatibilities between C and C++. I guess it will crash/error on real C code, which is fine? @premanandrao could you please take a look?
The main motivation appears to be the inline functions in C. These get emitted on device even when not used because of C rules for inline. Example:
Previously we would treat this as a C file, if its file-name were .c with -fsycl. Now we would treat this as a C++ file with -fsycl, unless explicitly overridden with -x c. |
As far as I can judge from the new code (and from the earlier patches), |
You are right about the driver; I was testing with the cc1 compiler. |
@keryell, AFAIU, the following background/justification come into play here:
|
switch (Ty) { | ||
case types::TY_C: | ||
Ty = types::TY_CXX; | ||
break; | ||
case types::TY_CHeader: | ||
Ty = types::TY_CXXHeader; | ||
break; | ||
case types::TY_PP_C: | ||
Ty = types::TY_PP_CXX; | ||
break; | ||
case types::TY_PP_CHeader: | ||
Ty = types::TY_PP_CXXHeader; | ||
break; | ||
default: | ||
break; | ||
} |
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.
Never thought I'd say this as a Python hater, but it's a shame we don't have something really analogous to a Python dict :D Take any alternative like a std::map
- it's too verbose and therefore meaningless for a 4-case switch...
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.
In C++23 I hope the pattern matching proposal https://wg21.link/p1371 will be voted in!
Python hater? Do not forget that C++23 is just Python, but running at 100x the speed. :-)
I guess that if a user is owning an HPC machine, this is not to compile with |
That's generally accurate, however there's a counter-example: we have early optimizations force-disabled for FPGA HW targets. I don't know if DCE gets run at the BE stage, but the risk remains. When @Fznamznon's back online, she should be able to provide more examples of "true C" behavior being problematic. |
This is a follow-up to 08884df Original commit: KhronosGroup/SPIRV-LLVM-Translator@89b19c46b5aaa2c
When compiling for SYCL, we want to enforce C++ compilations. For all C
source file types, enforce C++.
Also move the -x c check to be in line with the other -x processing