Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] USM_NONE testing fixes #243

Open
wants to merge 6 commits into
base: SYCLomatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions help_function/config/TEMPLATE_help_function_skip_usmnone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<test driverID="test_help" name="TEMPLATE">
<description>test help function cases with usm switch on </description>
<files>
<file path="src/${testName}.cpp" />
</files>
<rules>
<optlevelRule excludeOptlevelNameString="usmnone" />
<optlevelRule excludeOptlevelNameString="cuda_backend" />
</rules>
</test>
3 changes: 2 additions & 1 deletion help_function/help_function.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<test testName="onedpl_test_count_if" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_device_new_delete" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_device_ptr" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_device_malloc_free" configFile="config/TEMPLATE_help_function_skip_usmnone.xml" />
<test testName="onedpl_test_discard_iterator" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_equal_range" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_exclusive_scan" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
Expand Down Expand Up @@ -149,7 +150,7 @@
<!-- <test testName="onedpl_test_group_load" configFile="config/TEMPLATE_help_function.xml" /> -->
<test testName="onedpl_test_transform_reduce" configFile="config/TEMPLATE_help_function_skip_double.xml" splitGroup="double" />
<test testName="onedpl_test_translate_key" configFile="config/TEMPLATE_help_function_skip_double.xml" splitGroup="double" />
<test testName="onedpl_test_uninitialized_fill" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_uninitialized_fill" configFile="config/TEMPLATE_help_function_skip_usmnone.xml" />
<test testName="onedpl_test_unique_by_key_copy" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_unique_by_key" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
<test testName="onedpl_test_unique_count" configFile="config/TEMPLATE_help_function_skip_cuda_backend.xml" />
Expand Down
28 changes: 5 additions & 23 deletions help_function/src/onedpl_test_copy_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,8 @@ int main() {
// dcpt::copy_if with device_vector

{
// **FAILS AT RUNTIME**

// create src and dst device_vector
dpct::device_vector<int> src_dv(8);
dpct::device_vector<int> dst_dv(8);
std::vector<int> src_vec(8);
std::vector<int> dst_vec(8);

Expand All @@ -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<int> src_dv(src_vec);
dpct::device_vector<int> dst_dv(dst_vec);

// src_dv: { 0, 1, 2, 3, 4, 5, 6, 7 }
// dst_dv: { 0, 0, 0, 0, 0, 0, 0, 0 }
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions help_function/src/onedpl_test_exclusive_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions help_function/src/onedpl_test_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ int main() {
}

// Third 3 tests: Testing call to std::fill using device_pointer<T>


// These tests assume USM is available, disable when it isn't
#ifndef DPCT_USM_LEVEL_NONE
{
// test 1/3

Expand Down Expand Up @@ -420,38 +422,30 @@ 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<T>

// create device_vector and src vector
dpct::device_vector<int> dv(8);
std::vector<int> src(8);

iota_vector(src, 0, 8);
dpct::device_vector<int> dv(src);

dpct::get_default_queue().submit([&](sycl::handler& h) {
h.memcpy(dv.data(), src.data(), 8 * sizeof(int));
});
dpct::get_default_queue().wait();

{
// call algorithm on dv
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<T> 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);
Expand Down
30 changes: 9 additions & 21 deletions help_function/src/onedpl_test_for_each.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,11 @@ int main() {
// test 1/1

// create device_vector and src vector
dpct::device_vector<int> dv(8);
std::vector<int> 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<int> dv(src);

{
// call algorithm on dv
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions help_function/src/onedpl_test_sort_by_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<int, 1> keys_buf{ sycl::range<1>(16) };
Expand Down
44 changes: 15 additions & 29 deletions help_function/src/onedpl_test_transform_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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<double>(deviceArray);
auto dptr_end = dpct::device_pointer<double>(deviceArray + 4);
dpct::device_vector<double> dev_vec(host_vec);

// call algorithm
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0., std::plus<double>(), square());
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec.begin(), dev_vec.begin()+4, 0., std::plus<double>(), 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<bool> 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<bool>(deviceArray2 + 4);
auto dptr_end = dpct::device_pointer<bool>(deviceArray2 + 8);
dpct::device_vector<bool> dev_vec2(host_vec2);


// call algorithm
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0, std::plus<bool>(), oneapi::dpl::identity());
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec2.begin()+4, dev_vec2.end(), 0, std::plus<bool>(), 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);

}
Expand Down