Skip to content

Commit

Permalink
[libcxx] Set _LIBCPP_HAS_CLOCK_GETTIME for GPU targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Jul 16, 2024
1 parent 8393ea5 commit 678eb3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion libcxx/src/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

// OpenBSD does not have a fully conformant suite of POSIX timers, but
// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \
defined(__NVPTX__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
# define _LIBCPP_HAS_CLOCK_GETTIME
#endif

Expand Down
3 changes: 2 additions & 1 deletion libcxx/src/filesystem/filesystem_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# include <sys/time.h> // for gettimeofday and timeval
#endif

#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__NVPTX__) || defined(__AMDGPU__) || \
(defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
# define _LIBCPP_HAS_CLOCK_GETTIME
#endif

Expand Down

0 comments on commit 678eb3b

Please sign in to comment.