Skip to content

Commit

Permalink
[SYCL] Don't spoil MDeviceHostBaseTime during isGetDeviceAndHostTimer…
Browse files Browse the repository at this point in the history
…Supported (intel#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`.
  • Loading branch information
againull authored Aug 21, 2023
1 parent a08431c commit b9c8516
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,10 @@ uint64_t device_impl::getCurrentDeviceTime() {

bool device_impl::isGetDeviceAndHostTimerSupported() {
const auto &Plugin = getPlugin();
uint64_t DeviceTime = 0, HostTime = 0;
auto Result =
Plugin->call_nocheck<detail::PiApiKind::piGetDeviceAndHostTimer>(
MDevice, &MDeviceHostBaseTime.first, &MDeviceHostBaseTime.second);
MDevice, &DeviceTime, &HostTime);
return Result != PI_ERROR_INVALID_OPERATION;
}

Expand Down
34 changes: 34 additions & 0 deletions sycl/test-e2e/Basic/submit_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

// Check that device_impl::isGetDeviceAndHostTimerSupported() is not spoiling
// device_impl::MDeviceHostBaseTime values used for submit timestamp
// calculation.

#include <sycl/sycl.hpp>

using namespace sycl;

int main(void) {
sycl::queue queue(
sycl::property_list{sycl::property::queue::enable_profiling()});
sycl::event event = queue.submit([&](sycl::handler &cgh) {
cgh.parallel_for<class set_value>(sycl::range<1>{1024},
[=](sycl::id<1> idx) {});
});

// SYCL RT internally calls device_impl::isGetDeviceAndHostTimerSupported()
// to decide how to calculate "submit" timestamp - either using backend API
// call or using fallback implementation.
auto submit =
event.get_profiling_info<sycl::info::event_profiling::command_submit>();
auto start =
event.get_profiling_info<sycl::info::event_profiling::command_start>();
auto end =
event.get_profiling_info<sycl::info::event_profiling::command_end>();

if (!(submit <= start) || !(start <= end))
return -1;

return 0;
}

0 comments on commit b9c8516

Please sign in to comment.