kokkos-utils 0.0.2
 
Loading...
Searching...
No Matches
View.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_PRINTERS_VIEW_HPP
2#define KOKKOS_UTILS_PRINTERS_VIEW_HPP
3
4#include "Kokkos_View.hpp"
5
8
10{
11
13template <concepts::View ViewType>
14std::ostream& operator<<(std::ostream& out, const ViewType& view)
15{
17 const auto view_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, view);
18
19 std::ostringstream oss;
20 oss.copyfmt(out);
21
22 oss << "[";
23 if constexpr (ViewType::rank() == 0) {
24 oss << view_h();
25 } else
26 {
27 for (size_t idx = 0; idx < view_h.extent(0); ++idx)
28 {
29 if (idx > 0) oss << ", ";
30 if constexpr (ViewType::rank() == 1) {
31 oss << view_h(idx);
32 } else {
33 oss << view::slice<ViewType::rank()>(view_h, idx);
34 }
35 }
36 }
37 oss << "]";
38
39 return out << oss.str();
40}
41
42} // namespace Kokkos::utils::printers
43
44#endif // KOKKOS_UTILS_PRINTERS_VIEW_HPP
std::ostream & operator<<(std::ostream &out, const ViewType &view)
Print a Kokkos::View.
Definition View.hpp:14