42 #include "Tpetra_Details_StaticView.hpp"
54 constexpr
size_t minimum_initial_size =
sizeof (double) * 30 * 2;
60 #ifdef KOKKOS_ENABLE_CUDA
62 void* cuda_memory_ =
nullptr;
63 size_t cuda_memory_size_ = 0;
65 void finalize_cuda_memory ()
67 if (cuda_memory_ !=
nullptr) {
68 Kokkos::kokkos_free<Kokkos::CudaSpace> (cuda_memory_);
69 cuda_memory_ =
nullptr;
70 cuda_memory_size_ = 0;
74 void* cuda_uvm_memory_ =
nullptr;
75 size_t cuda_uvm_memory_size_ = 0;
77 void finalize_cuda_uvm_memory ()
79 if (cuda_uvm_memory_ !=
nullptr) {
80 Kokkos::kokkos_free<Kokkos::CudaUVMSpace> (cuda_uvm_memory_);
81 cuda_uvm_memory_ =
nullptr;
82 cuda_uvm_memory_size_ = 0;
86 void* cuda_host_pinned_memory_ =
nullptr;
87 size_t cuda_host_pinned_memory_size_ = 0;
89 void finalize_cuda_host_pinned_memory ()
91 if (cuda_host_pinned_memory_ !=
nullptr) {
92 Kokkos::kokkos_free<Kokkos::CudaHostPinnedSpace> (cuda_host_pinned_memory_);
93 cuda_host_pinned_memory_ =
nullptr;
94 cuda_host_pinned_memory_size_ = 0;
97 #endif // KOKKOS_ENABLE_CUDA
99 void* host_memory_ =
nullptr;
100 size_t host_memory_size_ = 0;
102 void finalize_host_memory ()
104 if (host_memory_ !=
nullptr) {
105 Kokkos::kokkos_free<Kokkos::HostSpace> (host_memory_);
106 host_memory_ =
nullptr;
107 host_memory_size_ = 0;
113 #ifdef KOKKOS_ENABLE_CUDA
116 StaticKokkosAllocation<Kokkos::CudaSpace>::
117 resize (Kokkos::CudaSpace ,
120 using memory_space = Kokkos::CudaSpace;
121 static bool created_finalize_hook =
false;
123 if (size > cuda_memory_size_) {
124 if (cuda_memory_ !=
nullptr) {
125 Kokkos::kokkos_free<memory_space> (cuda_memory_);
127 const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
128 cuda_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
129 cuda_memory_size_ = size;
131 if (! created_finalize_hook) {
132 Kokkos::push_finalize_hook (finalize_cuda_memory);
133 created_finalize_hook =
true;
140 StaticKokkosAllocation<Kokkos::CudaUVMSpace>::
141 resize (Kokkos::CudaUVMSpace ,
144 using memory_space = Kokkos::CudaUVMSpace;
145 static bool created_finalize_hook =
false;
147 const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
148 if (req_size > cuda_uvm_memory_size_) {
149 if (cuda_uvm_memory_ !=
nullptr) {
150 Kokkos::kokkos_free<memory_space> (cuda_uvm_memory_);
152 cuda_uvm_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
153 cuda_uvm_memory_size_ = req_size;
155 if (! created_finalize_hook) {
156 Kokkos::push_finalize_hook (finalize_cuda_uvm_memory);
157 created_finalize_hook =
true;
160 return cuda_uvm_memory_;
164 StaticKokkosAllocation<Kokkos::CudaHostPinnedSpace>::
165 resize (Kokkos::CudaHostPinnedSpace ,
168 using memory_space = Kokkos::CudaHostPinnedSpace;
169 static bool created_finalize_hook =
false;
171 const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
172 if (req_size > cuda_host_pinned_memory_size_) {
173 if (cuda_host_pinned_memory_ !=
nullptr) {
174 Kokkos::kokkos_free<memory_space> (cuda_host_pinned_memory_);
176 cuda_host_pinned_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
177 cuda_host_pinned_memory_size_ = req_size;
179 if (! created_finalize_hook) {
180 Kokkos::push_finalize_hook (finalize_cuda_host_pinned_memory);
181 created_finalize_hook =
true;
184 return cuda_host_pinned_memory_;
187 #endif // KOKKOS_ENABLE_CUDA
190 StaticKokkosAllocation<Kokkos::HostSpace>::
191 resize (Kokkos::HostSpace ,
194 using memory_space = Kokkos::HostSpace;
195 static bool created_finalize_hook =
false;
197 const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
198 if (req_size > host_memory_size_) {
199 if (host_memory_ !=
nullptr) {
200 Kokkos::kokkos_free<memory_space> (host_memory_);
202 host_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
203 host_memory_size_ = req_size;
205 if (! created_finalize_hook) {
206 Kokkos::push_finalize_hook (finalize_host_memory);
207 created_finalize_hook =
true;