From 74d6c46847c3df34d09e23ae210d553a412c3a2a Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 24 Feb 2023 14:43:15 -0500 Subject: [PATCH 1/6] Addressing usm_none usage in onedpl_tests Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 3 +- help_function/src/onedpl_test_copy_if.cpp | 28 +++--------- .../src/onedpl_test_exclusive_scan.cpp | 4 ++ help_function/src/onedpl_test_fill.cpp | 22 ++++------ help_function/src/onedpl_test_for_each.cpp | 31 +++++-------- help_function/src/onedpl_test_sort_by_key.cpp | 11 +++-- .../src/onedpl_test_transform_reduce.cpp | 44 +++++++------------ 7 files changed, 52 insertions(+), 91 deletions(-) diff --git a/help_function/help_function.xml b/help_function/help_function.xml index 9bb4021c..7e3a30f0 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -102,6 +102,7 @@ + @@ -149,7 +150,7 @@ - + diff --git a/help_function/src/onedpl_test_copy_if.cpp b/help_function/src/onedpl_test_copy_if.cpp index 386bd31a..54336f79 100644 --- a/help_function/src/onedpl_test_copy_if.cpp +++ b/help_function/src/onedpl_test_copy_if.cpp @@ -226,11 +226,8 @@ int main() { // dcpt::copy_if with device_vector { - // **FAILS AT RUNTIME** // create src and dst device_vector - dpct::device_vector src_dv(8); - dpct::device_vector dst_dv(8); std::vector src_vec(8); std::vector dst_vec(8); @@ -239,17 +236,8 @@ int main() { dst_vec[i] = 0; } - //copy from src_vec to src_dv - dpct::get_default_queue().submit([&](sycl::handler& h) { - h.memcpy(src_dv.data(), src_vec.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); - - //copy from dst_vec to dst_dv - dpct::get_default_queue().submit([&](sycl::handler& h) { - h.memcpy(dst_dv.data(), dst_vec.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); + dpct::device_vector src_dv(src_vec); + dpct::device_vector dst_dv(dst_vec); // src_dv: { 0, 1, 2, 3, 4, 5, 6, 7 } // dst_dv: { 0, 0, 0, 0, 0, 0, 0, 0 } @@ -269,22 +257,16 @@ int main() { ); } - dpct::get_default_queue().submit([&](sycl::handler& h) { - // copy from dst_dv back to dst_vec - h.memcpy(dst_vec.data(), dst_dv.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); - std::string test_name = "copy_if with device_vector"; // expected dst_vec: { 5, 7, 0, 0, 0, 0, 0, 0 } for (int i = 0; i != 8; ++i) { if (i == 0) - num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 5); + num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 5); else if (i == 1) - num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 7); + num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 7); else - num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 0); + num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 0); } failed_tests += test_passed(num_failing, test_name); diff --git a/help_function/src/onedpl_test_exclusive_scan.cpp b/help_function/src/onedpl_test_exclusive_scan.cpp index 5dbfd068..985f7450 100644 --- a/help_function/src/onedpl_test_exclusive_scan.cpp +++ b/help_function/src/onedpl_test_exclusive_scan.cpp @@ -40,6 +40,9 @@ int main(){ int failed_tests = 0; int num_failing = 0; + + // These tests assume USM is available, disable when it isn't +#ifndef DPCT_USM_LEVEL_NONE { // Test One, test normal call to std::exclusive_scan with std::plus<> and USM allocations // create queue @@ -100,6 +103,7 @@ int main(){ failed_tests += test_passed(num_failing, test_name); num_failing = 0; } +#endif //DPCT_USM_LEVEL_NONE { // Test Two, test normal call to std::exclusive_scan with std::plus<> with overlapping source and destination diff --git a/help_function/src/onedpl_test_fill.cpp b/help_function/src/onedpl_test_fill.cpp index b7fb4b32..0feef944 100644 --- a/help_function/src/onedpl_test_fill.cpp +++ b/help_function/src/onedpl_test_fill.cpp @@ -7,6 +7,8 @@ // // ===----------------------------------------------------------------------===// +#define DPCT_USM_LEVEL_NONE + #include "oneapi/dpl/execution" #include "oneapi/dpl/iterator" #include "oneapi/dpl/algorithm" @@ -253,7 +255,9 @@ int main() { } // Third 3 tests: Testing call to std::fill using device_pointer - + + // These tests assume USM is available, disable when it isn't +#ifndef DPCT_USM_LEVEL_NONE { // test 1/3 @@ -420,19 +424,17 @@ int main() { failed_tests += test_passed(num_failing, test_name); num_failing = 0; } +#endif //DPCT_USM_LEVEL_NONE { // test 2/2: call to std::fill_n using device_vector // create device_vector and src vector - dpct::device_vector dv(8); std::vector src(8); iota_vector(src, 0, 8); + dpct::device_vector dv(src); - dpct::get_default_queue().submit([&](sycl::handler& h) { - h.memcpy(dv.data(), src.data(), 8 * sizeof(int)); - }); dpct::get_default_queue().wait(); { @@ -440,18 +442,12 @@ int main() { std::fill_n(oneapi::dpl::execution::make_device_policy(dpct::get_default_queue()), dv.begin(), 4, 10); } - dpct::get_default_queue().submit([&](sycl::handler& h) { - // copy dv back to src - h.memcpy(src.data(), dv.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); - std::string test_name = "std::fill_n with device_pointer 2/2"; for (int i = 0; i != 8; ++i) { if (i < 4) - num_failing += ASSERT_EQUAL(test_name, src[i], 10); + num_failing += ASSERT_EQUAL(test_name, dv[i], 10); else - num_failing += ASSERT_EQUAL(test_name, src[i], i); + num_failing += ASSERT_EQUAL(test_name, dv[i], i); } failed_tests += test_passed(num_failing, test_name); diff --git a/help_function/src/onedpl_test_for_each.cpp b/help_function/src/onedpl_test_for_each.cpp index 5efdc593..be4f9dfd 100644 --- a/help_function/src/onedpl_test_for_each.cpp +++ b/help_function/src/onedpl_test_for_each.cpp @@ -6,6 +6,7 @@ // // // ===----------------------------------------------------------------------===// +#define DPCT_USM_LEVEL_NONE #include "oneapi/dpl/execution" #include "oneapi/dpl/iterator" @@ -366,17 +367,11 @@ int main() { // test 1/1 // create device_vector and src vector - dpct::device_vector dv(8); std::vector src(8); src[0] = -3; src[1] = -2; src[2] = 1; src[3] = 0; src[4] = -1; src[5] = -4; src[6] = 2; src[7] = 3; // src: { -3, -2, 1, 0, -1, -4, 2, 3 } - - // copy from src to dv - dpct::get_default_queue().submit([&](sycl::handler& h) { - h.memcpy(dv.data(), src.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); + dpct::device_vector dv(src); { // call algorithm on dv @@ -389,24 +384,18 @@ int main() { ); } - dpct::get_default_queue().submit([&](sycl::handler& h) { - // copy dv back to src - h.memcpy(src.data(), dv.data(), 8 * sizeof(int)); - }); - dpct::get_default_queue().wait(); - // check that src is now { 3, 2, 1, 0, -1, -4, 2, 3 } // actual result is no change in src elements test_name = "std::for_each using device_vector"; - num_failing += ASSERT_EQUAL(test_name, src[0], 3); - num_failing += ASSERT_EQUAL(test_name, src[1], 2); - num_failing += ASSERT_EQUAL(test_name, src[2], 1); - num_failing += ASSERT_EQUAL(test_name, src[3], 0); - num_failing += ASSERT_EQUAL(test_name, src[4], -1); - num_failing += ASSERT_EQUAL(test_name, src[5], -4); - num_failing += ASSERT_EQUAL(test_name, src[6], 2); - num_failing += ASSERT_EQUAL(test_name, src[7], 3); + num_failing += ASSERT_EQUAL(test_name, dv[0], 3); + num_failing += ASSERT_EQUAL(test_name, dv[1], 2); + num_failing += ASSERT_EQUAL(test_name, dv[2], 1); + num_failing += ASSERT_EQUAL(test_name, dv[3], 0); + num_failing += ASSERT_EQUAL(test_name, dv[4], -1); + num_failing += ASSERT_EQUAL(test_name, dv[5], -4); + num_failing += ASSERT_EQUAL(test_name, dv[6], 2); + num_failing += ASSERT_EQUAL(test_name, dv[7], 3); failed_tests += test_passed(num_failing, test_name); num_failing = 0; diff --git a/help_function/src/onedpl_test_sort_by_key.cpp b/help_function/src/onedpl_test_sort_by_key.cpp index a0429591..7501af66 100644 --- a/help_function/src/onedpl_test_sort_by_key.cpp +++ b/help_function/src/onedpl_test_sort_by_key.cpp @@ -6,6 +6,7 @@ // // // ===----------------------------------------------------------------------===// +#define DPCT_USM_LEVEL_NONE #include @@ -144,6 +145,8 @@ int main() { } } + // These tests assume USM is available, disable when it isn't +#ifndef DPCT_USM_LEVEL_NONE { // Test One, call to dpct::sort using USM allocations // create queue @@ -199,6 +202,7 @@ int main() { failed_tests += test_passed(num_failing, test_name); num_failing = 0; } +#endif //DPCT_USM_LEVEL_NONE { // Test Two, test calls to dpct::sort using device vectors @@ -218,10 +222,6 @@ int main() { // values is now = {19, 10, 18, 11, 13, 17, 15, 12, 16, 14} } - { - int check_keys[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int check_values[10] = {19, 10, 18, 11, 13, 17, 15, 12, 16, 14}; - test_name = "sort using device_vector"; // check that values and keys are correct @@ -274,6 +274,8 @@ int main() { } } + // These tests assume USM is available, disable when it isn't +#ifndef DPCT_USM_LEVEL_NONE { // Test Three, call to dpct::stable_sort using USM allocations // create queue @@ -331,6 +333,7 @@ int main() { failed_tests += test_passed(num_failing, test_name); num_failing = 0; } +#endif // DPCT_USM_LEVEL_NONE { // Test Four, test calls to dpct::stable_sort with duplicate key values sycl::buffer keys_buf{ sycl::range<1>(16) }; diff --git a/help_function/src/onedpl_test_transform_reduce.cpp b/help_function/src/onedpl_test_transform_reduce.cpp index 890c6a27..5e8c0cce 100644 --- a/help_function/src/onedpl_test_transform_reduce.cpp +++ b/help_function/src/onedpl_test_transform_reduce.cpp @@ -50,59 +50,45 @@ int main() { auto dev = myQueue.get_device(); auto ctxt = myQueue.get_context(); - // create host and device arrays - double hostArray[8]; - double *deviceArray = (double*) malloc_device(8 * sizeof(double), dev, ctxt); + // create host and device vectors + std::vector host_vec(8); - // hostArray = { 0, 1, 2, 3, 4, 5, 6, 7 } + // host_vec = { 0, 1, 2, 3, 4, 5, 6, 7 } for (int i = 0; i != 8; ++i) { - hostArray[i] = i; + host_vec[i] = i; } - myQueue.submit([&](sycl::handler& h) { - // copy hostArray to deviceArray - h.memcpy(deviceArray, hostArray, 8 * sizeof(double)); - }); - myQueue.wait(); { - auto dptr_begin = dpct::device_pointer(deviceArray); - auto dptr_end = dpct::device_pointer(deviceArray + 4); + dpct::device_vector dev_vec(host_vec); // call algorithm - auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0., std::plus(), square()); + auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec.begin(), dev_vec.begin()+4, 0., std::plus(), square()); - test_name = "transform_reduce with USM allocation"; + test_name = "transform_reduce with device_vector"; failed_tests += ASSERT_EQUAL(test_name, result, 14); } // test 2/2 - bool hostArray2[8]; - bool *deviceArray2 = (bool*) malloc_device(8 * sizeof(bool), dev, ctxt); + std::vector host_vec2(8); - // hostArray2 = { 1, 1, 1, 1, 0, 0, 0, 0 } + // host_vec2 = { 1, 1, 1, 1, 0, 0, 0, 0 } for (int i = 0; i != 8; ++i) { if (i < 4) - hostArray2[i] = 1; + host_vec2[i] = 1; else - hostArray2[i] = 0; + host_vec2[i] = 0; } - myQueue.submit([&](sycl::handler& h) { - // copy hostArray2 to deviceArray2 - h.memcpy(deviceArray2, hostArray2, 8 * sizeof(bool)); - }); - myQueue.wait(); - { - auto dptr_begin = dpct::device_pointer(deviceArray2 + 4); - auto dptr_end = dpct::device_pointer(deviceArray2 + 8); + dpct::device_vector dev_vec2(host_vec2); + // call algorithm - auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0, std::plus(), oneapi::dpl::identity()); + auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec2.begin()+4, dev_vec2.end(), 0, std::plus(), oneapi::dpl::identity()); - test_name = "transform_reduce with USM allocation 2"; + test_name = "transform_reduce with device_vector 2"; failed_tests += ASSERT_EQUAL(test_name, result, 0); } From 4333cde5b641230e147853fce1972ad0f9847924 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 24 Feb 2023 15:01:50 -0500 Subject: [PATCH 2/6] adding onedpl_test_transform to test list Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/help_function/help_function.xml b/help_function/help_function.xml index 7e3a30f0..c28f0cfb 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -140,6 +140,7 @@ + From e7bdf7c81d6504b6351e27916376ee0d45bd0118 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Fri, 24 Feb 2023 17:01:41 -0500 Subject: [PATCH 3/6] excluding usmnone in new xml Signed-off-by: Dan Hoeflinger --- .../config/TEMPLATE_help_function_skip_usmnone.xml | 12 ++++++++++++ help_function/help_function.xml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 help_function/config/TEMPLATE_help_function_skip_usmnone.xml diff --git a/help_function/config/TEMPLATE_help_function_skip_usmnone.xml b/help_function/config/TEMPLATE_help_function_skip_usmnone.xml new file mode 100644 index 00000000..09184a0f --- /dev/null +++ b/help_function/config/TEMPLATE_help_function_skip_usmnone.xml @@ -0,0 +1,12 @@ + + + + test help function cases with usm switch on + + + + + + + + diff --git a/help_function/help_function.xml b/help_function/help_function.xml index c28f0cfb..30575f72 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -151,7 +151,7 @@ - + From f23212570de5c35572992ec20437012c19559cd9 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 29 Jun 2023 09:25:05 -0400 Subject: [PATCH 4/6] removing accidental testing check-in Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_fill.cpp | 2 -- help_function/src/onedpl_test_for_each.cpp | 1 - help_function/src/onedpl_test_sort_by_key.cpp | 1 - 3 files changed, 4 deletions(-) diff --git a/help_function/src/onedpl_test_fill.cpp b/help_function/src/onedpl_test_fill.cpp index 0feef944..db896a2f 100644 --- a/help_function/src/onedpl_test_fill.cpp +++ b/help_function/src/onedpl_test_fill.cpp @@ -7,8 +7,6 @@ // // ===----------------------------------------------------------------------===// -#define DPCT_USM_LEVEL_NONE - #include "oneapi/dpl/execution" #include "oneapi/dpl/iterator" #include "oneapi/dpl/algorithm" diff --git a/help_function/src/onedpl_test_for_each.cpp b/help_function/src/onedpl_test_for_each.cpp index be4f9dfd..c8629581 100644 --- a/help_function/src/onedpl_test_for_each.cpp +++ b/help_function/src/onedpl_test_for_each.cpp @@ -6,7 +6,6 @@ // // // ===----------------------------------------------------------------------===// -#define DPCT_USM_LEVEL_NONE #include "oneapi/dpl/execution" #include "oneapi/dpl/iterator" diff --git a/help_function/src/onedpl_test_sort_by_key.cpp b/help_function/src/onedpl_test_sort_by_key.cpp index 7501af66..3d08acdb 100644 --- a/help_function/src/onedpl_test_sort_by_key.cpp +++ b/help_function/src/onedpl_test_sort_by_key.cpp @@ -6,7 +6,6 @@ // // // ===----------------------------------------------------------------------===// -#define DPCT_USM_LEVEL_NONE #include From 6e3ff930186a0be5848cb147b22514513f7a62c3 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Thu, 28 Mar 2024 17:01:54 -0400 Subject: [PATCH 5/6] removing redundant entry Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/help_function/help_function.xml b/help_function/help_function.xml index 30575f72..b4ae3938 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -140,7 +140,6 @@ - From 5ff64a07f5b22b49a5ee1eb1833711b15d65fee1 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 4 Sep 2024 15:41:56 -0400 Subject: [PATCH 6/6] fix bad merge Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_sort_by_key.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/help_function/src/onedpl_test_sort_by_key.cpp b/help_function/src/onedpl_test_sort_by_key.cpp index 3d08acdb..0ca06fad 100644 --- a/help_function/src/onedpl_test_sort_by_key.cpp +++ b/help_function/src/onedpl_test_sort_by_key.cpp @@ -221,6 +221,10 @@ int main() { // values is now = {19, 10, 18, 11, 13, 17, 15, 12, 16, 14} } + { + int check_keys[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int check_values[10] = {19, 10, 18, 11, 13, 17, 15, 12, 16, 14}; + test_name = "sort using device_vector"; // check that values and keys are correct