Skip to content

Commit 41a3708

Browse files
committed
Adding tests for device_pointer inside a permutation_iterator
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
1 parent aa031a2 commit 41a3708

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

help_function/src/onedpl_test_device_ptr.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,33 @@
2020
#include <iostream>
2121

2222
template<typename String, typename _T1, typename _T2>
23-
int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y) {
23+
int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y, bool skip_pass_msg = false) {
2424
if(X!=Y) {
2525
std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl;
2626
return 1;
2727
}
28-
else {
28+
else if (!skip_pass_msg){
29+
std::cout << "PASS: " << msg << std::endl;
30+
}
31+
return 0;
32+
}
33+
34+
template <typename String, typename _T1, typename _T2>
35+
int
36+
ASSERT_EQUAL_N(String msg, _T1&& X, _T2&& Y, ::std::size_t n)
37+
{
38+
int failed_tests = 0;
39+
for (size_t i = 0; i < n; i++)
40+
{
41+
failed_tests += ASSERT_EQUAL(msg, *X, *Y, true);
42+
X++;
43+
Y++;
44+
}
45+
if (failed_tests == 0)
46+
{
2947
std::cout << "PASS: " << msg << std::endl;
30-
return 0;
3148
}
49+
return failed_tests;
3250
}
3351

3452
int test_device_ptr_manipulation(void)
@@ -115,9 +133,42 @@ int test_device_ptr_iteration(void)
115133
return failing_tests;
116134
}
117135

136+
int
137+
test_permutation_iterator()
138+
{
139+
int failing_tests = 0;
140+
typedef size_t T;
141+
#ifdef DPCT_USM_LEVEL_NONE
142+
sycl::buffer<T, 1> data(sycl::range<1>(1024));
143+
144+
dpct::device_pointer<T> begin(data, 0);
145+
dpct::device_pointer<T> end(data, 1024);
146+
147+
sycl::buffer<T, 1> data_res(sycl::range<1>(1024));
148+
dpct::device_pointer<T> begin_res(data_res, 0);
149+
dpct::device_pointer<T> end_res(data_res, 1024);
150+
#else
151+
dpct::device_pointer<T> data(1024*sizeof(T));
152+
dpct::device_pointer<T> begin(data);
153+
dpct::device_pointer<T> end(data + 1024);
154+
155+
dpct::device_pointer<T> data_res(1024*sizeof(T));
156+
dpct::device_pointer<T> begin_res(data_res);
157+
dpct::device_pointer<T> end_res(data_res + 1024);
158+
#endif
159+
auto policy = oneapi::dpl::execution::make_device_policy(dpct::get_default_queue());
160+
std::fill(begin, end, T(1));
161+
std::fill(begin_res, end_res, T(99));
162+
auto perm = oneapi::dpl::make_permutation_iterator(begin, oneapi::dpl::counting_iterator(0));
163+
std::copy(policy, perm, perm + 1024, begin_res);
164+
return ASSERT_EQUAL_N("device_ptr in permutation_iterator", begin_res, dpct::make_constant_iterator(T(1)), 1024);
165+
}
166+
118167
int main() {
119-
int failed_tests = test_device_ptr_manipulation();
168+
int failed_tests = 0;
169+
failed_tests += test_device_ptr_manipulation();
120170
failed_tests += test_device_ptr_iteration();
171+
failed_tests += test_permutation_iterator();
121172

122173
std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl;
123174
if (failed_tests == 0) {

0 commit comments

Comments
 (0)