44 #ifndef KOKKOS_HOSTSPACE_HPP 45 #define KOKKOS_HOSTSPACE_HPP 52 #include <Kokkos_Core_fwd.hpp> 53 #include <Kokkos_MemoryTraits.hpp> 55 #include <impl/Kokkos_Traits.hpp> 56 #include <impl/Kokkos_Error.hpp> 58 #include <impl/Kokkos_AllocationTracker.hpp> 59 #include <impl/Kokkos_BasicAllocators.hpp> 61 #include <impl/KokkosExp_SharedAlloc.hpp> 74 void init_lock_array_host_space();
81 bool lock_address_host_space(
void* ptr);
89 void unlock_address_host_space(
void* ptr);
106 typedef size_t size_type ;
114 #if defined( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP ) 115 typedef Kokkos::OpenMP execution_space ;
116 #elif defined( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS ) 117 typedef Kokkos::Threads execution_space ;
118 #elif defined( KOKKOS_HAVE_OPENMP ) 119 typedef Kokkos::OpenMP execution_space ;
120 #elif defined( KOKKOS_HAVE_PTHREAD ) 121 typedef Kokkos::Threads execution_space ;
122 #elif defined( KOKKOS_HAVE_SERIAL ) 123 typedef Kokkos::Serial execution_space ;
125 # error "At least one of the following host execution spaces must be defined: Kokkos::OpenMP, Kokkos::Serial, or Kokkos::Threads. You might be seeing this message if you disabled the Kokkos::Serial device explicitly using the Kokkos_ENABLE_Serial:BOOL=OFF CMake option, but did not enable any of the other host execution space devices." 132 #if ! defined( KOKKOS_USING_EXPERIMENTAL_VIEW ) 134 #if defined( KOKKOS_USE_PAGE_ALIGNED_HOST_MEMORY ) 135 typedef Impl::PageAlignedAllocator allocator ;
137 typedef Impl::AlignedAllocator allocator ;
146 static Impl::AllocationTracker allocate_and_track(
const std::string & label,
const size_t size );
152 static int in_parallel();
154 static void register_in_parallel(
int (*)() );
172 void * allocate(
const size_t arg_alloc_size )
const ;
175 void deallocate(
void *
const arg_alloc_ptr
176 ,
const size_t arg_alloc_size )
const ;
182 friend class Kokkos::Experimental::Impl::SharedAllocationRecord< Kokkos::
HostSpace , void > ;
195 class SharedAllocationRecord< Kokkos::
HostSpace , void >
196 :
public SharedAllocationRecord< void , void >
202 typedef SharedAllocationRecord< void , void > RecordBase ;
204 SharedAllocationRecord(
const SharedAllocationRecord & ) = delete ;
205 SharedAllocationRecord & operator = (
const SharedAllocationRecord & ) = delete ;
207 static void deallocate( RecordBase * );
210 static RecordBase s_root_record ;
216 ~SharedAllocationRecord();
217 SharedAllocationRecord() = default ;
220 ,
const std::string & arg_label
221 ,
const size_t arg_alloc_size
222 ,
const RecordBase::function_type arg_dealloc = & deallocate
228 std::string get_label()
const 230 return std::string( RecordBase::head()->m_label );
233 KOKKOS_INLINE_FUNCTION
static 235 ,
const std::string & arg_label
236 ,
const size_t arg_alloc_size
239 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST ) 240 return new SharedAllocationRecord( arg_space , arg_label , arg_alloc_size );
242 return (SharedAllocationRecord *) 0 ;
249 ,
const std::string & arg_label
250 ,
const size_t arg_alloc_size );
254 void * reallocate_tracked(
void *
const arg_alloc_ptr
255 ,
const size_t arg_alloc_size );
259 void deallocate_tracked(
void *
const arg_alloc_ptr );
262 static SharedAllocationRecord * get_record(
void * arg_alloc_ptr );
264 static void print_records( std::ostream & ,
const Kokkos::HostSpace & ,
bool detail =
false );
277 template<
class DstSpace,
class SrcSpace,
class ExecutionSpace =
typename DstSpace::execution_space>
struct DeepCopy ;
279 template<
class ExecutionSpace>
280 struct DeepCopy<HostSpace,HostSpace,ExecutionSpace> {
281 DeepCopy(
void * dst ,
const void * src ,
size_t n ) {
282 memcpy( dst , src , n );
284 DeepCopy(
const ExecutionSpace& exec,
void * dst ,
const void * src ,
size_t n ) {
286 memcpy( dst , src , n );
AllocationMechanism
Non-default memory space instance to choose allocation mechansim, if available.
Memory space for main process and CPU execution spaces.
Memory management for host memory.
Kokkos::Device< execution_space, memory_space > device_type
This memory space preferred device_type.
HostSpace memory_space
Tag this class as a kokkos memory space.