From dad81340bd4ec4dd94fad94d6b10861959ac4f44 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 23 Oct 2024 16:36:28 +0200 Subject: [PATCH] [oneDPL][ranges][test] + support arbitrary n for ranges tests (#1908) * [oneDPL][ranges][test] + support arbitrary n for 'data_in' test mode * [oneDPL][ranges][test] + support arbitrary n for 'data_in_out' test mode * [oneDPL][ranges][test] + big data size cases * [oneDPL][ranges][test] + support arbitrary n for 'data_in_in' test mode * [oneDPL][ranges][test] + support arbitrary n for 'data_in_in_out' test mode * [oneDPL][ranges][test] + big data size test cases * [oneDPL][ranges][test] corrected number of element for the algo result checks * [oneDPL][ranges][test] + big_sz as one shared constant for the all tests * [oneDPL][ranges][tests] + fixes for arbitrary n support * [oneDPL][ranges][tests] + comment for static_assert(std::is_trivially_copyable_v --- .../ranges/std_ranges_adjacent_find.pass.cpp | 2 +- .../ranges/std_ranges_all_of.pass.cpp | 2 +- .../ranges/std_ranges_any_of.pass.cpp | 2 +- .../ranges/std_ranges_copy.pass.cpp | 2 +- .../ranges/std_ranges_copy_if.pass.cpp | 2 +- .../ranges/std_ranges_count.pass.cpp | 2 +- .../ranges/std_ranges_count_if.pass.cpp | 2 +- .../ranges/std_ranges_equal.pass.cpp | 2 +- .../ranges/std_ranges_find.pass.cpp | 2 +- .../ranges/std_ranges_find_if.pass.cpp | 2 +- .../ranges/std_ranges_find_if_not.pass.cpp | 2 +- .../ranges/std_ranges_for_each.pass.cpp | 2 +- .../ranges/std_ranges_is_sorted.pass.cpp | 2 +- .../ranges/std_ranges_max_element.pass.cpp | 2 +- .../ranges/std_ranges_merge.pass.cpp | 2 +- .../ranges/std_ranges_min_element.pass.cpp | 2 +- .../ranges/std_ranges_none_of.pass.cpp | 2 +- .../ranges/std_ranges_search.pass.cpp | 2 +- .../ranges/std_ranges_search_n.pass.cpp | 2 +- .../ranges/std_ranges_sort.pass.cpp | 2 +- .../ranges/std_ranges_stable_sort.pass.cpp | 2 +- test/parallel_api/ranges/std_ranges_test.h | 220 +++++++++++------- .../ranges/std_ranges_transform.pass.cpp | 4 +- .../ranges/std_ranges_transform_iota.pass.cpp | 2 +- .../std_ranges_transform_iota_sycl.pass.cpp | 2 +- 25 files changed, 155 insertions(+), 115 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_adjacent_find.pass.cpp b/test/parallel_api/ranges/std_ranges_adjacent_find.pass.cpp index b3d92deb897..22c89084edc 100644 --- a/test/parallel_api/ranges/std_ranges_adjacent_find.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_adjacent_find.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::adjacent_find, std::ranges::adjacent_find, binary_pred); + test_range_algo<0>{big_sz}(dpl_ranges::adjacent_find, std::ranges::adjacent_find, binary_pred); test_range_algo<1>{}(dpl_ranges::adjacent_find, std::ranges::adjacent_find, binary_pred, proj); test_range_algo<2, P2>{}(dpl_ranges::adjacent_find, std::ranges::adjacent_find, binary_pred, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::adjacent_find, std::ranges::adjacent_find, binary_pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_all_of.pass.cpp b/test/parallel_api/ranges/std_ranges_all_of.pass.cpp index 5804ac2d0e7..333ba284d1c 100644 --- a/test/parallel_api/ranges/std_ranges_all_of.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_all_of.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::all_of, std::ranges::all_of, pred1); + test_range_algo<0>{big_sz}(dpl_ranges::all_of, std::ranges::all_of, pred1); test_range_algo<1>{}(dpl_ranges::all_of, std::ranges::all_of, pred1, proj); test_range_algo<2, P2>{}(dpl_ranges::all_of, std::ranges::all_of, pred1, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::all_of, std::ranges::all_of, pred1, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_any_of.pass.cpp b/test/parallel_api/ranges/std_ranges_any_of.pass.cpp index 9a9971d93cd..c60beaa6c92 100644 --- a/test/parallel_api/ranges/std_ranges_any_of.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_any_of.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::any_of, std::ranges::any_of, pred2); + test_range_algo<0>{big_sz}(dpl_ranges::any_of, std::ranges::any_of, pred2); test_range_algo<1>{}(dpl_ranges::any_of, std::ranges::any_of, pred2, proj); test_range_algo<2, P2>{}(dpl_ranges::any_of, std::ranges::any_of, pred2, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::any_of, std::ranges::any_of, pred2, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_copy.pass.cpp b/test/parallel_api/ranges/std_ranges_copy.pass.cpp index b0177f409b5..b0179404a05 100644 --- a/test/parallel_api/ranges/std_ranges_copy.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_copy.pass.cpp @@ -35,7 +35,7 @@ main() return ret_type{std::ranges::begin(r_in) + size, std::ranges::begin(r_out) + size}; }; - test_range_algo<0, int, data_in_out_lim>{}(dpl_ranges::copy, copy_checker); + test_range_algo<0, int, data_in_out_lim>{big_sz}(dpl_ranges::copy, copy_checker); #endif //_ENABLE_STD_RANGES_TESTING diff --git a/test/parallel_api/ranges/std_ranges_copy_if.pass.cpp b/test/parallel_api/ranges/std_ranges_copy_if.pass.cpp index ec4bed91780..842d9038b52 100644 --- a/test/parallel_api/ranges/std_ranges_copy_if.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_copy_if.pass.cpp @@ -33,7 +33,7 @@ main() return ret_type{res.in, res.out}; }; - test_range_algo<0, int, data_in_out>{}(dpl_ranges::copy_if, copy_if_checker, pred); + test_range_algo<0, int, data_in_out>{big_sz}(dpl_ranges::copy_if, copy_if_checker, pred); test_range_algo<1, int, data_in_out>{}(dpl_ranges::copy_if, copy_if_checker, pred, proj); test_range_algo<2, P2, data_in_out>{}(dpl_ranges::copy_if, copy_if_checker, pred, &P2::x); test_range_algo<3, P2, data_in_out>{}(dpl_ranges::copy_if, copy_if_checker, pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_count.pass.cpp b/test/parallel_api/ranges/std_ranges_count.pass.cpp index 849fb7fea0e..bc352a2da42 100644 --- a/test/parallel_api/ranges/std_ranges_count.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_count.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::count, std::ranges::count, 4); + test_range_algo<0>{big_sz}(dpl_ranges::count, std::ranges::count, 4); test_range_algo<1>{}(dpl_ranges::count, std::ranges::count, 4, proj); test_range_algo<2, P2>{}(dpl_ranges::count, std::ranges::count, 4, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::count, std::ranges::count, 4, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_count_if.pass.cpp b/test/parallel_api/ranges/std_ranges_count_if.pass.cpp index 3a9743a5e86..7cf589512cb 100644 --- a/test/parallel_api/ranges/std_ranges_count_if.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_count_if.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::count_if, std::ranges::count_if, pred); + test_range_algo<0>{big_sz}(dpl_ranges::count_if, std::ranges::count_if, pred); test_range_algo<1>{}(dpl_ranges::count_if, std::ranges::count_if, pred, proj); test_range_algo<2, P2>{}(dpl_ranges::count_if, std::ranges::count_if, pred, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::count_if, std::ranges::count_if, pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_equal.pass.cpp b/test/parallel_api/ranges/std_ranges_equal.pass.cpp index f968528cd90..0bf0da41489 100644 --- a/test/parallel_api/ranges/std_ranges_equal.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_equal.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0, int, data_in_in>{}(dpl_ranges::equal, std::ranges::equal, binary_pred); + test_range_algo<0, int, data_in_in>{big_sz}(dpl_ranges::equal, std::ranges::equal, binary_pred); test_range_algo<1, int, data_in_in>{}(dpl_ranges::equal, std::ranges::equal, binary_pred, proj, proj); test_range_algo<2, P2, data_in_in>{}(dpl_ranges::equal, std::ranges::equal, binary_pred, &P2::x, &P2::x); test_range_algo<3, P2, data_in_in>{}(dpl_ranges::equal, std::ranges::equal, binary_pred, &P2::proj, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_find.pass.cpp b/test/parallel_api/ranges/std_ranges_find.pass.cpp index 8133f6c0c17..e94ef1983b2 100644 --- a/test/parallel_api/ranges/std_ranges_find.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_find.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::find, std::ranges::find, 4); //found case + test_range_algo<0>{big_sz}(dpl_ranges::find, std::ranges::find, 4); //found case test_range_algo<1>{}(dpl_ranges::find, std::ranges::find, -1); //not found case test_range_algo<2>{}(dpl_ranges::find, std::ranges::find, 4, proj); test_range_algo<3, P2>{}(dpl_ranges::find, std::ranges::find, 4, &P2::x); diff --git a/test/parallel_api/ranges/std_ranges_find_if.pass.cpp b/test/parallel_api/ranges/std_ranges_find_if.pass.cpp index c8d4e43c02e..2c714f17985 100644 --- a/test/parallel_api/ranges/std_ranges_find_if.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_find_if.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::find_if, std::ranges::find_if, pred); + test_range_algo<0>{big_sz}(dpl_ranges::find_if, std::ranges::find_if, pred); test_range_algo<1>{}(dpl_ranges::find_if, std::ranges::find_if, pred, proj); test_range_algo<2, P2>{}(dpl_ranges::find_if, std::ranges::find_if, pred, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::find_if, std::ranges::find_if, pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_find_if_not.pass.cpp b/test/parallel_api/ranges/std_ranges_find_if_not.pass.cpp index 4a32062fbd5..8a9c0f94541 100644 --- a/test/parallel_api/ranges/std_ranges_find_if_not.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_find_if_not.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::find_if_not, std::ranges::find_if_not, pred1); + test_range_algo<0>{big_sz}(dpl_ranges::find_if_not, std::ranges::find_if_not, pred1); test_range_algo<1>{}(dpl_ranges::find_if_not, std::ranges::find_if_not, pred, proj); test_range_algo<2, P2>{}(dpl_ranges::find_if_not, std::ranges::find_if_not, pred, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::find_if_not, std::ranges::find_if_not, pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_for_each.pass.cpp b/test/parallel_api/ranges/std_ranges_for_each.pass.cpp index bb83fd7041d..91f7f17c791 100644 --- a/test/parallel_api/ranges/std_ranges_for_each.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_for_each.pass.cpp @@ -28,7 +28,7 @@ main() return res.in; }; - test_range_algo<0>{}(dpl_ranges::for_each, for_each_checker, f_mutuable); + test_range_algo<0>{big_sz}(dpl_ranges::for_each, for_each_checker, f_mutuable); test_range_algo<1>{}(dpl_ranges::for_each, for_each_checker, f_mutuable, proj_mutuable); test_range_algo<2, P2>{}(dpl_ranges::for_each, for_each_checker, f_mutuable, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::for_each, for_each_checker, f_mutuable, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_is_sorted.pass.cpp b/test/parallel_api/ranges/std_ranges_is_sorted.pass.cpp index fa050e08c24..5ddd4741146 100644 --- a/test/parallel_api/ranges/std_ranges_is_sorted.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_is_sorted.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::is_sorted, std::ranges::is_sorted, std::ranges::less{}); + test_range_algo<0>{big_sz}(dpl_ranges::is_sorted, std::ranges::is_sorted, std::ranges::less{}); test_range_algo<1>{}(dpl_ranges::is_sorted, std::ranges::is_sorted, std::ranges::less{}, proj); test_range_algo<2, P2>{}(dpl_ranges::is_sorted, std::ranges::is_sorted, std::ranges::less{}, &P2::x); diff --git a/test/parallel_api/ranges/std_ranges_max_element.pass.cpp b/test/parallel_api/ranges/std_ranges_max_element.pass.cpp index ef008a5c14a..6e03904bb19 100644 --- a/test/parallel_api/ranges/std_ranges_max_element.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_max_element.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::max_element, std::ranges::max_element, std::ranges::less{}); + test_range_algo<0>{big_sz}(dpl_ranges::max_element, std::ranges::max_element, std::ranges::less{}); test_range_algo<1>{}(dpl_ranges::max_element, std::ranges::max_element, std::ranges::less{}, proj); test_range_algo<2, P2>{}(dpl_ranges::max_element, std::ranges::max_element, std::ranges::less{}, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::max_element, std::ranges::max_element, std::ranges::less{}, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_merge.pass.cpp b/test/parallel_api/ranges/std_ranges_merge.pass.cpp index 15112aa38e5..7752c82f275 100644 --- a/test/parallel_api/ranges/std_ranges_merge.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_merge.pass.cpp @@ -35,7 +35,7 @@ main() return ret_type{res.in1, res.in2, res.out}; }; - test_range_algo<0, int, data_in_in_out>{}(dpl_ranges::merge, merge_checker, std::ranges::less{}); + test_range_algo<0, int, data_in_in_out>{big_sz}(dpl_ranges::merge, merge_checker, std::ranges::less{}); test_range_algo<1, int, data_in_in_out>{}(dpl_ranges::merge, merge_checker, std::ranges::less{}, proj, proj); test_range_algo<2, P2, data_in_in_out>{}(dpl_ranges::merge, merge_checker, std::ranges::less{}, &P2::x, &P2::x); diff --git a/test/parallel_api/ranges/std_ranges_min_element.pass.cpp b/test/parallel_api/ranges/std_ranges_min_element.pass.cpp index fdd8d4403b7..9f60c4fef29 100644 --- a/test/parallel_api/ranges/std_ranges_min_element.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_min_element.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::min_element, std::ranges::min_element, std::ranges::less{}); + test_range_algo<0>{big_sz}(dpl_ranges::min_element, std::ranges::min_element, std::ranges::less{}); test_range_algo<1>{}(dpl_ranges::min_element, std::ranges::min_element, std::ranges::less{}, proj); test_range_algo<2, P2>{}(dpl_ranges::min_element, std::ranges::min_element, std::ranges::less{}, &P2::x); diff --git a/test/parallel_api/ranges/std_ranges_none_of.pass.cpp b/test/parallel_api/ranges/std_ranges_none_of.pass.cpp index af1778b1b78..45b5a3c2e23 100644 --- a/test/parallel_api/ranges/std_ranges_none_of.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_none_of.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::none_of, std::ranges::none_of, pred3); + test_range_algo<0>{big_sz}(dpl_ranges::none_of, std::ranges::none_of, pred3); test_range_algo<1>{}(dpl_ranges::none_of, std::ranges::none_of, pred2, proj); test_range_algo<2, P2>{}(dpl_ranges::none_of, std::ranges::none_of, pred3, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::none_of, std::ranges::none_of, pred3, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_search.pass.cpp b/test/parallel_api/ranges/std_ranges_search.pass.cpp index 2ddd99bb8e6..b8168518f97 100644 --- a/test/parallel_api/ranges/std_ranges_search.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_search.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0, int, data_in_in>{}(dpl_ranges::search, std::ranges::search, binary_pred); + test_range_algo<0, int, data_in_in>{big_sz}(dpl_ranges::search, std::ranges::search, binary_pred); test_range_algo<1, int, data_in_in>{}(dpl_ranges::search, std::ranges::search, binary_pred, proj, proj); test_range_algo<2, P2, data_in_in>{}(dpl_ranges::search, std::ranges::search, binary_pred, &P2::x, &P2::x); test_range_algo<3, P2, data_in_in>{}(dpl_ranges::search, std::ranges::search, binary_pred, &P2::proj, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_search_n.pass.cpp b/test/parallel_api/ranges/std_ranges_search_n.pass.cpp index 9447fb453ce..132242ed82a 100644 --- a/test/parallel_api/ranges/std_ranges_search_n.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_search_n.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::search_n, std::ranges::search_n, 1, 5, binary_pred); + test_range_algo<0>{big_sz}(dpl_ranges::search_n, std::ranges::search_n, 1, 5, binary_pred); test_range_algo<1>{}(dpl_ranges::search_n, std::ranges::search_n, 3, 5, binary_pred, proj); test_range_algo<2, P2>{}(dpl_ranges::search_n, std::ranges::search_n, 1, 2, binary_pred, &P2::x); test_range_algo<3, P2>{}(dpl_ranges::search_n, std::ranges::search_n, 3, 5, binary_pred, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_sort.pass.cpp b/test/parallel_api/ranges/std_ranges_sort.pass.cpp index 00cdff4f51a..7b86f106967 100644 --- a/test/parallel_api/ranges/std_ranges_sort.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_sort.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::sort, std::ranges::sort); + test_range_algo<0>{big_sz}(dpl_ranges::sort, std::ranges::sort); test_range_algo<1>{}(dpl_ranges::sort, std::ranges::sort, std::ranges::less{}); test_range_algo<2>{}(dpl_ranges::sort, std::ranges::sort, std::ranges::less{}, proj); diff --git a/test/parallel_api/ranges/std_ranges_stable_sort.pass.cpp b/test/parallel_api/ranges/std_ranges_stable_sort.pass.cpp index 923e0d49fa8..8acbaf3ef3a 100644 --- a/test/parallel_api/ranges/std_ranges_stable_sort.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_stable_sort.pass.cpp @@ -22,7 +22,7 @@ main() using namespace test_std_ranges; namespace dpl_ranges = oneapi::dpl::ranges; - test_range_algo<0>{}(dpl_ranges::stable_sort, std::ranges::stable_sort); + test_range_algo<0>{big_sz}(dpl_ranges::stable_sort, std::ranges::stable_sort); test_range_algo<1>{}(dpl_ranges::stable_sort, std::ranges::stable_sort, std::ranges::less{}); test_range_algo<2>{}(dpl_ranges::stable_sort, std::ranges::stable_sort, std::ranges::less{}, proj); diff --git a/test/parallel_api/ranges/std_ranges_test.h b/test/parallel_api/ranges/std_ranges_test.h index 5ae36cc4aca..74743733bdb 100644 --- a/test/parallel_api/ranges/std_ranges_test.h +++ b/test/parallel_api/ranges/std_ranges_test.h @@ -32,10 +32,14 @@ static_assert(ONEDPL_HAS_RANGE_ALGORITHMS >= 202409L); #include #include #include +#include +#include namespace test_std_ranges { +inline constexpr std::size_t big_sz = (1<<25) + 10; //32M + #if TEST_DPCPP_BACKEND_PRESENT template auto dpcpp_policy() @@ -143,6 +147,7 @@ bool is_range().begin())>> = true; template struct test { + const int max_n = 10; template std::enable_if_t> operator()(Policy, auto algo, auto& checker, auto... args) @@ -157,28 +162,25 @@ struct test std::enable_if_t && mode == data_in> operator()(Policy&& exec, Algo algo, Checker& checker, TransIn tr_in, TransOut, auto... args) { - constexpr int max_n = 10; - DataType data[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - DataType expected[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + Container cont_in(exec, max_n, [](auto i) { return i;}); + Container cont_exp(exec, max_n, [](auto i) { return i;}); - auto expected_view = tr_in(std::ranges::subrange(expected, expected + max_n)); + auto expected_view = tr_in(std::views::all(cont_exp())); auto expected_res = checker(expected_view, args...); - { - Container cont(exec, std::ranges::begin(data), max_n); - typename Container::type& A = cont(); - auto res = algo(exec, tr_in(A), args...); + typename Container::type& A = cont_in(); + auto res = algo(exec, tr_in(A), args...); - //check result - static_assert(std::is_same_v, "Wrong return type"); + //check result + static_assert(std::is_same_v, "Wrong return type"); - auto bres = ret_in_val(expected_res, expected_view.begin()) == ret_in_val(res, tr_in(A).begin()); - EXPECT_TRUE(bres, (std::string("wrong return value from algo with ranges: ") + typeid(Algo).name() + + auto bres = ret_in_val(expected_res, expected_view.begin()) == ret_in_val(res, tr_in(A).begin()); + EXPECT_TRUE(bres, (std::string("wrong return value from algo with ranges: ") + typeid(Algo).name() + typeid(decltype(tr_in(std::declval()()))).name()).c_str()); - } //check result - EXPECT_EQ_N(expected, data, max_n, (std::string("wrong effect algo with ranges: ") + auto n = std::ranges::size(expected_view); + EXPECT_EQ_N(cont_exp().begin(), cont_in().begin(), n, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name() + typeid(decltype(tr_in(std::declval()()))).name()).c_str()); } @@ -190,37 +192,34 @@ struct test { static_assert(mode == data_in_out || mode == data_in_out_lim); - constexpr int max_n = 10; - DataType data_in[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - DataType data_out[max_n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - DataType expected[max_n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + Container cont_in(exec, n_in, [](auto i) { return i;}); + Container cont_out(exec, n_out, [](auto i) { return 0;}); + Container cont_exp(exec, n_out, [](auto i) { return 0;}); assert(n_in <= max_n); assert(n_out <= max_n); - auto src_view = tr_in(std::ranges::subrange(data_in, data_in + n_in)); - auto expected_res = checker(src_view, std::ranges::subrange(expected, expected + n_out), args...); - { - Container cont_in(exec, data_in, n_in); - Container cont_out(exec, data_out, n_out); + auto src_view = tr_in(std::views::all(cont_in())); + auto exp_view = tr_out(std::views::all(cont_exp())); + auto expected_res = checker(src_view, exp_view, args...); - typename Container::type& A = cont_in(); - typename Container::type& B = cont_out(); + typename Container::type& A = cont_in(); + typename Container::type& B = cont_out(); - auto res = algo(exec, tr_in(A), tr_out(B), args...); + auto res = algo(exec, tr_in(A), tr_out(B), args...); - //check result - static_assert(std::is_same_v, "Wrong return type"); + //check result + static_assert(std::is_same_v, "Wrong return type"); - auto bres_in = ret_in_val(expected_res, src_view.begin()) == ret_in_val(res, tr_in(A).begin()); - EXPECT_TRUE(bres_in, (std::string("wrong return value from algo with input range: ") + typeid(Algo).name()).c_str()); + auto bres_in = ret_in_val(expected_res, src_view.begin()) == ret_in_val(res, tr_in(A).begin()); + EXPECT_TRUE(bres_in, (std::string("wrong return value from algo with input range: ") + typeid(Algo).name()).c_str()); - auto bres_out = ret_out_val(expected_res, expected) == ret_out_val(res, B.begin()); - EXPECT_TRUE(bres_out, (std::string("wrong return value from algo with output range: ") + typeid(Algo).name()).c_str()); - } + auto bres_out = ret_out_val(expected_res, exp_view.begin()) == ret_out_val(res, tr_out(B).begin()); + EXPECT_TRUE(bres_out, (std::string("wrong return value from algo with output range: ") + typeid(Algo).name()).c_str()); //check result - EXPECT_EQ_N(expected, data_out, n_out, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); + auto n = std::ranges::size(exp_view); + EXPECT_EQ_N(cont_exp().begin(), cont_out().begin(), n, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); } public: @@ -228,7 +227,7 @@ struct test std::enable_if_t && mode == data_in_out> operator()(Policy&& exec, Algo algo, Checker& checker, auto... args) { - const int r_size = 10; + const int r_size = max_n; process_data_in_out(r_size, r_size, std::forward(exec), algo, checker, args...); } @@ -236,7 +235,7 @@ struct test std::enable_if_t && mode == data_in_out_lim> operator()(Policy&& exec, Algo algo, Checker& checker, auto... args) { - const int r_size = 10; + const int r_size = max_n; process_data_in_out(r_size, r_size, std::forward(exec), algo, checker, args...); //test case size of input range is less than size of output and viceversa @@ -248,28 +247,23 @@ struct test std::enable_if_t && mode == data_in_in> operator()(Policy&& exec, Algo algo, Checker& checker, TransIn tr_in, TransOut, auto... args) { - constexpr int max_n = 10; - DataType data_in1[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - DataType data_in2[max_n] = {0, 0, 2, 3, 4, 5, 0, 0, 0, 0}; + Container cont_in1(exec, max_n, [](auto i) { return i;}); + Container cont_in2(exec, max_n, [](auto i) { return i % 5 ? i : 0;}); - auto src_view1 = tr_in(std::ranges::subrange(data_in1, data_in1 + max_n)); - auto src_view2 = tr_in(std::ranges::subrange(data_in2, data_in2 + max_n)); + auto src_view1 = tr_in(std::views::all(cont_in1())); + auto src_view2 = tr_in(std::views::all(cont_in2())); auto expected_res = checker(src_view1, src_view2, args...); - { - Container cont_in1(exec, data_in1, max_n); - Container cont_in2(exec, data_in2, max_n); - typename Container::type& A = cont_in1(); - typename Container::type& B = cont_in2(); + typename Container::type& A = cont_in1(); + typename Container::type& B = cont_in2(); - auto res = algo(exec, tr_in(A), tr_in(B), args...); + auto res = algo(exec, tr_in(A), tr_in(B), args...); - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); - auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr_in(A).begin()); - EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + - typeid(decltype(tr_in(std::declval()()))).name()).c_str()); - } + auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr_in(A).begin()); + EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + + typeid(decltype(tr_in(std::declval()()))).name()).c_str()); } private: @@ -279,39 +273,37 @@ struct test { static_assert(mode == data_in_in_out || mode == data_in_in_out_lim); - constexpr int max_n = 10; - DataType data_in1[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - DataType data_in2[max_n] = {0, 0, 2, 3, 4, 5, 6, 6, 6, 6}; - constexpr int max_n_out = max_n*2; - DataType data_out[max_n_out] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //TODO: size - DataType expected[max_n_out] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + Container cont_in1(exec, n_in1, [](auto i) { return i;}); + Container cont_in2(exec, n_in2, [](auto i) { return i/3;}); + + const int max_n_out = max_n*2; + Container cont_out(exec, max_n_out, [](auto i) { return 0;}); + Container cont_exp(exec, max_n_out, [](auto i) { return 0;}); assert(n_in1 <= max_n); assert(n_in2 <= max_n); assert(n_out <= max_n_out); - auto src_view1 = tr_in(std::ranges::subrange(data_in1, data_in1 + n_in1)); - auto src_view2 = tr_in(std::ranges::subrange(data_in2, data_in2 + n_in2)); - auto expected_res = checker(src_view1, src_view2, std::ranges::subrange(expected, expected + n_out), args...); - { - Container cont_in1(exec, data_in1, n_in1); - Container cont_in2(exec, data_in2, n_in2); - Container cont_out(exec, data_out, n_out); + auto src_view1 = tr_in(std::views::all(cont_in1())); + auto src_view2 = tr_in(std::views::all(cont_in2())); + auto expected_view = tr_out(std::views::all(cont_exp())); + auto expected_res = checker(src_view1, src_view2, expected_view, args...); - typename Container::type& A = cont_in1(); - typename Container::type& B = cont_in2(); - typename Container::type& C = cont_out(); + typename Container::type& A = cont_in1(); + typename Container::type& B = cont_in2(); + typename Container::type& C = cont_out(); - auto res = algo(exec, tr_in(A), tr_in(B), tr_out(C), args...); + auto res = algo(exec, tr_in(A), tr_in(B), tr_out(C), args...); - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); + + auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr_in(A).begin()); + EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + + typeid(decltype(tr_in(std::declval()()))).name()).c_str()); - auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr_in(A).begin()); - EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + - typeid(decltype(tr_in(std::declval()()))).name()).c_str()); - } //check result - EXPECT_EQ_N(expected, data_out, n_out, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); + auto n = std::ranges::size(expected_view); + EXPECT_EQ_N(cont_exp().begin(), cont_out().begin(), n, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); } public: @@ -319,7 +311,7 @@ struct test std::enable_if_t && mode == data_in_in_out> operator()(Policy&& exec, Algo algo, Checker& checker, auto... args) { - const int r_size = 10; + const int r_size = max_n; process_data_in_in_out(r_size, r_size, r_size*2, std::forward(exec), algo, checker, args...); } @@ -327,7 +319,7 @@ struct test std::enable_if_t && mode == data_in_in_out_lim> operator()(Policy&& exec, Algo algo, Checker& checker, auto... args) { - const int r_size = 10; + const int r_size = max_n; process_data_in_in_out(r_size, r_size, r_size, exec, algo, checker, args...); process_data_in_in_out(r_size/2, r_size, r_size, exec, algo, checker, args...); process_data_in_in_out(r_size, r_size/2, r_size, exec, algo, checker, args...); @@ -369,15 +361,35 @@ struct test template struct host_subrange_impl { + static_assert(std::is_trivially_copyable_v, + "Memory initialization within the class relies on trivially copyability of the type T"); + using type = ViewType; ViewType view; + T* mem = NULL; + + std::allocator alloc; template host_subrange_impl(Policy&&, T* data, int n): view(data, data + n) {} + + template + host_subrange_impl(Policy&&, int n, DataGen gen) + { + mem = alloc.allocate(n); + view = ViewType(mem, mem + n); + for(int i = 0; i < n; ++i) + view[i] = gen(i); + } ViewType& operator()() { return view; } + ~host_subrange_impl() + { + if(mem) + alloc.deallocate(mem, view.size()); + } }; template @@ -397,13 +409,21 @@ struct host_vector template host_vector(Policy&&, T* data, int n): vec(data, data + n), p(data) {} + + template + host_vector(Policy&&, int n, DataGen gen): vec(n) + { + for(int i = 0; i < n; ++i) + vec[i] = gen(i); + } type& operator()() { return vec; } ~host_vector() { - std::copy_n(vec.begin(), vec.size(), p); + if(p) + std::copy_n(vec.begin(), vec.size(), p); } }; @@ -422,19 +442,29 @@ struct usm_vector { assert(vec.size() == n); } + template + usm_vector(Policy&& exec, int n, DataGen gen): vec(n, shared_allocator(exec.queue())) + { + for(int i = 0; i < n; ++i) + vec[i] = gen(i); + } type& operator()() { return vec; } ~usm_vector() { - std::copy_n(vec.begin(), vec.size(), p); + if(p) + std::copy_n(vec.begin(), vec.size(), p); } }; template struct usm_subrange_impl { + static_assert(std::is_trivially_copyable_v, + "Memory initialization within the class relies on trivially copyability of the type T"); + using shared_allocator = sycl::usm_allocator; using type = ViewType; @@ -449,6 +479,14 @@ struct usm_subrange_impl view = ViewType(mem, mem + n); std::copy_n(data, n, view.data()); } + template + usm_subrange_impl(Policy&& exec, int n, DataGen gen): alloc(exec.queue()) + { + auto mem = alloc.allocate(n); + view = ViewType(mem, mem + n); + for(int i = 0; i < n; ++i) + view[i] = gen(i); + } ViewType& operator()() { @@ -457,7 +495,8 @@ struct usm_subrange_impl ~usm_subrange_impl() { - std::copy_n(view.data(), view.size(), p); + if(p) + std::copy_n(view.data(), view.size(), p); alloc.deallocate(view.data(), view.size()); } }; @@ -475,6 +514,7 @@ using usm_span = usm_subrange_impl>; template struct test_range_algo { + const int max_n = 10; void operator()(auto algo, auto& checker, auto... args) { @@ -483,13 +523,13 @@ struct test_range_algo auto span_view = [](auto&& v) { return std::span(v); }; #endif - test, mode>{}(host_policies(), algo, checker, std::identity{}, std::identity{}, args...); - test, mode>{}(host_policies(), algo, checker, subrange_view, std::identity{}, args...); - test, mode>{}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); - test, mode>{}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, std::identity{}, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, subrange_view, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); #if TEST_CPP20_SPAN_PRESENT - test, mode>{}(host_policies(), algo, checker, span_view, std::identity{}, args...); - test, mode>{}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, span_view, std::identity{}, args...); + test, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); #endif #if TEST_DPCPP_BACKEND_PRESENT @@ -500,11 +540,11 @@ struct test_range_algo if constexpr(!std::disjunction_v...>) #endif { - test, mode>{}(dpcpp_policy(), algo, checker, subrange_view, subrange_view, args...); - test, mode>{}(dpcpp_policy(), algo, checker, std::identity{}, std::identity{}, args...); + test, mode>{max_n}(dpcpp_policy(), algo, checker, subrange_view, subrange_view, args...); + test, mode>{max_n}(dpcpp_policy(), algo, checker, std::identity{}, std::identity{}, args...); #if TEST_CPP20_SPAN_PRESENT - test, mode>{}(dpcpp_policy(), algo, checker, span_view, subrange_view, args...); - test, mode>{}(dpcpp_policy(), algo, checker, std::identity{}, std::identity{}, args...); + test, mode>{max_n}(dpcpp_policy(), algo, checker, span_view, subrange_view, args...); + test, mode>{max_n}(dpcpp_policy(), algo, checker, std::identity{}, std::identity{}, args...); #endif } } diff --git a/test/parallel_api/ranges/std_ranges_transform.pass.cpp b/test/parallel_api/ranges/std_ranges_transform.pass.cpp index 4718750626e..feac30191e9 100644 --- a/test/parallel_api/ranges/std_ranges_transform.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_transform.pass.cpp @@ -38,7 +38,7 @@ main() return ret_type{std::ranges::begin(r_in) + size, std::ranges::begin(r_out) + size}; }; - test_range_algo<0, int, data_in_out_lim>{}(dpl_ranges::transform, transform_unary_checker, f); + test_range_algo<0, int, data_in_out_lim>{big_sz}(dpl_ranges::transform, transform_unary_checker, f); test_range_algo<1, int, data_in_out_lim>{}(dpl_ranges::transform, transform_unary_checker, f, proj); test_range_algo<2, P2, data_in_out_lim>{}(dpl_ranges::transform, transform_unary_checker, f, &P2::x); test_range_algo<3, P2, data_in_out_lim>{}(dpl_ranges::transform, transform_unary_checker, f, &P2::proj); @@ -65,7 +65,7 @@ main() return ret_type{std::ranges::begin(r_1) + size, std::ranges::begin(r_2) + size, std::ranges::begin(r_out) + size}; }; - test_range_algo<4, int, data_in_in_out_lim>{}(dpl_ranges::transform, transform_binary_checker, binary_f); + test_range_algo<4, int, data_in_in_out_lim>{big_sz}(dpl_ranges::transform, transform_binary_checker, binary_f); test_range_algo<5, int, data_in_in_out_lim>{}(dpl_ranges::transform, transform_binary_checker, binary_f, proj, proj); test_range_algo<6, P2, data_in_in_out_lim>{}(dpl_ranges::transform, transform_binary_checker, binary_f, &P2::x, &P2::x); test_range_algo<7, P2, data_in_in_out_lim>{}(dpl_ranges::transform, transform_binary_checker, binary_f, &P2::proj, &P2::proj); diff --git a/test/parallel_api/ranges/std_ranges_transform_iota.pass.cpp b/test/parallel_api/ranges/std_ranges_transform_iota.pass.cpp index 376c4db3d9a..d1bf7e06fd8 100644 --- a/test/parallel_api/ranges/std_ranges_transform_iota.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_transform_iota.pass.cpp @@ -23,7 +23,7 @@ main() namespace dpl_ranges = oneapi::dpl::ranges; const char* err_msg = "Wrong effect algo transform with unsized ranges."; - const int n = 100; + const int n = 1<<25; //32M std::ranges::iota_view view1(0, n); //size range std::ranges::iota_view view2(0, std::unreachable_sentinel_t{}); //unsized diff --git a/test/parallel_api/ranges/std_ranges_transform_iota_sycl.pass.cpp b/test/parallel_api/ranges/std_ranges_transform_iota_sycl.pass.cpp index dc55f50ae3b..1694ce8c99d 100644 --- a/test/parallel_api/ranges/std_ranges_transform_iota_sycl.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_transform_iota_sycl.pass.cpp @@ -23,7 +23,7 @@ main() namespace dpl_ranges = oneapi::dpl::ranges; const char* err_msg = "Wrong effect algo transform with unsized ranges."; - const int n = 100; + const int n = 1<<25; //32M std::ranges::iota_view view1(0, n); //size range std::ranges::iota_view view2(0, std::unreachable_sentinel_t{}); //unsized