44 #ifndef KOKKOS_HOSTSPACE_HPP 45 #define KOKKOS_HOSTSPACE_HPP 52 #include <Kokkos_Core_fwd.hpp> 53 #include <Kokkos_Concepts.hpp> 54 #include <Kokkos_MemoryTraits.hpp> 56 #include <impl/Kokkos_Traits.hpp> 57 #include <impl/Kokkos_Error.hpp> 58 #include <impl/Kokkos_SharedAlloc.hpp> 71 void init_lock_array_host_space();
78 bool lock_address_host_space(
void* ptr);
86 void unlock_address_host_space(
void* ptr);
103 typedef size_t size_type ;
111 #if defined( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP ) 112 typedef Kokkos::OpenMP execution_space ;
113 #elif defined( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS ) 114 typedef Kokkos::Threads execution_space ;
115 #elif defined( KOKKOS_HAVE_OPENMP ) 116 typedef Kokkos::OpenMP execution_space ;
117 #elif defined( KOKKOS_HAVE_PTHREAD ) 118 typedef Kokkos::Threads execution_space ;
119 #elif defined( KOKKOS_HAVE_SERIAL ) 120 typedef Kokkos::Serial execution_space ;
122 # 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." 130 static int in_parallel();
132 static void register_in_parallel(
int (*)() );
152 void *
allocate(
const size_t arg_alloc_size )
const ;
156 ,
const size_t arg_alloc_size )
const ;
162 friend class Kokkos::Impl::SharedAllocationRecord<
Kokkos::
HostSpace , void > ;
176 template<
typename S >
193 typedef typename std::conditional
194 < keep_exe && keep_mem
196 ,
typename std::conditional
199 ,
typename S::memory_space >
216 :
public SharedAllocationRecord< void , void >
222 typedef SharedAllocationRecord< void , void > RecordBase ;
224 SharedAllocationRecord(
const SharedAllocationRecord & ) = delete ;
225 SharedAllocationRecord & operator = (
const SharedAllocationRecord & ) = delete ;
230 static RecordBase s_root_record ;
236 ~SharedAllocationRecord();
237 SharedAllocationRecord() = default ;
240 ,
const std::string & arg_label
241 ,
const size_t arg_alloc_size
242 ,
const RecordBase::function_type arg_dealloc = &
deallocate 248 std::string get_label()
const 250 return std::string( RecordBase::head()->m_label );
253 KOKKOS_INLINE_FUNCTION
static 255 ,
const std::string & arg_label
256 ,
const size_t arg_alloc_size
259 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST ) 260 return new SharedAllocationRecord( arg_space , arg_label , arg_alloc_size );
262 return (SharedAllocationRecord *) 0 ;
269 ,
const std::string & arg_label
270 ,
const size_t arg_alloc_size );
274 void * reallocate_tracked(
void *
const arg_alloc_ptr
275 ,
const size_t arg_alloc_size );
279 void deallocate_tracked(
void *
const arg_alloc_ptr );
282 static SharedAllocationRecord * get_record(
void * arg_alloc_ptr );
284 static void print_records( std::ostream & ,
const Kokkos::HostSpace & ,
bool detail =
false );
296 template<
class DstSpace,
class SrcSpace,
class ExecutionSpace =
typename DstSpace::execution_space>
struct DeepCopy ;
298 template<
class ExecutionSpace>
300 DeepCopy(
void * dst ,
const void * src ,
size_t n ) {
301 memcpy( dst , src , n );
303 DeepCopy(
const ExecutionSpace& exec,
void * dst ,
const void * src ,
size_t n ) {
305 memcpy( dst , src , n );
AllocationMechanism
Non-default memory space instance to choose allocation mechansim, if available.
void * allocate(const size_t arg_alloc_size) const
Allocate untracked memory in the space.
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()
Default memory space instance.
HostSpace memory_space
Tag this class as a kokkos memory space.
void deallocate(void *const arg_alloc_ptr, const size_t arg_alloc_size) const
Deallocate untracked memory in the space.
Access relationship between DstMemorySpace and SrcMemorySpace.