Skip to content

Commit 61cadcf

Browse files
committed
Address review
1 parent de7cf82 commit 61cadcf

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,28 @@ void event_impl::setQueue(queue_impl &Queue) {
198198
MIsDefaultConstructed = false;
199199
}
200200

201+
void event_impl::initHostProfilingInfo() {
202+
assert(isHost() && "This must be a host event");
203+
assert(MState == HES_NotComplete &&
204+
"Host event must be incomplete to initialize profiling info");
205+
206+
std::shared_ptr<queue_impl> QueuePtr = MSubmittedQueue.lock();
207+
assert(QueuePtr && "Queue must be valid to initialize host profiling info");
208+
assert(QueuePtr->MIsProfilingEnabled && "Queue must have profiling enabled");
209+
210+
MIsProfilingEnabled = true;
211+
MHostProfilingInfo.reset(new HostProfilingInfo());
212+
if (!MHostProfilingInfo)
213+
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
214+
"Out of host memory " +
215+
codeToString(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
216+
217+
device_impl &Device = QueuePtr->getDeviceImpl();
218+
MHostProfilingInfo->setDevice(&Device);
219+
}
220+
201221
void event_impl::setSubmittedQueue(std::weak_ptr<queue_impl> SubmittedQueue) {
202222
MSubmittedQueue = std::move(SubmittedQueue);
203-
if (isHost()) {
204-
if (auto QueuePtr = MSubmittedQueue.lock()) {
205-
// Enable profiling for host events only if the queue where host task was
206-
// submitted has profiling enabled.
207-
MIsProfilingEnabled = QueuePtr->MIsProfilingEnabled;
208-
if (!MIsProfilingEnabled || MState == HES_Discarded ||
209-
MState == HES_Complete)
210-
return;
211-
212-
MHostProfilingInfo.reset(new HostProfilingInfo());
213-
if (!MHostProfilingInfo)
214-
throw sycl::exception(
215-
sycl::make_error_code(sycl::errc::runtime),
216-
"Out of host memory " +
217-
codeToString(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
218-
219-
device_impl &Device = QueuePtr->getDeviceImpl();
220-
MHostProfilingInfo->setDevice(&Device);
221-
}
222-
}
223223
}
224224

225225
void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,

sycl/source/detail/event_impl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ class event_impl : public std::enable_shared_from_this<event_impl> {
379379
return MEvent && MQueue.expired() && !MIsEnqueued && !MCommand;
380380
}
381381

382+
// Initializes the host profiling info for the event.
383+
void initHostProfilingInfo();
384+
382385
protected:
383386
// When instrumentation is enabled emits trace event for event wait begin and
384387
// returns the telemetry event generated for the wait

sycl/source/detail/scheduler/commands.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,8 +1963,13 @@ ExecCGCommand::ExecCGCommand(
19631963
Dependencies),
19641964
MEventNeeded(EventNeeded), MCommandGroup(std::move(CommandGroup)) {
19651965
if (MCommandGroup->getType() == detail::CGType::CodeplayHostTask) {
1966-
MEvent->setSubmittedQueue(
1967-
static_cast<detail::CGHostTask *>(MCommandGroup.get())->MQueue);
1966+
const auto &SubmitQueue =
1967+
static_cast<detail::CGHostTask *>(MCommandGroup.get())->MQueue;
1968+
MEvent->setSubmittedQueue(SubmitQueue);
1969+
// Initialize host profiling info if the queue has profiling enabled.
1970+
if (SubmitQueue && SubmitQueue->MIsProfilingEnabled) {
1971+
MEvent->initHostProfilingInfo();
1972+
}
19681973
}
19691974
if (MCommandGroup->getType() == detail::CGType::ProfilingTag)
19701975
MEvent->markAsProfilingTagEvent();

0 commit comments

Comments
 (0)