openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
target.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
19 #include <map>
20 #include <string>
21 #include <sstream>
22 
23 #include "target.h"
24 
25 namespace limpet {
26 
27  namespace {
30  static std::map<std::string, Target> const map = {
31  {"cpu", Target::CPU},
32  {"mlir-cpu", Target::MLIR_CPU},
33  {"mlir-rocm", Target::MLIR_ROCM},
34  {"mlir-cuda", Target::MLIR_CUDA},
35  {"auto", Target::AUTO}
36 };
37 }
38 
39 Target get_target_from_string(std::string const str) {
40  auto t = map.find(str);
41  if (t == map.end()) {
42  return Target::UNKNOWN;
43  }
44  else {
45  return t->second;
46  }
47 }
48 
49 std::string get_string_from_target(Target const target) {
50  for (auto t: map) {
51  if (t.second == target) {
52  return t.first;
53  }
54  }
55  return "unknown";
56 }
57 
58 std::string get_target_list_string() {
59  std::stringstream list;
60  for (auto target : map) {
61  list << target.first << ", ";
62  }
63  // remove last ', '
64  return list.str().substr(0, list.str().length() - 2);
65 }
66 
67 bool is_gpu(Target const target) {
68  return target == Target::MLIR_CUDA || target == Target::MLIR_ROCM;
69 }
70 
71 bool is_concrete(Target const target) {
72  return target > Target::UNKNOWN && target < Target::N_TARGETS;
73 }
74 
75 } // namespace limpet
bool is_concrete(Target const target)
Checks if target is a real, concrete target.
Definition: target.cc:71
Target
enum that represents different targets to run ionic models on.
Definition: target.h:45
@ AUTO
Definition: target.h:46
@ MLIR_ROCM
ROCM code for AMD GPUs generated with MLIR.
Definition: target.h:50
@ CPU
baseline CPU model generated with the original opencarp code generator
Definition: target.h:48
@ UNKNOWN
special value to handle unknown targets
Definition: target.h:47
@ MLIR_CUDA
CUDA code for NVIDIA GPUs generated with MLIR.
Definition: target.h:51
@ N_TARGETS
a token to indicate the maximum number of targets
Definition: target.h:52
@ MLIR_CPU
vectorized CPU code generated with MLIR
Definition: target.h:49
std::string get_string_from_target(Target const target)
Get a string representation of a given target.
Definition: target.cc:49
std::string get_target_list_string()
Returns a string containing the list of available targets.
Definition: target.cc:58
bool is_gpu(Target const target)
Checks if this is a GPU target.
Definition: target.cc:67
Target get_target_from_string(std::string const str)
Returns a value from the Target enum from a given string.
Definition: target.cc:39
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...