Skip to content

[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

Merged
merged 3 commits into from
Sep 22, 2020

Conversation

mdtoguchi
Copy link
Contributor

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

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
@keryell
Copy link
Contributor

keryell commented Sep 17, 2020

What is the motivation for this or the use-case?
If you have real C code it will break the mangling, you cannot use SYCL in a TU except if it is actually C++.

@mdtoguchi
Copy link
Contributor Author

@keryell, @Fznamznon is better suited to answer here.

@mdtoguchi
Copy link
Contributor Author

@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.

Copy link
Contributor

@erichkeane erichkeane left a 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.">;
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

@elizabethandrews elizabethandrews left a 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?

@premanandrao
Copy link
Contributor

What is the motivation for this or the use-case?
If you have real C code it will break the mangling, you cannot use SYCL in a TU except if it is actually C++.

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:

inline int foo() { return 5; }
int foo();

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.

@AGindinson
Copy link
Contributor

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), -x c would not be permitted in SYCL mode.

@premanandrao
Copy link
Contributor

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), -x c would not be permitted in SYCL mode.

You are right about the driver; I was testing with the cc1 compiler.

@AGindinson
Copy link
Contributor

What is the motivation for this or the use-case?
If you have real C code it will break the mangling, you cannot use SYCL in a TU except if it is actually C++.

@keryell, AFAIU, the following background/justification come into play here:

  1. C function emitting rules being different from C++, there have been cases where device code became invalidated by stuff like FE-generated variadic functions
  2. The most common use-case for .c files is the client code performing a C -> C++ -> SYCL/DPC++ switch without any extension renaming taking place. In this scenario, the "legacy" file extension doesn't play any role, as it's essentially treated as a C++ input that had been striped of all "real C" code.

Comment on lines +2446 to +2461
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;
}
Copy link
Contributor

@AGindinson AGindinson Sep 21, 2020

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...

Copy link
Contributor

@keryell keryell Sep 22, 2020

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. :-)

@keryell
Copy link
Contributor

keryell commented Sep 22, 2020

2. The most common use-case for `.c` files is the client code performing a C -> C++ -> SYCL/DPC++ switch without any extension renaming taking place. In this scenario, the "legacy" file extension doesn't play any role, as it's essentially treated as a C++ input that had been striped of all "real C" code.

I guess that if a user is owning an HPC machine, this is not to compile with -O0 to skip any deadcode elimination... :-)

@romanovvlad romanovvlad merged commit adc2ac7 into intel:sycl Sep 22, 2020
@AGindinson
Copy link
Contributor

2. The most common use-case for `.c` files is the client code performing a C -> C++ -> SYCL/DPC++ switch without any extension renaming taking place. In this scenario, the "legacy" file extension doesn't play any role, as it's essentially treated as a C++ input that had been striped of all "real C" code.

I guess that if a user is owning an HPC machine, this is not to compile with -O0 to skip any deadcode elimination... :-)

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.

jsji pushed a commit that referenced this pull request Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants