Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / time / gpu / time_utils.h
blob53548181e17e25cdc698d3edcd0ea24c33127881
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H
10 #define LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H
12 #include "src/__support/GPU/utils.h"
14 namespace LIBC_NAMESPACE {
16 #if defined(LIBC_TARGET_ARCH_IS_AMDGPU)
17 // AMDGPU does not have a single set frequency. Different architectures and
18 // cards can have vary values. Here we default to a few known values, but for
19 // complete support the frequency needs to be read from the kernel driver.
20 #if defined(__gfx1010__) || defined(__gfx1011__) || defined(__gfx1012__) || \
21 defined(__gfx1013__) || defined(__gfx1030__) || defined(__gfx1031__) || \
22 defined(__gfx1032__) || defined(__gfx1033__) || defined(__gfx1034__) || \
23 defined(__gfx1035__) || defined(__gfx1036__) || defined(__gfx1100__) || \
24 defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1103__) || \
25 defined(__gfx1150__) || defined(__gfx1151__)
26 // These architectures use a 100 MHz fixed frequency clock.
27 constexpr uint64_t clock_freq = 100000000;
28 #elif defined(__gfx900__) || defined(__gfx902__) || defined(__gfx904__) || \
29 defined(__gfx906__) || defined(__gfx908__) || defined(__gfx909__) || \
30 defined(__gfx90a__) || defined(__gfx90c__) || defined(__gfx940__)
31 // These architectures use a 25 MHz fixed frequency clock expect for Vega 10
32 // which is actually 27 Mhz. We default to 25 MHz in all cases anyway.
33 constexpr uint64_t clock_freq = 25000000;
34 #else
35 // The frequency for these architecture is unknown. We simply default to zero.
36 constexpr uint64_t clock_freq = 0;
37 #endif
39 // We provide an externally visible symbol such that the runtime can set this to
40 // the correct value. If it is not set we try to default to the known values.
41 extern "C" [[gnu::visibility("protected")]] uint64_t
42 [[clang::address_space(4)]] __llvm_libc_clock_freq;
43 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq)
45 #elif defined(LIBC_TARGET_ARCH_IS_NVPTX)
46 // NPVTX uses a single 1 GHz fixed frequency clock for all target architectures.
47 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(1000000000UL)
48 #else
49 #error "Unsupported target"
50 #endif
52 } // namespace LIBC_NAMESPACE
54 #endif // LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H