17#ifndef KOKKOS_CORE_HPP
18#define KOKKOS_CORE_HPP
19#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20#define KOKKOS_IMPL_PUBLIC_INCLUDE
21#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
30#pragma push_macro("min")
32#define KOKKOS_IMPL_PUSH_MACRO_MIN
35#pragma push_macro("max")
37#define KOKKOS_IMPL_PUSH_MACRO_MAX
43#include <Kokkos_Core_fwd.hpp>
45#include <KokkosCore_Config_DeclareBackend.hpp>
47#include <Kokkos_Half.hpp>
48#include <Kokkos_AnonymousSpace.hpp>
49#include <Kokkos_LogicalSpaces.hpp>
51#include <Kokkos_MinMaxClamp.hpp>
52#include <Kokkos_MathematicalConstants.hpp>
53#include <Kokkos_MathematicalFunctions.hpp>
54#include <Kokkos_MathematicalSpecialFunctions.hpp>
55#include <Kokkos_NumericTraits.hpp>
56#include <Kokkos_MemoryPool.hpp>
57#include <Kokkos_Array.hpp>
58#include <Kokkos_View.hpp>
61#include <Kokkos_hwloc.hpp>
62#include <Kokkos_Timer.hpp>
63#include <Kokkos_Tuners.hpp>
64#include <Kokkos_TaskScheduler.hpp>
65#include <Kokkos_Complex.hpp>
66#include <Kokkos_CopyViews.hpp>
67#include <impl/Kokkos_TeamMDPolicy.hpp>
68#include <impl/Kokkos_InitializationSettings.hpp>
78void initialize(
int& argc,
char* argv[]);
81 InitializationSettings
const& settings = InitializationSettings());
85void pre_initialize(
const InitializationSettings& settings);
87void post_initialize(
const InitializationSettings& settings);
93void declare_configuration_metadata(
const std::string& category,
94 const std::string& key,
95 const std::string& value);
99[[nodiscard]]
bool is_initialized() noexcept;
100[[nodiscard]]
bool is_finalized() noexcept;
102bool show_warnings() noexcept;
103bool tune_internals() noexcept;
128void push_finalize_hook(std::function<
void()> f);
130void fence(const std::
string& name );
133void print_configuration(std::ostream& os,
bool verbose = false);
146template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
147inline void* kokkos_malloc(
const std::string& arg_alloc_label,
148 const size_t arg_alloc_size) {
149 using MemorySpace =
typename Space::memory_space;
150 return Impl::SharedAllocationRecord<MemorySpace>::allocate_tracked(
151 MemorySpace(), arg_alloc_label, arg_alloc_size);
154template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
155inline void* kokkos_malloc(
const size_t arg_alloc_size) {
156 using MemorySpace =
typename Space::memory_space;
157 return Impl::SharedAllocationRecord<MemorySpace>::allocate_tracked(
158 MemorySpace(),
"no-label", arg_alloc_size);
161template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
162inline void kokkos_free(
void* arg_alloc) {
163 using MemorySpace =
typename Space::memory_space;
164 return Impl::SharedAllocationRecord<MemorySpace>::deallocate_tracked(
168template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
169inline void* kokkos_realloc(
void* arg_alloc,
const size_t arg_alloc_size) {
170 using MemorySpace =
typename Space::memory_space;
171 return Impl::SharedAllocationRecord<MemorySpace>::reallocate_tracked(
172 arg_alloc, arg_alloc_size);
189inline std::string scopeguard_correct_usage() {
192 " std::unique_ptr<Kokkos::ScopeGuard> guard =\n"
193 " !Kokkos::is_initialized() && !Kokkos::is_finalized()?\n"
194 " new ScopeGuard(argc,argv) : nullptr;\n");
197inline std::string scopeguard_create_while_initialized_warning() {
199 "Kokkos Error: Creating a ScopeGuard while Kokkos is initialized "
201 .append(scopeguard_correct_usage());
204inline std::string scopeguard_create_after_finalize_warning() {
206 "Kokkos Error: Creating a ScopeGuard after Kokkos was finalized "
208 .append(scopeguard_correct_usage());
211inline std::string scopeguard_destruct_after_finalize_warning() {
213 "Kokkos Error: Destroying a ScopeGuard after Kokkos was finalized "
215 .append(scopeguard_correct_usage());
220class KOKKOS_ATTRIBUTE_NODISCARD ScopeGuard {
222 template <
class... Args>
223#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) >= 201907
226 ScopeGuard(Args&&... args) {
227 if (is_initialized()) {
229 Impl::scopeguard_create_while_initialized_warning().c_str());
231 if (is_finalized()) {
232 Kokkos::abort(Impl::scopeguard_create_after_finalize_warning().c_str());
234 initialize(
static_cast<Args&&
>(args)...);
238 if (is_finalized()) {
239 Kokkos::abort(Impl::scopeguard_destruct_after_finalize_warning().c_str());
244 ScopeGuard& operator=(
const ScopeGuard&) =
delete;
245 ScopeGuard& operator=(ScopeGuard&&) =
delete;
246 ScopeGuard(
const ScopeGuard&) =
delete;
247 ScopeGuard(ScopeGuard&&) =
delete;
258template <
class ExecSpace,
class... Args>
259std::vector<ExecSpace> partition_space(ExecSpace
const& space, Args...) {
260 static_assert(is_execution_space<ExecSpace>::value,
261 "Kokkos Error: partition_space expects an Execution Space as "
264 (... && std::is_arithmetic_v<Args>),
265 "Kokkos Error: partitioning arguments must be integers or floats");
266 std::vector<ExecSpace> instances(
sizeof...(Args));
267 for (
int s = 0; s < int(
sizeof...(Args)); s++) instances[s] = space;
271template <
class ExecSpace,
class T>
272std::vector<ExecSpace> partition_space(ExecSpace
const& space,
273 std::vector<T>& weights) {
274 static_assert(is_execution_space<ExecSpace>::value,
275 "Kokkos Error: partition_space expects an Execution Space as "
278 std::is_arithmetic<T>::value,
279 "Kokkos Error: partitioning arguments must be integers or floats");
281 std::vector<ExecSpace> instances(weights.size());
282 for (
int s = 0; s < int(weights.size()); s++) instances[s] = space;
288#include <Kokkos_Crs.hpp>
289#include <Kokkos_WorkGraphPolicy.hpp>
294#include <impl/Kokkos_Combined_Reducer.hpp>
297#include <Kokkos_AcquireUniqueTokenImpl.hpp>
300#include <KokkosCore_Config_PostInclude.hpp>
305#if defined(KOKKOS_IMPL_PUSH_MACRO_MIN)
306#pragma pop_macro("min")
307#undef KOKKOS_IMPL_PUSH_MACRO_MIN
309#if defined(KOKKOS_IMPL_PUSH_MACRO_MAX)
310#pragma pop_macro("max")
311#undef KOKKOS_IMPL_PUSH_MACRO_MAX
317#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
318#undef KOKKOS_IMPL_PUBLIC_INCLUDE
319#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
Declaration and definition of Kokkos::pair.
Declaration and definition of Kokkos::Vectorization interface.