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 <unordered_map>
20 #include <string>
21 #include <sstream>
22 
23 #include "target.h"
24 
25 namespace limpet {
26 
27  namespace {
30  static std::unordered_map<std::string, Target const> const map = { {"cpu",
31  Target::CPU}, {"mlir-cpu", Target::MLIR_CPU}, {"mlir-rocm",
32  Target::MLIR_ROCM}, {"mlir-cuda", Target::MLIR_CUDA},
33  {"auto", Target::AUTO}};
34  }
35 
36 Target get_target_from_string(std::string const str) {
37  auto t = map.find(str);
38  if (t == map.end()) {
39  return Target::UNKNOWN;
40  }
41  else {
42  return t->second;
43  }
44 }
45 
46 std::string get_string_from_target(Target const target) {
47  for (auto t: map) {
48  if (t.second == target) {
49  return t.first;
50  }
51  }
52  return "unknown";
53 }
54 
55 std::string get_target_list_string() {
56  std::stringstream list;
57  for (auto target : map) {
58  list << target.first << ", ";
59  }
60  // remove last ', '
61  return list.str().substr(0, list.str().length() - 2);
62 }
63 
64 bool is_gpu(Target const target) {
65  return target == Target::MLIR_CUDA || target == Target::MLIR_ROCM;
66 }
67 
68 bool is_concrete(Target const target) {
69  return target > Target::UNKNOWN && target < Target::N_TARGETS;
70 }
71 
72 } // namespace limpet
std::string get_string_from_target(Target const target)
Get a string representation of a given target.
Definition: target.cc:46
vectorized CPU code generated with MLIR
Definition: target.h:49
bool is_gpu(Target const target)
Checks if this is a GPU target.
Definition: target.cc:64
special value to handle unknown targets
Definition: target.h:47
std::string get_target_list_string()
Returns a string containing the list of available targets.
Definition: target.cc:55
a token to indicate the maximum number of targets
Definition: target.h:52
bool is_concrete(Target const target)
Checks if target is a real, concrete target.
Definition: target.cc:68
Defines valid targets for an ionic model to run on and an allocator for allocating memory on a specif...
baseline CPU model generated with the original opencarp code generator
Definition: target.h:48
CUDA code for NVIDIA GPUs generated with MLIR.
Definition: target.h:51
Target get_target_from_string(std::string const str)
Returns a value from the Target enum from a given string.
Definition: target.cc:36
Target
enum that represents different targets to run ionic models on.
Definition: target.h:45
ROCM code for AMD GPUs generated with MLIR.
Definition: target.h:50