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.
33template <typename... Args>
34KOKKOS_FORCEINLINE_FUNCTION void printf(const char* format, Args... args) {
35#ifdef KOKKOS_ENABLE_SYCL
36 // Some compilers warn if "args" is empty and format is not a string literal
37 if constexpr (sizeof...(Args) == 0)
38 sycl::ext::oneapi::experimental::printf("%s", format);
39 else
40 sycl::ext::oneapi::experimental::printf(format, args...);
41#else
42 if constexpr (sizeof...(Args) == 0)
43 ::printf("%s", format);
44 else
45 ::printf(format, args...);
46#endif
47}
48
49} // namespace Kokkos
50
51#endif /* #ifndef KOKKOS_PRINTF_HPP */