|
20 | 20 | #include <iostream>
|
21 | 21 |
|
22 | 22 | 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) { |
24 | 24 | if(X!=Y) {
|
25 | 25 | std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl;
|
26 | 26 | return 1;
|
27 | 27 | }
|
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 | + { |
29 | 47 | std::cout << "PASS: " << msg << std::endl;
|
30 |
| - return 0; |
31 | 48 | }
|
| 49 | + return failed_tests; |
32 | 50 | }
|
33 | 51 |
|
34 | 52 | int test_device_ptr_manipulation(void)
|
@@ -115,9 +133,42 @@ int test_device_ptr_iteration(void)
|
115 | 133 | return failing_tests;
|
116 | 134 | }
|
117 | 135 |
|
| 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 | + |
118 | 167 | int main() {
|
119 |
| - int failed_tests = test_device_ptr_manipulation(); |
| 168 | + int failed_tests = 0; |
| 169 | + failed_tests += test_device_ptr_manipulation(); |
120 | 170 | failed_tests += test_device_ptr_iteration();
|
| 171 | + failed_tests += test_permutation_iterator(); |
121 | 172 |
|
122 | 173 | std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl;
|
123 | 174 | if (failed_tests == 0) {
|
|
0 commit comments