From 1d2744fe7d58250cd9856925c03993a6a6f7549e Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 25 Apr 2024 16:42:57 -0400 Subject: [PATCH 1/4] simplify check for usm allocated vector iterator Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/sycl_iterator.h | 27 +++++-------------- test/support/utils.h | 6 ++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index a38d6520b4f..b7bc20ef6e6 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -17,6 +17,7 @@ #define _ONEDPL_SYCL_ITERATOR_H #include +#include #include "../../onedpl_config.h" #include "sycl_defs.h" @@ -149,14 +150,14 @@ struct _ModeConverter static constexpr access_mode __value = access_mode::discard_write; }; -template ::value_type> +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; -template ::value_type> +template ::value_type>> using __usm_host_alloc_vec_iter = typename std::vector>::iterator; @@ -178,12 +179,12 @@ struct __vector_iter_distinguishes_by_allocator< }; template -struct __is_known_usm_vector_iter_impl : std::false_type +struct __is_known_usm_vector_iter : std::false_type { }; template -struct __is_known_usm_vector_iter_impl< +struct __is_known_usm_vector_iter< Iter, std::enable_if_t>, std::is_same>>, @@ -191,22 +192,6 @@ struct __is_known_usm_vector_iter_impl< { }; -template -struct __is_known_usm_vector_iter : std::false_type -{ -}; - -//We must avoid instantiating vector of const, reference, or function elements to avoid ill-formed vector instantiation -template -struct __is_known_usm_vector_iter< - Iter, std::enable_if_t::value_type>, - std::is_reference::value_type>, - std::is_function::value_type>>>, - oneapi::dpl::__internal::__is_known_usm_vector_iter_impl>::value>> : std::true_type -{ -}; - } // namespace __internal template diff --git a/test/support/utils.h b/test/support/utils.h index d314346875b..f017af23f8f 100644 --- a/test/support/utils.h +++ b/test/support/utils.h @@ -854,14 +854,14 @@ struct _ZipIteratorAdapter }; #if TEST_DPCPP_BACKEND_PRESENT -template ::value_type> +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; -template ::value_type> +template ::value_type>> using __usm_host_alloc_vec_iter = typename std::vector>::iterator; From 0513bcad2057d9c5d314f047ac6786830ae81c1e Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 29 Apr 2024 10:54:33 -0400 Subject: [PATCH 2/4] further simplify to constexpr bool Signed-off-by: Dan Hoeflinger --- .../dpl/pstl/hetero/dpcpp/sycl_iterator.h | 27 ++++--------------- .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 4 +-- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index b7bc20ef6e6..154f1f6b7db 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -165,32 +165,15 @@ using __usm_host_alloc_vec_iter = // 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> && +constexpr bool __vector_iter_distinguishes_by_allocator_v = !std::is_same_v<__default_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 -{ -}; - -template -struct __is_known_usm_vector_iter : std::false_type -{ -}; + !std::is_same_v<__usm_host_alloc_vec_iter, __usm_shared_alloc_vec_iter>; template -struct __is_known_usm_vector_iter< - Iter, std::enable_if_t>, - std::is_same>>, - oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator>::value>> : std::true_type -{ -}; +constexpr bool __is_known_usm_vector_iter_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator_v && + (std::is_same_v> || + std::is_same_v>); } // namespace __internal 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 4e2f8626950..a141158720e 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -209,7 +209,7 @@ struct is_passed_directly -struct is_passed_directly::value>> +struct is_passed_directly>> : std::true_type { }; @@ -236,7 +236,7 @@ struct is_passed_directly> : is_pas template struct is_passed_directly> - : ::std::conjunction, is_passed_directly> + : ::std::conjunction, is_passed_directly::IndexMap>> { }; From b66ea51e2f38938d97f142ea6a72b8be7bba951c Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 29 Apr 2024 10:55:50 -0400 Subject: [PATCH 3/4] formatting Signed-off-by: Dan Hoeflinger --- .../oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h | 14 ++++++++------ .../dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h index 154f1f6b7db..b238133ace0 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_iterator.h @@ -166,14 +166,16 @@ using __usm_host_alloc_vec_iter = // 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 -constexpr bool __vector_iter_distinguishes_by_allocator_v = !std::is_same_v<__default_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>; +constexpr bool __vector_iter_distinguishes_by_allocator_v = + !std::is_same_v<__default_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>; template -constexpr bool __is_known_usm_vector_iter_v = oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator_v && - (std::is_same_v> || - std::is_same_v>); +constexpr bool __is_known_usm_vector_iter_v = + oneapi::dpl::__internal::__vector_iter_distinguishes_by_allocator_v && + (std::is_same_v> || + std::is_same_v>); } // namespace __internal 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 a141158720e..09f17157c20 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h @@ -236,7 +236,9 @@ struct is_passed_directly> : is_pas template struct is_passed_directly> - : ::std::conjunction, is_passed_directly::IndexMap>> + : ::std::conjunction< + is_passed_directly, + is_passed_directly::IndexMap>> { }; From 17e6258a0b049804e9fb834f899dbd921779e0b7 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Mon, 29 Apr 2024 11:02:19 -0400 Subject: [PATCH 4/4] fixing tests as well. Signed-off-by: Dan Hoeflinger --- .../input_data_sweep_usm_allocator.pass.cpp | 4 ++-- test/support/utils.h | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/test/parallel_api/iterator/input_data_sweep_usm_allocator.pass.cpp b/test/parallel_api/iterator/input_data_sweep_usm_allocator.pass.cpp index 90b635a4e86..ceb0d2036c9 100644 --- a/test/parallel_api/iterator/input_data_sweep_usm_allocator.pass.cpp +++ b/test/parallel_api/iterator/input_data_sweep_usm_allocator.pass.cpp @@ -47,7 +47,7 @@ test_usm_shared_alloc(Policy&& policy, T trash, size_t n, const std::string& typ __recurse, 0, /*__read =*/true, /*__reset_read=*/true, /*__write=*/true, /*__check_write=*/true, /*__usable_as_perm_map=*/true, /*__usable_as_perm_src=*/ - TestUtils::__vector_impl_distinguishes_usm_allocator_from_default::value, + TestUtils::__vector_impl_distinguishes_usm_allocator_from_default_v, /*__is_reversible=*/true>(policy, shared_data_vec.begin(), shared_data_vec.end(), counting, copy_out.get_data(), shared_data_vec.begin(), copy_out.get_data(), counting, trash, std::string("usm_shared_alloc_vector<") + type_text + std::string(">")); @@ -77,7 +77,7 @@ test_usm_host_alloc(Policy&& policy, T trash, size_t n, const std::string& type_ wrap_recurse< __recurse, 0, /*__read =*/true, /*__reset_read=*/true, /*__write=*/true, /*__check_write=*/true, /*__usable_as_perm_map=*/true, /*__usable_as_perm_src=*/ - TestUtils::__vector_impl_distinguishes_usm_allocator_from_default::value, + TestUtils::__vector_impl_distinguishes_usm_allocator_from_default_v, /*__is_reversible=*/true>(policy, host_data_vec.begin(), host_data_vec.end(), counting, copy_out.get_data(), host_data_vec.begin(), copy_out.get_data(), counting, trash, std::string("usm_host_alloc_vector<") + type_text + std::string(">")); diff --git a/test/support/utils.h b/test/support/utils.h index f017af23f8f..ccbd4d4ba68 100644 --- a/test/support/utils.h +++ b/test/support/utils.h @@ -869,19 +869,12 @@ using __usm_host_alloc_vec_iter = // 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_impl_distinguishes_usm_allocator_from_default : std::false_type -{ -}; - template -struct __vector_impl_distinguishes_usm_allocator_from_default< - 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 -{ -}; +constexpr bool __vector_impl_distinguishes_usm_allocator_from_default_v = + !std::is_same_v<__default_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>; + #endif //TEST_DPCPP_BACKEND_PRESENT ////////////////////////////////////////////////////////////////////////////////