-
Notifications
You must be signed in to change notification settings - Fork 114
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
Adding std::vector<T, usm_allocator>::iterator to is_passed_directly types #1438
Adding std::vector<T, usm_allocator>::iterator to is_passed_directly types #1438
Conversation
Our documentation only makes mention of the case where we use a |
Its a good question, I will need to look into it some. @MikeDvorskiy @rarutyun @akukanov do you have an opinion on how we should handle |
After some thought, I believe we should support |
When run through the input data sweep tests from #1429, it seems that both |
There was a bug of miss-placed |
@MikeDvorskiy @mmichel11 Actually there is a fundamental problem with this, and it will not work. This breaks host_iterators because This is problematic though, because as it stands (without this PR), we have an extra copy to a host memory location, and also these iterators are unable to be used as the source iterator for permutation iterators (the same as host_iterators). Sadly, I see no apparent solution to this issue. |
Update: I've provided a solution which should hopefully allow support when it is possible to, without breaking host_iterators. It first checks if we can distinguish between host_iterator and @MikeDvorskiy Please take a look and see if you can find problems with this approach. |
…types Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
typename ::std::vector<ValueType, typename sycl::usm_allocator<ValueType, sycl::usm::alloc::host>>::iterator; | ||
|
||
template <typename Iter> | ||
struct __vector_iter_distinguishes_by_allocator< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we played it extra safe here, but let be so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this provides more and better evidence that unique allocators (not defined by the standard) result in iterator types which are unique from each other. All of it is done at compile time, so I don't see a downside.
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
documentation/library_guide/parallel_api/pass_data_algorithms.rst
Outdated
Show resolved
Hide resolved
documentation/library_guide/parallel_api/pass_data_algorithms.rst
Outdated
Show resolved
Hide resolved
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with a couple of minor comments.
template <typename Iter> | ||
struct is_passed_directly< | ||
Iter, std::enable_if_t<(std::is_same_v<Iter, oneapi::dpl::__internal::__usm_shared_alloc_vec_iter<Iter>> || | ||
std::is_same_v<Iter, oneapi::dpl::__internal::__usm_host_alloc_vec_iter<Iter>>)&&oneapi:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneapi::dpl::__internal::__usm_host_alloc_vec_iter<Iter>>)&&oneapi::
=> oneapi::dpl::__internal::__usm_host_alloc_vec_iter<Iter>>) && oneapi::
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed formatting. (clang format will now complain)
on details of the C++ standard library implementation and what information about the | ||
allocator is included in the ``std::vector::iterator`` type definition. If USM allocated | ||
vector iterators are not detectable with your C++ standard library, they will still function | ||
as inputs to oneDPL, but they will be treated as if they were host-side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, it makes sense to add the clarification that in case "USM allocated
vector iterators are not detectable with your C++ standard library" a user can use vec.data()
instead of "vec.begin()". It guarantees data processing w/o host-device extra copying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After offline discussion, I've made these changes, but also separated out the documentation changes into another PR #1477.
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It seems that
std::vector
withusm_allocator
withsycl::usm::alloc::shared
data were being processed as if they were host_iterators when being passed to oneDPL with device policy and dpcpp backend.This means that they were being used to initialize a
sycl::buffer
which includes an extra copy to intermediate host memory. This is unnecessary because iterators to such data should be passed directly, and directly usable within a kernel.This PR adds a specialization for the is_passed_directly trait, which enables such iterators to be properly passed directly. This avoids the extra copy.
This was uncovered in investigation #1429, and will be tested by those tests, after a suggestion from @mmichel11 .