forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Kokkos::printf (kokkos#6083)
* Implement Kokkos::printf * Use Kokkos::printf * Update core/unit_test/TestPrintf.hpp Co-authored-by: Damien L-G <dalg24+github@gmail.com> --------- Co-authored-by: Damien L-G <dalg24+github@gmail.com>
- Loading branch information
1 parent
53a5aef
commit 597bc36
Showing
17 changed files
with
208 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#ifndef KOKKOS_IMPL_PRINTF_HPP | ||
#define KOKKOS_IMPL_PRINTF_HPP | ||
|
||
#include <Kokkos_Macros.hpp> | ||
|
||
#ifdef KOKKOS_ENABLE_SYCL | ||
#include <sycl/sycl.hpp> | ||
#else | ||
#include <cstdio> | ||
#endif | ||
|
||
namespace Kokkos { | ||
|
||
// In contrast to std::printf, return void to get a consistent behavior across | ||
// backends. The GPU backends always return 1 and NVHPC only compiles if we | ||
// don't ask for the return value. | ||
template <typename... Args> | ||
KOKKOS_FUNCTION void printf(const char* format, Args... args) { | ||
#ifdef KOKKOS_ENABLE_SYCL | ||
// Some compilers warn if "args" is empty and format is not a string literal | ||
if constexpr (sizeof...(Args) == 0) | ||
sycl::ext::oneapi::experimental::printf("%s", format); | ||
else | ||
sycl::ext::oneapi::experimental::printf(format, args...); | ||
#else | ||
if constexpr (sizeof...(Args) == 0) | ||
::printf("%s", format); | ||
else | ||
::printf(format, args...); | ||
#endif | ||
} | ||
|
||
} // namespace Kokkos | ||
|
||
#endif /* #ifndef KOKKOS_IMPL_PRINTF_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
template <class ExecutionSpace> | ||
void test_kokkos_printf() { | ||
::testing::internal::CaptureStdout(); | ||
Kokkos::parallel_for( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, 1), | ||
KOKKOS_LAMBDA(int) { Kokkos::printf("Print an integer: %d", 2); }); | ||
Kokkos::fence(); | ||
auto const captured = ::testing::internal::GetCapturedStdout(); | ||
std::string expected_string("Print an integer: 2"); | ||
ASSERT_EQ(captured, expected_string); | ||
} | ||
|
||
TEST(TEST_CATEGORY, kokkos_printf) { test_kokkos_printf<TEST_EXECSPACE>(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.