include/pops/core/foundation/kokkos_env.hpp Source FileΒΆ

adc_cpp: include/pops/core/foundation/kokkos_env.hpp Source File
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
kokkos_env.hpp
Go to the documentation of this file.
1
12
13#pragma once
14
15#ifdef POPS_HAS_KOKKOS
16#include <Kokkos_Core.hpp>
17
18#include <cstdlib> // std::atexit
19#endif
20
21namespace pops {
22
23#ifdef POPS_HAS_KOKKOS
24namespace detail {
29inline void ensure_kokkos_initialized() {
30 if (!Kokkos::is_initialized() && !Kokkos::is_finalized()) {
31 Kokkos::initialize();
32 std::atexit([] {
33 if (Kokkos::is_initialized())
34 Kokkos::finalize();
35 });
36 }
37}
38} // namespace detail
39#endif
40
43inline void device_fence() {
44#ifdef POPS_HAS_KOKKOS
45 if (Kokkos::is_initialized())
46 Kokkos::fence();
47#endif
48}
49
50} // namespace pops
Definition amr_hierarchy.hpp:29
void device_fence()
Device barrier: waits for in-flight kernels to finish before a HOST access to unified memory.
Definition kokkos_env.hpp:43