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

Commit 4577a65

Browse files
[SYCL] Add one more ESIMD regression test (#568)
1 parent 2d0a31f commit 4577a65

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <CL/sycl.hpp>
2+
#include <sycl/ext/intel/experimental/esimd.hpp>
3+
4+
static constexpr const int VL = 4;
5+
6+
sycl::event add(size_t n, sycl::buffer<int, 1> &buf_a,
7+
sycl::buffer<int, 1> &buf_b, sycl::buffer<int, 1> &buf_c,
8+
sycl::queue &Q) {
9+
auto E = Q.submit([&](sycl::handler &H) {
10+
sycl::accessor acc_a{buf_a, H, sycl::read_only};
11+
sycl::accessor acc_b{buf_b, H, sycl::read_only};
12+
sycl::accessor acc_c{buf_c, H, sycl::write_only};
13+
14+
H.parallel_for(n, [=](sycl::id<1> i) SYCL_ESIMD_KERNEL {
15+
using namespace sycl::ext::intel::experimental::esimd;
16+
unsigned int offset = i * VL * sizeof(int);
17+
simd<int, VL> va(acc_a, offset);
18+
simd<int, VL> vb(acc_b, offset);
19+
simd<int, VL> vc = va + vb;
20+
vc.copy_to(acc_c, offset);
21+
});
22+
});
23+
return E;
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <CL/sycl.hpp>
2+
3+
sycl::event iota(size_t n, sycl::buffer<int, 1> &buf, sycl::queue &Q) {
4+
auto HK = [&](sycl::handler &H) {
5+
sycl::accessor acc_y{buf, H, sycl::write_only};
6+
auto K = [=](sycl::id<1> id) {
7+
int *y = acc_y.get_pointer();
8+
size_t i = id.get(0);
9+
y[i] = static_cast<int>(i);
10+
};
11+
H.parallel_for(n, K);
12+
};
13+
return Q.submit(HK);
14+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <CL/sycl.hpp>
2+
#include <cstdio>
3+
4+
sycl::event iota(size_t n, sycl::buffer<int, 1> &d, sycl::queue &Q);
5+
sycl::event add(size_t n, sycl::buffer<int, 1> &buf_a,
6+
sycl::buffer<int, 1> &buf_b, sycl::buffer<int, 1> &buf_c,
7+
sycl::queue &Q);
8+
9+
int main(int argc, char *argv[]) {
10+
try {
11+
size_t i;
12+
size_t N = 1024;
13+
sycl::device D(sycl::default_selector{});
14+
sycl::context Ctx(D);
15+
sycl::queue Q(Ctx, D);
16+
17+
std::vector<int> A(N), B(N), C(N);
18+
{
19+
sycl::buffer<int, 1> buf_A(A.data(), N);
20+
sycl::buffer<int, 1> buf_B(B.data(), N);
21+
iota(N, buf_A, Q);
22+
iota(N, buf_B, Q);
23+
}
24+
25+
bool pass = true;
26+
for (i = 0; i < 10; ++i) {
27+
pass = pass && (A[i] == i);
28+
pass = pass && (B[i] == i);
29+
}
30+
31+
{
32+
sycl::buffer<int, 1> buf_A(A.data(), N);
33+
sycl::buffer<int, 1> buf_B(B.data(), N);
34+
sycl::buffer<int, 1> buf_C(C.data(), N);
35+
add(N, buf_A, buf_B, buf_C, Q);
36+
}
37+
38+
for (i = 0; i < 10; ++i) {
39+
pass = pass && (A[i] + B[i] == C[i]);
40+
}
41+
42+
fprintf(stdout, "%s: %s\n", argv[0], pass ? "PASS" : "FAIL");
43+
} catch (sycl::exception const &se) {
44+
fprintf(stderr, "%s failed with %s (%d)\n", argv[0], se.what(),
45+
se.code().value());
46+
47+
return 1;
48+
} catch (std::exception const &e) {
49+
fprintf(stderr, "failed with %s\n", e.what());
50+
return 2;
51+
} catch (...) {
52+
fprintf(stderr, "failed\n");
53+
return -1;
54+
}
55+
return 0;
56+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This test is intended to check a certain approach of compiling libraries and
2+
// application, when both regular SYCL and ESIMD are used.
3+
//
4+
// We used to have a bug, when under some circumstances compiler created empty
5+
// device images, but at the same time it stated that they contain some kernels.
6+
// More details can be found in intel/llvm#4927.
7+
//
8+
// REQUIRES: linux,gpu
9+
// UNSUPPORTED: cuda || hip
10+
//
11+
// RUN: %clangxx -fsycl -fPIC -O3 %S/Inputs/complex-lib-sycl.cpp -c -o %t-lib-sycl.o
12+
// RUN: %clangxx -fsycl -fPIC -O3 %S/Inputs/complex-lib-esimd.cpp -c -o %t-lib-esimd.o
13+
// RUN: %clangxx -fsycl -fPIC -O3 %S/Inputs/complex-lib-test.cpp -c -o %t-test.o
14+
//
15+
// RUN: ar crsv %t-lib-sycl.a %t-lib-sycl.o
16+
// RUN: ar crsv %t-lib-esimd.a %t-lib-esimd.o
17+
//
18+
// One shared library is built using static libraries
19+
//
20+
// RUN: %clangxx -fsycl -shared %t-lib-sycl.a %t-lib-esimd.a \
21+
// RUN: -fsycl-device-code-split=per_kernel -Wl,--whole-archive \
22+
// RUN: %t-lib-sycl.a %t-lib-esimd.a -Wl,--no-whole-archive -Wl,-soname,%S -o %t-lib-a.so
23+
//
24+
// And another one is constructed directly from object files
25+
//
26+
// RUN: %clangxx -fsycl -shared %t-lib-sycl.o %t-lib-esimd.o \
27+
// RUN: -fsycl-device-code-split=per_kernel -Wl,-soname,%S -o %t-lib-o.so
28+
//
29+
// RUN: %clangxx -fsycl %t-test.o %t-lib-a.so -o %t-a.run
30+
// RUN: %clangxx -fsycl %t-test.o %t-lib-o.so -o %t-o.run
31+
//
32+
// FIXME: is there better way to handle libraries loading than LD_PRELOAD?
33+
// There is no LIT substitution, which would point to a directory, where
34+
// temporary files are located. There is %T, but it is marked as "deprecated,
35+
// do not use"
36+
// RUN: %GPU_RUN_PLACEHOLDER LD_PRELOAD=%t-lib-a.so %t-a.run
37+
// RUN: %GPU_RUN_PLACEHOLDER LD_PRELOAD=%t-lib-o.so %t-o.run

0 commit comments

Comments
 (0)