-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Fix sycl::span type deduction #4970
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,7 +608,11 @@ as_writable_bytes(span<_Tp, _Extent> __s) noexcept | |
} | ||
|
||
// Deduction guides | ||
template <class _Tp, size_t _Sz> span(_Tp (&)[_Sz])->span<_Tp, _Sz>; | ||
|
||
// array arg deduction guide. dynamic_extent arg used to select | ||
// the correct template. The _Sz will be used for the __size of the span. | ||
template <class _Tp, size_t _Sz> | ||
span(_Tp (&)[_Sz]) -> span<_Tp, dynamic_extent>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love comments! Thanks. Send more! :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keryell , I think this previous discussion (the one that led to the comment in the first place) answers your question: But if it doesn't, perhaps you could rephrase it? Regardless, it appears I should expand the comment even more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I see what the question is, and maybe I misspoke when answering @steffenlarsen earlier. The _Sz does not end up changing the extent (which is const) but ends up setting the __size of the span. I guess a variation on these questions might be, "why is an array of known size end up constructing a span with dynamic_extent"? And while not the author of the code, I believe the answer to that is very simply that the dynamic_extent specialization tracks both data and size, while the other specialization does not. So the array constructor was placed there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds to me like there's something wrong with the implementation. Correct me if I am wrong, but this way we won't have the "same" type deduced as for int arr[] {1,2,3,4};
sycl::span SYCLSpan {arr}; // will have type sycl::span<int, sycl::dynamic_extent>
std::span STDSpan {arr}; // will have type std::span<int, 4> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it looks like there is a problem in the implementation. I'll open up a ticket for it, rather than try to address it here. Being unable to instantiate spans at all from an array without a type specifier is a more immediate problem. I went and compared GCC span, Clang libc++ span, and our SYCL span, and discovered that not only are we not handling fully specialized spans-from-arrays, but, surprisingly, partially specialized ones had dynamic extent in GCC and Clang stdlib, which I wasn't expecting.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least this shows it is good to add some comments and it can exhibit some bugs :-) |
||
|
||
template <class _Tp, size_t _Sz> span(std::array<_Tp, _Sz> &)->span<_Tp, _Sz>; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.