preCICE
Loading...
Searching...
No Matches
Device.cpp
Go to the documentation of this file.
1#include "Device.hpp"
2
3#include "logging/Logger.hpp"
4
5#if !defined(PRECICE_NO_GINKGO) || !defined(PRECICE_NO_KOKKOS_KERNELS)
6#include <Kokkos_Core.hpp>
7
8namespace precice::device {
9
10bool Device::weInitialized = false;
11
12void Device::initialize(int *argc, char ***argv)
13{
14 if (!Kokkos::is_initialized() && !Kokkos::is_finalized()) {
15 Kokkos::initialize(*argc, *argv);
16 weInitialized = true;
17 }
18}
19
20void Device::initialize(int nThreads, int deviceId)
21{
22 if (!Kokkos::is_initialized() && !Kokkos::is_finalized()) {
23 const int autoDeviceID = -1;
24 // Strategy to select a device automatically from the GPUs available for execution. Must be either "mpi_rank" for round-robin assignment based on the local MPI rank or "random".
25 // If kokkos was compiled with GPU as one backend, the GPU will always be initialized
26 if (deviceId == autoDeviceID)
27 Kokkos::initialize(Kokkos::InitializationSettings().set_num_threads(nThreads).set_map_device_id_by("mpi_rank").set_disable_warnings(true).set_print_configuration(false));
28 else {
29 Kokkos::initialize(Kokkos::InitializationSettings().set_num_threads(nThreads).set_device_id(deviceId).set_disable_warnings(true).set_print_configuration(false));
30 }
31 weInitialized = true;
32 }
33}
34
36{
37 if (weInitialized && Kokkos::is_initialized()) {
38 Kokkos::finalize();
39 }
40}
41
42} // namespace precice::device
43
44#endif
static void finalize()
Definition Device.cpp:35
static bool weInitialized
Whether we have initialized Ginkgo or if it was initialized by an application calling us.
Definition Device.hpp:15
static void initialize(int *argc, char ***argv)
Definition Device.cpp:12