Skip to content

Commit 7ca2a87

Browse files
authored
[SYCL][RTC] Add E2E test for mixed SYCL and ESIMD source strings (#17208)
Refactor existing ESIMD test to also exercise the ability to mix SYCL and ESIMD kernels in the same source string, as was already supported by the `sycl_jit`-language pipeline. Signed-off-by: Julian Oppermann <julian.oppermann@codeplay.com>
1 parent 8e69702 commit 7ca2a87

File tree

1 file changed

+54
-31
lines changed

1 file changed

+54
-31
lines changed

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit.cpp

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void ff_cp(int *ptr) {
133133
}
134134
)===";
135135

136-
void test_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
136+
void run_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
137137
constexpr int Range = 10;
138138
int *usmPtr = sycl::malloc_shared<int>(Range, Queue);
139139
int start = 3;
@@ -159,6 +159,41 @@ void test_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
159159
sycl::free(usmPtr, Queue);
160160
}
161161

162+
void run_2(sycl::queue &Queue, sycl::kernel &Kernel, bool ESIMD, float seed) {
163+
constexpr int VL = 16; // this constant also in ESIMDSource string.
164+
constexpr int size = VL * 16;
165+
166+
float *A = sycl::malloc_shared<float>(size, Queue);
167+
float *B = sycl::malloc_shared<float>(size, Queue);
168+
float *C = sycl::malloc_shared<float>(size, Queue);
169+
for (size_t i = 0; i < size; i++) {
170+
A[i] = seed;
171+
B[i] = seed * 2.0f;
172+
C[i] = 0.0f;
173+
}
174+
sycl::range<1> GlobalRange(size / (ESIMD ? VL : 1));
175+
sycl::range<1> LocalRange(ESIMD ? 1 : VL);
176+
sycl::nd_range<1> NDRange{GlobalRange, LocalRange};
177+
178+
Queue
179+
.submit([&](sycl::handler &Handler) {
180+
Handler.set_arg(0, A);
181+
Handler.set_arg(1, B);
182+
Handler.set_arg(2, C);
183+
Handler.parallel_for(NDRange, Kernel);
184+
})
185+
.wait();
186+
187+
// Check.
188+
for (size_t i = 0; i < size; i++) {
189+
assert(C[i] == seed * 3.0f);
190+
}
191+
192+
sycl::free(A, Queue);
193+
sycl::free(B, Queue);
194+
sycl::free(C, Queue);
195+
}
196+
162197
int test_build_and_run() {
163198
namespace syclex = sycl::ext::oneapi::experimental;
164199
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
@@ -220,8 +255,8 @@ int test_build_and_run() {
220255
assert(kbExe2.ext_oneapi_has_kernel(cgn2));
221256

222257
// Test the kernels.
223-
test_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
224-
test_1(q, k2, 38 + 6); // ff_templated seeds 38. PlusEm adds 6 more.
258+
run_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
259+
run_1(q, k2, 38 + 6); // ff_templated seeds 38. PlusEm adds 6 more.
225260

226261
// Create and compile new bundle with different header.
227262
std::string AddEmHModified = AddEmH;
@@ -234,11 +269,11 @@ int test_build_and_run() {
234269

235270
exe_kb kbExe3 = syclex::build(kbSrc2);
236271
sycl::kernel k3 = kbExe3.ext_oneapi_get_kernel("ff_cp");
237-
test_1(q, k3, 37 + 7);
272+
run_1(q, k3, 37 + 7);
238273

239274
// Can we still run the original compilation?
240275
sycl::kernel k4 = kbExe1.ext_oneapi_get_kernel("ff_cp");
241-
test_1(q, k4, 37 + 5);
276+
run_1(q, k4, 37 + 5);
242277

243278
return 0;
244279
}
@@ -382,36 +417,24 @@ int test_esimd() {
382417
sycl::kernel k = kbExe.ext_oneapi_get_kernel("vector_add_esimd");
383418

384419
// Now test it.
385-
constexpr int VL = 16; // this constant also in ESIMDSource string.
386-
constexpr int size = VL * 16;
420+
run_2(q, k, true, 3.14f);
387421

388-
float *A = sycl::malloc_shared<float>(size, q);
389-
float *B = sycl::malloc_shared<float>(size, q);
390-
float *C = sycl::malloc_shared<float>(size, q);
391-
for (size_t i = 0; i < size; i++) {
392-
A[i] = float(1);
393-
B[i] = float(2);
394-
C[i] = 0.0f;
395-
}
396-
sycl::range<1> GlobalRange{size / VL};
397-
sycl::range<1> LocalRange{1};
398-
sycl::nd_range<1> NDRange{GlobalRange, LocalRange};
422+
// Mix ESIMD and normal kernel.
423+
std::string mixedSource = std::string{ESIMDSource} + SYCLSource2;
424+
source_kb kbSrcMixed = syclex::create_kernel_bundle_from_source(
425+
ctx, syclex::source_language::sycl_jit, mixedSource);
426+
exe_kb kbExeMixed = syclex::build(kbSrcMixed);
399427

400-
q.submit([&](sycl::handler &h) {
401-
h.set_arg(0, A);
402-
h.set_arg(1, B);
403-
h.set_arg(2, C);
404-
h.parallel_for(NDRange, k);
405-
}).wait();
428+
// Both kernels should be available.
429+
sycl::kernel kESIMD = kbExeMixed.ext_oneapi_get_kernel("vector_add_esimd");
430+
sycl::kernel kSYCL = kbExeMixed.ext_oneapi_get_kernel("vec_add");
406431

407-
// Check.
408-
for (size_t i = 0; i < size; i++) {
409-
assert(C[i] == 3.0f);
410-
}
432+
// Device code split is mandatory.
433+
assert(std::distance(kbExeMixed.begin(), kbExeMixed.end()) == 2);
411434

412-
sycl::free(A, q);
413-
sycl::free(B, q);
414-
sycl::free(C, q);
435+
// Test execution.
436+
run_2(q, kESIMD, true, 2.38f);
437+
run_2(q, kSYCL, false, 1.41f);
415438

416439
return 0;
417440
}

0 commit comments

Comments
 (0)