44 #ifndef KOKKOS_CORE_HPP 45 #define KOKKOS_CORE_HPP 50 #include <Kokkos_Core_fwd.hpp> 52 #if defined( KOKKOS_HAVE_SERIAL ) 56 #if defined( KOKKOS_HAVE_OPENMP ) 57 #include <Kokkos_OpenMP.hpp> 60 #if defined( KOKKOS_HAVE_PTHREAD ) 61 #include <Kokkos_Threads.hpp> 64 #if defined( KOKKOS_HAVE_CUDA ) 65 #include <Kokkos_Cuda.hpp> 69 #include <Kokkos_Array.hpp> 70 #include <Kokkos_View.hpp> 73 #include <Kokkos_hwloc.hpp> 75 #ifdef KOKKOS_HAVE_CXX11 76 #include <Kokkos_Complex.hpp> 84 struct InitArguments {
96 void initialize(
int& narg,
char* arg[]);
98 void initialize(
const InitArguments& args = InitArguments());
120 template<
class Space =
typename Kokkos::DefaultExecutionSpace::memory_space >
122 void * kokkos_malloc(
const std::string & arg_alloc_label
123 ,
const size_t arg_alloc_size )
125 typedef typename Space::memory_space MemorySpace ;
126 return Impl::SharedAllocationRecord< MemorySpace >::
127 allocate_tracked( MemorySpace() , arg_alloc_label , arg_alloc_size );
130 template<
class Space =
typename Kokkos::DefaultExecutionSpace::memory_space >
132 void * kokkos_malloc(
const size_t arg_alloc_size )
134 typedef typename Space::memory_space MemorySpace ;
135 return Impl::SharedAllocationRecord< MemorySpace >::
136 allocate_tracked( MemorySpace() ,
"no-label" , arg_alloc_size );
139 template<
class Space =
typename Kokkos::DefaultExecutionSpace::memory_space >
141 void kokkos_free(
void * arg_alloc )
143 typedef typename Space::memory_space MemorySpace ;
144 return Impl::SharedAllocationRecord< MemorySpace >::
145 deallocate_tracked( arg_alloc );
148 template<
class Space =
typename Kokkos::DefaultExecutionSpace::memory_space >
150 void * kokkos_realloc(
void * arg_alloc ,
const size_t arg_alloc_size )
152 typedef typename Space::memory_space MemorySpace ;
153 return Impl::SharedAllocationRecord< MemorySpace >::
154 reallocate_tracked( arg_alloc , arg_alloc_size );
160 #if defined( KOKKOS_USING_EXPERIMENTAL_VIEW ) 164 using Kokkos::Experimental::kokkos_malloc ;
165 using Kokkos::Experimental::kokkos_realloc ;
166 using Kokkos::Experimental::kokkos_free ;
178 static void increment_ref_count( AllocationTracker
const & tracker )
180 tracker.increment_ref_count();
183 static void decrement_ref_count( AllocationTracker
const & tracker )
185 tracker.decrement_ref_count();
194 template<
class Arg = DefaultExecutionSpace>
195 void* kokkos_malloc(
const std::string label,
size_t count) {
196 if(count == 0)
return NULL;
197 typedef typename Arg::memory_space MemorySpace;
198 Impl::AllocationTracker tracker = MemorySpace::allocate_and_track(label,count);;
199 Impl::MallocHelper::increment_ref_count( tracker );
200 return tracker.alloc_ptr();
203 template<
class Arg = DefaultExecutionSpace>
204 void* kokkos_malloc(
const size_t& count) {
205 return kokkos_malloc<Arg>(
"DefaultLabel",count);
211 template<
class Arg = DefaultExecutionSpace>
212 void kokkos_free(
const void* ptr) {
213 typedef typename Arg::memory_space MemorySpace;
214 typedef typename MemorySpace::allocator allocator;
215 Impl::AllocationTracker tracker = Impl::AllocationTracker::find<allocator>(ptr);
216 if (tracker.is_valid()) {
217 Impl::MallocHelper::decrement_ref_count( tracker );
222 template<
class Arg = DefaultExecutionSpace>
223 void* kokkos_realloc(
const void* old_ptr,
size_t size) {
225 return kokkos_malloc<Arg>(size);
227 typedef typename Arg::memory_space MemorySpace;
228 typedef typename MemorySpace::allocator allocator;
229 Impl::AllocationTracker tracker = Impl::AllocationTracker::find<allocator>(old_ptr);
231 tracker.reallocate(size);
233 return tracker.alloc_ptr();
Declaration and definition of Kokkos::Vectorization interface.
Declaration and definition of Kokkos::pair.
Declaration and definition of Kokkos::Serial device.
void finalize_all()
Finalize all known execution spaces.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.