44 #ifndef KOKKOS_OPENMPTARGETSPACE_HPP
45 #define KOKKOS_OPENMPTARGETSPACE_HPP
52 #include <Kokkos_Core_fwd.hpp>
54 #ifdef KOKKOS_ENABLE_OPENMPTARGET
56 #include <Kokkos_HostSpace.hpp>
90 namespace Experimental {
97 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
130 ,
const size_t arg_alloc_size )
const ;
134 friend class Kokkos::Impl::SharedAllocationRecord< Kokkos::Experimental::OpenMPTargetSpace , void > ;
146 class SharedAllocationRecord< Kokkos::Experimental::OpenMPTargetSpace , void >
147 :
public SharedAllocationRecord< void , void >
151 friend Kokkos::Experimental::OpenMPTargetSpace ;
153 typedef SharedAllocationRecord< void , void > RecordBase ;
155 SharedAllocationRecord(
const SharedAllocationRecord & ) = delete ;
156 SharedAllocationRecord & operator = (
const SharedAllocationRecord & ) = delete ;
158 static void deallocate( RecordBase * );
161 static RecordBase s_root_record ;
163 const Kokkos::Experimental::OpenMPTargetSpace m_space ;
167 ~SharedAllocationRecord();
168 SharedAllocationRecord() = default ;
170 SharedAllocationRecord(
const Kokkos::Experimental::OpenMPTargetSpace & arg_space
171 ,
const std::string & arg_label
172 ,
const size_t arg_alloc_size
173 ,
const RecordBase::function_type arg_dealloc = & deallocate
178 std::string get_label()
const;
180 KOKKOS_INLINE_FUNCTION
static
181 SharedAllocationRecord * allocate(
const Kokkos::Experimental::OpenMPTargetSpace & arg_space
182 ,
const std::string & arg_label
183 ,
const size_t arg_alloc_size
188 void * allocate_tracked(
const Kokkos::Experimental::OpenMPTargetSpace & arg_space
189 ,
const std::string & arg_label
190 ,
const size_t arg_alloc_size );
194 void * reallocate_tracked(
void *
const arg_alloc_ptr
195 ,
const size_t arg_alloc_size );
199 void deallocate_tracked(
void *
const arg_alloc_ptr );
202 static SharedAllocationRecord * get_record(
void * arg_alloc_ptr );
204 static void print_records( std::ostream & ,
const Kokkos::Experimental::OpenMPTargetSpace & ,
bool detail =
false );
217 template<
class ExecutionSpace>
218 struct DeepCopy<Kokkos::Experimental::OpenMPTargetSpace,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, omp_get_default_device(), omp_get_default_device());
222 DeepCopy(
const ExecutionSpace& exec,
void * dst ,
const void * src ,
size_t n ) {
224 omp_target_memcpy( dst , const_cast<void*> (src) , n, 0, 0, omp_get_default_device(), omp_get_default_device());
229 template<
class ExecutionSpace>
230 struct DeepCopy<Kokkos::Experimental::OpenMPTargetSpace,HostSpace,ExecutionSpace> {
231 DeepCopy(
void * dst ,
const void * src ,
size_t n ) {
232 omp_target_memcpy( dst , const_cast<void*> (src) , n, 0, 0, omp_get_default_device(), omp_get_initial_device());
234 DeepCopy(
const ExecutionSpace& exec,
void * dst ,
const void * src ,
size_t n ) {
236 omp_target_memcpy( dst , const_cast<void*> (src) , n, 0, 0, omp_get_default_device(), omp_get_initial_device());
240 template<
class ExecutionSpace>
241 struct DeepCopy<HostSpace,Kokkos::Experimental::OpenMPTargetSpace,ExecutionSpace> {
242 DeepCopy(
void * dst ,
const void * src ,
size_t n ) {
243 omp_target_memcpy( dst , const_cast<void*> (src) , n, 0, 0, omp_get_initial_device(), omp_get_default_device());
245 DeepCopy(
const ExecutionSpace& exec,
void * dst ,
const void * src ,
size_t n ) {
247 omp_target_memcpy( dst , const_cast<void*> (src) , n, 0, 0, omp_get_initial_device(), omp_get_default_device());
253 struct VerifyExecutionCanAccessMemorySpace< Kokkos::HostSpace , Kokkos::Experimental::OpenMPTargetSpace >
255 enum { value =
false };
256 inline static void verify(
void ) { }
257 inline static void verify(
const void * ) { }