44 #ifndef KOKKOS_HBWSPACE_HPP
45 #define KOKKOS_HBWSPACE_HPP
47 #include <Kokkos_Macros.hpp>
48 #ifdef KOKKOS_ENABLE_HBWSPACE
50 #include <Kokkos_HostSpace.hpp>
54 namespace Experimental {
64 void init_lock_array_hbw_space();
71 bool lock_address_hbw_space(
void* ptr );
79 void unlock_address_hbw_space(
void* ptr );
89 namespace Experimental {
99 typedef HBWSpace memory_space;
100 typedef size_t size_type;
108 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
109 typedef Kokkos::OpenMP execution_space;
110 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
111 typedef Kokkos::Threads execution_space;
114 #elif defined( KOKKOS_ENABLE_OPENMP )
115 typedef Kokkos::OpenMP execution_space;
116 #elif defined( KOKKOS_ENABLE_THREADS )
117 typedef Kokkos::Threads execution_space;
120 #elif defined( KOKKOS_ENABLE_SERIAL )
121 typedef Kokkos::Serial execution_space;
123 # error "At least one of the following host execution spaces must be defined: Kokkos::OpenMP, Kokkos::Threads, Kokkos::Qhreads, 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."
127 typedef Kokkos::Device< execution_space, memory_space > device_type;
131 HBWSpace(
const HBWSpace & rhs ) =
default;
132 HBWSpace & operator = (
const HBWSpace & ) =
default;
133 ~HBWSpace() =
default;
137 enum AllocationMechanism { STD_MALLOC, POSIX_MEMALIGN, POSIX_MMAP, INTEL_MM_ALLOC };
140 HBWSpace(
const AllocationMechanism & );
143 void * allocate(
const size_t arg_alloc_size )
const;
146 void deallocate(
void *
const arg_alloc_ptr
147 ,
const size_t arg_alloc_size )
const;
150 static constexpr
const char* name() {
return "HBW"; }
154 AllocationMechanism m_alloc_mech;
155 friend class Kokkos::Impl::SharedAllocationRecord< Kokkos::Experimental::HBWSpace, void >;
169 class SharedAllocationRecord< Kokkos::Experimental::HBWSpace, void >
170 :
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;
192 ~SharedAllocationRecord();
193 SharedAllocationRecord() =
default;
195 SharedAllocationRecord(
const Kokkos::Experimental::HBWSpace & arg_space
196 ,
const std::string & arg_label
197 ,
const size_t arg_alloc_size
198 ,
const RecordBase::function_type arg_dealloc = & deallocate
204 std::string get_label()
const
206 return std::string( RecordBase::head()->m_label );
209 KOKKOS_INLINE_FUNCTION
static
210 SharedAllocationRecord * allocate(
const Kokkos::Experimental::HBWSpace & arg_space
211 ,
const std::string & arg_label
212 ,
const size_t arg_alloc_size
215 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
216 return new SharedAllocationRecord( arg_space, arg_label, arg_alloc_size );
218 return (SharedAllocationRecord *) 0;
224 void * allocate_tracked(
const Kokkos::Experimental::HBWSpace & arg_space
225 ,
const std::string & arg_label
226 ,
const size_t arg_alloc_size );
230 void * reallocate_tracked(
void *
const arg_alloc_ptr
231 ,
const size_t arg_alloc_size );
235 void deallocate_tracked(
void *
const arg_alloc_ptr );
237 static SharedAllocationRecord * get_record(
void * arg_alloc_ptr );
239 static void print_records( std::ostream &,
const Kokkos::Experimental::HBWSpace &,
bool detail =
false );
255 struct MemorySpaceAccess< Kokkos::HostSpace, Kokkos::Experimental::HBWSpace > {
256 enum { assignable =
true };
257 enum { accessible =
true };
258 enum { deepcopy =
true };
263 enum { assignable =
false };
264 enum { accessible =
true };
265 enum { deepcopy =
true };
278 template<
class ExecutionSpace >
279 struct DeepCopy< Experimental::HBWSpace, Experimental::HBWSpace, ExecutionSpace > {
280 DeepCopy(
void * dst,
const void * src,
size_t n ) {
281 memcpy( dst, src, n );
284 DeepCopy(
const ExecutionSpace& exec,
void * dst,
const void * src,
size_t n ) {
286 memcpy( dst, src, n );
290 template<
class ExecutionSpace >
291 struct DeepCopy< HostSpace, Experimental::HBWSpace, ExecutionSpace > {
292 DeepCopy(
void * dst,
const void * src,
size_t n ) {
293 memcpy( dst, src, n );
296 DeepCopy(
const ExecutionSpace& exec,
void * dst,
const void * src,
size_t n ) {
298 memcpy( dst, src, n );
302 template<
class ExecutionSpace >
303 struct DeepCopy< Experimental::HBWSpace, HostSpace, ExecutionSpace > {
304 DeepCopy(
void * dst,
const void * src,
size_t n ) {
305 memcpy( dst, src, n );
308 DeepCopy(
const ExecutionSpace& exec,
void * dst,
const void * src,
size_t n ) {
310 memcpy( dst, src, n );
323 struct VerifyExecutionCanAccessMemorySpace< Kokkos::HostSpace, Kokkos::Experimental::HBWSpace >
325 enum { value =
true };
326 inline static void verify(
void ) { }
327 inline static void verify(
const void * ) { }
331 struct VerifyExecutionCanAccessMemorySpace< Kokkos::Experimental::HBWSpace,
Kokkos::HostSpace >
333 enum { value =
true };
334 inline static void verify(
void ) { }
335 inline static void verify(
const void * ) { }
343 #endif // #define KOKKOS_HBWSPACE_HPP
Memory management for host memory.
Access relationship between DstMemorySpace and SrcMemorySpace.