36#ifndef PECLET_CORE_PYTHON_KOKKOS_TEARDOWN_HPP
37#define PECLET_CORE_PYTHON_KOKKOS_TEARDOWN_HPP
39#include <nanobind/nanobind.h>
42#include <Kokkos_Core.hpp>
69 static auto* s =
new std::set<Releasable*>;
76 static auto* v =
new std::vector<std::function<
void()>>;
99 if (Kokkos::is_initialized() && !Kokkos::is_finalized())
109 nb::handle h = nb::find(
self);
111 nb::inst_destruct(h);
117 if (!Kokkos::is_initialized()) {
128 Kokkos::InitializationSettings
settings;
129#if defined(KOKKOS_ENABLE_OPENMP)
131 std::is_same_v<Kokkos::DefaultHostExecutionSpace, Kokkos::OpenMP>;
140 "Release every live object and zero-copy array of this module, then Kokkos::finalize() "
141 "(deterministic teardown; also run automatically at interpreter exit). Idempotent. After "
142 "it, the module's solver objects and *_view arrays must not be used.");
143 m.attr(
"execution_space") = nb::str(Kokkos::DefaultExecutionSpace::name());
144 nb::module_::import_(
"atexit").attr(
"register")(nb::cpp_function(&
shutdown));
Base of everything on the binding side that owns Kokkos Views on Python's behalf.
Releasable & operator=(const Releasable &) noexcept
Releasable(Releasable &&) noexcept
Releasable(const Releasable &) noexcept
static std::set< Releasable * > & registry()
This module's live registry.
Releasable & operator=(Releasable &&) noexcept
virtual void release() noexcept=0
void shutdown() noexcept
release_all() and then Kokkos::finalize().
void add_release_hook(std::function< void()> f)
void destruct_bound_instance(T *self) noexcept
Release a bound wrapper by destroying its C++ instance in place (for types whose Kokkos state cannot ...
void install(nb::module_ &m)
Module setup: initialize Kokkos (once per module — each module carries its own static Kokkos),...
void release_all() noexcept
Drop every Kokkos View owned on Python's behalf in this module (registry + hooks).
std::vector< std::function< void()> > & release_hooks()
Extra release callbacks (e.g. a C++ class's own releaseAll), run after the registry.
int defaultHostThreads(bool hostBackendSizesItself)
The host thread count to hand a backend that has not been told one, or 0 for "say nothing".
Kokkos::View< T *, MemSpace > View
1D device array.