Skip to content

[SYCL] Profile host events only if the submitted queue has profiling enabled #18982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,9 @@ event_impl::event_impl(queue_impl &Queue, private_tag)
}

event_impl::event_impl(HostEventState State, private_tag) : MState(State) {
switch (State) {
case HES_Discarded:
case HES_Complete: {
MIsHostEvent = true;
if (State == HES_Discarded || State == HES_Complete)
MIsFlushed = true;
MIsHostEvent = true;
break;
}
case HES_NotComplete: {
MIsProfilingEnabled = true;
MHostProfilingInfo.reset(new HostProfilingInfo());
if (!MHostProfilingInfo)
throw sycl::exception(
sycl::make_error_code(sycl::errc::runtime),
"Out of host memory " +
codeToString(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
}
}
}

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

void event_impl::setSubmittedQueue(std::weak_ptr<queue_impl> SubmittedQueue) {
MSubmittedQueue = std::move(SubmittedQueue);
if (MHostProfilingInfo) {
if (isHost()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early returns for both ifs would help readability here.

if (auto QueuePtr = MSubmittedQueue.lock()) {
// Enable profiling for host events only if the queue where host task was
// submitted has profiling enabled.
MIsProfilingEnabled = QueuePtr->MIsProfilingEnabled;
if (!MIsProfilingEnabled || MState == HES_Discarded ||
MState == HES_Complete)
return;
Comment on lines +208 to +210
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks sketchy. Can we assert that event is incomplete?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what would "profiling enabled" even mean for the discarded events?


MHostProfilingInfo.reset(new HostProfilingInfo());
if (!MHostProfilingInfo)
throw sycl::exception(
sycl::make_error_code(sycl::errc::runtime),
"Out of host memory " +
codeToString(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));

device_impl &Device = QueuePtr->getDeviceImpl();
MHostProfilingInfo->setDevice(&Device);
}
Expand Down
30 changes: 30 additions & 0 deletions sycl/unittests/queue/GetProfilingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,33 @@ TEST(GetProfilingInfo, check_command_submission_time_with_host_accessor) {

EXPECT_TRUE(DeviceTimerCalled);
}

// Check that query fails for host task if queue doesn't have profiling
// enabled.
TEST(GetProfilingInfo, check_host_task_profiling_info) {
using namespace sycl;
queue Queue;
event E = Queue.submit([&](handler &cgh) { cgh.host_task([]() {}); });

auto expect_profiling_exception = [&](auto profiling_query) {
try {
std::ignore = profiling_query();
FAIL();
} catch (sycl::exception const &e) {
EXPECT_STREQ(
e.what(),
"Profiling information is unavailable as the queue associated "
"with the event does not have the 'enable_profiling' property.");
}
};

expect_profiling_exception([&] {
return E.get_profiling_info<info::event_profiling::command_submit>();
});
expect_profiling_exception([&] {
return E.get_profiling_info<info::event_profiling::command_start>();
});
expect_profiling_exception([&] {
return E.get_profiling_info<info::event_profiling::command_end>();
});
}
Loading