-
Notifications
You must be signed in to change notification settings - Fork 407
/
Kokkos_OpenMPTarget.hpp
156 lines (127 loc) · 4.79 KB
/
Kokkos_OpenMPTarget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
#include <Kokkos_Macros.hpp>
static_assert(false,
"Including non-public Kokkos header files is not allowed.");
#endif
#ifndef KOKKOS_OPENMPTARGET_HPP
#define KOKKOS_OPENMPTARGET_HPP
#include <Kokkos_Core_fwd.hpp>
#if defined(KOKKOS_ENABLE_OPENMPTARGET) && defined(_OPENMP)
#include <omp.h>
#include <cstddef>
#include <iosfwd>
#include <OpenMPTarget/Kokkos_OpenMPTargetSpace.hpp>
#include <Kokkos_ScratchSpace.hpp>
#include <Kokkos_Parallel.hpp>
#include <Kokkos_TaskScheduler.hpp>
#include <Kokkos_Layout.hpp>
#include <impl/Kokkos_Profiling_Interface.hpp>
#include <impl/Kokkos_InitializationSettings.hpp>
#include <KokkosExp_MDRangePolicy.hpp>
/*--------------------------------------------------------------------------*/
namespace Kokkos {
namespace Experimental {
namespace Impl {
class OpenMPTargetInternal;
}
/// \class OpenMPTarget
/// \brief Kokkos device for multicore processors in the host memory space.
class OpenMPTarget {
public:
//------------------------------------
//! \name Type declarations that all Kokkos devices must provide.
//@{
//! Tag this class as a kokkos execution space
using execution_space = OpenMPTarget;
using memory_space = OpenMPTargetSpace;
//! This execution space preferred device_type
using device_type = Kokkos::Device<execution_space, memory_space>;
using array_layout = LayoutLeft;
using size_type = memory_space::size_type;
using scratch_memory_space = ScratchMemorySpace<OpenMPTarget>;
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
KOKKOS_DEPRECATED inline static bool in_parallel() {
return omp_in_parallel();
}
#endif
static void fence(const std::string& name =
"Kokkos::OpenMPTarget::fence: Unnamed Instance Fence");
static void impl_static_fence(const std::string& name);
/** \brief Return the maximum amount of concurrency. */
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
static int concurrency();
#else
int concurrency() const;
#endif
//! Print configuration information to the given output stream.
void print_configuration(std::ostream& os, bool verbose = false) const;
static const char* name();
//! Free any resources being consumed by the device.
static void impl_finalize();
//! Has been initialized
static int impl_is_initialized();
//! Initialize, telling the CUDA run-time library which device to use.
static void impl_initialize(InitializationSettings const&);
inline Impl::OpenMPTargetInternal* impl_internal_space_instance() const {
return m_space_instance;
}
OpenMPTarget();
uint32_t impl_instance_id() const noexcept;
private:
friend bool operator==(OpenMPTarget const& lhs, OpenMPTarget const& rhs) {
return lhs.impl_internal_space_instance() ==
rhs.impl_internal_space_instance();
}
friend bool operator!=(OpenMPTarget const& lhs, OpenMPTarget const& rhs) {
return !(lhs == rhs);
}
Impl::OpenMPTargetInternal* m_space_instance;
};
} // namespace Experimental
namespace Impl {
template <>
struct MemorySpaceAccess<
Kokkos::Experimental::OpenMPTargetSpace,
Kokkos::Experimental::OpenMPTarget::scratch_memory_space> {
enum : bool { assignable = false };
enum : bool { accessible = true };
enum : bool { deepcopy = false };
};
} // namespace Impl
namespace Tools {
namespace Experimental {
template <>
struct DeviceTypeTraits<::Kokkos::Experimental::OpenMPTarget> {
static constexpr DeviceType id =
::Kokkos::Profiling::Experimental::DeviceType::OpenMPTarget;
static int device_id(const Kokkos::Experimental::OpenMPTarget&) {
return omp_get_default_device();
}
};
} // namespace Experimental
} // namespace Tools
} // namespace Kokkos
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
#include <OpenMPTarget/Kokkos_OpenMPTarget_Parallel.hpp>
#include <OpenMPTarget/Kokkos_OpenMPTarget_ParallelFor_MDRange.hpp>
#include <OpenMPTarget/Kokkos_OpenMPTarget_ParallelReduce_MDRange.hpp>
#include <OpenMPTarget/Kokkos_OpenMPTarget_Task.hpp>
/*--------------------------------------------------------------------------*/
#endif /* #if defined( KOKKOS_ENABLE_OPENMPTARGET ) && defined( _OPENMP ) */
#endif /* #ifndef KOKKOS_OPENMPTARGET_HPP */