45 #ifndef KOKKOS_HBWSPACE_HPP
46 #define KOKKOS_HBWSPACE_HPP
48 #include <Kokkos_Macros.hpp>
49 #ifdef KOKKOS_ENABLE_HBWSPACE
51 #include <Kokkos_HostSpace.hpp>
55 namespace Experimental {
65 void init_lock_array_hbw_space();
72 bool lock_address_hbw_space(
void* ptr);
80 void unlock_address_hbw_space(
void* ptr);
90 namespace Experimental {
100 typedef HBWSpace memory_space;
101 typedef size_t size_type;
109 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
110 typedef Kokkos::OpenMP execution_space;
111 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
112 typedef Kokkos::Threads execution_space;
113 #elif defined(KOKKOS_ENABLE_OPENMP)
114 typedef Kokkos::OpenMP execution_space;
115 #elif defined(KOKKOS_ENABLE_THREADS)
116 typedef Kokkos::Threads execution_space;
117 #elif defined(KOKKOS_ENABLE_SERIAL)
118 typedef Kokkos::Serial execution_space;
121 "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."
125 typedef Kokkos::Device<execution_space, memory_space> device_type;
129 HBWSpace(
const HBWSpace& rhs) =
default;
130 HBWSpace& operator=(
const HBWSpace&) =
default;
131 ~HBWSpace() =
default;
136 enum AllocationMechanism {
143 explicit HBWSpace(
const AllocationMechanism&);
146 void* allocate(
const size_t arg_alloc_size)
const;
149 void deallocate(
void*
const arg_alloc_ptr,
const size_t arg_alloc_size)
const;
152 static constexpr
const char* name() {
return "HBW"; }
155 AllocationMechanism m_alloc_mech;
156 friend class Kokkos::Impl::SharedAllocationRecord<
157 Kokkos::Experimental::HBWSpace, void>;
171 class SharedAllocationRecord<Kokkos::Experimental::HBWSpace, void>
172 :
public SharedAllocationRecord<void, void> {
174 friend Kokkos::Experimental::HBWSpace;
176 typedef SharedAllocationRecord<void, void> RecordBase;
178 SharedAllocationRecord(
const SharedAllocationRecord&) =
delete;
179 SharedAllocationRecord& operator=(
const SharedAllocationRecord&) =
delete;
181 static void deallocate(RecordBase*);
185 static RecordBase s_root_record;
188 const Kokkos::Experimental::HBWSpace m_space;
191 ~SharedAllocationRecord()
193 KOKKOS_IMPL_INTEL_WORKAROUND_NOEXCEPT_SPECIFICATION_VIRTUAL_FUNCTION)
197 SharedAllocationRecord() =
default;
199 SharedAllocationRecord(
200 const Kokkos::Experimental::HBWSpace& arg_space,
201 const std::string& arg_label,
const size_t arg_alloc_size,
202 const RecordBase::function_type arg_dealloc = &deallocate);
205 inline std::string get_label()
const {
206 return std::string(RecordBase::head()->m_label);
209 KOKKOS_INLINE_FUNCTION
static SharedAllocationRecord* allocate(
210 const Kokkos::Experimental::HBWSpace& arg_space,
211 const std::string& arg_label,
const size_t arg_alloc_size) {
212 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
213 return new SharedAllocationRecord(arg_space, arg_label, arg_alloc_size);
215 return (SharedAllocationRecord*)0;
220 static void* allocate_tracked(
const Kokkos::Experimental::HBWSpace& arg_space,
221 const std::string& arg_label,
222 const size_t arg_alloc_size);
225 static void* reallocate_tracked(
void*
const arg_alloc_ptr,
226 const size_t arg_alloc_size);
229 static void deallocate_tracked(
void*
const arg_alloc_ptr);
231 static SharedAllocationRecord* get_record(
void* arg_alloc_ptr);
233 static void print_records(std::ostream&,
234 const Kokkos::Experimental::HBWSpace&,
235 bool detail =
false);
250 Kokkos::Experimental::HBWSpace>::assignable,
254 struct MemorySpaceAccess<Kokkos::HostSpace, Kokkos::Experimental::HBWSpace> {
255 enum { assignable =
true };
256 enum { accessible =
true };
257 enum { deepcopy =
true };
262 enum { assignable =
false };
263 enum { accessible =
true };
264 enum { deepcopy =
true };
277 template <
class ExecutionSpace>
278 struct DeepCopy<Kokkos::Experimental::HBWSpace, Kokkos::Experimental::HBWSpace,
280 DeepCopy(
void* dst,
const void* src,
size_t n) { memcpy(dst, src, n); }
282 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
288 template <
class ExecutionSpace>
289 struct DeepCopy<HostSpace, Kokkos::Experimental::HBWSpace, ExecutionSpace> {
290 DeepCopy(
void* dst,
const void* src,
size_t n) { memcpy(dst, src, n); }
292 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
298 template <
class ExecutionSpace>
299 struct DeepCopy<Kokkos::Experimental::HBWSpace, HostSpace, ExecutionSpace> {
300 DeepCopy(
void* dst,
const void* src,
size_t n) { memcpy(dst, src, n); }
302 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
317 struct VerifyExecutionCanAccessMemorySpace<Kokkos::HostSpace,
318 Kokkos::Experimental::HBWSpace> {
319 enum { value =
true };
320 inline static void verify(
void) {}
321 inline static void verify(
const void*) {}
325 struct VerifyExecutionCanAccessMemorySpace<Kokkos::Experimental::HBWSpace,
327 enum { value =
true };
328 inline static void verify(
void) {}
329 inline static void verify(
const void*) {}
337 #endif // #define KOKKOS_HBWSPACE_HPP
Memory management for host memory.
Access relationship between DstMemorySpace and SrcMemorySpace.