Skip to content

Commit c5afb4e

Browse files
committed
Addressing usm_none usage in onedpl_tests
Signed-off-by: Dan Hoeflinger <[email protected]>
1 parent 01f0f67 commit c5afb4e

7 files changed

+56
-107
lines changed

help_function/help_function.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<test testName="onedpl_test_copy" configFile="config/TEMPLATE_help_function.xml" />
8888
<test testName="onedpl_test_copy_if" configFile="config/TEMPLATE_help_function.xml" />
8989
<test testName="onedpl_test_count_if" configFile="config/TEMPLATE_help_function.xml" />
90+
<test testName="onedpl_test_device_malloc_free" configFile="config/TEMPLATE_help_function_usm.xml" />
9091
<test testName="onedpl_test_discard_iterator" configFile="config/TEMPLATE_help_function.xml" />
9192
<test testName="onedpl_test_exclusive_scan" configFile="config/TEMPLATE_help_function.xml" />
9293
<test testName="onedpl_test_fill" configFile="config/TEMPLATE_help_function.xml" />
@@ -114,7 +115,7 @@
114115
<test testName="onedpl_test_tabulate" configFile="config/TEMPLATE_help_function.xml" />
115116
<test testName="onedpl_test_transform_if" configFile="config/TEMPLATE_help_function.xml" />
116117
<test testName="onedpl_test_transform_reduce" configFile="config/TEMPLATE_help_function_skip_double.xml" splitGroup="double" />
117-
<test testName="onedpl_test_uninitialized_fill" configFile="config/TEMPLATE_help_function.xml" />
118+
<test testName="onedpl_test_uninitialized_fill" configFile="config/TEMPLATE_help_function_usm.xml" />
118119
<test testName="onedpl_test_unique_by_key_copy" configFile="config/TEMPLATE_help_function.xml" />
119120
<test testName="onedpl_test_unique_by_key" configFile="config/TEMPLATE_help_function.xml" />
120121
<test testName="onedpl_test_unique" configFile="config/TEMPLATE_help_function.xml" />

help_function/src/onedpl_test_copy_if.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ int main() {
226226
// dcpt::copy_if with device_vector
227227

228228
{
229-
// **FAILS AT RUNTIME**
230229

231230
// create src and dst device_vector
232-
dpct::device_vector<int> src_dv(8);
233-
dpct::device_vector<int> dst_dv(8);
234231
std::vector<int> src_vec(8);
235232
std::vector<int> dst_vec(8);
236233

@@ -239,17 +236,8 @@ int main() {
239236
dst_vec[i] = 0;
240237
}
241238

242-
//copy from src_vec to src_dv
243-
dpct::get_default_queue().submit([&](sycl::handler& h) {
244-
h.memcpy(src_dv.data(), src_vec.data(), 8 * sizeof(int));
245-
});
246-
dpct::get_default_queue().wait();
247-
248-
//copy from dst_vec to dst_dv
249-
dpct::get_default_queue().submit([&](sycl::handler& h) {
250-
h.memcpy(dst_dv.data(), dst_vec.data(), 8 * sizeof(int));
251-
});
252-
dpct::get_default_queue().wait();
239+
dpct::device_vector<int> src_dv(src_vec);
240+
dpct::device_vector<int> dst_dv(dst_vec);
253241

254242
// src_dv: { 0, 1, 2, 3, 4, 5, 6, 7 }
255243
// dst_dv: { 0, 0, 0, 0, 0, 0, 0, 0 }
@@ -269,22 +257,16 @@ int main() {
269257
);
270258
}
271259

272-
dpct::get_default_queue().submit([&](sycl::handler& h) {
273-
// copy from dst_dv back to dst_vec
274-
h.memcpy(dst_vec.data(), dst_dv.data(), 8 * sizeof(int));
275-
});
276-
dpct::get_default_queue().wait();
277-
278260
std::string test_name = "copy_if with device_vector";
279261

280262
// expected dst_vec: { 5, 7, 0, 0, 0, 0, 0, 0 }
281263
for (int i = 0; i != 8; ++i) {
282264
if (i == 0)
283-
num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 5);
265+
num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 5);
284266
else if (i == 1)
285-
num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 7);
267+
num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 7);
286268
else
287-
num_failing += ASSERT_EQUAL(test_name, dst_vec[i], 0);
269+
num_failing += ASSERT_EQUAL(test_name, dst_dv[i], 0);
288270
}
289271

290272
failed_tests += test_passed(num_failing, test_name);

help_function/src/onedpl_test_exclusive_scan.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ int main(){
4040
int failed_tests = 0;
4141
int num_failing = 0;
4242

43+
44+
// These tests assume USM is available, disable when it isn't
45+
#ifndef DPCT_USM_LEVEL_NONE
4346
{
4447
// Test One, test normal call to std::exclusive_scan with std::plus<> and USM allocations
4548
// create queue
@@ -100,6 +103,7 @@ int main(){
100103
failed_tests += test_passed(num_failing, test_name);
101104
num_failing = 0;
102105
}
106+
#endif //DPCT_USM_LEVEL_NONE
103107

104108
{
105109
// Test Two, test normal call to std::exclusive_scan with std::plus<> with overlapping source and destination

help_function/src/onedpl_test_fill.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88
// ===----------------------------------------------------------------------===//
99

10+
#define DPCT_USM_LEVEL_NONE
11+
1012
#include "oneapi/dpl/execution"
1113
#include "oneapi/dpl/iterator"
1214
#include "oneapi/dpl/algorithm"
@@ -253,7 +255,9 @@ int main() {
253255
}
254256

255257
// Third 3 tests: Testing call to std::fill using device_pointer<T>
256-
258+
259+
// These tests assume USM is available, disable when it isn't
260+
#ifndef DPCT_USM_LEVEL_NONE
257261
{
258262
// test 1/3
259263

@@ -420,38 +424,30 @@ int main() {
420424
failed_tests += test_passed(num_failing, test_name);
421425
num_failing = 0;
422426
}
427+
#endif //DPCT_USM_LEVEL_NONE
423428

424429
{
425430
// test 2/2: call to std::fill_n using device_vector<T>
426431

427432
// create device_vector and src vector
428-
dpct::device_vector<int> dv(8);
429433
std::vector<int> src(8);
430434

431435
iota_vector(src, 0, 8);
436+
dpct::device_vector<int> dv(src);
432437

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

438440
{
439441
// call algorithm on dv
440442
std::fill_n(oneapi::dpl::execution::make_device_policy(dpct::get_default_queue()), dv.begin(), 4, 10);
441443
}
442444

443-
dpct::get_default_queue().submit([&](sycl::handler& h) {
444-
// copy dv back to src
445-
h.memcpy(src.data(), dv.data(), 8 * sizeof(int));
446-
});
447-
dpct::get_default_queue().wait();
448-
449445
std::string test_name = "std::fill_n with device_pointer<T> 2/2";
450446
for (int i = 0; i != 8; ++i) {
451447
if (i < 4)
452-
num_failing += ASSERT_EQUAL(test_name, src[i], 10);
448+
num_failing += ASSERT_EQUAL(test_name, dv[i], 10);
453449
else
454-
num_failing += ASSERT_EQUAL(test_name, src[i], i);
450+
num_failing += ASSERT_EQUAL(test_name, dv[i], i);
455451
}
456452

457453
failed_tests += test_passed(num_failing, test_name);

help_function/src/onedpl_test_for_each.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//
88
// ===----------------------------------------------------------------------===//
9+
#define DPCT_USM_LEVEL_NONE
910

1011
#include "oneapi/dpl/execution"
1112
#include "oneapi/dpl/iterator"
@@ -366,17 +367,11 @@ int main() {
366367
// test 1/1
367368

368369
// create device_vector and src vector
369-
dpct::device_vector<int> dv(8);
370370
std::vector<int> src(8);
371371

372372
src[0] = -3; src[1] = -2; src[2] = 1; src[3] = 0; src[4] = -1; src[5] = -4; src[6] = 2; src[7] = 3;
373373
// src: { -3, -2, 1, 0, -1, -4, 2, 3 }
374-
375-
// copy from src to dv
376-
dpct::get_default_queue().submit([&](sycl::handler& h) {
377-
h.memcpy(dv.data(), src.data(), 8 * sizeof(int));
378-
});
379-
dpct::get_default_queue().wait();
374+
dpct::device_vector<int> dv(src);
380375

381376
{
382377
// call algorithm on dv
@@ -389,24 +384,18 @@ int main() {
389384
);
390385
}
391386

392-
dpct::get_default_queue().submit([&](sycl::handler& h) {
393-
// copy dv back to src
394-
h.memcpy(src.data(), dv.data(), 8 * sizeof(int));
395-
});
396-
dpct::get_default_queue().wait();
397-
398387
// check that src is now { 3, 2, 1, 0, -1, -4, 2, 3 }
399388
// actual result is no change in src elements
400389
test_name = "std::for_each using device_vector";
401390

402-
num_failing += ASSERT_EQUAL(test_name, src[0], 3);
403-
num_failing += ASSERT_EQUAL(test_name, src[1], 2);
404-
num_failing += ASSERT_EQUAL(test_name, src[2], 1);
405-
num_failing += ASSERT_EQUAL(test_name, src[3], 0);
406-
num_failing += ASSERT_EQUAL(test_name, src[4], -1);
407-
num_failing += ASSERT_EQUAL(test_name, src[5], -4);
408-
num_failing += ASSERT_EQUAL(test_name, src[6], 2);
409-
num_failing += ASSERT_EQUAL(test_name, src[7], 3);
391+
num_failing += ASSERT_EQUAL(test_name, dv[0], 3);
392+
num_failing += ASSERT_EQUAL(test_name, dv[1], 2);
393+
num_failing += ASSERT_EQUAL(test_name, dv[2], 1);
394+
num_failing += ASSERT_EQUAL(test_name, dv[3], 0);
395+
num_failing += ASSERT_EQUAL(test_name, dv[4], -1);
396+
num_failing += ASSERT_EQUAL(test_name, dv[5], -4);
397+
num_failing += ASSERT_EQUAL(test_name, dv[6], 2);
398+
num_failing += ASSERT_EQUAL(test_name, dv[7], 3);
410399

411400
failed_tests += test_passed(num_failing, test_name);
412401
num_failing = 0;

help_function/src/onedpl_test_sort_by_key.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//
88
// ===----------------------------------------------------------------------===//
9+
#define DPCT_USM_LEVEL_NONE
910

1011
#include <oneapi/dpl/execution>
1112

@@ -143,6 +144,8 @@ int main() {
143144
}
144145
}
145146

147+
// These tests assume USM is available, disable when it isn't
148+
#ifndef DPCT_USM_LEVEL_NONE
146149
{
147150
// Test One, call to dpct::sort using USM allocations
148151
// create queue
@@ -198,23 +201,16 @@ int main() {
198201
failed_tests += test_passed(num_failing, test_name);
199202
num_failing = 0;
200203
}
204+
#endif //DPCT_USM_LEVEL_NONE
201205

202206
{
203207
// Test Two, test calls to dpct::sort using device vectors
204-
dpct::device_vector<int> keys_vec(10);
205-
dpct::device_vector<int> values_vec(10);
206208

207209
std::vector<int> keys_data{4, 8, 5, 3, 0, 9, 7, 2, 1, 6};
208210
std::vector<int> values_data{13, 16, 17, 11, 19, 14, 12, 18, 10, 15};
209211

210-
dpct::get_default_queue().submit([&](sycl::handler& h) {
211-
h.memcpy(keys_vec.data(), keys_data.data(), 10 * sizeof(int));
212-
});
213-
214-
dpct::get_default_queue().submit([&](sycl::handler& h) {
215-
h.memcpy(values_vec.data(), values_data.data(), 10 * sizeof(int));
216-
});
217-
dpct::get_default_queue().wait();
212+
dpct::device_vector<int> keys_vec(keys_data);
213+
dpct::device_vector<int> values_vec(values_data);
218214

219215
auto keys_it = keys_vec.begin();
220216
auto keys_it_end = keys_vec.end();
@@ -226,14 +222,6 @@ int main() {
226222
// values is now = {19, 10, 18, 11, 13, 17, 15, 12, 16, 14}
227223
}
228224

229-
dpct::get_default_queue().submit([&](sycl::handler& h) {
230-
h.memcpy(keys_data.data(), keys_vec.data(), 10 * sizeof(int));
231-
});
232-
233-
dpct::get_default_queue().submit([&](sycl::handler& h) {
234-
h.memcpy(values_data.data(), values_vec.data(), 10 * sizeof(int));
235-
});
236-
dpct::get_default_queue().wait();
237225

238226
{
239227
int check_keys[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
@@ -243,8 +231,8 @@ int main() {
243231
// check that values and keys are correct
244232

245233
for (int i = 0; i != 10; ++i) {
246-
num_failing += ASSERT_EQUAL(test_name, values_data[i], check_values[i]);
247-
num_failing += ASSERT_EQUAL(test_name, keys_data[i], check_keys[i]);
234+
num_failing += ASSERT_EQUAL(test_name, values_vec[i], check_values[i]);
235+
num_failing += ASSERT_EQUAL(test_name, keys_vec[i], check_keys[i]);
248236
}
249237

250238
failed_tests += test_passed(num_failing, test_name);
@@ -291,6 +279,8 @@ int main() {
291279
}
292280
}
293281

282+
// These tests assume USM is available, disable when it isn't
283+
#ifndef DPCT_USM_LEVEL_NONE
294284
{
295285
// Test Three, call to dpct::stable_sort using USM allocations
296286
// create queue
@@ -348,6 +338,7 @@ int main() {
348338
failed_tests += test_passed(num_failing, test_name);
349339
num_failing = 0;
350340
}
341+
#endif // DPCT_USM_LEVEL_NONE
351342

352343
{ // Test Four, test calls to dpct::stable_sort with duplicate key values
353344
sycl::buffer<int, 1> keys_buf{ sycl::range<1>(16) };

help_function/src/onedpl_test_transform_reduce.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,59 +50,45 @@ int main() {
5050
auto dev = myQueue.get_device();
5151
auto ctxt = myQueue.get_context();
5252

53-
// create host and device arrays
54-
double hostArray[8];
55-
double *deviceArray = (double*) malloc_device(8 * sizeof(double), dev, ctxt);
53+
// create host and device vectors
54+
std::vector<double> host_vec(8);
5655

57-
// hostArray = { 0, 1, 2, 3, 4, 5, 6, 7 }
56+
// host_vec = { 0, 1, 2, 3, 4, 5, 6, 7 }
5857
for (int i = 0; i != 8; ++i) {
59-
hostArray[i] = i;
58+
host_vec[i] = i;
6059
}
6160

62-
myQueue.submit([&](sycl::handler& h) {
63-
// copy hostArray to deviceArray
64-
h.memcpy(deviceArray, hostArray, 8 * sizeof(double));
65-
});
66-
myQueue.wait();
6761

6862
{
69-
auto dptr_begin = dpct::device_pointer<double>(deviceArray);
70-
auto dptr_end = dpct::device_pointer<double>(deviceArray + 4);
63+
dpct::device_vector<double> dev_vec(host_vec);
7164

7265
// call algorithm
73-
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0., std::plus<double>(), square());
66+
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec.begin(), dev_vec.begin()+4, 0., std::plus<double>(), square());
7467

75-
test_name = "transform_reduce with USM allocation";
68+
test_name = "transform_reduce with device_vector";
7669
failed_tests += ASSERT_EQUAL(test_name, result, 14);
7770
}
7871

7972
// test 2/2
8073

81-
bool hostArray2[8];
82-
bool *deviceArray2 = (bool*) malloc_device(8 * sizeof(bool), dev, ctxt);
74+
std::vector<bool> host_vec2(8);
8375

84-
// hostArray2 = { 1, 1, 1, 1, 0, 0, 0, 0 }
76+
// host_vec2 = { 1, 1, 1, 1, 0, 0, 0, 0 }
8577
for (int i = 0; i != 8; ++i) {
8678
if (i < 4)
87-
hostArray2[i] = 1;
79+
host_vec2[i] = 1;
8880
else
89-
hostArray2[i] = 0;
81+
host_vec2[i] = 0;
9082
}
9183

92-
myQueue.submit([&](sycl::handler& h) {
93-
// copy hostArray2 to deviceArray2
94-
h.memcpy(deviceArray2, hostArray2, 8 * sizeof(bool));
95-
});
96-
myQueue.wait();
97-
9884
{
99-
auto dptr_begin = dpct::device_pointer<bool>(deviceArray2 + 4);
100-
auto dptr_end = dpct::device_pointer<bool>(deviceArray2 + 8);
85+
dpct::device_vector<bool> dev_vec2(host_vec2);
86+
10187

10288
// call algorithm
103-
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dptr_begin, dptr_end, 0, std::plus<bool>(), oneapi::dpl::identity());
89+
auto result = std::transform_reduce(oneapi::dpl::execution::dpcpp_default, dev_vec2.begin()+4, dev_vec2.end(), 0, std::plus<bool>(), oneapi::dpl::identity());
10490

105-
test_name = "transform_reduce with USM allocation 2";
91+
test_name = "transform_reduce with device_vector 2";
10692
failed_tests += ASSERT_EQUAL(test_name, result, 0);
10793

10894
}

0 commit comments

Comments
 (0)