-
Notifications
You must be signed in to change notification settings - Fork 113
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 public utility for users to check if usm_allocators are supported #1476
Adding public utility for users to check if usm_allocators are supported #1476
Conversation
d994552
to
2e10abf
Compare
@@ -233,6 +233,11 @@ __internal::sycl_iterator<access_mode::discard_read_write, T, Allocator> end(syc | |||
return __internal::sycl_iterator<access_mode::discard_read_write, T, Allocator>{buf, | |||
__dpl_sycl::__get_buffer_size(buf)}; | |||
} | |||
|
|||
template <typename ValueType> | |||
constexpr static bool usm_allocated_vector_iterators_supported_v = |
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 the traits doesn't depend on
ValueType
. - As an idea - to make such public trait more general, for example,
template <typename Container>
constexpr static bool is_usm_container_supported = ...
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.
Sadly, I believe it can depend on the ValueType
, for example std::vector<bool>
. GNU c++ standard library implementation normally includes allocator type in the iterator, but not for std::vector<bool>
with the bitfield "optimization".
(This is the only instance I know of, but it shows that we cant guarantee that the implementation details are consistent across value type)
|
||
template <typename ValueType> | ||
constexpr static bool usm_allocated_vector_iterators_supported_v = | ||
oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator<ValueType*>::value; |
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.
BTW, what if ValueType
is a pointer to the host data?
It is rather a kind of general question connected to "Pass Data to algorithms" topic.
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.
If I understand correctly, you suggest the following type:
std::vector<int*, usm_allocator<int*, ...>>
In theory, a vector of host pointers will be very similar to a vector of integers I think.
In principle, as long as they are not dereferencing the pointers on the device, there is nothing wrong with this.
b4022c0
to
07dffec
Compare
}; | ||
template <typename Iter> | ||
struct __vector_iter_distinguishes_by_allocator< | ||
Iter, std::enable_if_t<!std::is_same_v<__default_alloc_vec_iter<Iter>, __usm_shared_alloc_vec_iter<Iter>> && |
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.
Should we apply here std::decay_t
for Iter
template param?
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.
Actually, this is already merged code from #1438 . Working to rebase, to make this focus on just what is added by this PR.
If we need to go back and fix something here, it will needs its own PR I think.
//support std::vector::iterator with usm host / shared allocator as passed directly | ||
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>> || |
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.
Should we apply here std::decay_t
for Iter
template param?
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.
Same as above, this is merged code from #1438. The duplicated conflict code has been fixed via rebase. Any changes here will need a new PR.
2e10abf
to
411ad2f
Compare
documentation/library_guide/parallel_api/pass_data_algorithms.rst
Outdated
Show resolved
Hide resolved
allocator is included in the ``std::vector::iterator`` type definition. You can check | ||
if your C++ standard library implementation provides enough information by checking the | ||
value of ``oneapi::dpl::usm_allocated_vector_iterators_supported_v<ValueType>``. This will | ||
evaluate to ``true`` for C++ standard library implementations which allow oneDPL to support |
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.
Please add a comma between "implementations" and "which" and add an "s" to "allow". The final sentence should read:
This will evaluate to true
for C++ standard library implementations, which allows oneDPL to support USM allocators with this ValueType and false
otherwise.
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 think there was some confusion by my wording. I've expanded this some to hopefully make things more clear.
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.
Thanks for the update. My suggestions on the new content (ignore spacing; I broke things up for this review).
This evaluates to true
when using a C++ standard library implementation, which allows oneDPL to detect and
support USM allocators for ValueType
and false
.
When oneapi::dpl::usm_allocated_vector_iterators_supported_v<ValueType>
evaluates to false
,
you should rely on USM pointers directly instead of using iterators to vectors with USM allocators.
documentation/library_guide/parallel_api/pass_data_algorithms.rst
Outdated
Show resolved
Hide resolved
47b9858
to
8a67a8f
Compare
c748730
to
0d69123
Compare
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]>
8a67a8f
to
45ebb8d
Compare
I think that with the direction we are going with #1477, this does not make sense to continue with such a public API. |
Support for USM allocators depends on the implementation details of the C++ standard library used after #1438, and after doc changes of #1477.
This PR adds a public utility (
usm_allocated_vector_iterators_supported_v<ValueType>
) which users can use at compile time to check if usm_allocators are available to them as efficient input to oneDPL algorithms.If
usm_allocated_vector_iterators_supported_v<ValueType>
evaluates totrue
,std::vector<ValueType, usm_allocator>::iterator
input types are passed directly to sycl kernels, and are an efficient way of using oneDPL.If
usm_allocated_vector_iterators_supported_v<ValueType>
evaluates tofalse
,std::vector<ValueType, usm_allocator>::iterator
input types are treated as if they were host-side iterators, and wrapped insycl::buffer
before use in sycl kernels. This includes all that comes with that, an extra host-side copy in and out. Also these cannot then be used as the source iterator forpermutation_iterator
.