Skip to content

Commit de7cf82

Browse files
committed
[SYCL] Track profiling info for host events only if queue has profiling enabled
Currently profiling for host tasks is tracked no matter what. Track it only if the queue, where host task is submitted, has profiling enabled.
1 parent acbabef commit de7cf82

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,9 @@ event_impl::event_impl(queue_impl &Queue, private_tag)
183183
}
184184

185185
event_impl::event_impl(HostEventState State, private_tag) : MState(State) {
186-
switch (State) {
187-
case HES_Discarded:
188-
case HES_Complete: {
186+
MIsHostEvent = true;
187+
if (State == HES_Discarded || State == HES_Complete)
189188
MIsFlushed = true;
190-
MIsHostEvent = true;
191-
break;
192-
}
193-
case HES_NotComplete: {
194-
MIsProfilingEnabled = true;
195-
MHostProfilingInfo.reset(new HostProfilingInfo());
196-
if (!MHostProfilingInfo)
197-
throw sycl::exception(
198-
sycl::make_error_code(sycl::errc::runtime),
199-
"Out of host memory " +
200-
codeToString(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
201-
}
202-
}
203189
}
204190

205191
void event_impl::setQueue(queue_impl &Queue) {
@@ -214,8 +200,22 @@ void event_impl::setQueue(queue_impl &Queue) {
214200

215201
void event_impl::setSubmittedQueue(std::weak_ptr<queue_impl> SubmittedQueue) {
216202
MSubmittedQueue = std::move(SubmittedQueue);
217-
if (MHostProfilingInfo) {
203+
if (isHost()) {
218204
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+
219219
device_impl &Device = QueuePtr->getDeviceImpl();
220220
MHostProfilingInfo->setDevice(&Device);
221221
}

sycl/unittests/queue/GetProfilingInfo.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,33 @@ TEST(GetProfilingInfo, check_command_submission_time_with_host_accessor) {
345345

346346
EXPECT_TRUE(DeviceTimerCalled);
347347
}
348+
349+
// Check that query fails for host task if queue doesn't have profiling
350+
// enabled.
351+
TEST(GetProfilingInfo, check_host_task_profiling_info) {
352+
using namespace sycl;
353+
queue Queue;
354+
event E = Queue.submit([&](handler &cgh) { cgh.host_task([]() {}); });
355+
356+
auto expect_profiling_exception = [&](auto profiling_query) {
357+
try {
358+
std::ignore = profiling_query();
359+
FAIL();
360+
} catch (sycl::exception const &e) {
361+
EXPECT_STREQ(
362+
e.what(),
363+
"Profiling information is unavailable as the queue associated "
364+
"with the event does not have the 'enable_profiling' property.");
365+
}
366+
};
367+
368+
expect_profiling_exception([&] {
369+
return E.get_profiling_info<info::event_profiling::command_submit>();
370+
});
371+
expect_profiling_exception([&] {
372+
return E.get_profiling_info<info::event_profiling::command_start>();
373+
});
374+
expect_profiling_exception([&] {
375+
return E.get_profiling_info<info::event_profiling::command_end>();
376+
});
377+
}

0 commit comments

Comments
 (0)