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] Fix EnableIfOutputIteratorT trait #12834

Open
wants to merge 13 commits into
base: sycl
Choose a base branch
from
2 changes: 2 additions & 0 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ class buffer : public detail::buffer_plain,
template <typename Destination>
detail::EnableIfOutputIteratorT<Destination>
set_final_data_internal(Destination FinalData) {
static_assert(!std::is_const_v<std::remove_reference_t<decltype(*FinalData)>>,
"set_final_data must be called with a non-const iterator!");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this and not the fix in EnableIfOutputIteratorT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning was that by adding it to EnableIfOutputIteratorT, when we call set_final_data_internal with a const iterator it simply gets ignored by overload resolution and the compiler diagnostics will most likely be confusing for someone who is not that familiar with template errors. Furthermore, this is an easy mistake to make when writing SYCL code and therefore it would be nice to get a clear error message telling you what you did wrong and thats what a static_assert does. If you're not convinced however, I can add it to EnableIfOutputIteratorT.

Copy link
Contributor

Choose a reason for hiding this comment

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

it simply gets ignored by overload resolution

And that's what the spec says should happen, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you provide the part of the spec that says this?
All I can see is that the spec says what to do if the iterator is not const, I cant see anything regarding what to do if it is const.

Copy link
Contributor

Choose a reason for hiding this comment

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

SYCL:

Destination can be either an output iterator or a std::weak_ptr.

C++:

The output_iterator concept is a refinement of input_or_output_iterator, adding the requirement that it can be used to write values of type and value category encoded by T (via indirectly_writable). equality_comparable is not required.

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 see, thanks for the clarification!
I will make the suggested changes!

const size_t Size = size();
buffer_plain::set_final_data_internal(
[FinalData, Size](const std::function<void(void *const Ptr)> &F) {
Expand Down
Loading