Skip to content

Commit 4cf7087

Browse files
authored
[NFC][SYCL] Add e2e test for early-AOT behavior (#11701)
Add a basic E2E test that exercises early-AOT behavior when using -fsycl -fno-sycl-rdc -c -fsycl-targets=spir64_gen when building objects.
1 parent 34a0635 commit 4cf7087

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

sycl/test-e2e/AOT/early_aot.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Test early-AOT behaviors with -fsycl -fno-sycl-rdc. This targets spir64_gen
2+
3+
// REQUIRES: ocloc, gpu
4+
// UNSUPPORTED: cuda, hip
5+
6+
// Build the early AOT device binaries
7+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen %gpu_aot_target_opts -fno-sycl-rdc -c -DADD_CPP %s -o %t_add.o
8+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen %gpu_aot_target_opts -fno-sycl-rdc -c -DSUB_CPP %s -o %t_sub.o
9+
// RUN: %clangxx -fsycl -DMAIN_CPP %s %t_add.o %t_sub.o -o %t.out
10+
11+
// RUN: %{run} %t.out
12+
13+
#ifdef MAIN_CPP
14+
// main.cpp
15+
16+
#include "sycl/sycl.hpp"
17+
#include <iostream>
18+
19+
void add(sycl::queue q, int *result, int a, int b);
20+
void sub(sycl::queue q, int *result, int a, int b);
21+
22+
int main() {
23+
sycl::queue q;
24+
int *result = sycl::malloc_host<int>(2, q);
25+
if (!result)
26+
std::cout << "Error: failed to allocate USM host memory\n";
27+
28+
try {
29+
add(q, &(result[0]), 2, 1);
30+
} catch (sycl::exception const &e) {
31+
std::cout
32+
<< "Caught synchronous SYCL exception while launching add kernel:\n"
33+
<< e.what() << "\n";
34+
std::terminate();
35+
}
36+
try {
37+
sub(q, &(result[1]), 2, 1);
38+
} catch (sycl::exception const &e) {
39+
std::cout
40+
<< "Caught synchronous SYCL exception while launching sub kernel:\n"
41+
<< e.what() << "\n";
42+
std::terminate();
43+
}
44+
q.wait();
45+
46+
// Check the results
47+
if (!(result[0] == 3 && result[1] == 1)) {
48+
std::cout << "FAILED\n";
49+
return 1;
50+
}
51+
std::cout << "PASSED\n";
52+
return 0;
53+
}
54+
55+
#endif // MAIN_CPP
56+
57+
#ifdef ADD_CPP
58+
// add.cpp
59+
#include "sycl/sycl.hpp"
60+
61+
void add(sycl::queue q, int *result, int a, int b) {
62+
q.single_task<class add_dummy>([=] { *result = a + b; });
63+
}
64+
65+
#endif // ADD_CPP
66+
67+
#ifdef SUB_CPP
68+
// sub.cpp
69+
#include "sycl/sycl.hpp"
70+
71+
void sub(sycl::queue q, int *result, int a, int b) {
72+
q.single_task<class sub_dummy>([=] { *result = a - b; });
73+
}
74+
#endif // SUB_CPP

0 commit comments

Comments
 (0)