Skip to content
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

[SYCL] Make swizzle mutating operators const friends #13012

Merged

Conversation

steffenlarsen
Copy link
Contributor

In #12682 the mutating operators for swizzles (+=, -=, ..., ++, --) were reverted to be members rather than friends. Since swizzles mutate the underlying vec rather than themselves these operators should take and return constant references instead, which this commit implements.

In intel#12682 the mutating operators for
swizzles (+=, -=, ..., ++, --) were reverted to be members rather than
friends. Since swizzles mutate the underlying vec rather than themselves
these operators should take and return constant references instead,
which this commit implements.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
@steffenlarsen steffenlarsen requested a review from a team as a code owner March 13, 2024 15:44
@steffenlarsen steffenlarsen marked this pull request as draft March 13, 2024 15:44
steffenlarsen added a commit to steffenlarsen/llvm that referenced this pull request Mar 14, 2024
Swizzles should not expose mutating functions when the underlying vector
is const. This commit SFINAEs these out.

This is built on top of intel#13012.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
*(ResultIt++) = (VecVal.swizzle<1>() OP## = 2)[0] == ExpectedRes && \
VecVal[1] == ExpectedRes; \
}
TestCase(+);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can do TestCase([](auto x, auto y) { return x + y; }) to avoid the macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that would help here. Note that in this case the line will resolve to:

  {
    sycl::vec<int, 4> VecVal{1, 2, 3, 4};
    int ExpectedRes = VecVal[1] + 2;
    ResultsAcc[I++] = (VecVal.swizzle<1>() += 2)[0] == ExpectedRes &&
                      VecVal[1] == ExpectedRes; 
  }

The important check here is really the += as it is the mutating function, but I can see if the TestCase macro is a little hard to read, due to the space the formatter adds in OP##=.

I could change it to be TestCase(+, +=) instead, but I'm not sure if there's a way to make it take a lambda function without it being way more verbose.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
@steffenlarsen steffenlarsen marked this pull request as ready for review June 27, 2024 16:24
@steffenlarsen
Copy link
Contributor Author

KhronosGroup/SYCL-Docs#514 has been merged. This is ready for review!

@steffenlarsen
Copy link
Contributor Author

Sorry, grabbed the wrong tag.

@intel/llvm-reviewers-runtime - Friendly ping.

@aelovikov-intel
Copy link
Contributor

I believe the change is rather isolated and can be merged without re-test.

@aelovikov-intel aelovikov-intel merged commit 21c2e1c into intel:sycl Jul 16, 2024
14 checks passed
smanna12 pushed a commit to smanna12/llvm that referenced this pull request Jul 16, 2024
In intel#12682 the mutating operators for
swizzles (+=, -=, ..., ++, --) were reverted to be members rather than
friends. Since swizzles mutate the underlying vec rather than themselves
these operators should take and return constant references instead,
which this commit implements.

---------

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
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.

2 participants