45 #ifndef KOKKOS_OPENMPTARGETSPACE_HPP
46 #define KOKKOS_OPENMPTARGETSPACE_HPP
53 #include <Kokkos_Core_fwd.hpp>
55 #ifdef KOKKOS_ENABLE_OPENMPTARGET
57 #include <Kokkos_HostSpace.hpp>
91 namespace Experimental {
98 class OpenMPTargetSpace {
101 typedef OpenMPTargetSpace memory_space;
102 typedef size_t size_type;
110 typedef Kokkos::Experimental::OpenMPTarget execution_space;
113 typedef Kokkos::Device<execution_space, memory_space> device_type;
119 OpenMPTargetSpace(OpenMPTargetSpace&& rhs) =
default;
120 OpenMPTargetSpace(
const OpenMPTargetSpace& rhs) =
default;
121 OpenMPTargetSpace& operator=(OpenMPTargetSpace&&) =
default;
122 OpenMPTargetSpace& operator=(
const OpenMPTargetSpace&) =
default;
123 ~OpenMPTargetSpace() =
default;
126 void* allocate(
const size_t arg_alloc_size)
const;
129 void deallocate(
void*
const arg_alloc_ptr,
const size_t arg_alloc_size)
const;
131 static constexpr
const char* name() {
return "OpenMPTargetSpace"; }
134 friend class Kokkos::Impl::SharedAllocationRecord<
135 Kokkos::Experimental::OpenMPTargetSpace, void>;
147 class SharedAllocationRecord<Kokkos::Experimental::OpenMPTargetSpace, void>
148 :
public SharedAllocationRecord<void, void> {
150 friend Kokkos::Experimental::OpenMPTargetSpace;
152 typedef SharedAllocationRecord<void, void> RecordBase;
154 SharedAllocationRecord(
const SharedAllocationRecord&) =
delete;
155 SharedAllocationRecord& operator=(
const SharedAllocationRecord&) =
delete;
157 static void deallocate(RecordBase*);
161 static RecordBase s_root_record;
163 const Kokkos::Experimental::OpenMPTargetSpace m_space;
166 ~SharedAllocationRecord();
167 SharedAllocationRecord() =
default;
169 SharedAllocationRecord(
170 const Kokkos::Experimental::OpenMPTargetSpace& arg_space,
171 const std::string& arg_label,
const size_t arg_alloc_size,
172 const RecordBase::function_type arg_dealloc = &deallocate);
175 std::string get_label()
const;
177 KOKKOS_INLINE_FUNCTION
static SharedAllocationRecord* allocate(
178 const Kokkos::Experimental::OpenMPTargetSpace& arg_space,
179 const std::string& arg_label,
const size_t arg_alloc_size) {
180 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
181 return new SharedAllocationRecord(arg_space, arg_label, arg_alloc_size);
188 static void* allocate_tracked(
189 const Kokkos::Experimental::OpenMPTargetSpace& arg_space,
190 const std::string& arg_label,
const size_t arg_alloc_size);
193 static void* reallocate_tracked(
void*
const arg_alloc_ptr,
194 const size_t arg_alloc_size);
197 static void deallocate_tracked(
void*
const arg_alloc_ptr);
199 static SharedAllocationRecord* get_record(
void* arg_alloc_ptr);
201 static void print_records(std::ostream&,
202 const Kokkos::Experimental::OpenMPTargetSpace&,
203 bool detail =
false);
216 template <
class ExecutionSpace>
217 struct DeepCopy<Kokkos::Experimental::OpenMPTargetSpace,
218 Kokkos::Experimental::OpenMPTargetSpace, ExecutionSpace> {
219 DeepCopy(
void* dst,
const void* src,
size_t n) {
220 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
221 omp_get_default_device(), omp_get_default_device());
223 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
225 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
226 omp_get_default_device(), omp_get_default_device());
230 template <
class ExecutionSpace>
231 struct DeepCopy<Kokkos::Experimental::OpenMPTargetSpace, HostSpace,
233 DeepCopy(
void* dst,
const void* src,
size_t n) {
234 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
235 omp_get_default_device(), omp_get_initial_device());
237 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
239 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
240 omp_get_default_device(), omp_get_initial_device());
244 template <
class ExecutionSpace>
245 struct DeepCopy<HostSpace, Kokkos::Experimental::OpenMPTargetSpace,
247 DeepCopy(
void* dst,
const void* src,
size_t n) {
248 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
249 omp_get_initial_device(), omp_get_default_device());
251 DeepCopy(
const ExecutionSpace& exec,
void* dst,
const void* src,
size_t n) {
253 omp_target_memcpy(dst, const_cast<void*>(src), n, 0, 0,
254 omp_get_initial_device(), omp_get_default_device());
259 struct VerifyExecutionCanAccessMemorySpace<
260 Kokkos::HostSpace, Kokkos::Experimental::OpenMPTargetSpace> {
261 enum { value =
false };
262 inline static void verify(
void) {}
263 inline static void verify(
const void*) {}