42#ifndef TPETRA_DETAILS_STATICVIEW_HPP
43#define TPETRA_DETAILS_STATICVIEW_HPP
45#include "TpetraCore_config.h"
47#include "Kokkos_DualView.hpp"
53template<
class MemorySpace>
54class 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
70class 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);
83class 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);
96class 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);
109#ifdef KOKKOS_ENABLE_HIP
111class StaticKokkosAllocation<Kokkos::Experimental::HIPSpace> {
113 StaticKokkosAllocation () =
delete;
114 ~StaticKokkosAllocation () =
delete;
115 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
116 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
117 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
118 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
120 static void* resize (Kokkos::Experimental::HIPSpace space,
const size_t size);
124class StaticKokkosAllocation<Kokkos::Experimental::HIPHostPinnedSpace> {
126 StaticKokkosAllocation () =
delete;
127 ~StaticKokkosAllocation () =
delete;
128 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
129 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
130 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
131 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
133 static void* resize (Kokkos::Experimental::HIPHostPinnedSpace space,
const size_t size);
138class StaticKokkosAllocation<Kokkos::HostSpace> {
140 StaticKokkosAllocation () =
delete;
141 ~StaticKokkosAllocation () =
delete;
142 StaticKokkosAllocation (
const StaticKokkosAllocation&) =
delete;
143 StaticKokkosAllocation& operator= (
const StaticKokkosAllocation&) =
delete;
144 StaticKokkosAllocation (StaticKokkosAllocation&&) =
delete;
145 StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) =
delete;
147 static void* resize (Kokkos::HostSpace space,
const size_t size);
150template<
class ValueType,
class MemorySpace>
152getStaticKokkosMemory (MemorySpace space,
153 const size_t num_entries,
154 const size_t value_size =
sizeof (ValueType))
156 void* ptr = StaticKokkosAllocation<MemorySpace>::resize
157 (space, num_entries * value_size);
158 return reinterpret_cast<ValueType*
> (ptr);
163template<
class ValueType,
class DeviceType>
164Kokkos::View<ValueType*, DeviceType>
165getStatic1dView (
const size_t size)
167 using Impl::getStaticKokkosMemory;
168 using mem_space =
typename DeviceType::memory_space;
169 using view_type = Kokkos::View<ValueType*, DeviceType>;
171 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
172 return view_type (ptr, size);
175template<
class ValueType,
class DeviceType>
176Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>
177getStatic2dView (
const size_t num_rows,
const size_t num_cols)
179 using Impl::getStaticKokkosMemory;
180 using mem_space =
typename DeviceType::memory_space;
181 using view_type = Kokkos::View<ValueType**, Kokkos::LayoutLeft, DeviceType>;
183 const size_t size = num_rows * num_cols;
184 ValueType* ptr = getStaticKokkosMemory<ValueType> (mem_space (), size);
185 return view_type (ptr, num_rows, num_cols);
188template<
class ValueType,
class DeviceType>
189Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>
190getStatic2dDualView (
const size_t num_rows,
const size_t num_cols)
192 using dual_view_type =
193 Kokkos::DualView<ValueType**, Kokkos::LayoutLeft, DeviceType>;
194 using d_view_type =
typename dual_view_type::t_dev;
195 using h_view_type =
typename dual_view_type::t_host;
197 auto d_view = getStatic2dView<ValueType, DeviceType> (num_rows, num_cols);
202 if (std::is_same<
typename d_view_type::memory_space,
203 typename h_view_type::memory_space>::value) {
204 h_view = Kokkos::create_mirror_view (d_view);
207 h_view = getStatic2dView<ValueType,
208 typename h_view_type::device_type> (num_rows, num_cols);
211 return dual_view_type (d_view, h_view);
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.