17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_HOSTSPACE_HPP
23#define KOKKOS_HOSTSPACE_HPP
30#include <Kokkos_Core_fwd.hpp>
31#include <Kokkos_Concepts.hpp>
32#include <Kokkos_MemoryTraits.hpp>
34#include <impl/Kokkos_Traits.hpp>
35#include <impl/Kokkos_Error.hpp>
36#include <impl/Kokkos_SharedAlloc.hpp>
37#include <impl/Kokkos_Tools.hpp>
39#include "impl/Kokkos_HostSpace_deepcopy.hpp"
40#include <impl/Kokkos_MemorySpace.hpp>
54 using size_type = size_t;
65 using device_type = Kokkos::Device<execution_space, memory_space>;
88 void*
allocate(
const size_t arg_alloc_size)
const;
89 void*
allocate(
const char* arg_label,
const size_t arg_alloc_size,
90 const size_t arg_logical_size = 0)
const;
93 void deallocate(
void*
const arg_alloc_ptr,
const size_t arg_alloc_size)
const;
94 void deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
95 const size_t arg_alloc_size,
96 const size_t arg_logical_size = 0)
const;
99 template <
class,
class,
class,
class>
102 void* impl_allocate(
const char* arg_label,
const size_t arg_alloc_size,
103 const size_t arg_logical_size = 0,
104 const Kokkos::Tools::SpaceHandle =
105 Kokkos::Tools::make_space_handle(
name()))
const;
106 void impl_deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
107 const size_t arg_alloc_size,
108 const size_t arg_logical_size = 0,
109 const Kokkos::Tools::SpaceHandle =
110 Kokkos::Tools::make_space_handle(
name()))
const;
114 static constexpr const char*
name() {
return m_name; }
118 static constexpr const char* m_name =
"Host";
119 friend class Kokkos::Impl::SharedAllocationRecord<Kokkos::
HostSpace, void>;
141 typename S::execution_space::memory_space,
150 typename S::memory_space>::accessible
154 using Space = std::conditional_t<
155 keep_exe && keep_mem, S,
156 std::conditional_t<keep_mem,
158 typename S::memory_space>,
173class SharedAllocationRecord<Kokkos::HostSpace, void>
174 :
public SharedAllocationRecordCommon<Kokkos::HostSpace> {
176 friend Kokkos::HostSpace;
177 friend class SharedAllocationRecordCommon<Kokkos::HostSpace>;
179 using base_t = SharedAllocationRecordCommon<Kokkos::HostSpace>;
180 using RecordBase = SharedAllocationRecord<void, void>;
182 SharedAllocationRecord(const SharedAllocationRecord&) = delete;
183 SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
185#ifdef KOKKOS_ENABLE_DEBUG
187 static RecordBase s_root_record;
190 const Kokkos::HostSpace m_space;
193 ~SharedAllocationRecord();
194 SharedAllocationRecord() = default;
200 template <typename ExecutionSpace>
201 SharedAllocationRecord(
202 const ExecutionSpace& , const Kokkos::HostSpace& arg_space,
203 const std::string& arg_label, const size_t arg_alloc_size,
204 const RecordBase::function_type arg_dealloc = &deallocate)
206#ifdef KOKKOS_ENABLE_DEBUG
207 &SharedAllocationRecord<Kokkos::HostSpace, void>::s_root_record,
209 Impl::checked_allocation_with_header(arg_space, arg_label,
211 sizeof(SharedAllocationHeader) + arg_alloc_size, arg_dealloc,
214 this->base_t::_fill_host_accessible_header_info(*RecordBase::m_alloc_ptr,
218 SharedAllocationRecord(
219 const Kokkos::HostSpace& arg_space,
const std::string& arg_label,
220 const size_t arg_alloc_size,
221 const RecordBase::function_type arg_dealloc = &deallocate);
224 KOKKOS_INLINE_FUNCTION
static SharedAllocationRecord*
allocate(
225 const Kokkos::HostSpace& arg_space,
const std::string& arg_label,
226 const size_t arg_alloc_size) {
227 KOKKOS_IF_ON_HOST((
return new SharedAllocationRecord(arg_space, arg_label,
229 KOKKOS_IF_ON_DEVICE(((
void)arg_space; (void)arg_label; (void)arg_alloc_size;
245struct DeepCopy<HostSpace, HostSpace, DefaultHostExecutionSpace> {
246 DeepCopy(
void* dst,
const void* src,
size_t n) {
247 hostspace_parallel_deepcopy(dst, src, n);
250 DeepCopy(
const DefaultHostExecutionSpace& exec,
void* dst,
const void* src,
252 hostspace_parallel_deepcopy_async(exec, dst, src, n);
256template <
class ExecutionSpace>
257struct DeepCopy<HostSpace, HostSpace, ExecutionSpace> {
258 DeepCopy(
void* dst,
const void* src,
size_t n) {
259 hostspace_parallel_deepcopy(dst, src, n);
262 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
264 "Kokkos::Impl::DeepCopy<HostSpace, HostSpace, "
265 "ExecutionSpace>::DeepCopy: fence before copy");
266 hostspace_parallel_deepcopy_async(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.
HostSpace memory_space
Tag this class as a kokkos memory space.
static constexpr const char * name()
Return Name of the MemorySpace.
DefaultHostExecutionSpace execution_space
Default execution space for this memory space.
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.
ScopeGuard Some user scope issues have been identified with some Kokkos::finalize calls; ScopeGuard a...
Access relationship between DstMemorySpace and SrcMemorySpace.