Skip to content

[SYCL][ESIMD] Support bool conversion to simd_mask in invoke_simd #8524

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
Mar 14, 2023

Conversation

sarnex
Copy link
Contributor

@sarnex sarnex commented Mar 2, 2023

As per our recent discussions, bool passed into invoke_simd should convert to simd_mask with a user-defined type. Conversely, simd_mask will convert back to bool from inside the invoked function.

I also had to fix a couple of minor bugs in the implementation of the DPCPP-specific changes in std::experimental::simd.

I will make a follow-up PR to update the invoke_simd spec with the results of our recent discussion.

Test PR: intel/llvm-test-suite#1630

@sarnex sarnex changed the title [SYCL[ESIMD] Support bool conversion to simd_mask in invoke_simd [SYCL][ESIMD] Support bool conversion to simd_mask in invoke_simd Mar 2, 2023
@sarnex sarnex temporarily deployed to aws March 3, 2023 16:32 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to aws March 3, 2023 22:03 — with GitHub Actions Inactive
@sarnex sarnex closed this Mar 3, 2023
@sarnex sarnex reopened this Mar 3, 2023
@sarnex sarnex temporarily deployed to aws March 4, 2023 02:41 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to aws March 4, 2023 03:19 — with GitHub Actions Inactive
@sarnex sarnex marked this pull request as ready for review March 6, 2023 15:47
@sarnex sarnex requested review from a team and rolandschulz as code owners March 6, 2023 15:47
@sarnex sarnex requested a review from Pennycook March 6, 2023 15:47
@sarnex
Copy link
Contributor Author

sarnex commented Mar 6, 2023

@rolandschulz @Pennycook Hey guys, do you mind looking at this PR, particular at my std/experimental/simd.hpp change? It seems the original implementation has a couple of minor bugs fixed in this PR, but definitely would like a closer look. Thanks

Comment on lines 1687 to 1691
simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {
simd_mask(const simd_mask<_Up, abi_type>& __v) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this change.

TS2 shows that this constructor is only available from fixed-sized masks: https://en.cppreference.com/w/cpp/experimental/simd/simd_mask/simd_mask

Copy link
Contributor Author

@sarnex sarnex Mar 6, 2023

Choose a reason for hiding this comment

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

Thanks for the review. The problem I'm trying to fix is the implicit conversion constructor doesn't work. Mind helping me find a better fix?

test.cpp:

#include <std/experimental/simd.hpp>

namespace simd_abi {
template <class T, int N>
using native_fixed_size = typename std::experimental::__simd_abi<
    std::experimental::_StorageKind::_VecExt, N>;
}

template <class T, int N>
using simd_mask =
    std::experimental::simd_mask<T, simd_abi::native_fixed_size<T, N>>;

int main() {

simd_mask<int, 8> x;
simd_mask<double, 8> y(x);
}

error:

test.cpp:16:22: error: no matching constructor for initialization of 'simd_mask<double, 8>' (aka 'simd_mask<double, __simd_abi<std::experimental::_StorageKind::_VecExt, 8>>')
simd_mask<double, 8> y(x);
                     ^ ~
../include/std/experimental/simd.hpp:1648:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'simd_mask<int, [...]>' to 'const simd_mask<double, [...]>' for 1st argument
class simd_mask {
      ^
../include/std/experimental/simd.hpp:1648:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'simd_mask<int, [...]>' to 'simd_mask<double, [...]>' for 1st argument
../include/std/experimental/simd.hpp:1674:12: note: candidate constructor not viable: no known conversion from 'simd_mask<int, 8>' (aka 'simd_mask<int, __simd_abi<std::experimental::_StorageKind::_VecExt, 8>>') to 'value_type' (aka 'bool') for 1st argument
  explicit simd_mask(value_type __v) noexcept {
           ^
../include/std/experimental/simd.hpp:1687:3: note: candidate template ignored: could not match '__simd_abi<1, [...]>' against '__simd_abi<2, [...]>'
  simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {
  ^
../include/std/experimental/simd.hpp:1669:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
  simd_mask() = default;
  ^
../include/std/experimental/simd.hpp:1699:3: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
  simd_mask(const value_type*, _Flags);
  ^
1 error generated.

important part:

../include/std/experimental/simd.hpp:1687:3: note: candidate template ignored: could not match '__simd_abi<1, [...]>' against '__simd_abi<2, [...]>'
  simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see... We should wait to hear from @rolandschulz (because he's more familiar with the std::simd proposal), but I would be tempted to add a new constructor alongside the existing one, rather than replacing it. So, we'd have both:

simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept;
simd_mask(const simd_mask<_Up, abi_type>& __v) noexcept;

Does that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah thats a better idea thanks, let me tentatively implement that

@sarnex sarnex temporarily deployed to aws March 6, 2023 20:21 — with GitHub Actions Inactive
@v-klochkov
Copy link
Contributor

@sarnex Jenkins/Precommit failed catastrophically. Can you please do 'git fetch' + 'git merge' to re-start testing?

@sarnex
Copy link
Contributor Author

sarnex commented Mar 7, 2023

@v-klochkov I think you can do it by closing/reopening PR, let me try that

@sarnex sarnex closed this Mar 7, 2023
@sarnex sarnex reopened this Mar 7, 2023
@v-klochkov
Copy link
Contributor

@v-klochkov I think you can do it by closing/reopening PR, let me try that

It may work. git-merge though additionally may pick useful fixes for testing infra (if there were any)

@sarnex
Copy link
Contributor Author

sarnex commented Mar 7, 2023

It may work. git-merge though additionally may pick useful fixes for testing infra (if there were any)

good point

@sarnex sarnex temporarily deployed to aws March 7, 2023 17:47 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to aws March 7, 2023 21:07 — with GitHub Actions Inactive
@v-klochkov
Copy link
Contributor

I am not merging yet because not sure if @rolandschulz had any comments.
Roland, if there are no comments or suggestions to changes something, then I'll merge it on Thursday evening.

@sarnex sarnex temporarily deployed to aws March 9, 2023 12:24 — with GitHub Actions Inactive
@sarnex
Copy link
Contributor Author

sarnex commented Mar 13, 2023

@v-klochkov Think we can merge this and the test PR and address any feedback from Roland in a follow up?

sarnex added 3 commits March 13, 2023 16:44
As per our recent discussions, bool passed into invoke_simd
should convert to simd_mask with a user-defined type.
Conversely, simd_mask will convert back to bool from inside the
invoked function.

I also had to fix a couple of minor bugs in the implementation
of the DPCPP-specific changes in std::experimental::simd.

I will make a follow-up PR to update the invoke_simd spec with
the results of our recent discussion.

Signed-off-by: Sarnie, Nick <[email protected]>
Signed-off-by: Sarnie, Nick <[email protected]>
Signed-off-by: Sarnie, Nick <[email protected]>
@sarnex sarnex temporarily deployed to aws March 13, 2023 22:37 — with GitHub Actions Inactive
@sarnex sarnex temporarily deployed to aws March 13, 2023 23:07 — with GitHub Actions Inactive
@v-klochkov v-klochkov merged commit 8e08ca3 into intel:sycl Mar 14, 2023
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.

3 participants