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>
60#include <impl/Kokkos_Tools.hpp>
62#include "impl/Kokkos_HostSpace_deepcopy.hpp"
76void init_lock_array_host_space();
83bool lock_address_host_space(
void* ptr);
91void unlock_address_host_space(
void* ptr);
107 using size_type = size_t;
115#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
116 using execution_space = Kokkos::OpenMP;
117#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
118 using execution_space = Kokkos::Threads;
119#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
120 using execution_space = Kokkos::Experimental::HPX;
121#elif defined(KOKKOS_ENABLE_OPENMP)
122 using execution_space = Kokkos::OpenMP;
123#elif defined(KOKKOS_ENABLE_THREADS)
124 using execution_space = Kokkos::Threads;
125#elif defined(KOKKOS_ENABLE_HPX)
126 using execution_space = Kokkos::Experimental::HPX;
127#elif defined(KOKKOS_ENABLE_SERIAL)
128 using execution_space = Kokkos::Serial;
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 using device_type = Kokkos::Device<execution_space, memory_space>;
159 void*
allocate(
const char* arg_label,
const size_t arg_alloc_size,
160 const size_t arg_logical_size = 0)
const;
163 void deallocate(
void*
const arg_alloc_ptr,
const size_t arg_alloc_size)
const;
164 void deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
165 const size_t arg_alloc_size,
166 const size_t arg_logical_size = 0)
const;
169 template <
class,
class,
class,
class>
172 void* impl_allocate(
const char* arg_label,
const size_t arg_alloc_size,
173 const size_t arg_logical_size = 0,
174 const Kokkos::Tools::SpaceHandle =
175 Kokkos::Tools::make_space_handle(
name()))
const;
176 void impl_deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
177 const size_t arg_alloc_size,
178 const size_t arg_logical_size = 0,
179 const Kokkos::Tools::SpaceHandle =
180 Kokkos::Tools::make_space_handle(
name()))
const;
184 static constexpr const char*
name() {
return m_name; }
188 static constexpr const char* m_name =
"Host";
189 friend class Kokkos::Impl::SharedAllocationRecord<Kokkos::
HostSpace, void>;
211 typename S::execution_space::memory_space,
220 typename S::memory_space>::accessible
224 using Space =
typename std::conditional<
225 keep_exe && keep_mem, S,
226 typename std::conditional<
228 Kokkos::Device<Kokkos::HostSpace::execution_space,
229 typename S::memory_space>,
244class SharedAllocationRecord<Kokkos::
HostSpace, void>
245 :
public SharedAllocationRecordCommon<Kokkos::HostSpace> {
248 friend class SharedAllocationRecordCommon<Kokkos::
HostSpace>;
250 using base_t = SharedAllocationRecordCommon<Kokkos::HostSpace>;
251 using RecordBase = SharedAllocationRecord<void, void>;
253 SharedAllocationRecord(const SharedAllocationRecord&) = delete;
254 SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
256#ifdef KOKKOS_ENABLE_DEBUG
258 static RecordBase s_root_record;
264 ~SharedAllocationRecord()
266 KOKKOS_IMPL_INTEL_WORKAROUND_NOEXCEPT_SPECIFICATION_VIRTUAL_FUNCTION)
270 SharedAllocationRecord() = default;
272 SharedAllocationRecord(
273 const Kokkos::HostSpace& arg_space, const std::string& arg_label,
274 const size_t arg_alloc_size,
275 const RecordBase::function_type arg_dealloc = &deallocate);
278 KOKKOS_INLINE_FUNCTION static SharedAllocationRecord*
allocate(
279 const Kokkos::HostSpace& arg_space, const std::string& arg_label,
280 const size_t arg_alloc_size) {
281#if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
282 return new SharedAllocationRecord(arg_space, arg_label, arg_alloc_size);
286 (void)arg_alloc_size;
287 return (SharedAllocationRecord*)0;
302template <
class ExecutionSpace>
304 DeepCopy(
void* dst,
const void* src,
size_t n) {
305 hostspace_parallel_deepcopy(dst, src, n);
308 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
310 hostspace_parallel_deepcopy(dst, src, n);
LogicalMemorySpace is a space that is identical to another space, but differentiable by name and temp...
Memory management for host memory.
HostSpace()
Default memory space instance.
static constexpr const char * name()
Return Name of the MemorySpace.
void deallocate(void *const arg_alloc_ptr, const size_t arg_alloc_size) const
Deallocate untracked memory in the space.
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.
Kokkos::Device< execution_space, memory_space > device_type
This memory space preferred device_type.
Access relationship between DstMemorySpace and SrcMemorySpace.