Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Kokkos_Printf.hpp
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
17#ifndef KOKKOS_PRINTF_HPP
18#define KOKKOS_PRINTF_HPP
19
20#include <Kokkos_Macros.hpp>
21
22#ifdef KOKKOS_ENABLE_SYCL
23#include <sycl/sycl.hpp>
24#else
25#include <cstdio>
26#endif
27
28namespace Kokkos {
29
30// In contrast to std::printf, return void to get a consistent behavior across
31// backends. The GPU backends always return 1 and NVHPC only compiles if we
32// don't ask for the return value.
33#if defined(KOKKOS_ENABLE_OPENMPTARGET) && defined(KOKKOS_ARCH_INTEL_GPU)
34using ::printf;
35#else
36template <typename... Args>
37KOKKOS_FORCEINLINE_FUNCTION void printf(const char* format, Args... args) {
38#ifdef KOKKOS_ENABLE_SYCL
39 // Some compilers warn if "args" is empty and format is not a string literal
40 if constexpr (sizeof...(Args) == 0)
41 sycl::ext::oneapi::experimental::printf("%s", format);
42 else
43 sycl::ext::oneapi::experimental::printf(format, args...);
44#else
45 if constexpr (sizeof...(Args) == 0)
46 ::printf("%s", format);
47 else
48 ::printf(format, args...);
49#endif
50}
51#endif
52
53} // namespace Kokkos
54
55#endif /* #ifndef KOKKOS_PRINTF_HPP */