diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
|---|---|---|
| committer | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
| commit | 38500d63e14ce340236840f60d356cdefb56a52c (patch) | |
| tree | 17edbec446ce9b50d2f215a483b83afb293a635d /libc/src/time/gpu | |
| parent | 1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff) | |
| parent | 27f30029741ecf023baece7b3dde1ff9011ffefc (diff) | |
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'libc/src/time/gpu')
| -rw-r--r-- | libc/src/time/gpu/CMakeLists.txt | 36 | ||||
| -rw-r--r-- | libc/src/time/gpu/clock.cpp | 2 | ||||
| -rw-r--r-- | libc/src/time/gpu/clock_gettime.cpp | 19 | ||||
| -rw-r--r-- | libc/src/time/gpu/nanosleep.cpp | 4 | ||||
| -rw-r--r-- | libc/src/time/gpu/time_utils.cpp | 22 | ||||
| -rw-r--r-- | libc/src/time/gpu/time_utils.h | 43 | ||||
| -rw-r--r-- | libc/src/time/gpu/timespec_get.cpp | 1 |
7 files changed, 23 insertions, 104 deletions
diff --git a/libc/src/time/gpu/CMakeLists.txt b/libc/src/time/gpu/CMakeLists.txt index 8da5d3a22f5a..31a60595d68f 100644 --- a/libc/src/time/gpu/CMakeLists.txt +++ b/libc/src/time/gpu/CMakeLists.txt @@ -1,14 +1,3 @@ -add_object_library( - time_utils - SRCS - time_utils.cpp - HDRS - time_utils.h - DEPENDS - libc.hdr.types.clock_t - libc.hdr.time_macros -) - add_entrypoint_object( clock SRCS @@ -18,7 +7,8 @@ add_entrypoint_object( DEPENDS libc.include.time libc.src.__support.GPU.utils - .time_utils + libc.src.__support.time.clock_gettime + libc.src.__support.time.gpu.time_utils ) add_entrypoint_object( @@ -30,29 +20,31 @@ add_entrypoint_object( DEPENDS libc.include.time libc.src.__support.GPU.utils - .time_utils + libc.src.__support.time.gpu.time_utils ) add_entrypoint_object( - clock_gettime + timespec_get SRCS - clock_gettime.cpp + timespec_get.cpp HDRS - ../clock_gettime.h + ../timespec_get.h DEPENDS - libc.hdr.types.clockid_t + libc.hdr.time_macros libc.hdr.types.struct_timespec - .time_utils + libc.src.__support.time.gpu.time_utils ) add_entrypoint_object( - timespec_get + clock_gettime SRCS - timespec_get.cpp + clock_gettime.cpp HDRS - ../timespec_get.h + ../clock_gettime.h DEPENDS libc.hdr.time_macros + libc.hdr.types.clockid_t libc.hdr.types.struct_timespec - .time_utils + libc.src.__support.time.gpu.time_utils + libc.src.__support.time.clock_gettime ) diff --git a/libc/src/time/gpu/clock.cpp b/libc/src/time/gpu/clock.cpp index 4cdb1d505aed..add5b2725ef8 100644 --- a/libc/src/time/gpu/clock.cpp +++ b/libc/src/time/gpu/clock.cpp @@ -8,7 +8,7 @@ #include "src/time/clock.h" #include "src/__support/macros/config.h" -#include "src/time/gpu/time_utils.h" +#include "src/__support/time/gpu/time_utils.h" namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/time/gpu/clock_gettime.cpp b/libc/src/time/gpu/clock_gettime.cpp index de7899a2a17c..81547ef7f1ca 100644 --- a/libc/src/time/gpu/clock_gettime.cpp +++ b/libc/src/time/gpu/clock_gettime.cpp @@ -10,23 +10,16 @@ #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include "time_utils.h" +#include "src/__support/time/clock_gettime.h" +#include "src/__support/time/gpu/time_utils.h" namespace LIBC_NAMESPACE_DECL { -constexpr uint64_t TICKS_PER_SEC = 1000000000UL; - LLVM_LIBC_FUNCTION(int, clock_gettime, (clockid_t clockid, timespec *ts)) { - if (clockid != CLOCK_MONOTONIC || !ts) - return -1; - - uint64_t ns_per_tick = TICKS_PER_SEC / GPU_CLOCKS_PER_SEC; - uint64_t ticks = gpu::fixed_frequency_clock(); - - ts->tv_nsec = (ticks * ns_per_tick) % TICKS_PER_SEC; - ts->tv_sec = (ticks * ns_per_tick) / TICKS_PER_SEC; - - return 0; + ErrorOr<int> result = internal::clock_gettime(clockid, ts); + if (result) + return result.value(); + return result.error(); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/gpu/nanosleep.cpp b/libc/src/time/gpu/nanosleep.cpp index 3f4a609dd40e..a92f660f225c 100644 --- a/libc/src/time/gpu/nanosleep.cpp +++ b/libc/src/time/gpu/nanosleep.cpp @@ -9,12 +9,10 @@ #include "src/time/nanosleep.h" #include "src/__support/macros/config.h" -#include "time_utils.h" +#include "src/__support/time/gpu/time_utils.h" namespace LIBC_NAMESPACE_DECL { -constexpr uint64_t TICKS_PER_SEC = 1000000000UL; - LLVM_LIBC_FUNCTION(int, nanosleep, (const struct timespec *req, struct timespec *rem)) { if (!GPU_CLOCKS_PER_SEC || !req) diff --git a/libc/src/time/gpu/time_utils.cpp b/libc/src/time/gpu/time_utils.cpp deleted file mode 100644 index 38e09f600f36..000000000000 --- a/libc/src/time/gpu/time_utils.cpp +++ /dev/null @@ -1,22 +0,0 @@ -//===-- Generic utilities for GPU timing ----------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "time_utils.h" -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -#if defined(LIBC_TARGET_ARCH_IS_AMDGPU) -// This is expected to be initialized by the runtime if the default value is -// insufficient. -// TODO: Once we have another use-case for this we should put it in a common -// device environment struct. -gpu::Constant<uint64_t> __llvm_libc_clock_freq = clock_freq; -#endif - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/time/gpu/time_utils.h b/libc/src/time/gpu/time_utils.h deleted file mode 100644 index c631a38d91ba..000000000000 --- a/libc/src/time/gpu/time_utils.h +++ /dev/null @@ -1,43 +0,0 @@ -//===-- Generic utilities for GPU timing ----------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H -#define LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H - -#include "hdr/time_macros.h" -#include "hdr/types/clock_t.h" -#include "src/__support/GPU/utils.h" -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -#if defined(LIBC_TARGET_ARCH_IS_AMDGPU) -// AMDGPU does not have a single set frequency. Different architectures and -// cards can have different values. The actualy frequency needs to be read from -// the kernel driver and will be between 25 MHz and 100 MHz on most cards. All -// cards following the GFX9 ISAs use a 100 MHz clock so we will default to that. -constexpr uint64_t clock_freq = 100000000UL; - -// We provide an externally visible symbol such that the runtime can set -// this to the correct value. -extern "C" { -[[gnu::visibility("protected")]] -extern gpu::Constant<uint64_t> __llvm_libc_clock_freq; -} -#define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq) - -#elif defined(LIBC_TARGET_ARCH_IS_NVPTX) -// NPVTX uses a single 1 GHz fixed frequency clock for all target architectures. -#define GPU_CLOCKS_PER_SEC static_cast<clock_t>(1000000000UL) -#else -#error "Unsupported target" -#endif - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H diff --git a/libc/src/time/gpu/timespec_get.cpp b/libc/src/time/gpu/timespec_get.cpp index f4ef328a8312..0dd128444aa8 100644 --- a/libc/src/time/gpu/timespec_get.cpp +++ b/libc/src/time/gpu/timespec_get.cpp @@ -10,6 +10,7 @@ #include "hdr/time_macros.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" +#include "src/__support/time/gpu/time_utils.h" namespace LIBC_NAMESPACE_DECL { |
