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

source code of libc/src/time/gpu/time_utils.h