45 #ifndef KOKKOS_HOSTSPACE_HPP
46 #define KOKKOS_HOSTSPACE_HPP
53 #include <Kokkos_Core_fwd.hpp>
54 #include <Kokkos_Concepts.hpp>
55 #include <Kokkos_MemoryTraits.hpp>
57 #include <impl/Kokkos_Traits.hpp>
58 #include <impl/Kokkos_Error.hpp>
59 #include <impl/Kokkos_SharedAlloc.hpp>
61 #include "impl/Kokkos_HostSpace_deepcopy.hpp"
75 void init_lock_array_host_space();
82 bool lock_address_host_space(
void* ptr);
90 void unlock_address_host_space(
void* ptr);
107 typedef size_t size_type;
115 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
116 typedef Kokkos::OpenMP execution_space;
117 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
118 typedef Kokkos::Threads execution_space;
119 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
120 typedef Kokkos::Experimental::HPX execution_space;
121 #elif defined(KOKKOS_ENABLE_OPENMP)
122 typedef Kokkos::OpenMP execution_space;
123 #elif defined(KOKKOS_ENABLE_THREADS)
124 typedef Kokkos::Threads execution_space;
125 #elif defined(KOKKOS_ENABLE_HPX)
126 typedef Kokkos::Experimental::HPX execution_space;
127 #elif defined(KOKKOS_ENABLE_SERIAL)
128 typedef Kokkos::Serial execution_space;
131 "At least one of the following host execution spaces must be defined: Kokkos::OpenMP, Kokkos::Threads, or Kokkos::Serial. 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."
135 typedef Kokkos::Device<execution_space, memory_space>
device_type;
158 void*
allocate(
const size_t arg_alloc_size)
const;
161 void deallocate(
void*
const arg_alloc_ptr,
const size_t arg_alloc_size)
const;
164 static constexpr
const char*
name() {
return m_name; }
168 static constexpr
const char* m_name =
"Host";
169 friend class Kokkos::Impl::SharedAllocationRecord<Kokkos::
HostSpace, void>;
184 template <
typename S>
191 typename S::execution_space::memory_space,
200 typename S::memory_space>::accessible
204 typedef typename std::conditional<
208 typename std::conditional<
211 Kokkos::Device<Kokkos::HostSpace::execution_space,
212 typename S::memory_space>,
227 class SharedAllocationRecord<Kokkos::
HostSpace, void>
228 :
public SharedAllocationRecord<void, void> {
232 typedef SharedAllocationRecord<void, void> RecordBase;
234 SharedAllocationRecord(
const SharedAllocationRecord&) =
delete;
235 SharedAllocationRecord& operator=(
const SharedAllocationRecord&) =
delete;
241 static RecordBase s_root_record;
247 ~SharedAllocationRecord()
249 KOKKOS_IMPL_INTEL_WORKAROUND_NOEXCEPT_SPECIFICATION_VIRTUAL_FUNCTION)
253 SharedAllocationRecord() =
default;
255 SharedAllocationRecord(
257 const size_t arg_alloc_size,
258 const RecordBase::function_type arg_dealloc = &
deallocate);
261 inline std::string get_label()
const {
262 return std::string(RecordBase::head()->m_label);
265 KOKKOS_INLINE_FUNCTION
static SharedAllocationRecord*
allocate(
267 const size_t arg_alloc_size) {
268 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
269 return new SharedAllocationRecord(arg_space, arg_label, arg_alloc_size);
273 (void)arg_alloc_size;
274 return (SharedAllocationRecord*)0;
280 const std::string& arg_label,
281 const size_t arg_alloc_size);
284 static void* reallocate_tracked(
void*
const arg_alloc_ptr,
285 const size_t arg_alloc_size);
288 static void deallocate_tracked(
void*
const arg_alloc_ptr);
290 static SharedAllocationRecord* get_record(
void* arg_alloc_ptr);
293 bool detail =
false);
306 template <
class ExecutionSpace>
308 DeepCopy(
void* dst,
const void* src,
size_t n) {
309 hostspace_parallel_deepcopy(dst, src, n);
312 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
314 hostspace_parallel_deepcopy(dst, src, n);
323 #endif // #define KOKKOS_HOSTSPACE_HPP
void * allocate(const size_t arg_alloc_size) const
Allocate untracked memory in the space.
Kokkos::Device< execution_space, memory_space > device_type
This memory space preferred device_type.
AllocationMechanism
Non-default memory space instance to choose allocation mechansim, if available.
void deallocate(void *const arg_alloc_ptr, const size_t arg_alloc_size) const
Deallocate untracked memory in the space.
Memory management for host memory.
static constexpr const char * name()
Return Name of the MemorySpace.
HostSpace()
Default memory space instance.
HostSpace memory_space
Tag this class as a kokkos memory space.
Access relationship between DstMemorySpace and SrcMemorySpace.