Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
Config.hpp
Go to the documentation of this file.
1#ifndef PROTEUS_CONFIG_HPP
2#define PROTEUS_CONFIG_HPP
3
4#include <string>
5
6#include "proteus/Logger.hpp"
7
8namespace proteus {
9
10enum class CodegenOption {
11 RTC,
12 Serial,
15};
16
17inline std::string toString(CodegenOption Option) {
18 switch (Option) {
20 return "RTC";
22 return "Serial";
24 return "Parallel";
26 return "ParallelThinLTO";
27 default:
28 return "Unknown";
29 }
30}
31
32inline bool getEnvOrDefaultBool(const char *VarName, bool Default) {
33
34 const char *EnvValue = std::getenv(VarName);
35 return EnvValue ? static_cast<bool>(std::stoi(EnvValue)) : Default;
36}
37
38inline int getEnvOrDefaultInt(const char *VarName, int Default) {
39
40 const char *EnvValue = std::getenv(VarName);
41 return EnvValue ? std::stoi(EnvValue) : Default;
42}
43
45 CodegenOption Default) {
46
47 const char *EnvValue = std::getenv(VarName);
48 if (!EnvValue)
49 return Default;
50
51 std::string EnvValueStr{EnvValue};
52 std::transform(EnvValueStr.begin(), EnvValueStr.end(), EnvValueStr.begin(),
53 ::tolower);
54 if (EnvValueStr == "rtc")
55 return CodegenOption::RTC;
56 if (EnvValueStr == "serial")
58 if (EnvValueStr == "parallel")
60 if (EnvValueStr == "thinlto")
62
63 Logger::outs("proteus") << "Unknown codegen option " << EnvValueStr
64 << ", using default codegen option: "
65 << toString(Default) << "\n";
66 return Default;
67}
68
69class Config {
70public:
71 static Config &get() {
72 static Config Conf;
73 return Conf;
74 }
75
89
90private:
91 Config() {
93 getEnvOrDefaultBool("PROTEUS_USE_STORED_CACHE", true);
95 getEnvOrDefaultBool("PROTEUS_SPECIALIZE_LAUNCH_BOUNDS", true);
97 getEnvOrDefaultBool("PROTEUS_SPECIALIZE_ARGS", true);
99 getEnvOrDefaultBool("PROTEUS_SPECIALIZE_DIMS", true);
101#if PROTEUS_ENABLE_CUDA
103 Logger::outs("proteus")
104 << "Warning: Proteus supports only RTC compilation for CUDA, "
105 "setting Codegen to RTC\n";
107 }
108#endif
109#if PROTEUS_ENABLE_HIP
110#if LLVM_VERSION_MAJOR < 18
112 Logger::outs("proteus")
113 << "Warning: Proteus with LLVM < 18 supports only RTC compilation, "
114 "setting Codegen to RTC\n";
116 }
117#endif
118#endif
119 ProteusDisable = getEnvOrDefaultBool("PROTEUS_DISABLE", false);
120 ProteusDumpLLVMIR = getEnvOrDefaultBool("PROTEUS_DUMP_LLVM_IR", false);
122 getEnvOrDefaultBool("PROTEUS_RELINK_GLOBALS_BY_COPY", false);
124 getEnvOrDefaultBool("PROTEUS_ASYNC_COMPILATION", false);
126 getEnvOrDefaultBool("PROTEUS_ASYNC_TEST_BLOCKING", false);
127 ProteusAsyncThreads = getEnvOrDefaultInt("PROTEUS_ASYNC_THREADS", 1);
129 getEnvOrDefaultBool("PROTEUS_USE_LIGHTWEIGHT_KERNEL_CLONE", true);
130 ProteusEnableTimers = getEnvOrDefaultBool("PROTEUS_ENABLE_TIMERS", false);
131 }
132};
133} // namespace proteus
134
135#endif
const char * VarName
Definition CompilerInterfaceDevice.cpp:20
Definition Config.hpp:69
CodegenOption ProteusCodegen
Definition Config.hpp:88
bool ProteusDisable
Definition Config.hpp:80
static Config & get()
Definition Config.hpp:71
bool ProteusUseLightweightKernelClone
Definition Config.hpp:86
bool ProteusRelinkGlobalsByCopy
Definition Config.hpp:82
bool ProteusSpecializeDims
Definition Config.hpp:79
bool ProteusDumpLLVMIR
Definition Config.hpp:81
bool ProteusUseStoredCache
Definition Config.hpp:76
int ProteusAsyncThreads
Definition Config.hpp:84
bool ProteusSpecializeArgs
Definition Config.hpp:78
bool ProteusEnableTimers
Definition Config.hpp:87
bool ProteusAsyncTestBlocking
Definition Config.hpp:85
bool ProteusSpecializeLaunchBounds
Definition Config.hpp:77
bool ProteusAsyncCompilation
Definition Config.hpp:83
static llvm::raw_ostream & outs(const std::string &Name)
Definition Logger.hpp:24
Definition JitEngine.cpp:21
int getEnvOrDefaultInt(const char *VarName, int Default)
Definition Config.hpp:38
CodegenOption
Definition Config.hpp:10
CodegenOption getEnvOrDefaultCG(const char *VarName, CodegenOption Default)
Definition Config.hpp:44
std::string toString(CodegenOption Option)
Definition Config.hpp:17
bool getEnvOrDefaultBool(const char *VarName, bool Default)
Definition Config.hpp:32