Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 14 additions & 3 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,20 @@ event queue_impl::mem_advise(const shared_ptr_class<detail::queue_impl> &Self,
}

void queue_impl::addEvent(const event &Event) {
std::weak_ptr<event_impl> EventWeakPtr{getSyclObjImpl(Event)};
std::lock_guard<mutex_class> Lock(MMutex);
MEvents.push_back(std::move(EventWeakPtr));
// if the command behind the event has no memory dependencies,
// we need to track the event with the USMEvents, or it won't be properly
// released.
EventImplPtr Eimpl = getSyclObjImpl(Event);
Command *Cmd = (Command *)(Eimpl->getCommand());
if (Cmd && Cmd->MDeps.size() == 0) {
addUSMEvent(Event);
Eimpl->setCommand(nullptr); // decouple and free the command
delete Cmd;
} else {
std::weak_ptr<event_impl> EventWeakPtr{Eimpl};
std::lock_guard<mutex_class> Lock(MMutex);
MEvents.push_back(std::move(EventWeakPtr));
}
}

void queue_impl::addUSMEvent(const event &Event) {
Expand Down
19 changes: 19 additions & 0 deletions sycl/test/basic_tests/queue/release.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out | FileCheck %s

#include <CL/sycl.hpp>
int main() {
sycl::queue q;

q.single_task<class test>([]() {});
// no wait. ensure resources are released anyway.

return 0;
}

//CHECK: ---> piEnqueueKernelLaunch(
//CHECK: ---> piQueueRelease(
//CHECK: ---> piEventRelease(
//CHECK: ---> piContextRelease(
//CHECK: ---> piKernelRelease(
//CHECK: ---> piProgramRelease(