|
22 | 22 | // - use std::move() to provide it to simd constructor
|
23 | 23 | // - bitwise compare expected and retrieved values
|
24 | 24 |
|
25 |
| -#include "common.hpp" |
| 25 | +#include "ctor_array.hpp" |
26 | 26 |
|
27 | 27 | using namespace esimd_test::api::functional;
|
28 |
| -using namespace sycl::ext::intel::experimental::esimd; |
29 |
| - |
30 |
| -// Descriptor class for the case of calling constructor in initializer context. |
31 |
| -struct initializer { |
32 |
| - static std::string get_description() { return "initializer"; } |
33 |
| - |
34 |
| - template <typename DataT, int NumElems> |
35 |
| - static void call_simd_ctor(DataT (&&ref_data)[NumElems], DataT *const out) { |
36 |
| - static_assert( |
37 |
| - type_traits::is_nonconst_rvalue_reference_v<decltype(ref_data)>, |
38 |
| - "Provided input data is not nonconst rvalue reference"); |
39 |
| - const auto simd_by_init = simd<DataT, NumElems>(std::move(ref_data)); |
40 |
| - simd_by_init.copy_to(out); |
41 |
| - } |
42 |
| -}; |
43 |
| - |
44 |
| -// Descriptor class for the case of calling constructor in variable declaration |
45 |
| -// context. |
46 |
| -struct var_decl { |
47 |
| - static std::string get_description() { return "variable declaration"; } |
48 |
| - |
49 |
| - template <typename DataT, int NumElems> |
50 |
| - static void call_simd_ctor(DataT (&&ref_data)[NumElems], DataT *const out) { |
51 |
| - static_assert( |
52 |
| - type_traits::is_nonconst_rvalue_reference_v<decltype(ref_data)>, |
53 |
| - "Provided input data is not nonconst rvalue reference"); |
54 |
| - const simd<DataT, NumElems> simd_by_var_decl(std::move(ref_data)); |
55 |
| - simd_by_var_decl.copy_to(out); |
56 |
| - } |
57 |
| -}; |
58 |
| - |
59 |
| -// Descriptor class for the case of calling constructor in rvalue in an |
60 |
| -// expression context. |
61 |
| -struct rval_in_expr { |
62 |
| - static std::string get_description() { return "rvalue in an expression"; } |
63 |
| - |
64 |
| - template <typename DataT, int NumElems> |
65 |
| - static void call_simd_ctor(DataT (&&ref_data)[NumElems], DataT *const out) { |
66 |
| - static_assert( |
67 |
| - type_traits::is_nonconst_rvalue_reference_v<decltype(ref_data)>, |
68 |
| - "Provided input data is not nonconst rvalue reference"); |
69 |
| - simd<DataT, NumElems> simd_by_rval; |
70 |
| - simd_by_rval = simd<DataT, NumElems>(std::move(ref_data)); |
71 |
| - simd_by_rval.copy_to(out); |
72 |
| - } |
73 |
| -}; |
74 |
| - |
75 |
| -// Descriptor class for the case of calling constructor in const reference |
76 |
| -// context. |
77 |
| -class const_ref { |
78 |
| -public: |
79 |
| - static std::string get_description() { return "const reference"; } |
80 |
| - |
81 |
| - template <typename DataT, int NumElems> |
82 |
| - static void call_simd_ctor(DataT (&&ref_data)[NumElems], DataT *const out) { |
83 |
| - static_assert( |
84 |
| - type_traits::is_nonconst_rvalue_reference_v<decltype(ref_data)>, |
85 |
| - "Provided input data is not nonconst rvalue reference"); |
86 |
| - call_simd_by_const_ref<DataT, NumElems>( |
87 |
| - simd<DataT, NumElems>(std::move(ref_data)), out); |
88 |
| - } |
89 |
| - |
90 |
| -private: |
91 |
| - template <typename DataT, int NumElems> |
92 |
| - static void |
93 |
| - call_simd_by_const_ref(const simd<DataT, NumElems> &simd_by_const_ref, |
94 |
| - DataT *out) { |
95 |
| - simd_by_const_ref.copy_to(out); |
96 |
| - } |
97 |
| -}; |
98 |
| - |
99 |
| -// The main test routine. |
100 |
| -// Using functor class to be able to iterate over the pre-defined data types. |
101 |
| -template <typename DataT, typename DimT, typename TestCaseT> class run_test { |
102 |
| - static constexpr int NumElems = DimT::value; |
103 |
| - |
104 |
| -public: |
105 |
| - bool operator()(sycl::queue &queue, const std::string &data_type) { |
106 |
| - |
107 |
| - bool passed = true; |
108 |
| - const std::vector<DataT> ref_data = generate_ref_data<DataT, NumElems>(); |
109 |
| - |
110 |
| - // If current number of elements is equal to one, then run test with each |
111 |
| - // one value from reference data. |
112 |
| - // If current number of elements is greater than one, then run tests with |
113 |
| - // whole reference data. |
114 |
| - if constexpr (NumElems == 1) { |
115 |
| - for (size_t i = 0; i < ref_data.size(); ++i) { |
116 |
| - passed &= run_verification(queue, {ref_data[i]}, data_type); |
117 |
| - } |
118 |
| - } else { |
119 |
| - passed &= run_verification(queue, ref_data, data_type); |
120 |
| - } |
121 |
| - return passed; |
122 |
| - } |
123 |
| - |
124 |
| -private: |
125 |
| - bool run_verification(sycl::queue &queue, const std::vector<DataT> &ref_data, |
126 |
| - const std::string &data_type) { |
127 |
| - assert(ref_data.size() == NumElems && |
128 |
| - "Reference data size is not equal to the simd vector length."); |
129 |
| - |
130 |
| - bool passed = true; |
131 |
| - |
132 |
| - shared_allocator<DataT> allocator(queue); |
133 |
| - shared_vector<DataT> result(NumElems, allocator); |
134 |
| - shared_vector<DataT> shared_ref_data(ref_data.begin(), ref_data.end(), |
135 |
| - allocator); |
136 |
| - |
137 |
| - queue.submit([&](sycl::handler &cgh) { |
138 |
| - const DataT *const ref = shared_ref_data.data(); |
139 |
| - DataT *const out = result.data(); |
140 |
| - |
141 |
| - cgh.single_task<ctors::Kernel<DataT, NumElems, TestCaseT>>( |
142 |
| - [=]() SYCL_ESIMD_KERNEL { |
143 |
| - DataT ref_on_dev[NumElems]; |
144 |
| - for (size_t i = 0; i < NumElems; ++i) { |
145 |
| - ref_on_dev[i] = ref[i]; |
146 |
| - } |
147 |
| - |
148 |
| - TestCaseT::template call_simd_ctor<DataT, NumElems>( |
149 |
| - std::move(ref_on_dev), out); |
150 |
| - }); |
151 |
| - }); |
152 |
| - queue.wait_and_throw(); |
153 |
| - |
154 |
| - for (size_t i = 0; i < result.size(); ++i) { |
155 |
| - if (!are_bitwise_equal(ref_data[i], result[i])) { |
156 |
| - passed = false; |
157 |
| - |
158 |
| - const auto description = |
159 |
| - ctors::TestDescription<DataT, NumElems, TestCaseT>( |
160 |
| - i, result[i], ref_data[i], data_type); |
161 |
| - log::fail(description); |
162 |
| - } |
163 |
| - } |
164 |
| - |
165 |
| - return passed; |
166 |
| - } |
167 |
| -}; |
168 | 28 |
|
169 | 29 | int main(int, char **) {
|
170 | 30 | sycl::queue queue(esimd_test::ESIMDSelector{},
|
171 | 31 | esimd_test::createExceptionHandler());
|
172 | 32 |
|
173 | 33 | bool passed = true;
|
174 | 34 |
|
175 |
| - const auto types = get_tested_types<tested_types::all>(); |
| 35 | + const auto types = get_tested_types<tested_types::core>(); |
176 | 36 | const auto dims = get_all_dimensions();
|
177 |
| - const auto contexts = unnamed_type_pack<initializer, var_decl, rval_in_expr, |
178 |
| - const_ref>::generate(); |
| 37 | + const auto contexts = |
| 38 | + unnamed_type_pack<ctors::initializer, ctors::var_decl, |
| 39 | + ctors::rval_in_expr, ctors::const_ref>::generate(); |
179 | 40 |
|
180 |
| - passed &= for_all_combinations<run_test>(types, dims, contexts, queue); |
| 41 | + passed &= for_all_combinations<ctors::run_test>(types, dims, contexts, queue); |
181 | 42 |
|
182 | 43 | std::cout << (passed ? "=== Test passed\n" : "=== Test FAILED\n");
|
183 | 44 | return passed ? 0 : 1;
|
|
0 commit comments