15#define _CRT_SECURE_NO_WARNINGS 1
25#include <boost/algorithm/string/classification.hpp>
26#include <boost/algorithm/string/split.hpp>
27#include <boost/program_options/options_description.hpp>
28#include <boost/program_options/parsers.hpp>
29#include <boost/program_options/variables_map.hpp>
50 return "INVALID_VERBOSITY_LEVEL";
55 const std::string &str,
56 std::function<
size_t(
const std::string & ,
size_t ,
size_t & )> findsplit)
58 std::list<std::string> ret;
62 size_t sepsize = std::string::npos;
63 size_t tmpfind = findsplit(str, find, sepsize);
64 if (tmpfind >= find && tmpfind != std::string::npos)
66 ret.push_back(str.substr(find, tmpfind - find));
67 find = tmpfind + sepsize;
71 if (str.size() > find)
73 ret.push_back(str.substr(find));
99 std::cerr <<
"ETISS: " <<
etiss::toString(level) <<
": " << msg << std::endl;
101 std::cout <<
"ETISS: " <<
etiss::toString(level) <<
": " << msg << std::endl;
119 std::vector<std::string> ret;
123 for (
unsigned pos = 0; pos < cmdline.length(); pos++)
130 switch (cmdline[pos])
144 switch (cmdline[pos])
153 if (pos + 1 < cmdline.length())
156 tmp = tmp + cmdline[pos];
160 tmp = tmp + cmdline[pos];
165 switch (cmdline[pos])
174 if (pos + 1 < cmdline.length())
177 tmp = tmp + cmdline[pos];
181 tmp = tmp + cmdline[pos];
184 if (pos + 1 >= cmdline.length())
191 std::cerr <<
"ERROR: etiss::parseCommand(1) parser failed" << std::endl;
205 std::list<std::string> list;
206 list.insert(list.end(), vec.begin(), vec.end());
227std::string Configuration::get<std::string>(
const std::string &key, std::string default_,
bool *default_used)
230 std::lock_guard<std::mutex> lock(mu_);
231 auto find = cfg_.find(key);
232 if (find != cfg_.end())
235 *default_used =
false;
243 return etiss::cfg().
get<std::string>(key, default_, default_used);
248 *default_used =
true;
254bool Configuration::get<bool>(
const std::string &key,
bool default_,
bool *default_used)
256 std::string val =
get<std::string>(key, default_ ?
"true" :
"false", default_used);
270 if (val ==
"true" || val ==
"1" || val ==
"on")
275 if (val ==
"false" || val ==
"0" || val ==
"off")
285int Configuration::get<int>(
const std::string &key,
int default_,
bool *default_used)
290 return std::stoi(val, 0, 0);
295 *default_used =
true;
297 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
303unsigned Configuration::get<unsigned>(
const std::string &key,
unsigned default_,
bool *default_used)
308 return static_cast<unsigned>(std::stoull(val, 0, 0));
313 *default_used =
true;
316 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
321uint64_t Configuration::get<uint64_t>(
const std::string &key, uint64_t default_,
bool *default_used)
326 return std::stoull(val, 0, 0);
331 *default_used =
true;
334 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
343 return get<bool>(
"debug",
false);
348 std::lock_guard<std::mutex> lock(mu_);
349 if (final_.find(key) != final_.end())
356 std::lock_guard<std::mutex> lock(mu_);
357 return cfg_.find(key) != cfg_.end();
362 namespace po = boost::program_options;
366 if (
s.find(
"-f") == 0)
368 size_t epos =
s.find_first_of(
'=');
369 if (
s.length() > 5 &&
s.substr(2, 3) ==
"no-")
371 if (epos == std::string::npos)
373 std::string tmp =
s.substr(5);
378 return make_pair(tmp, std::string(
"false"));
382 std::string tmp =
s.substr(5, epos - 5);
385 return make_pair(std::string(), std::string());
390 if (epos == std::string::npos)
392 std::string tmp =
s.substr(2);
397 return make_pair(
s.substr(2), std::string(
"true"));
401 std::string tmp =
s.substr(2, epos - 2);
402 std::string tval =
s.substr(epos + 1);
406 return make_pair(
s.substr(2), tval);
408 return make_pair(std::string(), std::string());
412 return make_pair(std::string(), std::string());
417 std::list<std::string> ret;
418 for (
auto iter = args.begin(); iter != args.end(); iter++)
420 const std::string &p = *iter;
424 if (p[0] ==
'-' && p[1] ==
'f')
428 size_t epos = p.find_first_of(
'=');
430 if (p.length() > 5 && p[2] ==
'n' && p[3] ==
'o' && p[4] ==
'-')
432 if (epos == std::string::npos)
434 std::string tmp = p.substr(5);
437 set<std::string>(tmp,
"false");
442 std::string tmp = p.substr(5, epos - 5);
449 if (epos == std::string::npos)
451 std::string tmp = p.substr(2);
454 set<std::string>(tmp,
"true");
459 std::string tmp = p.substr(2, epos - 2);
460 std::string tval = p.substr(epos + 1);
463 set<std::string>(tmp, tval);
468 if (p[0] ==
'-' && p[1] ==
'o')
471 std::string tmp = p.substr(2);
473 if (iter != args.end())
477 set<std::string>(tmp, *iter);
500 for (
auto iter = cfg_.begin(); iter != cfg_.end(); iter++)
502 ret[iter->first] = iter->second;
515 std::lock_guard<std::mutex> lock(mu_);
521 std::lock_guard<std::mutex> lock(mu_);
522 announced_[key] = std::tuple<std::string, std::string, std::string>(type, values, description);
527 std::lock_guard<std::mutex> lock(mu_);
533 std::string cfgName_ = cfgName;
540 static std::map<std::string, etiss::Configuration>
cfg;
541 if (
cfg.find(cfgName_) ==
cfg.end())
546 return cfg[cfgName_];
550 std::string cfgName =
"global";
557 auto libPathLoc = etissLib.find_last_of(
"/\\");
558 auto libPath = etissLib.substr(0, libPathLoc);
559 auto etissPathLoc = libPath.find_last_of(
"/\\");
560 return libPath.substr(0, etissPathLoc);
570 std::vector<std::string> x;
571 std::string range =
cfg().
get<std::string>(
"jit.external_headers",
"");
572 boost::split(x, range, boost::is_any_of(
";, "));
578 std::vector<std::string> x;
579 std::string range =
cfg().
get<std::string>(
"jit.external_libs",
"");
580 boost::split(x, range, boost::is_any_of(
";, "));
586 std::vector<std::string> x;
587 std::string range =
cfg().
get<std::string>(
"jit.external_header_paths",
"");
588 boost::split(x, range, boost::is_any_of(
";, "));
594 std::vector<std::string> x;
595 std::string range =
cfg().
get<std::string>(
"jit.external_lib_paths",
"");
596 boost::split(x, range, boost::is_any_of(
";, "));
601#if ETISS_USE_CONSTEXPR
604 "ETISS detected an invalid endianness configuartion of the floating point library. please change in the "
605 "file etiss/fpu/386-GCC.h the line #define LITTLEENDIAN (or similar) to #define BIGENDIAN");
609 "ETISS detected an invalid endianness configuartion of the floating point library. please change in the "
610 "file etiss/fpu/386-GCC.h the line #define BIGENDIAN (or similar) to #define LITTLEENDIAN");
613#pragma message("ETISS cannot check if endianess is configured correctly due to missing constexpr support")
Verbosity etiss_verbosity
bool etiss_log_to_stderr
verbosity level variable
static bool etiss_cfg_inConstructor
general configuration and logging
__device__ __2f16 float bool s
static __inline__ uint64_t
simple class to hold configuration options
std::map< std::string, std::string > & config()
access to the configuration key value map
void announce(std::string key, std::string type=std::string(), std::string values=std::string(), std::string description=std::string())
add a possible option to a list.
std::map< std::string, std::string > listFullConfiguration()
get a copy of the configuration as a map
static std::pair< std::string, std::string > set_cmd_line_boost(const std::string &s)
void makeFinal(const std::string &key)
makes an option final (option can no longer be changed)
std::map< std::string, std::tuple< std::string, std::string, std::string > > getAnnounced() const
get a map copy with announced options
bool isSet(std::string val)
return true if the value of an configuration key has been set
bool debug()
Get the value of the key "debug".
void remove(const std::string &key)
removes a key value mapping
bool set(const std::string &key, T value)
template function to set the value of a configuration key.
std::map< std::string, std::string > cfg_
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
std::vector< std::string > parseCommands(const std::string &cmdline)
std::list< std::string > split(const std::string &str, std::function< size_t(const std::string &, size_t, size_t &)> findsplit)
std::string jitFiles()
Get ETISS JIT files path.
void logC(Verbosity level, std::function< std::string(void)> msgGen)
write log message at the given level.
std::vector< std::string > jitExtLibPaths()
Get ETISS JIT external path.
std::string Configuration::get< std::string >(const std::string &key, std::string default_, bool *default_used)
std::string toString(const T &val)
conversion of type T to std::string.
std::string GetCurrentModulePath()
Returns the abolute path with filename to the own dynamic library.
std::string installDir()
Get ETISS installation directory.
std::vector< std::string > jitExtLibraries()
Get ETISS JIT external libraries.
std::vector< std::string > jitExtHeaders()
Get ETISS JIT external headers.
std::vector< std::string > jitExtHeaderPaths()
Get ETISS JIT external path.
Verbosity
Enumeration type for the log levels.
endian_t getEndianness()
evaluates the endianness of the current build as a constexpr.
Verbosity & verbosity()
Get log level reference.
void log(Verbosity level, std::string msg)
write log message at the given level.