Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 0d2eb25

Browse files
committed
Add test case for VL=1. Also, add test cases for intel/llvm/pull/4892
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 4bd587d commit 0d2eb25

File tree

1 file changed

+59
-41
lines changed

1 file changed

+59
-41
lines changed

SYCL/ESIMD/api/simd_view_copy_move_assign.cpp

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,56 @@
2424
using namespace cl::sycl;
2525
using namespace sycl::ext::intel::experimental::esimd;
2626

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";
3130
int A[VL];
3231
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;
3533

34+
// The expected result gets the first half of values from B,
35+
// the rest of values from A.
36+
int gold[VL];
3637
for (unsigned i = 0; i < VL; ++i) {
3738
A[i] = -i;
3839
B[i] = i;
40+
gold[i] = (i < HalfVL) ? B[i] : A[i];
3941
}
4042

4143
try {
4244
buffer<int, 1> bufA(A, range<1>(VL));
4345
buffer<int, 1> bufB(B, range<1>(VL));
4446
range<1> glob_range{1};
4547

46-
auto e = q.submit([&](handler &cgh) {
48+
q.submit([&](handler &cgh) {
4749
auto PA = bufA.template get_access<access::mode::read_write>(cgh);
4850
auto PB = bufB.template get_access<access::mode::read_write>(cgh);
4951
cgh.parallel_for(glob_range, [=](id<1> i) SYCL_ESIMD_KERNEL {
5052
using namespace sycl::ext::intel::experimental::esimd;
5153
unsigned int offset = i * VL * sizeof(int);
5254
simd<int, VL> va;
53-
va.copy_from(PA, offset);
5455
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);
5966
funcUnderTest(va_view, vb_view);
6067

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+
}
6375
});
64-
});
65-
q.wait_and_throw();
76+
}).wait_and_throw();
6677
} catch (sycl::exception const &e) {
6778
std::cout << "SYCL exception caught: " << e.what() << '\n';
6879
return false; // not success
@@ -86,41 +97,48 @@ template <class T> bool test(queue q, std::string str, T funcUnderTest) {
8697
return err_cnt > 0 ? false : true;
8798
}
8899

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+
89108
int main(void) {
90109
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
91110
auto dev = q.get_device();
92111
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
93112

94113
bool passed = true;
95114
// 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+
});
102121
// 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+
});
109128
// 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; });
113132
// 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); });
117136
// 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+
});
125143
return passed ? 0 : 1;
126144
}

0 commit comments

Comments
 (0)