• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace LIBC_NAMESPACE {
16 
17 #if defined(LIBC_TARGET_ARCH_IS_AMDGPU)
18 // AMDGPU does not have a single set frequency. Different architectures and
19 // cards can have different values. The actualy frequency needs to be read from
20 // the kernel driver and will be between 25 MHz and 100 MHz on most cards. All
21 // cards following the GFX9 ISAs use a 100 MHz clock so we will default to that.
22 constexpr uint64_t clock_freq = 100000000UL;
23 
24 // We provide an externally visible symbol such that the runtime can set
25 // this to the correct value.
26 extern "C" {
27 [[gnu::visibility("protected")]]
28 extern gpu::Constant<uint64_t> __llvm_libc_clock_freq;
29 }
30 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq)
31 
32 #elif defined(LIBC_TARGET_ARCH_IS_NVPTX)
33 // NPVTX uses a single 1 GHz fixed frequency clock for all target architectures.
34 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(1000000000UL)
35 #else
36 #error "Unsupported target"
37 #endif
38 
39 } // namespace LIBC_NAMESPACE
40 
41 #endif // LLVM_LIBC_SRC_TIME_GPU_TIME_UTILS_H
42