Skip to content

Commit ebf5c4e

Browse files
author
Alexander Batashev
authored
[SYCL] Enable USM indirect access for interop kernels (#2377)
1 parent ac0e692 commit ebf5c4e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

sycl/source/detail/kernel_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context)
2727
// Let the runtime caller handle native kernel retaining in other cases if
2828
// it's needed.
2929
getPlugin().call<PiApiKind::piKernelRetain>(MKernel);
30+
// Enable USM indirect access for interoperability kernels.
31+
// Some PI Plugins (like OpenCL) require this call to enable USM
32+
// For others, PI will turn this into a NOP.
33+
getPlugin().call<PiApiKind::piKernelSetExecInfo>(
34+
MKernel, PI_USM_INDIRECT_ACCESS, sizeof(pi_bool), &PI_TRUE);
3035
}
3136

3237
kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -lOpenCL %s -o %t1.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
4+
// REQUIRES: opencl
5+
6+
#include <CL/cl.h>
7+
#include <CL/sycl.hpp>
8+
9+
using namespace sycl;
10+
11+
static const char *Src = R"(
12+
kernel void test(global ulong *PSrc, global ulong *PDst) {
13+
global int *Src = (global int *) *PSrc;
14+
global int *Dst = (global int *) *PDst;
15+
int Old = *Src, New = Old + 1;
16+
printf("Read %d from %p; write %d to %p\n", Old, Src, New, Dst);
17+
*Dst = New;
18+
}
19+
)";
20+
21+
int main() {
22+
queue Q{};
23+
24+
cl_context Ctx = Q.get_context().get();
25+
cl_program Prog = clCreateProgramWithSource(Ctx, 1, &Src, NULL, NULL);
26+
clBuildProgram(Prog, 0, NULL, NULL, NULL, NULL);
27+
28+
cl_kernel OclKernel = clCreateKernel(Prog, "test", NULL);
29+
30+
cl::sycl::kernel SyclKernel(OclKernel, Q.get_context());
31+
32+
auto POuter = malloc_shared<int *>(1, Q);
33+
auto PInner = malloc_shared<int>(1, Q);
34+
auto QOuter = malloc_shared<int *>(1, Q);
35+
auto QInner = malloc_shared<int>(1, Q);
36+
37+
*PInner = 4;
38+
*POuter = PInner;
39+
*QInner = 0;
40+
*QOuter = QInner;
41+
42+
Q.submit([&](handler &CGH) {
43+
CGH.set_arg(0, POuter);
44+
CGH.set_arg(1, QOuter);
45+
CGH.parallel_for(cl::sycl::range<1>(1), SyclKernel);
46+
}).wait();
47+
48+
assert(*PInner == 4 && "Read value is corrupted");
49+
assert(*QInner == 5 && "Value value is incorrect");
50+
51+
std::cout << "Increment: " << *PInner << " -> " << *QInner << std::endl;
52+
53+
clReleaseKernel(OclKernel);
54+
clReleaseProgram(Prog);
55+
clReleaseContext(Ctx);
56+
}

0 commit comments

Comments
 (0)