Skip to content

[SYCL] Make reduction compatible with MSVC host compiler #6601

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 1 commit into from
Aug 19, 2022

Conversation

aelovikov-intel
Copy link
Contributor

This PR addresses two problems:

  1. MSVC has a bug in handling this in default mode (fine in /permissive-
    though). The issue affected compilation using MSVC as a host compiler.
    Simplified description of the problem:
  template <class Derived>
  class Base {
      using T = int;
  };

  template <class T>
  class A : public Base<A<T>> {
      // That's what we had in the codebase prior to this change. MSVC
      // complains here by default, accepts in "/permissive-".
      using T2 = T;
  };

  class Base2 {
      using T = int;
  };

  template <class T>
  class A2 : public Base2 {
      using T2 = T; // That's where the error has to be emitted.
  };

  int main() {
      A<int> a;
      A2<int> a2;
      return 0;
  }
  1. constexpr variables are part of lambda capture and result in
    incompatibilities between clang device and MSVC host. As such, don't use
    those when they're used inside kernel lambdas. Instead, make them
    regular variables and pay the price of increased number of arguments to
    the kernel.

This PR addresses two problems:

1) MSVC has a bug in handling this in default mode (fine in /permissive-
though). The issue affected compilation using MSVC as a host compiler.

Simplified description of the problem:

  template <class Derived>
  class Base {
      using T = int;
  };

  template <class T>
  class A : public Base<A<T>> {
      // That's what we had in the codebase prior to this change. MSVC
      // complains here by default, accepts in "/permissive-".
      using T2 = T;
  };

  class Base2 {
      using T = int;
  };

  template <class T>
  class A2 : public Base2 {
      using T2 = T; // That's where the error has to be emitted.
  };

  int main() {
      A<int> a;
      A2<int> a2;
      return 0;
  }

2) constexpr variable are part of lambda capture and result in
incompatibilities between clang device and MSVC host. As such, don't use
those when they're used inside kernel lambdas. Instead, make them
regular variable and pay the price of increased number of arguments to
the kernel.
@aelovikov-intel aelovikov-intel requested a review from a team as a code owner August 17, 2022 21:35
@aelovikov-intel
Copy link
Contributor Author

OCL's

Failed Tests (1):
  SYCL :: XPTI/kernel/content.cpp

is known and unrelated.

@v-klochkov
Copy link
Contributor

v-klochkov commented Aug 18, 2022

for (2) mentioned in the description: What do you mean by "incompatibilities between clang device and MSVC host"?
The tests (including reduction tests) work/pass on Windows now, right? If Yes, then what does this PR fix? Can you add a LIT test that fails without and passes with PR?

As I read that description tells me that constexpr must never be used, but that seems like a pretty severe restriction. Users can use constexpr variables in kernel/lambda.

Wouldn't it be useful to ask FE experts (e.g. @erichkeane ) to take a look at this problem too?

@v-klochkov v-klochkov requested a review from erichkeane August 18, 2022 01:57
@v-klochkov
Copy link
Contributor

class A : public Base<A>

Can you please give a reference (file & line number) that has such a crazy construction?

@erichkeane
Copy link
Contributor

for (2) mentioned in the description: What do you mean by "incompatibilities between clang device and MSVC host"? The tests (including reduction tests) work/pass on Windows now, right? If Yes, then what does this PR fix? Can you add a LIT test that fails without and passes with PR?

As I read that description tells me that constexpr must never be used, but that seems like a pretty severe restriction. Users can use constexpr variables in kernel/lambda.

Wouldn't it be useful to ask FE experts (e.g. @erichkeane ) to take a look at this problem too?

Unfortunately this is a type of implementation divergence that would be an ABI break on either side, and the standard permits both (but, I'll say, clangs implementation is more DEFENSIBLE by standard).

@steffenlarsen
Copy link
Contributor

@aelovikov-intel - In this case, the XPTI/kernel/content.cpp failure is likely related to this as the removal of the constexpr means the lambdas are going to capture more variables, which is part of what that test checks.

aelovikov-intel added a commit to aelovikov-intel/llvm-test-suite that referenced this pull request Aug 18, 2022
intel/llvm#6601 increases number of captured
variable and thus number of kernel arguments for reductions. Modify the
CHECKs accordingly.
@aelovikov-intel
Copy link
Contributor Author

@aelovikov-intel - In this case, the XPTI/kernel/content.cpp failure is likely related to this as the removal of the constexpr means the lambdas are going to capture more variables, which is part of what that test checks.

You're right. Created intel/llvm-test-suite#1164, let's wait for its pre-commit to finish.

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@v-klochkov
Copy link
Contributor

I am Ok with the changes. Thank you.
I still think having at least 1 LIT test (failing without this PR and passing with it) is needed, but consider this is non-blocking comment in this case, also relying on @steffenlarsen approval here.

@steffenlarsen steffenlarsen merged commit 94c4b80 into intel:sycl Aug 19, 2022
steffenlarsen pushed a commit to intel/llvm-test-suite that referenced this pull request Aug 19, 2022
intel/llvm#6601 increases number of captured
variable and thus number of kernel arguments for reductions. Modify the
CHECKs accordingly.
@aelovikov-intel aelovikov-intel deleted the red-host-cl branch August 25, 2022 20:10
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Feb 23, 2023
intel#6601 increases number of captured
variable and thus number of kernel arguments for reductions. Modify the
CHECKs accordingly.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Mar 27, 2023
…-suite#1164)

intel#6601 increases number of captured
variable and thus number of kernel arguments for reductions. Modify the
CHECKs accordingly.
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.

4 participants