21 #ifdef XPTI_ENABLE_INSTRUMENTATION
22 #include "xpti/xpti_trace_framework.hpp"
29 inline namespace _V1 {
31 #ifdef XPTI_ENABLE_INSTRUMENTATION
32 extern xpti::trace_event_data_t *GSYCLGraphEvent;
69 "waitInternal method cannot be used for a discarded event.");
72 std::unique_lock<std::mutex> lock(
MMutex);
84 std::unique_lock<std::mutex> lock(
MMutex);
89 bool Succeeded =
MState.compare_exchange_strong(Expected, Desired);
91 assert(Succeeded &&
"Unexpected state of event");
100 assert(
false &&
"setComplete is not supported for non-host event");
104 auto Timestamp = std::chrono::high_resolution_clock::now().time_since_epoch();
105 return std::chrono::duration_cast<std::chrono::nanoseconds>(Timestamp)
134 : MIsContextInitialized(true), MEvent(Event),
136 MIsFlushed(true), MState(HES_Complete) {
140 "The syclContext must match the OpenCL context "
141 "associated with the clEvent. " +
148 &TempContext,
nullptr);
149 if (
MContext->getHandleRef() != TempContext) {
151 "The syclContext must match the OpenCL context "
152 "associated with the clEvent. " +
159 MIsProfilingEnabled{Queue->is_host() || Queue->MIsProfilingEnabled},
160 MFallbackProfiling{MIsProfilingEnabled && Queue->isProfilingFallback()} {
161 this->setContextImpl(Queue->getContextImplPtr());
162 if (Queue->is_host()) {
163 MState.store(HES_NotComplete);
164 if (Queue->has_property<property::queue::enable_profiling>()) {
165 MHostProfilingInfo.reset(
new HostProfilingInfo());
166 if (!MHostProfilingInfo)
168 "Out of host memory " +
173 MState.store(HES_Complete);
177 uint64_t &IId)
const {
178 void *TraceEvent =
nullptr;
179 #ifdef XPTI_ENABLE_INSTRUMENTATION
180 constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
181 if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
185 static std::atomic<uint64_t> InstanceID = {1};
186 xpti::trace_event_data_t *WaitEvent =
nullptr;
190 xpti::utils::StringHelper SH;
201 WaitEvent = GSYCLGraphEvent;
205 xptiNotifySubscribers(StreamID, NotificationTraceType,
nullptr, WaitEvent,
206 IId,
static_cast<const void *
>(Name.c_str()));
207 TraceEvent = (
void *)WaitEvent;
213 const std::string &Name,
214 int32_t StreamID, uint64_t IId)
const {
215 #ifdef XPTI_ENABLE_INSTRUMENTATION
216 constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
217 if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
221 xpti::trace_event_data_t *TraceEvent =
222 (xpti::trace_event_data_t *)TelemetryEvent;
223 xptiNotifySubscribers(StreamID, NotificationTraceType,
nullptr, TraceEvent,
224 IId,
static_cast<const void *
>(Name.c_str()));
231 "wait method cannot be used for a discarded event.");
235 "wait method cannot be used for an event associated "
236 "with a command graph.");
239 #ifdef XPTI_ENABLE_INSTRUMENTATION
240 void *TelemetryEvent =
nullptr;
254 #ifdef XPTI_ENABLE_INSTRUMENTATION
260 std::shared_ptr<sycl::detail::event_impl> Self) {
264 SubmittedQueue->throw_asynchronous();
268 std::weak_ptr<queue_impl> EmptyPtr;
270 if (!EmptyPtr.owner_before(
MQueue) && !
MQueue.owner_before(EmptyPtr)) {
272 "Profiling information is unavailable as the event "
273 "has no associated queue.");
278 "Profiling information is unavailable as the queue associated with "
279 "the event does not have the 'enable_profiling' property.");
283 "Profiling information is unavailable for events "
284 "returned by a graph submission.");
290 event_impl::get_profiling_info<info::event_profiling::command_submit>() {
291 checkProfilingPreconditions();
297 event_impl::get_profiling_info<info::event_profiling::command_start>() {
298 checkProfilingPreconditions();
302 get_event_profiling_info<info::event_profiling::command_start>(
303 this->getHandleRef(), this->
getPlugin());
304 if (!MFallbackProfiling) {
307 auto DeviceBaseTime =
308 get_event_profiling_info<info::event_profiling::command_submit>(
309 this->getHandleRef(), this->
getPlugin());
310 return MHostBaseTime - DeviceBaseTime + StartTime;
315 if (!MHostProfilingInfo)
318 "Profiling info is not available. " +
320 return MHostProfilingInfo->getStartTime();
324 uint64_t event_impl::get_profiling_info<info::event_profiling::command_end>() {
325 checkProfilingPreconditions();
329 get_event_profiling_info<info::event_profiling::command_end>(
330 this->getHandleRef(), this->
getPlugin());
331 if (!MFallbackProfiling) {
334 auto DeviceBaseTime =
335 get_event_profiling_info<info::event_profiling::command_submit>(
336 this->getHandleRef(), this->
getPlugin());
337 return MHostBaseTime - DeviceBaseTime + EndTime;
342 if (!MHostProfilingInfo)
345 "Profiling info is not available. " +
347 return MHostProfilingInfo->getEndTime();
350 template <> uint32_t event_impl::get_info<info::event::reference_count>() {
351 if (!MHostEvent && MEvent) {
352 return get_event_info<info::event::reference_count>(this->getHandleRef(),
360 event_impl::get_info<info::event::command_execution_status>() {
361 if (MState == HES_Discarded)
367 return get_event_info<info::event::command_execution_status>(
368 this->getHandleRef(), this->
getPlugin());
371 return sycl::info::event_command_status::submitted;
374 return MHostEvent && MState.load() != HES_Complete
375 ? sycl::info::event_command_status::submitted
389 auto TempContext =
MContext.get()->getHandleRef();
403 "get_wait_list() cannot be used for a discarded event.");
405 std::lock_guard<std::mutex> Lock(
MMutex);
407 std::vector<EventImplPtr> Result;
430 if (Queue == UserQueue)
445 std::lock_guard<std::mutex> Lock(
MMutex);
451 std::lock_guard<std::mutex> Lock(
MMutex);
453 Event->cleanupDependencyEvents();
456 Event->cleanupDependencyEvents();
466 MSubmitTime = Queue->getDeviceImplPtr()->getCurrentDeviceTime();
470 std::string(
"Unable to get command group submission time: ") +
492 return get_info<info::event::command_execution_status>() ==