Skip to content

[SYCL] Extends support for SYCL 2020 implicitly device copyable types #8195

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 16 commits into from
Feb 15, 2023

Conversation

maarquitos14
Copy link
Contributor

Extends support for SYCL2020 implicitly device copyable types and adds new tests to check correct behavior.

@maarquitos14 maarquitos14 requested a review from a team as a code owner February 3, 2023 10:36
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
@maarquitos14 maarquitos14 temporarily deployed to aws February 3, 2023 12:09 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 3, 2023 12:41 — with GitHub Actions Inactive
Comment on lines 2444 to 2456
// std::variant<> is implicitly device copyable type
template <> struct is_device_copyable<std::variant<>> : std::true_type {};

// std::variant<Ts...> is implicitly device copyable type if each type T of
// Ts... is device copyable, and it is not trivially copyable (if it is
// trivially copyable it is device copyable by default)
template <typename T, typename... Ts>
struct is_device_copyable<std::variant<T, Ts...>,
std::enable_if_t<!std::is_trivially_copyable<
std::variant<T, Ts...>>::value>>
: detail::bool_constant<is_device_copyable<T>::value &&
is_device_copyable<std::variant<Ts...>>::value> {};

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer it written using fold expressions.

@@ -0,0 +1,161 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to have more runtime checks that the values of those types actually match between host/device, i.e. check the content of pair.first and/or pair.second.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify - this is my main concern, two other comments are more subjective in nature and thus optional to implement.

Copy link
Contributor

@AlexeySachkov AlexeySachkov Feb 6, 2023

Choose a reason for hiding this comment

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

I suggest that we perhaps have two test cases: one which simply contains a bunch of static_assert(sycl::is_device_copyable_v<some_type_here>) to check that we properly specialize the trait and another one, which checks runtime behavior, i.e. that we are actually able to properly copy values of those types to kernels and read them back.

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 have submitted a PR to llvm-test-suite repo adding tests that check the runtime behavior for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this test is supposed to be compile-only, then I suggest to remove -o %t.out and add -fsyntax-only, see docs for some BKMs. You can also remove any code which submits kernels, because that will be checked in the E2E test you have

Comment on lines 77 to 78
// std::variant with complex types relies on virtual functions, so
// they cannot be used within sycl kernels
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we verify it anywhere? If not, I'd suggest to modify this test as

// RUN: compile and run
// RUN: compile-only -fsyntax-only -Xclang <enable error/warning verification in clang> -DCOMPILE_ONLY
...
#if COMPILE_ONLY
  {
    std::variant<ACopyable>
    // try to pass it to device
    // expected-error: ...
  }
#endif

Copy link
Contributor Author

@maarquitos14 maarquitos14 Feb 10, 2023

Choose a reason for hiding this comment

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

I developed this test and tried both in Linux and Windows. Turns out there's no error in Windows (I guess MSVC doesn't require virtual functions to implement std::variant), so I don't think we should have this test. Also, I will update my comment to say that this only happens in some implementations of std::variant.

@@ -0,0 +1,161 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
Copy link
Contributor

@AlexeySachkov AlexeySachkov Feb 6, 2023

Choose a reason for hiding this comment

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

I suggest that we perhaps have two test cases: one which simply contains a bunch of static_assert(sycl::is_device_copyable_v<some_type_here>) to check that we properly specialize the trait and another one, which checks runtime behavior, i.e. that we are actually able to properly copy values of those types to kernels and read them back.

Signed-off-by: Maronas, Marcos <[email protected]>
@maarquitos14 maarquitos14 temporarily deployed to aws February 8, 2023 18:04 — with GitHub Actions Inactive
@maarquitos14
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1583

@maarquitos14 maarquitos14 temporarily deployed to aws February 9, 2023 14:38 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 9, 2023 16:42 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 9, 2023 19:17 — with GitHub Actions Inactive
Signed-off-by: Maronas, Marcos <[email protected]>
@maarquitos14 maarquitos14 temporarily deployed to aws February 10, 2023 10:45 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 10, 2023 11:17 — with GitHub Actions Inactive
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
@maarquitos14 maarquitos14 temporarily deployed to aws February 10, 2023 19:51 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 13, 2023 09:57 — with GitHub Actions Inactive
@maarquitos14 maarquitos14 temporarily deployed to aws February 13, 2023 10:41 — with GitHub Actions Inactive
@maarquitos14
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1583

1 similar comment
@maarquitos14
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1583

@aelovikov-intel
Copy link
Contributor

@AlexeySachkov is out of office but he marked all his questions/requests as resolved, so I am going LGTM this one.

@AlexeySachkov , please finish your review post-commit once you're back.

@maarquitos14
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1583

@bader bader changed the title [SYCL] Extends support for SYCL2020 implicitly device copyable types [SYCL] Extends support for SYCL 2020 implicitly device copyable types Feb 15, 2023
@bader bader merged commit bad3b38 into intel:sycl Feb 15, 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.

5 participants