Skip to content

[SYCL] Change trivially_copyable to device_copyable #8826

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 2 commits into from
Jun 12, 2023

Conversation

hdelan
Copy link
Contributor

@hdelan hdelan commented Mar 28, 2023

cgh.fill(...) was failing when T is a sycl::vec type, since sycl::vec types have no specialization for std::is_trivially_copyable. Since device_copyable is a sycl superset of trivially copyable we should use this instead in sycl headers.

I can add a test to check that cgh.fill works for vec types if necessary. Let me know if I should do this.

There are some other occurrences of std::is_trivially_copyable in the sycl headers. Let me know if I should replace more incidences.

@hdelan hdelan requested a review from a team as a code owner March 28, 2023 10:48
@hdelan hdelan requested a review from aelovikov-intel March 28, 2023 10:48
@hdelan hdelan changed the title Change trivially_copyable to device_copyable [SYCL] Change trivially_copyable to device_copyable Mar 28, 2023
@hdelan hdelan temporarily deployed to aws March 28, 2023 11:15 — with GitHub Actions Inactive
@hdelan hdelan temporarily deployed to aws March 28, 2023 12:16 — with GitHub Actions Inactive
Copy link
Contributor

@aelovikov-intel aelovikov-intel left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. Tagging @gmlueck and @AlexeySachkov just in case..

@AlexeySachkov
Copy link
Contributor

Looks reasonable to me. Tagging @gmlueck and @AlexeySachkov just in case..

The change seem to be ok from the point of view of our implementation, where we use custom kernel to implement fill. However, the spec currently does not impose any restrictions on T, so strictly speaking, both our implementations (existing one and proposed here) are incorrect, because they impose restrictions on T.

I wouldn't say that the spec is clear here as well, it says:

Replicates the value of src

Is src being copy-constructed to fill a buffer? Is it being simply byte-copied to fill a buffer? In OpenCL, corresponding interface does plain memcpy, but it accepts a pointer and size pair, it does not accept generic type T, which may not be trivially copyable, copy-constructible, or copy-assignable.

Since SYCL interface is a C++ interface accepting a reference to generic type T, I think that we should clarify in the spec which operations on T must be available for the implementation. Would be good to hear from @gmlueck here.

I'm still fine with merging this PR, though: it doesn't make the situation worse and actually relaxes restrictions we impose on T a bit.

@gmlueck
Copy link
Contributor

gmlueck commented Mar 29, 2023

Since SYCL interface is a C++ interface accepting a reference to generic type T, I think that we should clarify in the spec which operations on T must be available for the implementation. Would be good to hear from @gmlueck here.

I agree that this is unclear in the spec. I was looking at the git history of the spec, and I see that we used to say that T had to be trivially copyable, which explains the state of our implementation (before this PR). This wording got removed from the spec before it was published.

I think it is correct to restrict T to "device copyable", which means we can do a byte copy when implementing fill, so I agree with this PR.

I think we should make the same clarification for this member function of handler:

template <typename T> void copy(const T* src, T* dest, size_t count)

Do you have any objections if I clarify the spec for both fill and copy to say that T must be device copyable?

@hdelan
Copy link
Contributor Author

hdelan commented Jun 7, 2023

Sorry I thought that I had responded to this.

Do you have any objections if I clarify the spec for both fill and copy to say that T must be device copyable?

Yes @gmlueck I'd be happy if you clarified this in the spec. I have also added some static_asserts for copy(const T *src) as well as the smart pointer case to make sure that T is device_copyable. Hopefully this can be merged

@gmlueck
Copy link
Contributor

gmlueck commented Jun 7, 2023

Sorry I thought that I had responded to this.

Do you have any objections if I clarify the spec for both fill and copy to say that T must be device copyable?

Yes @gmlueck I'd be happy if you clarified this in the spec. I have also added some static_asserts for copy(const T *src) as well as the smart pointer case to make sure that T is device_copyable. Hopefully this can be merged

I submitted a PR to the spec: KhronosGroup/SYCL-Docs#425

@hdelan hdelan temporarily deployed to aws June 7, 2023 14:53 — with GitHub Actions Inactive
@hdelan hdelan temporarily deployed to aws June 7, 2023 16:22 — with GitHub Actions Inactive
@AlexeySachkov AlexeySachkov merged commit 9c662e2 into intel:sycl Jun 12, 2023
@dm-vodopyanov
Copy link
Contributor

dm-vodopyanov commented Jun 12, 2023

Failure in post-commit for E2E tests on Windows:

Failed Tests (1):
  SYCL :: Basic/handler/handler_mem_op.cpp

https://github.com/intel/llvm/actions/runs/5244433715/jobs/9471540544

@hdelan could you please address?

Upd: post commit on Linux is also failing: https://github.com/intel/llvm/actions/runs/5245429333/jobs/9473293760

@0x12CC
Copy link
Contributor

0x12CC commented Jun 12, 2023

#9829 fixes the E2E test failure caused by this PR.

@hdelan
Copy link
Contributor Author

hdelan commented Jun 15, 2023

Sorry I was on holiday the last few days. Is this resolved by #9829 ?

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.

6 participants