Skip to content
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
34 changes: 17 additions & 17 deletions sycl/source/detail/device_global_map_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
// and the event. When asserts are enabled the values are set, so we check
// these here.
assert(MPtr == nullptr && "MPtr has not been cleaned up.");
assert(!MInitEvent.has_value() && "MInitEvent has not been cleaned up.");
assert(MInitEvent == nullptr && "MInitEvent has not been cleaned up.");
}

OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(adapter_impl &Adapter) {
std::lock_guard<std::mutex> Lock(MInitEventMutex);
if (MInitEvent == nullptr)
return OwnedUrEvent(Adapter);

// If there is a init event we can remove it if it is done.
if (MInitEvent.has_value()) {
if (get_event_info<info::event::command_execution_status>(
*MInitEvent, Adapter) == info::event_command_status::complete) {
Adapter.call<UrApiKind::urEventRelease>(*MInitEvent);
MInitEvent = {};
return OwnedUrEvent(Adapter);
} else {
return OwnedUrEvent(*MInitEvent, Adapter);
}
if (get_event_info<info::event::command_execution_status>(
MInitEvent, Adapter) == info::event_command_status::complete) {
Adapter.call<UrApiKind::urEventRelease>(MInitEvent);
MInitEvent = nullptr;
return OwnedUrEvent(Adapter);
} else {
return OwnedUrEvent(MInitEvent, Adapter);
}
return OwnedUrEvent(Adapter);
}

DeviceGlobalUSMMem &
Expand Down Expand Up @@ -158,14 +158,14 @@ void DeviceGlobalMapEntry::removeAssociatedResources(
if (USMPtrIt != MDeviceToUSMPtrMap.end()) {
DeviceGlobalUSMMem &USMMem = USMPtrIt->second;
detail::usm::freeInternal(USMMem.MPtr, CtxImpl);
if (USMMem.MInitEvent.has_value())
if (USMMem.MInitEvent != nullptr)
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>(
*USMMem.MInitEvent);
USMMem.MInitEvent);
#ifndef NDEBUG
// For debugging we set the event and memory to some recognizable values
// to allow us to check that this cleanup happens before erasure.
USMMem.MPtr = nullptr;
USMMem.MInitEvent = {};
USMMem.MInitEvent = nullptr;
#endif
MDeviceToUSMPtrMap.erase(USMPtrIt);
}
Expand All @@ -183,13 +183,13 @@ void DeviceGlobalMapEntry::cleanup() {
const context_impl *CtxImpl = USMPtrIt.first.second;
DeviceGlobalUSMMem &USMMem = USMPtrIt.second;
detail::usm::freeInternal(USMMem.MPtr, CtxImpl);
if (USMMem.MInitEvent.has_value())
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>(*USMMem.MInitEvent);
if (USMMem.MInitEvent != nullptr)
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>(USMMem.MInitEvent);
#ifndef NDEBUG
// For debugging we set the event and memory to some recognizable values
// to allow us to check that this cleanup happens before erasure.
USMMem.MPtr = nullptr;
USMMem.MInitEvent = {};
USMMem.MInitEvent = nullptr;
#endif
}
MDeviceToUSMPtrMap.clear();
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_global_map_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct DeviceGlobalUSMMem {
private:
void *MPtr;
std::mutex MInitEventMutex;
std::optional<ur_event_handle_t> MInitEvent;
ur_event_handle_t MInitEvent = nullptr;

friend struct DeviceGlobalMapEntry;
};
Expand Down