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