1 //===-- Generic utilities for GPU timing ----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H
10 #define LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H
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"
17 namespace LIBC_NAMESPACE_DECL
{
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;
26 // We provide an externally visible symbol such that the runtime can set
27 // this to the correct value.
29 [[gnu::visibility("protected")]]
30 extern gpu::Constant
<uint64_t> __llvm_libc_clock_freq
;
32 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq)
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)
38 #error "Unsupported target"
41 } // namespace LIBC_NAMESPACE_DECL
43 #endif // LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H