From e9c0488751bff4bbe91ea3f8abc6dd8cdc6b1b9b Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 7 Mar 2024 17:12:57 -0500 Subject: [PATCH 01/27] adding std::vector::iterator to is_passed_directly types Signed-off-by: Dan Hoeflinger --- .../oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 1821301e911..e4a0705f698 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -206,6 +206,17 @@ struct is_passed_directly +struct is_passed_directly< + Iter, + ::std::enable_if_t<::std::is_same_v< + Iter, typename ::std::vector::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::shared>::iterator>>>> + : ::std::true_type +{ +}; + template struct is_passed_directly> : ::std::true_type { From 4c52a5fca0eab47adeec6069f87ed2f7ee1e2fd5 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 8 Mar 2024 08:36:30 -0500 Subject: [PATCH 02/27] adding host usm allocator support Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index e4a0705f698..20b179b77d4 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -206,6 +206,7 @@ struct is_passed_directly struct is_passed_directly< Iter, @@ -217,6 +218,18 @@ struct is_passed_directly< { }; +//support std::vector::iterator with usm host allocator as passed directly +template +struct is_passed_directly< + Iter, + ::std::enable_if_t<::std::is_same_v< + Iter, typename ::std::vector::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::host>::iterator>>>> + : ::std::true_type +{ +}; + template struct is_passed_directly> : ::std::true_type { From 5d5ae9ab59fde7feedb64f5ad75e40e7b926c2c7 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 8 Mar 2024 12:22:33 -0500 Subject: [PATCH 03/27] bugfix Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 20b179b77d4..6a4f0c4392c 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -213,7 +213,7 @@ struct is_passed_directly< ::std::enable_if_t<::std::is_same_v< Iter, typename ::std::vector::value_type, typename sycl::usm_allocator::value_type, - sycl::usm::alloc::shared>::iterator>>>> + sycl::usm::alloc::shared>>::iterator>>> : ::std::true_type { }; @@ -225,7 +225,7 @@ struct is_passed_directly< ::std::enable_if_t<::std::is_same_v< Iter, typename ::std::vector::value_type, typename sycl::usm_allocator::value_type, - sycl::usm::alloc::host>::iterator>>>> + sycl::usm::alloc::host>>::iterator>>> : ::std::true_type { }; From 897f5627285076b8207134e8e2073642fe432c33 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 11 Mar 2024 11:49:00 -0400 Subject: [PATCH 04/27] resolving ambiguity when these iterator types would match Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 6a4f0c4392c..e8d112155bf 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -78,7 +78,11 @@ class all_view { return begin() + size(); } - __return_t& operator[](__diff_type i) const { return begin()[i]; } + __return_t& + operator[](__diff_type i) const + { + return begin()[i]; + } __diff_type size() const @@ -206,26 +210,19 @@ struct is_passed_directly -struct is_passed_directly< - Iter, - ::std::enable_if_t<::std::is_same_v< - Iter, typename ::std::vector::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::shared>>::iterator>>> - : ::std::true_type -{ -}; - -//support std::vector::iterator with usm host allocator as passed directly +//support std::vector::iterator with usm host / shared allocator as passed directly template struct is_passed_directly< Iter, - ::std::enable_if_t<::std::is_same_v< - Iter, typename ::std::vector::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::host>>::iterator>>> + ::std::enable_if_t< + ::std::is_same_v< + Iter, typename ::std::vector::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::shared>>::iterator> || + ::std::is_same_v< + Iter, typename ::std::vector::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::host>>::iterator>>> : ::std::true_type { }; From b3306a4b9916f3802d5bf2fdcd2b96241c42c71a Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 11 Mar 2024 11:50:05 -0400 Subject: [PATCH 05/27] reverting formatting only change Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index e8d112155bf..9a2c3dee28a 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -78,11 +78,7 @@ class all_view { return begin() + size(); } - __return_t& - operator[](__diff_type i) const - { - return begin()[i]; - } + __return_t& operator[](__diff_type i) const { return begin()[i]; } __diff_type size() const From 00b87642289d5faf85c16ad26923e9b4f26d0f92 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 11 Mar 2024 15:44:34 -0400 Subject: [PATCH 06/27] only mark usm_allocator vector iterator as passed directly if we can distinguish from host_iter Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 9a2c3dee28a..a3699dca65a 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -45,6 +45,25 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) return {__buf, sycl::range<1>(__n_acc), __offset}; } + +// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a +// std::vector::iterator can be distinguished from std::vector::iterator +template +struct __vector_impl_distinguishes_usm_allocator_from_default : ::std::false_type +{ +}; + +template +struct __vector_impl_distinguishes_usm_allocator_from_default< + Iter, ::std::enable_if_t::value_type>::iterator, + typename ::std::vector::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::shared>>::iterator>>> + : ::std::true_type +{ +}; + } // namespace __internal //A SYCL range over SYCL buffer @@ -211,14 +230,15 @@ template struct is_passed_directly< Iter, ::std::enable_if_t< - ::std::is_same_v< - Iter, typename ::std::vector::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::shared>>::iterator> || - ::std::is_same_v< - Iter, typename ::std::vector::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::host>>::iterator>>> + oneapi::dpl::__ranges::__internal::__vector_impl_distinguishes_usm_allocator_from_default::value && + (::std::is_same_v::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::shared>>::iterator> || + ::std::is_same_v::value_type, + typename sycl::usm_allocator::value_type, + sycl::usm::alloc::host>>::iterator>)>> : ::std::true_type { }; From ba00bdcf858b3881b55c84c09be1483091dd502a Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 15 Mar 2024 08:17:45 -0400 Subject: [PATCH 07/27] name change for helper struct Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index a3699dca65a..41cf1d73fed 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -49,12 +49,12 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) // Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a // std::vector::iterator can be distinguished from std::vector::iterator template -struct __vector_impl_distinguishes_usm_allocator_from_default : ::std::false_type +struct __vector_iter_distinguishes_usm_allocator_from_default : ::std::false_type { }; template -struct __vector_impl_distinguishes_usm_allocator_from_default< +struct __vector_iter_distinguishes_usm_allocator_from_default< Iter, ::std::enable_if_t::value_type>::iterator, typename ::std::vector::value_type, @@ -230,7 +230,7 @@ template struct is_passed_directly< Iter, ::std::enable_if_t< - oneapi::dpl::__ranges::__internal::__vector_impl_distinguishes_usm_allocator_from_default::value && + oneapi::dpl::__ranges::__internal::__vector_iter_distinguishes_usm_allocator_from_default::value && (::std::is_same_v::value_type, typename sycl::usm_allocator::value_type, From 8d30b1b3d6d8b6fb2972d499f675d67f977a07a1 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Tue, 2 Apr 2024 14:40:59 -0400 Subject: [PATCH 08/27] make more readable, add check between different types of usm alloc Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 41cf1d73fed..851cd5f567c 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -49,17 +49,26 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) // Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a // std::vector::iterator can be distinguished from std::vector::iterator template -struct __vector_iter_distinguishes_usm_allocator_from_default : ::std::false_type +struct __vector_iter_distinguishes_by_allocator : ::std::false_type { }; +template ::value_type> +using __default_alloc_vec_iter = typename ::std::vector::iterator; + +template ::value_type> +using __usm_shared_alloc_vec_iter = + typename ::std::vector>::iterator; + +template ::value_type> +using __usm_host_alloc_vec_iter = + typename ::std::vector>::iterator; + template -struct __vector_iter_distinguishes_usm_allocator_from_default< - Iter, ::std::enable_if_t::value_type>::iterator, - typename ::std::vector::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::shared>>::iterator>>> +struct __vector_iter_distinguishes_by_allocator< + Iter, ::std::enable_if_t, __usm_shared_alloc_vec_iter> && + !::std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && + !::std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> : ::std::true_type { }; @@ -97,7 +106,11 @@ class all_view { return begin() + size(); } - __return_t& operator[](__diff_type i) const { return begin()[i]; } + __return_t& + operator[](__diff_type i) const + { + return begin()[i]; + } __diff_type size() const @@ -229,16 +242,9 @@ struct is_passed_directly struct is_passed_directly< Iter, - ::std::enable_if_t< - oneapi::dpl::__ranges::__internal::__vector_iter_distinguishes_usm_allocator_from_default::value && - (::std::is_same_v::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::shared>>::iterator> || - ::std::is_same_v::value_type, - typename sycl::usm_allocator::value_type, - sycl::usm::alloc::host>>::iterator>)>> + ::std::enable_if_t::value && + (::std::is_same_v> || + ::std::is_same_v>)>> : ::std::true_type { }; @@ -629,6 +635,8 @@ struct __get_sycl_range __process_input_iter(_Iter __first, _Iter __last) { assert(__first < __last); + std::cout<<"passed directly type\n"; + return __range_holder>{ oneapi::dpl::__ranges::guard_view<_Iter>{__first, __last - __first}}; } @@ -669,6 +677,7 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; + std::cout<<"contig host\n"; return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) @@ -698,7 +707,7 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; - + std::cout<<"non contig host\n"; return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) { From 2dabe9cdcf882d42adc3f7de60719118f240b5c5 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Tue, 2 Apr 2024 15:02:02 -0400 Subject: [PATCH 09/27] cleanup comments, debugging output, and formatting only changes --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 851cd5f567c..9cf83b5e59d 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -47,7 +47,9 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) } // Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a -// std::vector::iterator can be distinguished from std::vector::iterator +// std::vector::iterator can be distinguished between three different allocators, the +// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator +// could be confused with a usm allocator. template struct __vector_iter_distinguishes_by_allocator : ::std::false_type { @@ -106,11 +108,7 @@ class all_view { return begin() + size(); } - __return_t& - operator[](__diff_type i) const - { - return begin()[i]; - } + __return_t& operator[](__diff_type i) const { return begin()[i]; } __diff_type size() const @@ -635,8 +633,6 @@ struct __get_sycl_range __process_input_iter(_Iter __first, _Iter __last) { assert(__first < __last); - std::cout<<"passed directly type\n"; - return __range_holder>{ oneapi::dpl::__ranges::guard_view<_Iter>{__first, __last - __first}}; } @@ -677,8 +673,6 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; - std::cout<<"contig host\n"; - return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) { @@ -707,7 +701,6 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; - std::cout<<"non contig host\n"; return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) { From 8d43c85a9cb6a4c3a2789681558e299e4967b1f9 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Tue, 2 Apr 2024 15:03:25 -0400 Subject: [PATCH 10/27] returning original spacing Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 9cf83b5e59d..90b7b30c50c 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -673,6 +673,7 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; + return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) { @@ -701,6 +702,7 @@ struct __get_sycl_range __range_holder, _LocalAccMode>>> { using _T = val_t<_Iter>; + return __process_host_iter_impl<_LocalAccMode>(__first, __last, [&]() { if constexpr (__is_copy_direct_v<_LocalAccMode>) { From 5cc5eb4ad975ca1a1dc96d1d75d1c111060db3fe Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 10:52:18 -0400 Subject: [PATCH 11/27] ::std:: -> std:: Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 90b7b30c50c..21527f30d40 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -51,27 +51,27 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) // default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator // could be confused with a usm allocator. template -struct __vector_iter_distinguishes_by_allocator : ::std::false_type +struct __vector_iter_distinguishes_by_allocator : std::false_type { }; -template ::value_type> -using __default_alloc_vec_iter = typename ::std::vector::iterator; +template ::value_type> +using __default_alloc_vec_iter = typename std::vector::iterator; -template ::value_type> +template ::value_type> using __usm_shared_alloc_vec_iter = - typename ::std::vector>::iterator; + typename std::vector>::iterator; -template ::value_type> +template ::value_type> using __usm_host_alloc_vec_iter = - typename ::std::vector>::iterator; + typename std::vector>::iterator; template struct __vector_iter_distinguishes_by_allocator< - Iter, ::std::enable_if_t, __usm_shared_alloc_vec_iter> && - !::std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && - !::std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> - : ::std::true_type + Iter, std::enable_if_t, __usm_shared_alloc_vec_iter> && + !std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && + !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> + : std::true_type { }; @@ -240,10 +240,10 @@ struct is_passed_directly struct is_passed_directly< Iter, - ::std::enable_if_t::value && - (::std::is_same_v> || - ::std::is_same_v>)>> - : ::std::true_type + std::enable_if_t::value && + (std::is_same_v> || + std::is_same_v>)>> + : std::true_type { }; From a7fcff1e24a01abfb0f31ad13c4ed357e2267f4d Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 11:43:11 -0400 Subject: [PATCH 12/27] reorganize code and make public utilities Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/sycl_iterator.h | 37 +++++++++++++++++++ .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 37 +------------------ 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index 05047f61d77..ac8a3094d87 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -149,6 +149,35 @@ struct _ModeConverter static constexpr access_mode __value = access_mode::discard_write; }; +// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a +// std::vector::iterator can be distinguished between three different allocators, the +// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator +// could be confused with a usm allocator. +template +struct __vector_iter_distinguishes_by_allocator : std::false_type +{ +}; + +template ::value_type> +using __default_alloc_vec_iter = typename std::vector::iterator; + +template ::value_type> +using __usm_shared_alloc_vec_iter = + typename std::vector>::iterator; + +template ::value_type> +using __usm_host_alloc_vec_iter = + typename std::vector>::iterator; + +template +struct __vector_iter_distinguishes_by_allocator< + Iter, std::enable_if_t, __usm_shared_alloc_vec_iter> && + !std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && + !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> + : std::true_type +{ +}; + } // namespace __internal template @@ -206,6 +235,14 @@ __internal::sycl_iterator end(syc return __internal::sycl_iterator{buf, __dpl_sycl::__get_buffer_size(buf)}; } + +template +using is_usm_allocated_vector_iterator_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value && + std::is_same_v> || + std::is_same_v>; + +using usm_allocator_vector_iterators_supported_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator>::value; + } // namespace dpl } // namespace oneapi diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 21527f30d40..6d8f91cf8b8 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -22,6 +22,7 @@ #include "../../utils_ranges.h" #include "../../iterator_impl.h" #include "../../glue_numeric_defs.h" +#include "sycl_iterator.h" #include "sycl_defs.h" namespace oneapi @@ -46,35 +47,6 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) return {__buf, sycl::range<1>(__n_acc), __offset}; } -// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a -// std::vector::iterator can be distinguished between three different allocators, the -// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator -// could be confused with a usm allocator. -template -struct __vector_iter_distinguishes_by_allocator : std::false_type -{ -}; - -template ::value_type> -using __default_alloc_vec_iter = typename std::vector::iterator; - -template ::value_type> -using __usm_shared_alloc_vec_iter = - typename std::vector>::iterator; - -template ::value_type> -using __usm_host_alloc_vec_iter = - typename std::vector>::iterator; - -template -struct __vector_iter_distinguishes_by_allocator< - Iter, std::enable_if_t, __usm_shared_alloc_vec_iter> && - !std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && - !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> - : std::true_type -{ -}; - } // namespace __internal //A SYCL range over SYCL buffer @@ -238,12 +210,7 @@ struct is_passed_directly -struct is_passed_directly< - Iter, - std::enable_if_t::value && - (std::is_same_v> || - std::is_same_v>)>> - : std::true_type +struct is_passed_directly>> : std::true_type { }; From c7c9e31045df1eb58b40f5954021bd19830efd43 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 11:55:29 -0400 Subject: [PATCH 13/27] Add to the documentation Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index bdbe3704ede..6490e8271af 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -81,7 +81,20 @@ the buffer were created for the same queue. For example: return 0; } -Alternatively, use ``std::vector`` with a USM allocator. For example: +Alternatively, use ``std::vector`` with a USM allocator. +Note: The ability to appropriately detect USM allocated ``std::vector::iterator`` depends +on details of the C++ standard library implementation and what information about the +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_allocator_vector_iterators_supported_v``. This will evaluate +to ``true`` for C++ standard library implementations which allow oneDPL to support this +functionality and ``false`` otherwise. You can also specifically check an individual +iterator using ``oneapi::dpl::is_usm_allocated_vector_iterator_v`` with your +specific iterator. If usm_allocators are not supported with your C++ standard library, +they will still function as inputs to oneDPL, but they will be treated as if they were +host-side ``std::vector::iterator`` as described in the section below. + +For example: .. code:: cpp From 23ed3125ab08904d2ee53b78c82342cdb73571db Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 12:51:34 -0400 Subject: [PATCH 14/27] fixes for public utility Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/sycl_iterator.h | 25 +++++++------------ .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 6 +++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index ac8a3094d87..ba83dabc545 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -149,15 +149,6 @@ struct _ModeConverter static constexpr access_mode __value = access_mode::discard_write; }; -// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a -// std::vector::iterator can be distinguished between three different allocators, the -// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator -// could be confused with a usm allocator. -template -struct __vector_iter_distinguishes_by_allocator : std::false_type -{ -}; - template ::value_type> using __default_alloc_vec_iter = typename std::vector::iterator; @@ -168,7 +159,14 @@ using __usm_shared_alloc_vec_iter = template ::value_type> using __usm_host_alloc_vec_iter = typename std::vector>::iterator; - +// Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a +// std::vector::iterator can be distinguished between three different allocators, the +// default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator +// could be confused with a usm allocator. +template +struct __vector_iter_distinguishes_by_allocator : std::false_type +{ +}; template struct __vector_iter_distinguishes_by_allocator< Iter, std::enable_if_t, __usm_shared_alloc_vec_iter> && @@ -236,12 +234,7 @@ __internal::sycl_iterator end(syc __dpl_sycl::__get_buffer_size(buf)}; } -template -using is_usm_allocated_vector_iterator_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value && - std::is_same_v> || - std::is_same_v>; - -using usm_allocator_vector_iterators_supported_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator>::value; +constexpr static bool usm_allocated_vector_iterators_supported_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; } // namespace dpl } // namespace oneapi diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 6d8f91cf8b8..f7bf8bec3b5 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -209,8 +209,10 @@ struct is_passed_directly -struct is_passed_directly>> : std::true_type +template +struct is_passed_directly> || + std::is_same_v>) && + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : std::true_type { }; From 3d6372610fe99bda99358d4250969964841c55ea Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 12:51:50 -0400 Subject: [PATCH 15/27] fixes for documentation Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index 6490e8271af..e5c1ad4f20a 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -86,13 +86,11 @@ Note: The ability to appropriately detect USM allocated ``std::vector::iterator` on details of the C++ standard library implementation and what information about the 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_allocator_vector_iterators_supported_v``. This will evaluate +value of ``oneapi::dpl::usm_allocated_vector_iterators_supported_v``. This will evaluate to ``true`` for C++ standard library implementations which allow oneDPL to support this -functionality and ``false`` otherwise. You can also specifically check an individual -iterator using ``oneapi::dpl::is_usm_allocated_vector_iterator_v`` with your -specific iterator. If usm_allocators are not supported with your C++ standard library, -they will still function as inputs to oneDPL, but they will be treated as if they were -host-side ``std::vector::iterator`` as described in the section below. +functionality and ``false`` otherwise. If usm_allocators are not supported with your C++ +standard library, they will still function as inputs to oneDPL, but they will be treated +as if they were host-side ``std::vector::iterator`` as described in the section below. For example: From 3bb00d239dcfbd8dc7ac0daef665a202e0e99bfe Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 13:12:49 -0400 Subject: [PATCH 16/27] formatting Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 7 ++++--- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index ba83dabc545..ad7f0423bab 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -170,8 +170,8 @@ struct __vector_iter_distinguishes_by_allocator : std::false_type template struct __vector_iter_distinguishes_by_allocator< Iter, std::enable_if_t, __usm_shared_alloc_vec_iter> && - !std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && - !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> + !std::is_same_v<__default_alloc_vec_iter, __usm_host_alloc_vec_iter> && + !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>>> : std::true_type { }; @@ -234,7 +234,8 @@ __internal::sycl_iterator end(syc __dpl_sycl::__get_buffer_size(buf)}; } -constexpr static bool usm_allocated_vector_iterators_supported_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; +constexpr static bool usm_allocated_vector_iterators_supported_v = + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; } // namespace dpl } // namespace oneapi diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index f7bf8bec3b5..f9ed40ab5b6 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -210,9 +210,10 @@ struct is_passed_directly -struct is_passed_directly> || - std::is_same_v>) && - oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : std::true_type +struct is_passed_directly< + Iter, std::enable_if_t<(std::is_same_v> || + std::is_same_v>)&&oneapi:: + dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : std::true_type { }; From f8b310f191056e355271cc5c9278f5505ad80e91 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 3 Apr 2024 15:33:33 -0400 Subject: [PATCH 17/27] Adding value type to public utility Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 11 ++++++----- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index e5c1ad4f20a..bc695fd626b 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -86,11 +86,12 @@ Note: The ability to appropriately detect USM allocated ``std::vector::iterator` on details of the C++ standard library implementation and what information about the 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``. This will evaluate -to ``true`` for C++ standard library implementations which allow oneDPL to support this -functionality and ``false`` otherwise. If usm_allocators are not supported with your C++ -standard library, they will still function as inputs to oneDPL, but they will be treated -as if they were host-side ``std::vector::iterator`` as described in the section below. +value of ``oneapi::dpl::usm_allocated_vector_iterators_supported_v``. This will +evaluate to ``true`` for C++ standard library implementations which allow oneDPL to support +USM allocators with this ValueType and ``false`` otherwise. If usm_allocators are not +supported with your C++ standard library, they will still function as inputs to oneDPL, but +they will be treated as if they were host-side ``std::vector::iterator`` as described in +the section below. For example: diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index ad7f0423bab..d7d84405ee9 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -234,8 +234,9 @@ __internal::sycl_iterator end(syc __dpl_sycl::__get_buffer_size(buf)}; } +template constexpr static bool usm_allocated_vector_iterators_supported_v = - oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; } // namespace dpl } // namespace oneapi From 6082cd5f66c03d19537725e89f526f3e2152e2c0 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 08:53:07 -0400 Subject: [PATCH 18/27] Removing public utility (for now) Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 12 ++++-------- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index bc695fd626b..7160127688f 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -84,14 +84,10 @@ the buffer were created for the same queue. For example: Alternatively, use ``std::vector`` with a USM allocator. Note: The ability to appropriately detect USM allocated ``std::vector::iterator`` depends on details of the C++ standard library implementation and what information about the -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``. This will -evaluate to ``true`` for C++ standard library implementations which allow oneDPL to support -USM allocators with this ValueType and ``false`` otherwise. If usm_allocators are not -supported with your C++ standard library, they will still function as inputs to oneDPL, but -they will be treated as if they were host-side ``std::vector::iterator`` as described in -the section below. +allocator is included in the ``std::vector::iterator`` type definition. If usm_allocators +are not supported with your C++ standard library, they will still function as inputs to +oneDPL, but they will be treated as if they were host-side ``std::vector::iterator`` as +described in the section below. For example: diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index d7d84405ee9..da5fa62d7d8 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -234,10 +234,6 @@ __internal::sycl_iterator end(syc __dpl_sycl::__get_buffer_size(buf)}; } -template -constexpr static bool usm_allocated_vector_iterators_supported_v = - oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value; - } // namespace dpl } // namespace oneapi From 83e1a9a7bb40af881c0b1756aa6696c08721dee3 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 09:04:33 -0400 Subject: [PATCH 19/27] doc improvements Signed-off-by: Dan Hoeflinger --- .../library_guide/parallel_api/pass_data_algorithms.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index 7160127688f..08dc2d0af82 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -84,10 +84,10 @@ the buffer were created for the same queue. For example: Alternatively, use ``std::vector`` with a USM allocator. Note: The ability to appropriately detect USM allocated ``std::vector::iterator`` depends 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_allocators -are not supported with your C++ standard library, they will still function as inputs to -oneDPL, but they will be treated as if they were host-side ``std::vector::iterator`` as -described in the section below. +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 +``std::vector::iterator`` as described in the section below. For example: From 6e82fa3fe8ff2dca511c71503a4b893cd5ab9f4a Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 09:05:30 -0400 Subject: [PATCH 20/27] formatting of note Signed-off-by: Dan Hoeflinger --- .../library_guide/parallel_api/pass_data_algorithms.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index 08dc2d0af82..63e7ead0a93 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -82,6 +82,7 @@ the buffer were created for the same queue. For example: } Alternatively, use ``std::vector`` with a USM allocator. + Note: The ability to appropriately detect USM allocated ``std::vector::iterator`` depends 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 From 6ef2579743e235dc3ee2e1944a89a3907fa05eba Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 09:07:08 -0400 Subject: [PATCH 21/27] improve clarity of example intro Signed-off-by: Dan Hoeflinger --- .../library_guide/parallel_api/pass_data_algorithms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index 63e7ead0a93..ffcd8eeb43d 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -90,7 +90,7 @@ vector iterators are not detectable with your C++ standard library, they will st as inputs to oneDPL, but they will be treated as if they were host-side ``std::vector::iterator`` as described in the section below. -For example: +An example of ``std::vector`` with a USM allocator: .. code:: cpp From 1dc563412cb28b66145927d09af55a9053f80bc5 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 09:11:04 -0400 Subject: [PATCH 22/27] removing extra spaces Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 1 - include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 1 - 2 files changed, 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index da5fa62d7d8..a25ba87403d 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -233,7 +233,6 @@ __internal::sycl_iterator end(syc return __internal::sycl_iterator{buf, __dpl_sycl::__get_buffer_size(buf)}; } - } // namespace dpl } // namespace oneapi diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index f9ed40ab5b6..92f482fd67b 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -46,7 +46,6 @@ __create_accessor(_BufferType& __buf, _DiffType __offset, _DiffType __n) return {__buf, sycl::range<1>(__n_acc), __offset}; } - } // namespace __internal //A SYCL range over SYCL buffer From 55b0f8d04a6f43105f667e9ea32c477c4d874901 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 10:08:55 -0400 Subject: [PATCH 23/27] formatting (against clang-format suggestion) Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index 92f482fd67b..a8e7c86d154 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -211,8 +211,9 @@ struct is_passed_directly struct is_passed_directly< Iter, std::enable_if_t<(std::is_same_v> || - std::is_same_v>)&&oneapi:: - dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : std::true_type + std::is_same_v>) && + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : + std::true_type { }; From 22eaf87c5f74e759fb199ad77a625f94740dfef2 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 10:21:16 -0400 Subject: [PATCH 24/27] doc suggestion to use usm pointer Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index ffcd8eeb43d..23b32d8aadf 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -87,8 +87,11 @@ Note: The ability to appropriately detect USM allocated ``std::vector::iterator` 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 -``std::vector::iterator`` as described in the section below. +as inputs to oneDPL, but they will be treated as if they were host-side +``std::vector::iterator`` as described in the section below. To guarantee no additional +host-side copies, you can use ``std::vector::data()`` in combination with ``std::vector::size()`` +with USM allocated vectors to obtain a USM pointers. This will avoid extra host-side copies +regardless of the C++ standard library implementation. An example of ``std::vector`` with a USM allocator: @@ -105,6 +108,9 @@ An example of ``std::vector`` with a USM allocator: std::fill(policy, vec.begin(), vec.end(), 42); + //alternative to use USM pointers: + // std::fill(policy, vec.data(), vec.data() + vec.size(), 42); + return 0; } From ae0dac8661dd1eb950a66ea5f549dce8ca82f54b Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 10:23:13 -0400 Subject: [PATCH 25/27] removing doc changes (to separate into another PR) Signed-off-by: Dan Hoeflinger --- .../parallel_api/pass_data_algorithms.rst | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/documentation/library_guide/parallel_api/pass_data_algorithms.rst b/documentation/library_guide/parallel_api/pass_data_algorithms.rst index 23b32d8aadf..bdbe3704ede 100644 --- a/documentation/library_guide/parallel_api/pass_data_algorithms.rst +++ b/documentation/library_guide/parallel_api/pass_data_algorithms.rst @@ -81,19 +81,7 @@ the buffer were created for the same queue. For example: return 0; } -Alternatively, use ``std::vector`` with a USM allocator. - -Note: The ability to appropriately detect USM allocated ``std::vector::iterator`` depends -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 -``std::vector::iterator`` as described in the section below. To guarantee no additional -host-side copies, you can use ``std::vector::data()`` in combination with ``std::vector::size()`` -with USM allocated vectors to obtain a USM pointers. This will avoid extra host-side copies -regardless of the C++ standard library implementation. - -An example of ``std::vector`` with a USM allocator: +Alternatively, use ``std::vector`` with a USM allocator. For example: .. code:: cpp @@ -108,9 +96,6 @@ An example of ``std::vector`` with a USM allocator: std::fill(policy, vec.begin(), vec.end(), 42); - //alternative to use USM pointers: - // std::fill(policy, vec.data(), vec.data() + vec.size(), 42); - return 0; } From 843fa58c9d2fb6aa1f90488457e8f5fd5eb8dc47 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 4 Apr 2024 10:36:22 -0400 Subject: [PATCH 26/27] adding line break Signed-off-by: Dan Hoeflinger --- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index a25ba87403d..27bfb0d4a88 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -159,6 +159,7 @@ using __usm_shared_alloc_vec_iter = template ::value_type> using __usm_host_alloc_vec_iter = typename std::vector>::iterator; + // Evaluates to true if the provided type is an iterator with a value_type and if the implementation of a // std::vector::iterator can be distinguished between three different allocators, the // default, usm_shared, and usm_host. If all are distinct, it is very unlikely any non-usm based allocator From 3e4b38518ab764e8695587631fa9376c3b57e65c Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Thu, 4 Apr 2024 17:13:01 +0200 Subject: [PATCH 27/27] Update utils_ranges_sycl.h --- include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h index a8e7c86d154..9351b20dc88 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -212,7 +212,7 @@ template struct is_passed_directly< Iter, std::enable_if_t<(std::is_same_v> || std::is_same_v>) && - oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator::value>> : std::true_type { };