]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add files for making sure Kokkos is initialized
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 30 Nov 2022 16:32:44 +0000 (16:32 +0000)
committerDaniel Arndt <arndtd@ornl.gov>
Thu, 8 Dec 2022 22:13:14 +0000 (17:13 -0500)
include/deal.II/base/kokkos.h [new file with mode: 0644]
source/base/kokkos.cc [new file with mode: 0644]

diff --git a/include/deal.II/base/kokkos.h b/include/deal.II/base/kokkos.h
new file mode 100644 (file)
index 0000000..7117f02
--- /dev/null
@@ -0,0 +1,31 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2011 - 2021 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii_kokkos_h
+#define dealii_kokkos_h
+
+#include <deal.II/base/config.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace Impl
+{
+  void
+  ensure_kokkos_initialized();
+}
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif
diff --git a/source/base/kokkos.cc b/source/base/kokkos.cc
new file mode 100644 (file)
index 0000000..629c006
--- /dev/null
@@ -0,0 +1,59 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2011 - 2021 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+#include <deal.II/base/kokkos.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/vector_memory.h>
+
+#include <Kokkos_Core.hpp>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace Impl
+{
+  void
+  ensure_kokkos_initialized()
+  {
+    if (!Kokkos::is_initialized())
+      GrowingVectorMemory<
+        LinearAlgebra::distributed::Vector<double, MemorySpace::Host>>{};
+    GrowingVectorMemory<
+      LinearAlgebra::distributed::Vector<float, MemorySpace::Host>>{};
+    GrowingVectorMemory<
+      LinearAlgebra::distributed::Vector<double, MemorySpace::Device>>{};
+    GrowingVectorMemory<
+      LinearAlgebra::distributed::Vector<float, MemorySpace::Device>>{};
+    Kokkos::push_finalize_hook(
+      GrowingVectorMemory<
+        LinearAlgebra::distributed::Vector<double, MemorySpace::Host>>::
+        release_unused_memory);
+    Kokkos::push_finalize_hook(
+      GrowingVectorMemory<
+        LinearAlgebra::distributed::Vector<float, MemorySpace::Host>>::
+        release_unused_memory);
+    Kokkos::push_finalize_hook(
+      GrowingVectorMemory<
+        LinearAlgebra::distributed::Vector<double, MemorySpace::Device>>::
+        release_unused_memory);
+    Kokkos::push_finalize_hook(
+      GrowingVectorMemory<
+        LinearAlgebra::distributed::Vector<float, MemorySpace::Device>>::
+        release_unused_memory);
+    Kokkos::initialize();
+    std::atexit(Kokkos::finalize);
+  }
+} // namespace Impl
+DEAL_II_NAMESPACE_CLOSE

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.