Skip to content

Commit d8860ed

Browse files
fineg74bb-sycl
authored andcommitted
[ESIMD] Test mix of unnamed ESIMD and nonESIMD kernels compilation (intel#1143)
1 parent 4f0bf4a commit d8860ed

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//==--- sycl_esimd_mixed_unnamed.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+
// This is basic test for mixing unnamed SYCL and ESIMD kernels in the same
9+
// source and in the same program .
10+
11+
// REQUIRES: gpu
12+
// UNSUPPORTED: cuda || hip
13+
// UNSUPPORTED: esimd_emulator
14+
// RUN: %clangxx -fsycl %s -o %t.out
15+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
16+
// XFAIL: esimd_emulator
17+
18+
#include <iostream>
19+
#include <sycl/ext/intel/esimd.hpp>
20+
#include <sycl/sycl.hpp>
21+
22+
using namespace ::sycl;
23+
24+
bool checkResult(const std::vector<float> &A, int Inc) {
25+
int err_cnt = 0;
26+
unsigned Size = A.size();
27+
28+
for (unsigned i = 0; i < Size; ++i) {
29+
if (A[i] != i + Inc)
30+
if (++err_cnt < 10)
31+
std::cerr << "failed at A[" << i << "]: " << A[i] << " != " << i + Inc
32+
<< "\n";
33+
}
34+
35+
if (err_cnt > 0) {
36+
std::cout << " pass rate: "
37+
<< ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% ("
38+
<< (Size - err_cnt) << "/" << Size << ")\n";
39+
return false;
40+
}
41+
return true;
42+
}
43+
44+
int main(void) {
45+
constexpr unsigned Size = 32;
46+
constexpr unsigned VL = 16;
47+
48+
std::vector<float> A(Size);
49+
50+
for (unsigned i = 0; i < Size; ++i) {
51+
A[i] = i;
52+
}
53+
54+
try {
55+
buffer<float, 1> bufa(A.data(), range<1>(Size));
56+
57+
// We need that many workgroups
58+
::sycl::range<1> GlobalRange{Size};
59+
// We need that many threads in each group
60+
::sycl::range<1> LocalRange{1};
61+
62+
queue q;
63+
64+
auto dev = q.get_device();
65+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
66+
67+
auto e = q.submit([&](handler &cgh) {
68+
auto PA = bufa.get_access<access::mode::read_write>(cgh);
69+
cgh.parallel_for(GlobalRange * LocalRange,
70+
[=](id<1> i) { PA[i] = PA[i] + 1; });
71+
});
72+
e.wait();
73+
} catch (::sycl::exception const &e) {
74+
std::cout << "SYCL exception caught: " << e.what() << '\n';
75+
return 2;
76+
}
77+
78+
if (checkResult(A, 1)) {
79+
std::cout << "SYCL kernel passed\n";
80+
} else {
81+
std::cout << "SYCL kernel failed\n";
82+
return 1;
83+
}
84+
85+
try {
86+
buffer<float, 1> bufa(A.data(), range<1>(Size));
87+
88+
// We need that many workgroups
89+
::sycl::range<1> GlobalRange{Size / VL};
90+
// We need that many threads in each group
91+
::sycl::range<1> LocalRange{1};
92+
93+
queue q;
94+
95+
auto dev = q.get_device();
96+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
97+
98+
auto e = q.submit([&](handler &cgh) {
99+
auto PA = bufa.get_access<access::mode::read_write>(cgh);
100+
cgh.parallel_for(GlobalRange * LocalRange,
101+
[=](id<1> i) SYCL_ESIMD_KERNEL {
102+
using namespace sycl::ext::intel::esimd;
103+
unsigned int offset = i * VL * sizeof(float);
104+
simd<float, VL> va;
105+
va.copy_from(PA, offset);
106+
simd<float, VL> vc = va + 1;
107+
vc.copy_to(PA, offset);
108+
});
109+
});
110+
e.wait();
111+
} catch (::sycl::exception const &e) {
112+
std::cout << "SYCL exception caught: " << e.what() << '\n';
113+
return 2;
114+
}
115+
116+
if (checkResult(A, 2)) {
117+
std::cout << "ESIMD kernel passed\n";
118+
} else {
119+
std::cout << "ESIMD kernel failed\n";
120+
return 1;
121+
}
122+
return 0;
123+
}

0 commit comments

Comments
 (0)