Skip to content

Commit 0cdaa2a

Browse files
committed
[libcxx] Set _LIBCPP_HAS_CLOCK_GETTIME for GPU targets
Summary: I am attempting to get the GPU to build and support libc++. One issue I've encountered is that it will look for `timeval` unless this macro is set. We can support `CLOCK_MONOTONIC` on the GPU fairly easily as we have access to a fixed-frequency clock via `__builtin_readsteadycounter` intrinsics with a known frequency. This also requires `CLOCK_REALTIME` which we can't support, but provide anyway from the GPU `libc` to make this happy. It will return an error so at least that will be obvious. I may need a more consistent configuration for this in the future, maybe I should put a common macro in a different common header that's just `__GPU__`? I don't know where I would put such a thing however.
1 parent 47ff8f0 commit 0cdaa2a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libcxx/src/chrono.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
# include <sys/time.h> // for gettimeofday and timeval
3232
#endif
3333

34-
// OpenBSD does not have a fully conformant suite of POSIX timers, but
34+
// OpenBSD and GPU do not have a fully conformant suite of POSIX timers, but
3535
// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
36-
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
36+
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \
37+
defined(__NVPTX__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
3738
# define _LIBCPP_HAS_CLOCK_GETTIME
3839
#endif
3940

libcxx/src/filesystem/filesystem_clock.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
# include <sys/time.h> // for gettimeofday and timeval
3030
#endif
3131

32-
#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
32+
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__AMDGPU__) || defined(__NVPTX__) || \
33+
(defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
3334
# define _LIBCPP_HAS_CLOCK_GETTIME
3435
#endif
3536

0 commit comments

Comments
 (0)