Skip to content

[SYCL] Fix event usage in interop memory object constructors #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ void *MemoryManager::allocateInteropMemObject(
// Return cl_mem as is if contexts match.
if (TargetContext == InteropContext) {
OutEventToWait = InteropEvent->getHandleRef();
// Retain the event since it will be released during alloca command
// destruction
if (nullptr != OutEventToWait)
PI_CALL(piEventRetain)(OutEventToWait);
return UserPtr;
}
// Allocate new cl_mem and initialize from user provided one.
Expand Down
37 changes: 37 additions & 0 deletions sycl/test/basic_tests/buffer/buffer_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,42 @@ int main() {
Error = clReleaseMemObject(OpenCLBuffer);
CHECK_OCL_CODE(Error);
}
// Check interop constructor event
{
// Checks that the cl_event is not deleted on memory object destruction
queue MyQueue;
cl_context OpenCLContext = MyQueue.get_context().get();

int Val;
cl_int Error = CL_SUCCESS;
cl_mem OpenCLBuffer =
clCreateBuffer(OpenCLContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
sizeof(int), &Val, &Error);
CHECK_OCL_CODE(Error);
cl_event OpenCLEvent = clCreateUserEvent(OpenCLContext, &Error);
CHECK_OCL_CODE(Error);
CHECK_OCL_CODE(clSetUserEventStatus(OpenCLEvent, CL_COMPLETE));

{
event Event(OpenCLEvent, OpenCLContext);
buffer<int, 1> Buffer{OpenCLBuffer, MyQueue.get_context(), Event};

MyQueue.submit([&](handler &Cgh) {
auto Acc = Buffer.get_access<access::mode::write>(Cgh);
Cgh.single_task<class TestEvent>([=]() { Acc[0] = 42; });
});

auto Acc = Buffer.get_access<access::mode::read>();
if (42 != Acc[0]) {
assert(false);
Failed = true;
}
}

CHECK_OCL_CODE(clReleaseMemObject(OpenCLBuffer));
CHECK_OCL_CODE(clReleaseContext(OpenCLContext));
CHECK_OCL_CODE(clReleaseEvent(OpenCLEvent));
}

return Failed;
}