24
24
using namespace cl ::sycl;
25
25
using namespace sycl ::ext::intel::experimental::esimd;
26
26
27
- template <class T > bool test (queue q, std::string str, T funcUnderTest) {
28
- std::cout << " Testing " << str << " ...\n " ;
29
- constexpr unsigned VL = 8 ;
30
-
27
+ template <unsigned VL, class T >
28
+ bool test (queue q, std::string str, T funcUnderTest) {
29
+ std::cout << " Testing " << str << " , VL = " << VL << " ...\n " ;
31
30
int A[VL];
32
31
int B[VL];
33
- // As a result, A should have first 4 values from B, next 4 values from A.
34
- int gold[VL] = {0 , 1 , 2 , 3 , -4 , -5 , -6 , -7 };
32
+ constexpr unsigned HalfVL = VL > 1 ? (VL / 2 ) : 1 ;
35
33
34
+ // The expected result gets the first half of values from B,
35
+ // the rest of values from A.
36
+ int gold[VL];
36
37
for (unsigned i = 0 ; i < VL; ++i) {
37
38
A[i] = -i;
38
39
B[i] = i;
40
+ gold[i] = (i < HalfVL) ? B[i] : A[i];
39
41
}
40
42
41
43
try {
42
44
buffer<int , 1 > bufA (A, range<1 >(VL));
43
45
buffer<int , 1 > bufB (B, range<1 >(VL));
44
46
range<1 > glob_range{1 };
45
47
46
- auto e = q.submit ([&](handler &cgh) {
48
+ q.submit ([&](handler &cgh) {
47
49
auto PA = bufA.template get_access <access::mode::read_write>(cgh);
48
50
auto PB = bufB.template get_access <access::mode::read_write>(cgh);
49
51
cgh.parallel_for (glob_range, [=](id<1 > i) SYCL_ESIMD_KERNEL {
50
52
using namespace sycl ::ext::intel::experimental::esimd;
51
53
unsigned int offset = i * VL * sizeof (int );
52
54
simd<int , VL> va;
53
- va.copy_from (PA, offset);
54
55
simd<int , VL> vb;
55
- vb.copy_from (PB, offset);
56
- auto va_view = va.select <4 , 1 >(0 );
57
- auto vb_view = vb.select <4 , 1 >(0 );
58
-
56
+ if constexpr (VL == 1 ) {
57
+ va[0 ] = PA[0 ];
58
+ vb[0 ] = PB[0 ];
59
+ } else {
60
+ va.copy_from (PA, offset);
61
+ vb.copy_from (PB, offset);
62
+ }
63
+
64
+ auto va_view = va.template select <HalfVL, 1 >(0 );
65
+ auto vb_view = vb.template select <HalfVL, 1 >(0 );
59
66
funcUnderTest (va_view, vb_view);
60
67
61
- va.copy_to (PA, offset);
62
- vb.copy_to (PB, offset);
68
+ if constexpr (VL == 1 ) {
69
+ PA[0 ] = va[0 ];
70
+ PB[0 ] = vb[0 ];
71
+ } else {
72
+ va.copy_to (PA, offset);
73
+ vb.copy_to (PB, offset);
74
+ }
63
75
});
64
- });
65
- q.wait_and_throw ();
76
+ }).wait_and_throw ();
66
77
} catch (sycl::exception const &e) {
67
78
std::cout << " SYCL exception caught: " << e.what () << ' \n ' ;
68
79
return false ; // not success
@@ -86,41 +97,48 @@ template <class T> bool test(queue q, std::string str, T funcUnderTest) {
86
97
return err_cnt > 0 ? false : true ;
87
98
}
88
99
100
+ template <class FuncT >
101
+ bool tests (queue &Q, std::string Str, FuncT FuncUnderTest) {
102
+ bool Passed = true ;
103
+ Passed &= test<8 >(Q, Str, FuncUnderTest);
104
+ Passed &= test<1 >(Q, Str, FuncUnderTest);
105
+ return Passed;
106
+ }
107
+
89
108
int main (void ) {
90
109
queue q (esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler ());
91
110
auto dev = q.get_device ();
92
111
std::cout << " Running on " << dev.get_info <info::device::name>() << " \n " ;
93
112
94
113
bool passed = true ;
95
114
// copy constructor creates the same view of the underlying data.
96
- passed &= test (q, " copy constructor" ,
97
- [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
98
- auto va_view_copy (va_view);
99
- auto vb_view_copy (vb_view);
100
- va_view_copy = vb_view_copy;
101
- });
115
+ passed &= tests (q, " copy constructor" ,
116
+ [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
117
+ auto va_view_copy (va_view);
118
+ auto vb_view_copy (vb_view);
119
+ va_view_copy = vb_view_copy;
120
+ });
102
121
// move constructor transfers the same view of the underlying data.
103
- passed &= test (q, " move constructor" ,
104
- [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
105
- auto va_view_move (std::move (va_view));
106
- auto vb_view_move (std::move (vb_view));
107
- va_view_move = vb_view_move;
108
- });
122
+ passed &= tests (q, " move constructor" ,
123
+ [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
124
+ auto va_view_move (std::move (va_view));
125
+ auto vb_view_move (std::move (vb_view));
126
+ va_view_move = vb_view_move;
127
+ });
109
128
// assignment operator copies the underlying data.
110
- passed &= test (q, " assignment operator" ,
111
- [](auto &va_view, auto &vb_view)
112
- SYCL_ESIMD_FUNCTION { va_view = vb_view; });
129
+ passed &= tests (q, " assignment operator" ,
130
+ [](auto &va_view, auto &vb_view)
131
+ SYCL_ESIMD_FUNCTION { va_view = vb_view; });
113
132
// move assignment operator copies the underlying data.
114
- passed &= test (q, " move assignment operator" ,
115
- [](auto &va_view, auto &vb_view)
116
- SYCL_ESIMD_FUNCTION { va_view = std::move (vb_view); });
133
+ passed &= tests (q, " move assignment operator" ,
134
+ [](auto &va_view, auto &vb_view)
135
+ SYCL_ESIMD_FUNCTION { va_view = std::move (vb_view); });
117
136
// construct complete view of a vector.
118
- passed &= test (q, " constructor from simd" ,
119
- [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
120
- simd<int , 4 > vb = vb_view;
121
- simd_view new_vb_view = vb; // ctor from simd
122
- va_view = new_vb_view;
123
- });
124
-
137
+ passed &= tests (q, " constructor from simd" ,
138
+ [](auto &va_view, auto &vb_view) SYCL_ESIMD_FUNCTION {
139
+ simd vb = vb_view;
140
+ simd_view new_vb_view = vb; // ctor from simd
141
+ va_view = new_vb_view;
142
+ });
125
143
return passed ? 0 : 1 ;
126
144
}
0 commit comments