Skip to content

Change implementation of acl_hal_mmd_get_timestamp() to use std::chro… #41

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 3 additions & 17 deletions src/acl_hal_mmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <dirent.h>
#include <dlfcn.h>
#include <link.h>
#include <chrono>
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -2401,24 +2402,9 @@ cl_ulong acl_hal_mmd_get_timestamp() {

// Query the system timer, return a timer value in ns
cl_ulong acl_hal_mmd_get_timestamp() {
struct timespec a;
const cl_ulong NS_PER_S = 1000000000;
acl_assert_locked_or_sig();
// Must use the MONOTONIC clock because the REALTIME clock
// can go backwards due to adjustments by NTP for clock drift.
// The MONOTONIC clock provides a timestamp since some fixed point in
// the past, which might be system boot time or the start of the Unix
// epoch. This matches the Windows QueryPerformanceCounter semantics.
// The MONOTONIC clock is to be used for measuring time intervals, and
// fits the semantics of timestamps from the *device* perspective as defined
// in OpenCL for clGetEventProfilingInfo.
#ifdef CLOCK_MONOTONIC_RAW
clock_gettime(CLOCK_MONOTONIC_RAW, &a);
#else
clock_gettime(CLOCK_MONOTONIC, &a);
#endif

return (cl_ulong)(a.tv_nsec) + (cl_ulong)(a.tv_sec * NS_PER_S);
unsigned long nano_timestamp = std::chrono::steady_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
return (cl_ulong)nano_timestamp;
}
#endif

Expand Down