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

Commit 36abb60

Browse files
authored
[SYCL] Add a test for interop_handle::get_native_mem() with PH accessor (#263)
The added test case checks that placeholder accessor is handled properly if registered properly in the commnd group, and that exception is thrown otherwise. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 6f3ece3 commit 36abb60

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

SYCL/HostInteropTask/interop-task.cpp

+55-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
3737
auto DstA = Dst.template get_access<mode::write>(CGH);
3838

3939
CGH.codeplay_host_task([=](interop_handle IH) {
40-
auto NativeQ = IH.get_native_queue();
41-
auto SrcMem = IH.get_native_mem(SrcA);
42-
auto DstMem = IH.get_native_mem(DstA);
40+
auto NativeQ = IH.get_native_queue<backend::opencl>();
41+
auto SrcMem = IH.get_native_mem<backend::opencl>(SrcA);
42+
auto DstMem = IH.get_native_mem<backend::opencl>(DstA);
4343
cl_event Event;
4444

4545
int RC = clEnqueueCopyBuffer(NativeQ, SrcMem, DstMem, 0, 0,
@@ -221,13 +221,65 @@ void test5() {
221221
checkBufferValues(Buffer2, static_cast<int>(123));
222222
}
223223

224+
// The test checks that placeholder accessors are correctly handled,
225+
// when properly registered in the command group.
226+
// It also checks that an exception is thrown if the placeholder accessor
227+
// is not registered.
228+
void test6() {
229+
queue Queue([](sycl::exception_list ExceptionList) {
230+
if (ExceptionList.size() != 1) {
231+
std::cerr << "Should be one exception in exception list" << std::endl;
232+
std::abort();
233+
}
234+
std::rethrow_exception(*ExceptionList.begin());
235+
});
236+
237+
// Placeholder accessor that is properly registered in CGH.
238+
try {
239+
size_t size = 1;
240+
buffer<int, 1> Buf{size};
241+
accessor<int, 1, mode::write, target::global_buffer,
242+
access::placeholder::true_t>
243+
PHAcc(Buf);
244+
Queue.submit([&](sycl::handler &CGH) {
245+
CGH.require(PHAcc);
246+
CGH.codeplay_host_task(
247+
[=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
248+
});
249+
Queue.wait_and_throw();
250+
} catch (sycl::exception &E) {
251+
std::cerr << "Unexpected exception caught: " << E.what();
252+
assert(!"Unexpected exception caught");
253+
}
254+
255+
// Placeholder accessor that is NOT registered in CGH.
256+
try {
257+
size_t size = 1;
258+
buffer<int, 1> Buf{size};
259+
accessor<int, 1, mode::write, target::global_buffer,
260+
access::placeholder::true_t>
261+
PHAcc(Buf);
262+
Queue.submit([&](sycl::handler &CGH) {
263+
CGH.codeplay_host_task(
264+
[=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
265+
});
266+
Queue.wait_and_throw();
267+
assert(!"Expected exception was not caught");
268+
} catch (sycl::exception &E) {
269+
assert(std::string(E.what()).find("Invalid memory object") !=
270+
std::string::npos &&
271+
"Unexpected error was caught!");
272+
}
273+
}
274+
224275
int main() {
225276
test1();
226277
test2();
227278
test2_1();
228279
test3();
229280
test4();
230281
test5();
282+
test6();
231283
std::cout << "Test PASSED" << std::endl;
232284
return 0;
233285
}

0 commit comments

Comments
 (0)