Skip to content

Commit 8878962

Browse files
[SYCL] Fix get_native for sycl::event (#5765)
Reworked event_impl: added new member flag to observe the state of init of the event and edited getter alongside default event_impl constructor, also made necessary members mutable, so that it supports lazy init, which now occurs when a get_native (both member and free) tries to get implementation of event which is constructed with the default constructor. These changes are to make sycl::event class meet the ad hoc requirements of the specification.
1 parent 8d29567 commit 8878962

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void event_impl::setContextImpl(const ContextImplPtr &Context) {
9999
}
100100

101101
event_impl::event_impl(HostEventState State)
102-
: MIsFlushed(true), MState(State) {}
102+
: MIsInitialized(false), MIsFlushed(true), MState(State) {}
103103

104104
event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
105105
: MEvent(Event), MContext(detail::getSyclObjImpl(SyclContext)),
@@ -342,7 +342,18 @@ void HostProfilingInfo::start() { StartTime = getTimestamp(); }
342342
void HostProfilingInfo::end() { EndTime = getTimestamp(); }
343343

344344
pi_native_handle event_impl::getNative() const {
345+
if (!MContext) {
346+
static context SyclContext;
347+
MContext = getSyclObjImpl(SyclContext);
348+
MHostEvent = MContext->is_host();
349+
MOpenCLInterop = !MHostEvent;
350+
}
345351
auto Plugin = getPlugin();
352+
if (!MIsInitialized) {
353+
MIsInitialized = true;
354+
auto TempContext = MContext.get()->getHandleRef();
355+
Plugin.call<PiApiKind::piEventCreate>(TempContext, &MEvent);
356+
}
346357
if (Plugin.getBackend() == backend::opencl)
347358
Plugin.call<PiApiKind::piEventRetain>(getHandleRef());
348359
pi_native_handle Handle;

sycl/source/detail/event_impl.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ class event_impl {
215215
void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
216216
int32_t StreamID, uint64_t IId) const;
217217
void checkProfilingPreconditions() const;
218-
RT::PiEvent MEvent = nullptr;
219-
ContextImplPtr MContext;
220-
bool MOpenCLInterop = false;
221-
bool MHostEvent = true;
218+
mutable bool MIsInitialized = true;
219+
mutable RT::PiEvent MEvent = nullptr;
220+
mutable ContextImplPtr MContext;
221+
mutable bool MOpenCLInterop = false;
222+
mutable bool MHostEvent = true;
222223
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
223224
void *MCommand = nullptr;
224225
std::weak_ptr<queue_impl> MQueue;

0 commit comments

Comments
 (0)