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>
50#include <Kokkos_Clamp.hpp>
51#include <Kokkos_MinMax.hpp>
52#include <Kokkos_MathematicalConstants.hpp>
53#include <Kokkos_MathematicalFunctions.hpp>
54#include <Kokkos_MathematicalSpecialFunctions.hpp>
55#include <Kokkos_NumericTraits.hpp>
56#include <Kokkos_BitManipulation.hpp>
57#include <Kokkos_Swap.hpp>
58#include <Kokkos_MemoryPool.hpp>
59#include <Kokkos_Array.hpp>
60#include <Kokkos_View.hpp>
63#include <Kokkos_hwloc.hpp>
64#include <Kokkos_Timer.hpp>
65#include <Kokkos_Tuners.hpp>
66#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
67#include <Kokkos_TaskScheduler.hpp>
69#include <Kokkos_Complex.hpp>
70#include <Kokkos_CopyViews.hpp>
71#include <impl/Kokkos_TeamMDPolicy.hpp>
72#include <impl/Kokkos_InitializationSettings.hpp>
82void initialize(
int& argc,
char* argv[]);
85 InitializationSettings
const& settings = InitializationSettings());
89void pre_initialize(
const InitializationSettings& settings);
91void post_initialize(
const InitializationSettings& settings);
97void declare_configuration_metadata(
const std::string& category,
98 const std::string& key,
99 const std::string& value);
103[[nodiscard]]
bool is_initialized() noexcept;
104[[nodiscard]]
bool is_finalized() noexcept;
106[[nodiscard]]
int device_id() noexcept;
107[[nodiscard]]
int num_devices() noexcept;
108[[nodiscard]]
int num_threads() noexcept;
110bool show_warnings() noexcept;
111bool tune_internals() noexcept;
136void push_finalize_hook(std::function<
void()> f);
138void fence(const std::
string& name );
141void print_configuration(std::ostream& os,
bool verbose = false);
154template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
155inline void* kokkos_malloc(
const std::string& arg_alloc_label,
156 const size_t arg_alloc_size) {
157 using MemorySpace =
typename Space::memory_space;
158 return Impl::SharedAllocationRecord<MemorySpace>::allocate_tracked(
159 MemorySpace(), arg_alloc_label, arg_alloc_size);
162template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
163inline void* kokkos_malloc(
const size_t arg_alloc_size) {
164 using MemorySpace =
typename Space::memory_space;
165 return Impl::SharedAllocationRecord<MemorySpace>::allocate_tracked(
166 MemorySpace(),
"no-label", arg_alloc_size);
169template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
170inline void kokkos_free(
void* arg_alloc) {
171 using MemorySpace =
typename Space::memory_space;
172 return Impl::SharedAllocationRecord<MemorySpace>::deallocate_tracked(
176template <
class Space = Kokkos::DefaultExecutionSpace::memory_space>
177inline void* kokkos_realloc(
void* arg_alloc,
const size_t arg_alloc_size) {
178 using MemorySpace =
typename Space::memory_space;
179 return Impl::SharedAllocationRecord<MemorySpace>::reallocate_tracked(
180 arg_alloc, arg_alloc_size);
197inline std::string scopeguard_correct_usage() {
200 " std::unique_ptr<Kokkos::ScopeGuard> guard =\n"
201 " !Kokkos::is_initialized() && !Kokkos::is_finalized()?\n"
202 " new ScopeGuard(argc,argv) : nullptr;\n");
205inline std::string scopeguard_create_while_initialized_warning() {
207 "Kokkos Error: Creating a ScopeGuard while Kokkos is initialized "
209 .append(scopeguard_correct_usage());
212inline std::string scopeguard_create_after_finalize_warning() {
214 "Kokkos Error: Creating a ScopeGuard after Kokkos was finalized "
216 .append(scopeguard_correct_usage());
219inline std::string scopeguard_destruct_after_finalize_warning() {
221 "Kokkos Error: Destroying a ScopeGuard after Kokkos was finalized "
223 .append(scopeguard_correct_usage());
228class KOKKOS_ATTRIBUTE_NODISCARD ScopeGuard {
230 template <
class... Args>
231#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) >= 201907
234 ScopeGuard(Args&&... args) {
235 if (is_initialized()) {
237 Impl::scopeguard_create_while_initialized_warning().c_str());
239 if (is_finalized()) {
240 Kokkos::abort(Impl::scopeguard_create_after_finalize_warning().c_str());
242 initialize(
static_cast<Args&&
>(args)...);
246 if (is_finalized()) {
247 Kokkos::abort(Impl::scopeguard_destruct_after_finalize_warning().c_str());
252 ScopeGuard& operator=(
const ScopeGuard&) =
delete;
253 ScopeGuard& operator=(ScopeGuard&&) =
delete;
254 ScopeGuard(
const ScopeGuard&) =
delete;
255 ScopeGuard(ScopeGuard&&) =
delete;
261namespace Experimental {
266template <
class ExecSpace,
class... Args>
267std::vector<ExecSpace> partition_space(ExecSpace
const& space, Args...) {
268 static_assert(is_execution_space<ExecSpace>::value,
269 "Kokkos Error: partition_space expects an Execution Space as "
272 (... && std::is_arithmetic_v<Args>),
273 "Kokkos Error: partitioning arguments must be integers or floats");
274 std::vector<ExecSpace> instances(
sizeof...(Args));
275 for (
int s = 0; s < int(
sizeof...(Args)); s++) instances[s] = space;
279template <
class ExecSpace,
class T>
280std::vector<ExecSpace> partition_space(ExecSpace
const& space,
281 std::vector<T>
const& weights) {
282 static_assert(is_execution_space<ExecSpace>::value,
283 "Kokkos Error: partition_space expects an Execution Space as "
286 std::is_arithmetic_v<T>,
287 "Kokkos Error: partitioning arguments must be integers or floats");
289 std::vector<ExecSpace> instances(weights.size());
290 for (
int s = 0; s < int(weights.size()); s++) instances[s] = space;
296#include <Kokkos_Crs.hpp>
297#include <Kokkos_WorkGraphPolicy.hpp>
302#include <impl/Kokkos_Combined_Reducer.hpp>
305#include <Kokkos_AcquireUniqueTokenImpl.hpp>
310#if defined(KOKKOS_IMPL_PUSH_MACRO_MIN)
311#pragma pop_macro("min")
312#undef KOKKOS_IMPL_PUSH_MACRO_MIN
314#if defined(KOKKOS_IMPL_PUSH_MACRO_MAX)
315#pragma pop_macro("max")
316#undef KOKKOS_IMPL_PUSH_MACRO_MAX
322#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
323#undef KOKKOS_IMPL_PUBLIC_INCLUDE
324#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
Declaration and definition of Kokkos::pair.
Declaration and definition of Kokkos::Vectorization interface.
ScopeGuard Some user scope issues have been identified with some Kokkos::finalize calls; ScopeGuard a...