Skip to content

Commit b9c8516

Browse files
authored
[SYCL] Don't spoil MDeviceHostBaseTime during isGetDeviceAndHostTimerSupported (#10909)
`MDeviceHostBaseTime` data member of `device_impl` is supposed to be properly updated/calculated using `getCurrentDeviceTime()`. Currently it is also used to check `piGetDeviceAndHostTimer` support in `isGetDeviceAndHostTimerSupported()` which results in wrong values stored in `MDeviceHostBaseTime` and wrong calculation of submit time. That's why use temp variables to check support of `piGetDeviceAndHostTimer` to avoid spoiling `MDeviceHostBaseTime`.
1 parent a08431c commit b9c8516

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,10 @@ uint64_t device_impl::getCurrentDeviceTime() {
630630

631631
bool device_impl::isGetDeviceAndHostTimerSupported() {
632632
const auto &Plugin = getPlugin();
633+
uint64_t DeviceTime = 0, HostTime = 0;
633634
auto Result =
634635
Plugin->call_nocheck<detail::PiApiKind::piGetDeviceAndHostTimer>(
635-
MDevice, &MDeviceHostBaseTime.first, &MDeviceHostBaseTime.second);
636+
MDevice, &DeviceTime, &HostTime);
636637
return Result != PI_ERROR_INVALID_OPERATION;
637638
}
638639

sycl/test-e2e/Basic/submit_time.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
// Check that device_impl::isGetDeviceAndHostTimerSupported() is not spoiling
5+
// device_impl::MDeviceHostBaseTime values used for submit timestamp
6+
// calculation.
7+
8+
#include <sycl/sycl.hpp>
9+
10+
using namespace sycl;
11+
12+
int main(void) {
13+
sycl::queue queue(
14+
sycl::property_list{sycl::property::queue::enable_profiling()});
15+
sycl::event event = queue.submit([&](sycl::handler &cgh) {
16+
cgh.parallel_for<class set_value>(sycl::range<1>{1024},
17+
[=](sycl::id<1> idx) {});
18+
});
19+
20+
// SYCL RT internally calls device_impl::isGetDeviceAndHostTimerSupported()
21+
// to decide how to calculate "submit" timestamp - either using backend API
22+
// call or using fallback implementation.
23+
auto submit =
24+
event.get_profiling_info<sycl::info::event_profiling::command_submit>();
25+
auto start =
26+
event.get_profiling_info<sycl::info::event_profiling::command_start>();
27+
auto end =
28+
event.get_profiling_info<sycl::info::event_profiling::command_end>();
29+
30+
if (!(submit <= start) || !(start <= end))
31+
return -1;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)