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

Commit bbdb607

Browse files
Recovering 'esimd_check_vc_codegen.cpp' to its initial import version
- As 'CHECK' fails for 'piProgramBuild' PI_API call
1 parent 697e3bd commit bbdb607

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

SYCL/ESIMD/esimd_check_vc_codegen.cpp

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,82 @@
2121
using namespace cl::sycl;
2222

2323
int main(void) {
24+
constexpr unsigned Size = 1024 * 128;
25+
constexpr unsigned VL = 16;
26+
27+
float *A = new float[Size];
28+
float *B = new float[Size];
29+
float *C = new float[Size];
30+
31+
for (unsigned i = 0; i < Size; ++i) {
32+
A[i] = B[i] = i;
33+
C[i] = 0.0f;
34+
}
35+
2436
try {
25-
int data = 0;
37+
buffer<float, 1> bufa(A, range<1>(Size));
38+
buffer<float, 1> bufb(B, range<1>(Size));
39+
buffer<float, 1> bufc(C, range<1>(Size));
40+
41+
// We need that many workgroups
42+
range<1> GlobalRange{Size / VL};
43+
44+
// We need that many threads in each group
45+
range<1> LocalRange{1};
46+
2647
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
2748

2849
auto dev = q.get_device();
2950
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
3051

31-
cl::sycl::buffer<int, 1> buf(&data, cl::sycl::range<1>(1));
3252
auto e = q.submit([&](handler &cgh) {
33-
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
34-
cgh.single_task<class Test>([=] { acc[0] += 1; });
53+
auto PA = bufa.get_access<access::mode::read>(cgh);
54+
auto PB = bufb.get_access<access::mode::read>(cgh);
55+
auto PC = bufc.get_access<access::mode::write>(cgh);
56+
cgh.parallel_for<class Test>(
57+
GlobalRange * LocalRange, [=](id<1> i) SYCL_ESIMD_KERNEL {
58+
using namespace sycl::ext::intel::experimental::esimd;
59+
unsigned int offset = i * VL * sizeof(float);
60+
simd<float, VL> va;
61+
va.copy_from(PA, offset);
62+
simd<float, VL> vb;
63+
vb.copy_from(PB, offset);
64+
simd<float, VL> vc = va + vb;
65+
vc.copy_to(PC, offset);
66+
});
3567
});
3668
e.wait();
3769
} catch (sycl::exception const &e) {
3870
std::cout << "SYCL exception caught: " << e.what() << '\n';
71+
72+
delete[] A;
73+
delete[] B;
74+
delete[] C;
3975
return 1;
4076
}
41-
return 0;
77+
78+
int err_cnt = 0;
79+
80+
for (unsigned i = 0; i < Size; ++i) {
81+
if (A[i] + B[i] != C[i]) {
82+
if (++err_cnt < 10) {
83+
std::cout << "failed at index " << i << ", " << C[i] << " != " << A[i]
84+
<< " + " << B[i] << "\n";
85+
}
86+
}
87+
}
88+
if (err_cnt > 0) {
89+
std::cout << " pass rate: "
90+
<< ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% ("
91+
<< (Size - err_cnt) << "/" << Size << ")\n";
92+
}
93+
94+
delete[] A;
95+
delete[] B;
96+
delete[] C;
97+
98+
std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n");
99+
return err_cnt > 0 ? 1 : 0;
42100
}
43101

44102
// CHECK: ---> piProgramBuild(

0 commit comments

Comments
 (0)