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

[SYCL] Add a test case interop_handle accepting placeholder accessor #263

Merged
merged 1 commit into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions SYCL/HostInteropTask/interop-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
auto DstA = Dst.template get_access<mode::write>(CGH);

CGH.codeplay_host_task([=](interop_handle IH) {
auto NativeQ = IH.get_native_queue();
auto SrcMem = IH.get_native_mem(SrcA);
auto DstMem = IH.get_native_mem(DstA);
auto NativeQ = IH.get_native_queue<backend::opencl>();
auto SrcMem = IH.get_native_mem<backend::opencl>(SrcA);
auto DstMem = IH.get_native_mem<backend::opencl>(DstA);
cl_event Event;

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

// The test checks that placeholder accessors are correctly handled,
// when properly registered in the command group.
// It also checks that an exception is thrown if the placeholder accessor
// is not registered.
void test6() {
queue Queue([](sycl::exception_list ExceptionList) {
if (ExceptionList.size() != 1) {
std::cerr << "Should be one exception in exception list" << std::endl;
std::abort();
}
std::rethrow_exception(*ExceptionList.begin());
});

// Placeholder accessor that is properly registered in CGH.
try {
size_t size = 1;
buffer<int, 1> Buf{size};
accessor<int, 1, mode::write, target::global_buffer,
access::placeholder::true_t>
PHAcc(Buf);
Queue.submit([&](sycl::handler &CGH) {
CGH.require(PHAcc);
CGH.codeplay_host_task(
[=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
});
Queue.wait_and_throw();
} catch (sycl::exception &E) {
std::cerr << "Unexpected exception caught: " << E.what();
assert(!"Unexpected exception caught");
}

// Placeholder accessor that is NOT registered in CGH.
try {
size_t size = 1;
buffer<int, 1> Buf{size};
accessor<int, 1, mode::write, target::global_buffer,
access::placeholder::true_t>
PHAcc(Buf);
Queue.submit([&](sycl::handler &CGH) {
CGH.codeplay_host_task(
[=](interop_handle IH) { (void)IH.get_native_mem(PHAcc); });
});
Queue.wait_and_throw();
assert(!"Expected exception was not caught");
} catch (sycl::exception &E) {
assert(std::string(E.what()).find("Invalid memory object") !=
std::string::npos &&
"Unexpected error was caught!");
}
}

int main() {
test1();
test2();
test2_1();
test3();
test4();
test5();
test6();
std::cout << "Test PASSED" << std::endl;
return 0;
}