openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
target.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #include <map>
5 #include <string>
6 #include <sstream>
7 
8 #include "target.h"
9 
10 namespace limpet {
11 
12  namespace {
15  static std::map<std::string, Target> const map = {
16  {"cpu", Target::CPU},
17  {"mlir-cpu", Target::MLIR_CPU},
18  {"mlir-rocm", Target::MLIR_ROCM},
19  {"mlir-cuda", Target::MLIR_CUDA},
20  {"auto", Target::AUTO}
21 };
22 }
23 
24 Target get_target_from_string(std::string const str) {
25  auto t = map.find(str);
26  if (t == map.end()) {
27  return Target::UNKNOWN;
28  }
29  else {
30  return t->second;
31  }
32 }
33 
34 std::string get_string_from_target(Target const target) {
35  for (auto t: map) {
36  if (t.second == target) {
37  return t.first;
38  }
39  }
40  return "unknown";
41 }
42 
43 std::string get_target_list_string() {
44  std::stringstream list;
45  for (auto target : map) {
46  list << target.first << ", ";
47  }
48  // remove last ', '
49  return list.str().substr(0, list.str().length() - 2);
50 }
51 
52 bool is_gpu(Target const target) {
53  return target == Target::MLIR_CUDA || target == Target::MLIR_ROCM;
54 }
55 
56 bool is_concrete(Target const target) {
57  return target > Target::UNKNOWN && target < Target::N_TARGETS;
58 }
59 
60 } // namespace limpet
bool is_concrete(Target const target)
Checks if target is a real, concrete target.
Definition: target.cc:56
Target
enum that represents different targets to run ionic models on.
Definition: target.h:30
@ AUTO
Definition: target.h:31
@ MLIR_ROCM
ROCM code for AMD GPUs generated with MLIR.
Definition: target.h:35
@ CPU
baseline CPU model generated with the original opencarp code generator
Definition: target.h:33
@ UNKNOWN
special value to handle unknown targets
Definition: target.h:32
@ MLIR_CUDA
CUDA code for NVIDIA GPUs generated with MLIR.
Definition: target.h:36
@ N_TARGETS
a token to indicate the maximum number of targets
Definition: target.h:37
@ MLIR_CPU
vectorized CPU code generated with MLIR
Definition: target.h:34
std::string get_string_from_target(Target const target)
Get a string representation of a given target.
Definition: target.cc:34
std::string get_target_list_string()
Returns a string containing the list of available targets.
Definition: target.cc:43
bool is_gpu(Target const target)
Checks if this is a GPU target.
Definition: target.cc:52
Target get_target_from_string(std::string const str)
Returns a value from the Target enum from a given string.
Definition: target.cc:24
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...