From: Daniel Arndt Date: Wed, 30 Nov 2022 16:32:44 +0000 (+0000) Subject: Add files for making sure Kokkos is initialized X-Git-Tag: v9.5.0-rc1~697^2~44 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ce8b103213a35295b498151c85787d0cc6ebf04;p=dealii.git Add files for making sure Kokkos is initialized --- diff --git a/include/deal.II/base/kokkos.h b/include/deal.II/base/kokkos.h new file mode 100644 index 0000000000..7117f02fa8 --- /dev/null +++ b/include/deal.II/base/kokkos.h @@ -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_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 index 0000000000..629c0063d1 --- /dev/null +++ b/source/base/kokkos.cc @@ -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 + +#include +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +namespace Impl +{ + void + ensure_kokkos_initialized() + { + if (!Kokkos::is_initialized()) + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::initialize(); + std::atexit(Kokkos::finalize); + } +} // namespace Impl +DEAL_II_NAMESPACE_CLOSE