Optimized Belief Propagation (CPU and GPU)
InputSignature.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
29 #ifndef INPUT_SIGNATURE_H_
30 #define INPUT_SIGNATURE_H_
31 
32 #include <string_view>
33 #include <string>
34 #include <ostream>
35 #include <limits>
36 #include <optional>
38 
45 public:
52  explicit InputSignature(const std::array<std::string_view, 3>& in_sig_strings);
53 
62  explicit InputSignature(
63  std::optional<unsigned int> data_type_size,
64  std::optional<unsigned int> eval_set_num,
65  std::optional<bool> use_templated_loop_iters);
66 
79  bool operator<(const InputSignature& rhs) const;
80 
88  bool operator==(const InputSignature& rhs) const;
89 
100  bool EqualsUsingAny(const InputSignature& rhs) const;
101 
102  std::string DataTypeStr() const {
103  if (!data_type_size_) {
104  return "ANY";
105  }
106  if (*data_type_size_ == 2) {
107  return "HALF";
108  }
109  else if (*data_type_size_ == 4) {
110  return "FLOAT";
111  }
112  else if (*data_type_size_ == 8) {
113  return "DOUBLE";
114  }
115  return "UNKNOWN";
116  }
117 
118  std::string EvalSetNumStr() const {
119  if (!eval_set_num_) {
120  return "ANY";
121  }
122  else {
123  return std::to_string(*eval_set_num_);
124  }
125  }
126 
127  unsigned int EvalSetNum() const {
128  if (!eval_set_num_) {
129  return std::numeric_limits<unsigned int>::max();
130  }
131  else {
132  return *eval_set_num_;
133  }
134  }
135 
136  std::string UseTemplatedLoopItersStr() const {
137  if (!use_templated_loop_iters_) {
138  return "BOTH";
139  }
140  return ((!(*use_templated_loop_iters_)) ?
141  std::string(run_eval::kBoolValFalseTrueDispStr[0]) :
142  std::string(run_eval::kBoolValFalseTrueDispStr[1]));
143  }
144 
149  use_templated_loop_iters_.reset();
150  }
151 
156  data_type_size_.reset();
157  }
158 
159  std::optional<bool> TemplatedLoopIters() const {
160  return use_templated_loop_iters_;
161  }
162 
170  friend std::ostream& operator<<(
171  std::ostream& os,
172  const InputSignature& eval_input_sig);
173 
174 private:
175  std::optional<unsigned int> data_type_size_;
176  std::optional<unsigned int> eval_set_num_;
177  std::optional<bool> use_templated_loop_iters_;
178 };
179 
180 //overloaded << operator to write InputSignature object to stream
181 inline std::ostream& operator<<(
182  std::ostream& os,
183  const InputSignature& eval_input_sig)
184 {
185  os << eval_input_sig.DataTypeStr() << " " << eval_input_sig.EvalSetNumStr()
186  << " " << eval_input_sig.UseTemplatedLoopItersStr();
187  return os;
188 }
189 
190 #endif //INPUT_SIGNATURE_H_
std::ostream & operator<<(std::ostream &os, const InputSignature &eval_input_sig)
Contains namespace with enums and constants for implementation run evaluation.
Class defines input signature for evaluation run that contains evaluation set number,...
void RemoveTemplatedLoopIterSetting()
Remove templated loop iter setting and change it to "any".
std::string UseTemplatedLoopItersStr() const
bool operator==(const InputSignature &rhs) const
Equality operator for comparing evaluation input signatures.
std::string EvalSetNumStr() const
std::optional< bool > TemplatedLoopIters() const
friend std::ostream & operator<<(std::ostream &os, const InputSignature &eval_input_sig)
Overloaded << operator to write InputSignature object to stream.
void RemoveDatatypeSetting()
Remove data type setting and change it to "any".
bool operator<(const InputSignature &rhs) const
Less than operator for comparing evaluation input signatures so they can be ordered Operator needed ...
std::string DataTypeStr() const
InputSignature(const std::array< std::string_view, 3 > &in_sig_strings)
Constructor to generate evaluation input signature from string array with strings corresponding to ea...
unsigned int EvalSetNum() const
bool EqualsUsingAny(const InputSignature &rhs) const
Alternate "equal" operator where an attribute is considered "equal" in cases where one side is "ANY" ...
constexpr std::array< std::string_view, 2 > kBoolValFalseTrueDispStr
Define string for display of "true" and "false" values of bool value.