Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
accelerator.cpp
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
8 
9 #include "mfem.hpp"
10 
11 #include <memory>
12 
14 
15 namespace smith {
16 
17 namespace accelerator {
18 
19 // Restrict global to this file only
20 namespace {
21 std::unique_ptr<mfem::Device> device;
22 } // namespace
23 
25 {
26  SLIC_ERROR_ROOT_IF(device, "smith::accelerator::initializeDevice cannot be called more than once");
27  device = std::make_unique<mfem::Device>();
28  switch (exec_space) {
29  case ExecutionSpace::GPU:
30 #if defined(MFEM_USE_CUDA) && defined(SMITH_USE_CUDA_KERNEL_EVALUATION)
31  device->Configure("cuda");
32 #elif defined(MFEM_USE_HIP)
33  device->Configure("hip");
34 #endif
35  break;
36  case ExecutionSpace::CPU:
37  break;
38  case ExecutionSpace::Dynamic:
39  break;
40  }
41 }
42 
44 {
45  // Idempotent, no adverse affects if called multiple times
46  device.reset();
47 }
48 
49 } // namespace accelerator
50 
51 } // namespace smith
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
This file contains the all the necessary functions and macros required for logging as well as a helpe...
void initializeDevice(ExecutionSpace exec_space)
Initializes the device (GPU)
Definition: accelerator.cpp:24
void terminateDevice()
Cleans up the device, if applicable.
Definition: accelerator.cpp:43
Accelerator functionality.
Definition: smith.cpp:36
ExecutionSpace
enum used for signalling whether or not to perform certain calculations on the CPU or GPU
Definition: accelerator.hpp:88