Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_OpenMPTarget.hpp
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 
17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
19 static_assert(false,
20  "Including non-public Kokkos header files is not allowed.");
21 #endif
22 #ifndef KOKKOS_OPENMPTARGET_HPP
23 #define KOKKOS_OPENMPTARGET_HPP
24 
25 #include <Kokkos_Core_fwd.hpp>
26 
27 #if defined(KOKKOS_ENABLE_OPENMPTARGET) && defined(_OPENMP)
28 
29 #include <omp.h>
30 
31 #include <cstddef>
32 #include <iosfwd>
33 #include <Kokkos_OpenMPTargetSpace.hpp>
34 #include <Kokkos_ScratchSpace.hpp>
35 #include <Kokkos_Parallel.hpp>
36 #include <Kokkos_TaskScheduler.hpp>
37 #include <Kokkos_Layout.hpp>
38 #include <impl/Kokkos_Profiling_Interface.hpp>
39 #include <impl/Kokkos_InitializationSettings.hpp>
40 #include <KokkosExp_MDRangePolicy.hpp>
41 /*--------------------------------------------------------------------------*/
42 
43 namespace Kokkos {
44 namespace Experimental {
45 namespace Impl {
46 class OpenMPTargetInternal;
47 }
48 
51 class OpenMPTarget {
52  public:
53  //------------------------------------
55 
56 
58  using execution_space = OpenMPTarget;
59  using memory_space = OpenMPTargetSpace;
61  using device_type = Kokkos::Device<execution_space, memory_space>;
62 
63  using array_layout = LayoutLeft;
64  using size_type = memory_space::size_type;
65 
66  using scratch_memory_space = ScratchMemorySpace<OpenMPTarget>;
67 
68  inline static bool in_parallel() { return omp_in_parallel(); }
69 
70  static void fence(const std::string& name =
71  "Kokkos::OpenMPTarget::fence: Unnamed Instance Fence");
72 
73  static void impl_static_fence(const std::string& name);
74 
76 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
77  static int concurrency();
78 #else
79  int concurrency() const;
80 #endif
81 
83  void print_configuration(std::ostream& os, bool verbose = false) const;
84 
85  static const char* name();
86 
88  static void impl_finalize();
89 
91  static int impl_is_initialized();
92 
94  static void impl_initialize(InitializationSettings const&);
95 
96  inline Impl::OpenMPTargetInternal* impl_internal_space_instance() const {
97  return m_space_instance;
98  }
99 
100  OpenMPTarget();
101  uint32_t impl_instance_id() const noexcept;
102 
103  private:
104  friend bool operator==(OpenMPTarget const& lhs, OpenMPTarget const& rhs) {
105  return lhs.impl_internal_space_instance() ==
106  rhs.impl_internal_space_instance();
107  }
108  friend bool operator!=(OpenMPTarget const& lhs, OpenMPTarget const& rhs) {
109  return !(lhs == rhs);
110  }
111  Impl::OpenMPTargetInternal* m_space_instance;
112 };
113 } // namespace Experimental
114 
115 namespace Impl {
116 template <>
117 struct MemorySpaceAccess<
118  Kokkos::Experimental::OpenMPTargetSpace,
119  Kokkos::Experimental::OpenMPTarget::scratch_memory_space> {
120  enum : bool { assignable = false };
121  enum : bool { accessible = true };
122  enum : bool { deepcopy = false };
123 };
124 } // namespace Impl
125 
126 namespace Tools {
127 namespace Experimental {
128 template <>
129 struct DeviceTypeTraits<::Kokkos::Experimental::OpenMPTarget> {
130  static constexpr DeviceType id =
131  ::Kokkos::Profiling::Experimental::DeviceType::OpenMPTarget;
132  static int device_id(const Kokkos::Experimental::OpenMPTarget&) {
133  return omp_get_default_device();
134  }
135 };
136 } // namespace Experimental
137 } // namespace Tools
138 
139 } // namespace Kokkos
140 
141 /*--------------------------------------------------------------------------*/
142 /*--------------------------------------------------------------------------*/
143 
144 #include <OpenMPTarget/Kokkos_OpenMPTarget_Exec.hpp>
145 #include <OpenMPTarget/Kokkos_OpenMPTarget_Parallel.hpp>
146 #include <OpenMPTarget/Kokkos_OpenMPTarget_Parallel_MDRange.hpp>
147 #include <OpenMPTarget/Kokkos_OpenMPTarget_Task.hpp>
148 
149 /*--------------------------------------------------------------------------*/
150 
151 #endif /* #if defined( KOKKOS_ENABLE_OPENMPTARGET ) && defined( _OPENMP ) */
152 #endif /* #ifndef KOKKOS_OPENMPTARGET_HPP */