42 #ifndef TPETRA_DETAILS_STATICVIEW_HPP
43 #define TPETRA_DETAILS_STATICVIEW_HPP
45 #include "TpetraCore_config.h"
47 #include "Kokkos_DualView.hpp"
53 template<
class MemorySpace>
54 class StaticKokkosAllocation {
56 StaticKokkosAllocation () =
delete;
57 ~StaticKokkosAllocation () =
delete;
58 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
59 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
60 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
61 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
65 static void* resize (MemorySpace space,
const size_t size);
68 #ifdef KOKKOS_ENABLE_CUDA
70 class StaticKokkosAllocation<Kokkos::CudaSpace> {
72 StaticKokkosAllocation () =
delete;
73 ~StaticKokkosAllocation () =
delete;
74 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
75 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
76 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
77 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
79 static void* resize (Kokkos::CudaSpace space,
const size_t size);
83 class StaticKokkosAllocation<Kokkos::CudaUVMSpace> {
85 StaticKokkosAllocation () =
delete;
86 ~StaticKokkosAllocation () =
delete;
87 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
88 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
89 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
90 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
92 static void* resize (Kokkos::CudaUVMSpace space,
const size_t size);
96 class StaticKokkosAllocation<Kokkos::CudaHostPinnedSpace> {
98 StaticKokkosAllocation () =
delete;
99 ~StaticKokkosAllocation () =
delete;
100 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
101 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
102 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
103 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
105 static void* resize (Kokkos::CudaHostPinnedSpace space,
const size_t size);
107 #endif // KOKKOS_ENABLE_CUDA
110 class StaticKokkosAllocation<Kokkos::HostSpace> {
112 StaticKokkosAllocation () =
delete;
113 ~StaticKokkosAllocation () =
delete;
114 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
115 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
116 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
117 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
119 static void* resize (Kokkos::HostSpace space,
const size_t size);
122 template<
class ValueType,
class MemorySpace>
124 getStaticKokkosMemory (MemorySpace space,
125 const size_t num_entries,
126 const size_t value_size =
sizeof (ValueType))
128 void* ptr = StaticKokkosAllocation<MemorySpace>::resize
129 (space, num_entries * value_size);
130 return reinterpret_cast<ValueType*
> (ptr);
135 template<
class ValueType,
class DeviceType>
136 Kokkos::View<ValueType*, DeviceType>
137 getStatic1dView (
const size_t size)
139 using Impl::getStaticKokkosMemory;
140 using mem_space =
typename DeviceType::memory_space;
141 using view_type = Kokkos::View<ValueType*, DeviceType>;
143 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
144 return view_type (ptr, size);
147 template<
class ValueType,
class DeviceType>
148 Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>
149 getStatic2dView (
const size_t num_rows,
const size_t num_cols)
151 using Impl::getStaticKokkosMemory;
152 using mem_space =
typename DeviceType::memory_space;
153 using view_type = Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>;
155 const size_t size = num_rows * num_cols;
156 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
157 return view_type (ptr, num_rows, num_cols);
160 template<
class ValueType,
class DeviceType>
161 Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>
162 getStatic2dDualView (
const size_t num_rows,
const size_t num_cols)
164 using dual_view_type =
165 Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>;
166 using d_view_type =
typename dual_view_type::t_dev;
167 using h_view_type =
typename dual_view_type::t_host;
169 auto d_view = getStatic2dView<ValueType, DeviceType> (num_rows, num_cols);
174 if (std::is_same<
typename d_view_type::memory_space,
175 typename h_view_type::memory_space>::value) {
176 h_view = Kokkos::create_mirror_view (d_view);
179 h_view = getStatic2dView<ValueType,
180 typename h_view_type::device_type> (num_rows, num_cols);
183 return dual_view_type (d_view, h_view);
190 #endif // TPETRA_DETAILS_STATICVIEW_HPP