Skip to content

Commit f1b47c6

Browse files
committed
Add tests for uninitialized_fill[_n] for hetero backend
1 parent a1561db commit f1b47c6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/parallel_api/memory/specialized.algorithms/uninitialized_fill_destroy.pass.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,12 @@ void test_empty_list_initialization_for_uninitialized_fill()
260260
}
261261
}
262262
#if TEST_DPCPP_BACKEND_PRESENT
263-
std::vector<int> v{3,6,5,4,3,7,8,0,2,4};
264-
sycl::buffer<int> buf(v);
265-
auto it = oneapi::dpl::uninitialized_fill(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), oneapi::dpl::end(buf), {});
266-
EXPECT_TRUE(std::count(v.begin(), v.end(), 0) == v.size(), "a sequence is not filled properly by oneapi::dpl::uninitialized_fill with `device_policy` policy");
263+
auto usm_deleter = [] (auto ptr) { sycl::free(ptr, oneapi::dpl::execution::dpcpp_default.queue()); };
264+
using usm_deleter_type = decltype(usm_deleter);
265+
std::unique_ptr<int, usm_deleter_type> ptr{sycl::malloc_shared<int>(size, oneapi::dpl::execution::dpcpp_default.queue()), usm_deleter};
266+
oneapi::dpl::uninitialized_fill(oneapi::dpl::execution::dpcpp_default, ptr.get(), ptr.get() + size, {1});
267+
EXPECT_TRUE(std::count(ptr.get(), ptr.get() + size, 1) == size, "a sequence is not filled properly by oneapi::dpl::uninitialized_fill with `device_policy` policy");
268+
// no need to call destroy for a trivial type
267269
#endif
268270
}
269271

@@ -320,10 +322,12 @@ void test_empty_list_initialization_for_uninitialized_fill_n()
320322
}
321323
}
322324
#if TEST_DPCPP_BACKEND_PRESENT
323-
std::vector<int> v{3,6,5,4,3,7,8,0,2,4};
324-
sycl::buffer<int> buf(v);
325-
auto it = oneapi::dpl::uninitialized_fill_n(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), oneapi::dpl::end(buf), {});
326-
EXPECT_TRUE(std::count(v.begin(), v.end(), 0) == v.size(), "a sequence is not filled properly by oneapi::dpl::uninitialized_fill_n with `device_policy` policy");
325+
auto usm_deleter = [] (auto ptr) { sycl::free(ptr, oneapi::dpl::execution::dpcpp_default.queue()); };
326+
using usm_deleter_type = decltype(usm_deleter);
327+
std::unique_ptr<int, usm_deleter_type> ptr{sycl::malloc_shared<int>(size, oneapi::dpl::execution::dpcpp_default.queue()), usm_deleter};
328+
oneapi::dpl::uninitialized_fill_n(oneapi::dpl::execution::dpcpp_default, ptr.get(), size, {1});
329+
EXPECT_TRUE(std::count(ptr.get(), ptr.get() + size, 1) == size, "a sequence is not filled properly by oneapi::dpl::uninitialized_fill with `device_policy` policy");
330+
// no need to call destroy for a trivial type
327331
#endif
328332
}
329333

0 commit comments

Comments
 (0)