Skip to content

Commit 731b967

Browse files
authored
[SYCL] Record submit time for shortcut operations (#18455)
We record submission time for commands submitted via handler, but this was missing for shortcut commands. Also this PR changes the values returned by `command_submit`, `command_start`, `command_end` for non-host events without UR event handle - such events may appear if command is nop, for example, USM operations for 0 bytes. Such scenario is not explicitly specified in SYCL spec. Before changes, we used to return 0 for all three quieries. But for consistency,I believe it makes sense to return the same recorded submit time for all three: `command_submit = command_start = command_end`. It seems more convenient from user's perspective, for example if user submits sequence set of commands and there is some nop command in the middle of sequence: `command1` `command2 (nop)` `command3` and user calculates wants to calculate differences between submission time (or start time) of `command2` and `command1`, then he will get negative value: `0 - submit_time_of_command2` (if we return `0`). And there can be more nop operations (if SYCL runtime optimizes out something), so if we return `0`, user always has to check if the returned timestamp is 0 or not before using it in any calculations. So returning non-zero submit time seems better.
1 parent 68bf5a0 commit 731b967

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() {
348348
return get_event_profiling_info<info::event_profiling::command_start>(
349349
Handle, this->getAdapter());
350350
}
351-
return 0;
351+
// If command is nop (for example, USM operations for 0 bytes) return
352+
// recorded submission time. If event is created using default constructor,
353+
// 0 will be returned.
354+
return MSubmitTime;
352355
}
353356
if (!MHostProfilingInfo)
354357
throw sycl::exception(
@@ -367,7 +370,10 @@ uint64_t event_impl::get_profiling_info<info::event_profiling::command_end>() {
367370
return get_event_profiling_info<info::event_profiling::command_end>(
368371
Handle, this->getAdapter());
369372
}
370-
return 0;
373+
// If command is nop (for example, USM operations for 0 bytes) return
374+
// recorded submission time. If event is created using default constructor,
375+
// 0 will be returned.
376+
return MSubmitTime;
371377
}
372378
if (!MHostProfilingInfo)
373379
throw sycl::exception(

sycl/source/detail/queue_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
486486
{
487487
NestedCallsTracker tracker;
488488
ur_event_handle_t UREvent = nullptr;
489+
EventImpl->setSubmissionTime();
489490
MemOpFunc(MemOpArgs..., getUrEvents(ExpandedDepEvents), &UREvent);
490491
EventImpl->setHandle(UREvent);
491492
EventImpl->setEnqueued();

sycl/test-e2e/Basic/submit_time.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
// Test fails on hip flakily, disable temprorarily.
99
// UNSUPPORTED: hip
1010

11+
#include <cassert>
12+
#include <iostream>
1113
#include <sycl/detail/core.hpp>
1214
#include <sycl/properties/all_properties.hpp>
1315
#include <sycl/usm.hpp>
1416

1517
int main(void) {
18+
constexpr size_t n = 16;
1619
sycl::queue q({sycl::property::queue::enable_profiling{}});
17-
int *data = sycl::malloc_host<int>(1024, q);
20+
int *data = sycl::malloc_host<int>(n, q);
21+
int *dest = sycl::malloc_host<int>(n, q);
1822

19-
for (int i = 0; i < 20; i++) {
23+
for (int i = 0; i < 5; i++) {
2024
auto event = q.submit([&](sycl::handler &cgh) {
2125
cgh.parallel_for<class KernelTime>(
22-
sycl::range<1>(1024), [=](sycl::id<1> idx) { data[idx] = idx; });
26+
sycl::range<1>(n), [=](sycl::id<1> idx) { data[idx] = idx; });
2327
});
2428

2529
event.wait();
@@ -30,8 +34,42 @@ int main(void) {
3034
auto end_time =
3135
event.get_profiling_info<sycl::info::event_profiling::command_end>();
3236

37+
// Print for debugging
38+
std::cout << "Kernel Event - Submit: " << submit_time
39+
<< ", Start: " << start_time << ", End: " << end_time
40+
<< std::endl;
41+
42+
assert(submit_time != 0 && "Submit time should not be zero");
3343
assert((submit_time <= start_time) && (start_time <= end_time));
3444
}
45+
46+
// All shortcut memory operations use queue_impl::submitMemOpHelper.
47+
// This test covers memcpy as a representative, extend if other operations
48+
// diverge.
49+
for (int i = 0; i < 5; i++) {
50+
auto memcpy_event = q.memcpy(dest, data, sizeof(int) * n);
51+
memcpy_event.wait();
52+
53+
auto submit_time =
54+
memcpy_event
55+
.get_profiling_info<sycl::info::event_profiling::command_submit>();
56+
auto start_time =
57+
memcpy_event
58+
.get_profiling_info<sycl::info::event_profiling::command_start>();
59+
auto end_time =
60+
memcpy_event
61+
.get_profiling_info<sycl::info::event_profiling::command_end>();
62+
63+
// Print for debugging
64+
std::cout << "Memcpy Event - Submit: " << submit_time
65+
<< ", Start: " << start_time << ", End: " << end_time
66+
<< std::endl;
67+
68+
assert(submit_time != 0 && "Submit time should not be zero");
69+
assert((submit_time <= start_time) && (start_time <= end_time));
70+
}
71+
3572
sycl::free(data, q);
73+
sycl::free(dest, q);
3674
return 0;
3775
}

sycl/test-e2e/Regression/dummy_event_info.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ int main() {
1919
assert(e.get_info<info::event::command_execution_status>() ==
2020
info::event_command_status::complete);
2121
assert(e.get_info<info::event::reference_count>() == 0);
22-
assert(e.get_profiling_info<sycl::info::event_profiling::command_submit>() ==
23-
0);
24-
assert(e.get_profiling_info<sycl::info::event_profiling::command_start>() ==
25-
0);
26-
assert(e.get_profiling_info<sycl::info::event_profiling::command_end>() == 0);
22+
auto submit_time =
23+
e.get_profiling_info<sycl::info::event_profiling::command_submit>();
24+
auto start_time =
25+
e.get_profiling_info<sycl::info::event_profiling::command_start>();
26+
auto end_time =
27+
e.get_profiling_info<sycl::info::event_profiling::command_end>();
28+
29+
assert(submit_time == start_time);
30+
assert(start_time == end_time);
2731
}

0 commit comments

Comments
 (0)