1 | //===-- Generic utilities for GPU timing ----------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H |
10 | #define LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H |
11 | |
12 | #include "hdr/time_macros.h" |
13 | #include "hdr/types/clock_t.h" |
14 | #include "src/__support/GPU/utils.h" |
15 | #include "src/__support/macros/config.h" |
16 | |
17 | namespace LIBC_NAMESPACE_DECL { |
18 | |
19 | #if defined(LIBC_TARGET_ARCH_IS_AMDGPU) |
20 | // AMDGPU does not have a single set frequency. Different architectures and |
21 | // cards can have different values. The actualy frequency needs to be read from |
22 | // the kernel driver and will be between 25 MHz and 100 MHz on most cards. All |
23 | // cards following the GFX9 ISAs use a 100 MHz clock so we will default to that. |
24 | constexpr uint64_t clock_freq = 100000000UL; |
25 | |
26 | // We provide an externally visible symbol such that the runtime can set |
27 | // this to the correct value. |
28 | extern "C" { |
29 | [[gnu::visibility("protected" )]] |
30 | extern gpu::Constant<uint64_t> __llvm_libc_clock_freq; |
31 | } |
32 | #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq) |
33 | |
34 | #elif defined(LIBC_TARGET_ARCH_IS_NVPTX) |
35 | // NPVTX uses a single 1 GHz fixed frequency clock for all target architectures. |
36 | #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(1000000000UL) |
37 | #else |
38 | #error "Unsupported target" |
39 | #endif |
40 | |
41 | constexpr uint64_t TICKS_PER_SEC = 1000000000UL; |
42 | |
43 | } // namespace LIBC_NAMESPACE_DECL |
44 | |
45 | #endif // LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H |
46 | |