preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ginkgo.cpp
Go to the documentation of this file.
1#include "Ginkgo.hpp"
2
3#include "logging/Logger.hpp"
4
5#ifndef PRECICE_NO_GINKGO
6#include <Kokkos_Core.hpp>
7
8namespace precice::device {
9
10bool Ginkgo::weInitialized = false;
11
12void Ginkgo::initialize(int *argc, char ***argv)
13{
14 // We initialize Ginkgo internally through Kokkos
15 if (!Kokkos::is_initialized() && !Kokkos::is_finalized()) {
16 Kokkos::initialize(*argc, *argv);
17 }
18 weInitialized = true;
19}
20
21void Ginkgo::initialize(int nThreads, int deviceId)
22{
23 // We initialize Ginkgo internally through Kokkos
24 if (!Kokkos::is_initialized() && !Kokkos::is_finalized()) {
25 const int defaultDeviceID = -1;
26 // don't use and initialize the GPU if we don't use it
27 if (deviceId == defaultDeviceID)
28 Kokkos::initialize(Kokkos::InitializationSettings().set_num_threads(nThreads).set_disable_warnings(true));
29 else {
30 Kokkos::initialize(Kokkos::InitializationSettings().set_num_threads(nThreads).set_device_id(deviceId).set_disable_warnings(true));
31 }
32 }
33 weInitialized = true;
34}
35
37{
38 // we finalize internally through Kokkos as well
39 if (weInitialized && Kokkos::is_initialized()) {
40 Kokkos::finalize();
41 }
42}
43
44} // namespace precice::device
45
46#endif
static bool weInitialized
Whether we have initialized Ginkgo or if it was initialized by an application calling us.
Definition Ginkgo.hpp:15
static void finalize()
Definition Ginkgo.cpp:36
static void initialize(int *argc, char ***argv)
Definition Ginkgo.cpp:12