Skip to content

Commit f8ed65d

Browse files
[NFC][SYCL] No need for std::optional<ur_event_handle_t> in device_global_map_entry (#19595)
Using `nullptr` for not having an event is just fine.
1 parent 27dab6c commit f8ed65d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2828
OwnedUrEvent 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

4444
DeviceGlobalUSMMem &
@@ -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();

sycl/source/detail/device_global_map_entry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct DeviceGlobalUSMMem {
4444
private:
4545
void *MPtr;
4646
std::mutex MInitEventMutex;
47-
std::optional<ur_event_handle_t> MInitEvent;
47+
ur_event_handle_t MInitEvent = nullptr;
4848

4949
friend struct DeviceGlobalMapEntry;
5050
};

0 commit comments

Comments
 (0)