10 #ifndef TPETRA_DETAILS_STATICVIEW_HPP
11 #define TPETRA_DETAILS_STATICVIEW_HPP
13 #include "TpetraCore_config.h"
15 #include "Kokkos_DualView.hpp"
21 template<
class MemorySpace>
22 class StaticKokkosAllocation {
24 StaticKokkosAllocation () =
delete;
25 ~StaticKokkosAllocation () =
delete;
26 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
27 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
28 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
29 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
33 static void* resize (MemorySpace space,
const size_t size);
36 #ifdef KOKKOS_ENABLE_CUDA
38 class StaticKokkosAllocation<Kokkos::CudaSpace> {
40 StaticKokkosAllocation () =
delete;
41 ~StaticKokkosAllocation () =
delete;
42 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
43 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
44 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
45 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
47 static void* resize (Kokkos::CudaSpace space,
const size_t size);
51 class StaticKokkosAllocation<Kokkos::CudaUVMSpace> {
53 StaticKokkosAllocation () =
delete;
54 ~StaticKokkosAllocation () =
delete;
55 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
56 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
57 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
58 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
60 static void* resize (Kokkos::CudaUVMSpace space,
const size_t size);
64 class StaticKokkosAllocation<Kokkos::CudaHostPinnedSpace> {
66 StaticKokkosAllocation () =
delete;
67 ~StaticKokkosAllocation () =
delete;
68 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
69 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
70 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
71 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
73 static void* resize (Kokkos::CudaHostPinnedSpace space,
const size_t size);
75 #endif // KOKKOS_ENABLE_CUDA
77 #ifdef KOKKOS_ENABLE_HIP
79 class StaticKokkosAllocation<Kokkos::HIPSpace> {
81 StaticKokkosAllocation () =
delete;
82 ~StaticKokkosAllocation () =
delete;
83 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
84 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
85 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
86 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
88 static void* resize (Kokkos::HIPSpace space,
const size_t size);
92 class StaticKokkosAllocation<Kokkos::HIPHostPinnedSpace> {
94 StaticKokkosAllocation () =
delete;
95 ~StaticKokkosAllocation () =
delete;
96 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
97 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
98 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
99 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
101 static void* resize (Kokkos::HIPHostPinnedSpace space,
const size_t size);
103 #endif // KOKKOS_ENABLE_HIP
106 class StaticKokkosAllocation<Kokkos::HostSpace> {
108 StaticKokkosAllocation () =
delete;
109 ~StaticKokkosAllocation () =
delete;
110 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
111 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
112 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
113 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
115 static void* resize (Kokkos::HostSpace space,
const size_t size);
118 template<
class ValueType,
class MemorySpace>
120 getStaticKokkosMemory (MemorySpace space,
121 const size_t num_entries,
122 const size_t value_size =
sizeof (ValueType))
124 void* ptr = StaticKokkosAllocation<MemorySpace>::resize
125 (space, num_entries * value_size);
126 return reinterpret_cast<ValueType*
> (ptr);
131 template<
class ValueType,
class DeviceType>
132 Kokkos::View<ValueType*, DeviceType>
133 getStatic1dView (
const size_t size)
135 using Impl::getStaticKokkosMemory;
136 using mem_space =
typename DeviceType::memory_space;
137 using view_type = Kokkos::View<ValueType*, DeviceType>;
139 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
140 return view_type (ptr, size);
143 template<
class ValueType,
class DeviceType>
144 Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>
145 getStatic2dView (
const size_t num_rows,
const size_t num_cols)
147 using Impl::getStaticKokkosMemory;
148 using mem_space =
typename DeviceType::memory_space;
149 using view_type = Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>;
151 const size_t size = num_rows * num_cols;
152 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
153 return view_type (ptr, num_rows, num_cols);
156 template<
class ValueType,
class DeviceType>
157 Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>
158 getStatic2dDualView (
const size_t num_rows,
const size_t num_cols)
160 using dual_view_type =
161 Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>;
162 using d_view_type =
typename dual_view_type::t_dev;
163 using h_view_type =
typename dual_view_type::t_host;
165 auto d_view = getStatic2dView<ValueType, DeviceType> (num_rows, num_cols);
170 if (std::is_same<
typename d_view_type::memory_space,
171 typename h_view_type::memory_space>::value) {
172 h_view = Kokkos::create_mirror_view (d_view);
175 h_view = getStatic2dView<ValueType,
176 typename h_view_type::device_type> (num_rows, num_cols);
179 return dual_view_type (d_view, h_view);
186 #endif // TPETRA_DETAILS_STATICVIEW_HPP