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 9bb4021c..b4ae3938 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..db896a2f 100644
--- a/help_function/src/onedpl_test_fill.cpp
+++ b/help_function/src/onedpl_test_fill.cpp
@@ -253,7 +253,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 +422,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 +440,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..c8629581 100644
--- a/help_function/src/onedpl_test_for_each.cpp
+++ b/help_function/src/onedpl_test_for_each.cpp
@@ -366,17 +366,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 +383,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..0ca06fad 100644
--- a/help_function/src/onedpl_test_sort_by_key.cpp
+++ b/help_function/src/onedpl_test_sort_by_key.cpp
@@ -144,6 +144,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 +201,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
@@ -274,6 +277,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 +336,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);
}