@@ -22,23 +22,23 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
2222 // and the event. When asserts are enabled the values are set, so we check
2323 // these here.
2424 assert (MPtr == nullptr && " MPtr has not been cleaned up." );
25- assert (! MInitEvent. has_value () && " MInitEvent has not been cleaned up." );
25+ assert (MInitEvent == nullptr && " MInitEvent has not been cleaned up." );
2626}
2727
2828OwnedUrEvent DeviceGlobalUSMMem::getInitEvent (adapter_impl &Adapter) {
2929 std::lock_guard<std::mutex> Lock (MInitEventMutex);
30+ if (MInitEvent == nullptr )
31+ return OwnedUrEvent (Adapter);
32+
3033 // If there is a init event we can remove it if it is done.
31- if (MInitEvent.has_value ()) {
32- if (get_event_info<info::event::command_execution_status>(
33- *MInitEvent, Adapter) == info::event_command_status::complete) {
34- Adapter.call <UrApiKind::urEventRelease>(*MInitEvent);
35- MInitEvent = {};
36- return OwnedUrEvent (Adapter);
37- } else {
38- return OwnedUrEvent (*MInitEvent, Adapter);
39- }
34+ if (get_event_info<info::event::command_execution_status>(
35+ MInitEvent, Adapter) == info::event_command_status::complete) {
36+ Adapter.call <UrApiKind::urEventRelease>(MInitEvent);
37+ MInitEvent = nullptr ;
38+ return OwnedUrEvent (Adapter);
39+ } else {
40+ return OwnedUrEvent (MInitEvent, Adapter);
4041 }
41- return OwnedUrEvent (Adapter);
4242}
4343
4444DeviceGlobalUSMMem &
@@ -158,14 +158,14 @@ void DeviceGlobalMapEntry::removeAssociatedResources(
158158 if (USMPtrIt != MDeviceToUSMPtrMap.end ()) {
159159 DeviceGlobalUSMMem &USMMem = USMPtrIt->second ;
160160 detail::usm::freeInternal (USMMem.MPtr , CtxImpl);
161- if (USMMem.MInitEvent . has_value () )
161+ if (USMMem.MInitEvent != nullptr )
162162 CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(
163- * USMMem.MInitEvent );
163+ USMMem.MInitEvent );
164164#ifndef NDEBUG
165165 // For debugging we set the event and memory to some recognizable values
166166 // to allow us to check that this cleanup happens before erasure.
167167 USMMem.MPtr = nullptr ;
168- USMMem.MInitEvent = {} ;
168+ USMMem.MInitEvent = nullptr ;
169169#endif
170170 MDeviceToUSMPtrMap.erase (USMPtrIt);
171171 }
@@ -183,13 +183,13 @@ void DeviceGlobalMapEntry::cleanup() {
183183 const context_impl *CtxImpl = USMPtrIt.first .second ;
184184 DeviceGlobalUSMMem &USMMem = USMPtrIt.second ;
185185 detail::usm::freeInternal (USMMem.MPtr , CtxImpl);
186- if (USMMem.MInitEvent . has_value () )
187- CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(* USMMem.MInitEvent );
186+ if (USMMem.MInitEvent != nullptr )
187+ CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(USMMem.MInitEvent );
188188#ifndef NDEBUG
189189 // For debugging we set the event and memory to some recognizable values
190190 // to allow us to check that this cleanup happens before erasure.
191191 USMMem.MPtr = nullptr ;
192- USMMem.MInitEvent = {} ;
192+ USMMem.MInitEvent = nullptr ;
193193#endif
194194 }
195195 MDeviceToUSMPtrMap.clear ();
0 commit comments