Skip to content

Commit 51e8d95

Browse files
authored
[SYCL][host_task] Align host_task event submission clock with start/end clock (#18377)
The submission time for host_task events was previously obtained using `std::chrono::steady_clock`, while the command start and end times were derived from `high_resolution_clock`. This discrepancy in clock epochs led to meaningless duration calculations when users used submission time as a reference. This update standardizes the clock source by switching the submission time to use `high_resolution_clock`, ensuring consistent and meaningful timing results for host_task events. Note: `steady_clock` is not related to wall clock. See https://en.cppreference.com/w/cpp/chrono/steady_clock
1 parent 495f397 commit 51e8d95

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

sycl/source/detail/event_impl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ void event_impl::setSubmissionTime() {
581581
} else {
582582
// Returning host time
583583
using namespace std::chrono;
584-
MSubmitTime =
585-
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
586-
.count();
584+
MSubmitTime = duration_cast<nanoseconds>(
585+
high_resolution_clock::now().time_since_epoch())
586+
.count();
587587
}
588588
}
589589

sycl/test-e2e/Basic/profile_host_task.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <sycl/properties/all_properties.hpp>
88

99
int main() {
10+
const uint64_t timeout =
11+
60ul * 1e9; // 60 second, large enough for executing an empty host_task
1012
sycl::queue q{{sycl::property::queue::enable_profiling()}};
1113

1214
auto e = q.submit([&](sycl::handler &cgh) { cgh.host_task([=]() {}); });
@@ -29,10 +31,22 @@ int main() {
2931
return EXIT_FAILURE;
3032
}
3133

34+
if (start > submitted + timeout) {
35+
std::cerr << "Invalid latency between command_submit and command_start: "
36+
<< (start - submitted) << " ns" << std::endl;
37+
return EXIT_FAILURE;
38+
}
39+
3240
if (end < start) {
3341
std::cerr << "Invalid command_end time" << std::endl;
3442
return EXIT_FAILURE;
3543
}
3644

45+
if (end > start + timeout) {
46+
std::cerr << "Invalid latency between command_start and command_end: "
47+
<< (end - start) << " ns" << std::endl;
48+
return EXIT_FAILURE;
49+
}
50+
3751
return EXIT_SUCCESS;
3852
}

0 commit comments

Comments
 (0)