Skip to content

[SYCL] Check if the underlying buffer type is device copyable #4914

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 7 commits into from Nov 15, 2021
Merged

[SYCL] Check if the underlying buffer type is device copyable #4914

merged 7 commits into from Nov 15, 2021

Conversation

ghost
Copy link

@ghost ghost commented Nov 8, 2021

The implementation should diagnose an error if the underlying type "T"
of a buffer is not device copyable. The spec says that this is
a requirement for all buffers. It does not make any exception for
buffers that are used only on the host:

"The underlying data type of a buffer T must be device copyable as
defined in Section 3.13.1."

(https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#subsec:buffers)

Pavel Samolysov added 3 commits November 1, 2021 17:45
The implementation should diagnose an error if the underlying type "T"
of a buffer is not device copyable. The spec says that this is
a requirement for all buffers. It does not make any exception for
buffers that are used only on the host:

"The underlying data type of a buffer T must be device copyable as
defined in Section 3.13.1."

(https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#subsec:buffers)
See commit 43c6d7a4e1f78, the
sycl::vec class is not trivially copyable on the host side, so it is
not considered as device copyable. A partial specialization for the
sycl::is_device_copyable for sycl::vec is implemented to mark the class
as device copyable on the host side.
@ghost ghost requested review from bader, alexbatashev, gmlueck and vladimirlaz November 8, 2021 09:06
@ghost
Copy link
Author

ghost commented Nov 8, 2021

Since the sycl::vec class is trivially copyable only on device, I've added a workaround to mark sycl::vec as device copyable on host if and only if the underlying type is also device copyable.

vladimirlaz
vladimirlaz previously approved these changes Nov 8, 2021
#ifndef __SYCL_DEVICE_ONLY__
template <typename T, int N>
struct is_device_copyable<sycl::vec<T, N>,
std::enable_if_t<is_device_copyable<T>::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 don't think you need this enable_if. According to the spec, the underlying type dataT of vec "must be one of the basic scalar types supported in device code". I think this means that all possible types dataT will be trivially copyable (and thus device copyable).

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on this comment. While this file is too crowded with templates, that removing this one clause will not make any difference at all, it is still a good idea not to produce unnecessary template instantiations.

Copy link
Author

Choose a reason for hiding this comment

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

@gmlueck @alexbatashev Thanks for the suggestion. I've removed the check for the underlying type T.

#ifndef __SYCL_DEVICE_ONLY__
template <typename T, int N>
struct is_device_copyable<sycl::vec<T, N>,
std::enable_if_t<is_device_copyable<T>::value>>
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on this comment. While this file is too crowded with templates, that removing this one clause will not make any difference at all, it is still a good idea not to produce unnecessary template instantiations.

#include <sycl/sycl.hpp>
#include <string>

using namespace cl::sycl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
using namespace cl::sycl;
using namespace sycl;

Copy link
Author

Choose a reason for hiding this comment

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

@alexbatashev Thank you, the namespace is changed to sycl::.

vladimirlaz pushed a commit to intel/llvm-test-suite that referenced this pull request Nov 9, 2021
The class 'point' is used to test 'multi_ptr'. A 'sycl::buffer' for instances
of the class is created and the class must be a trivially copyable to be trait
as device copyable. Otherwise a compilation error will be generated after
a new check for device copyability in the 'sycl::buffer' class, see
intel/llvm#4914.

Signed-off-by: Pavel Samolysov <[email protected]>
Pavel Samolysov added 2 commits November 9, 2021 17:10
According to the spec, the underlying type dataT of vec "must be one of
the basic scalar types supported in device code". This means that all
possible types dataT will be trivially copyable (and thus device
copyable).
alexbatashev
alexbatashev previously approved these changes Nov 10, 2021
Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

lgtm

vladimirlaz
vladimirlaz previously approved these changes Nov 10, 2021
@ghost ghost dismissed stale reviews from vladimirlaz and alexbatashev via 192d8f3 November 15, 2021 11:15
@ghost ghost marked this pull request as ready for review November 15, 2021 15:01
@ghost ghost self-requested a review as a code owner November 15, 2021 15:01
@ghost ghost requested review from gmlueck, vladimirlaz and alexbatashev November 15, 2021 15:01
@dm-vodopyanov dm-vodopyanov merged commit 61f1ae6 into intel:sycl Nov 15, 2021
aelovikov-intel pushed a commit to aelovikov-intel/llvm that referenced this pull request Mar 27, 2023
…lvm-test-suite#555)

The class 'point' is used to test 'multi_ptr'. A 'sycl::buffer' for instances
of the class is created and the class must be a trivially copyable to be trait
as device copyable. Otherwise a compilation error will be generated after
a new check for device copyability in the 'sycl::buffer' class, see
intel#4914.

Signed-off-by: Pavel Samolysov <[email protected]>
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