Skip to content

Commit a3a8aa1

Browse files
authored
[SYCL][ESIMD][E2E] Add gen12 raw_send test (#14564)
Simple gen12 raw send test. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent cbbae74 commit a3a8aa1

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//==-- vadd_raw_send_gen12.cpp - DPC++ ESIMD on-device test --==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------===//
8+
// REQUIRES: gpu-intel-gen12
9+
// RUN: %{build} -o %t.out
10+
// RUN: %{run} %t.out
11+
12+
#include "esimd_test_utils.hpp"
13+
14+
using namespace sycl;
15+
using namespace sycl::ext::intel::esimd;
16+
17+
simd<int, 16> gather(int *addr) {
18+
uint32_t desc = 0x022D0BFF;
19+
simd<int, 16> ret;
20+
simd<uint64_t, 16> addrs(reinterpret_cast<uint64_t>(addr), sizeof(int));
21+
ret = raw_send<4, 12, 1, 2>(ret, addrs, 0, desc);
22+
return ret;
23+
}
24+
25+
void scatter(simd<int, 16> &vec, int *addr) {
26+
uint32_t desc = 0x080691FF;
27+
simd<uint64_t, 16> addrs(reinterpret_cast<uint64_t>(addr), sizeof(int));
28+
raw_sends<4, 12, 4, 2>(addrs, vec, 0, desc);
29+
}
30+
31+
int main(void) {
32+
constexpr unsigned Size = 16;
33+
constexpr unsigned VL = 16;
34+
35+
queue q(esimd_test::ESIMDSelector, esimd_test::createExceptionHandler());
36+
37+
auto dev = q.get_device();
38+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
39+
40+
int *A = malloc_shared<int>(Size, q);
41+
int *B = malloc_shared<int>(Size, q);
42+
int *C = malloc_shared<int>(Size, q);
43+
44+
for (unsigned i = 0; i < Size; ++i) {
45+
A[i] = B[i] = i;
46+
}
47+
48+
try {
49+
auto e = q.submit([&](handler &cgh) {
50+
cgh.single_task([=]() SYCL_ESIMD_KERNEL {
51+
simd<int, VL> va = gather(A);
52+
simd<int, VL> vb = gather(B);
53+
simd<int, VL> vc = va + vb;
54+
scatter(vc, C);
55+
});
56+
});
57+
e.wait();
58+
} catch (sycl::exception const &e) {
59+
std::cout << "SYCL exception caught: " << e.what() << '\n';
60+
free(A, q);
61+
free(B, q);
62+
free(C, q);
63+
return 1;
64+
}
65+
66+
int err_cnt = 0;
67+
68+
for (unsigned i = 0; i < Size; ++i) {
69+
if (A[i] + B[i] != C[i]) {
70+
if (++err_cnt < 10) {
71+
std::cout << "failed at index " << i << ", " << C[i] << " != " << A[i]
72+
<< " + " << B[i] << "\n";
73+
}
74+
}
75+
}
76+
if (err_cnt > 0) {
77+
std::cout << " pass rate: "
78+
<< ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% ("
79+
<< (Size - err_cnt) << "/" << Size << ")\n";
80+
}
81+
82+
free(A, q);
83+
free(B, q);
84+
free(C, q);
85+
std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n");
86+
return err_cnt > 0 ? 1 : 0;
87+
}

0 commit comments

Comments
 (0)