FreeTensor
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_CONFIG_H
2#define FREE_TENSOR_CONFIG_H
3
4#include <filesystem>
5#include <vector>
6
7#include <container_utils.h>
8#include <ref.h>
9
10namespace freetensor {
11
12class Target;
13class Device;
14
20class Config {
21 static bool prettyPrint_;
22 static bool printAllId_;
23 static bool printSourceLocation_;
24 static bool fastMath_;
25 static bool werror_;
26 static bool
27 debugBinary_;
29 static bool debugRuntimeCheck_;
30 static bool
31 debugCUDAWithUM_;
36 static std::vector<std::filesystem::path>
37 backendCompilerCXX_;
40 static std::vector<std::filesystem::path>
41 backendCompilerNVCC_;
44 static std::vector<std::filesystem::path>
45 backendOpenMP_; // Env and macro FT_BACKEND_OPENMP. Colon-separated
46 // paths, linked from left to right
47
48 static Ref<Target>
49 defaultTarget_;
51 static Ref<Device> defaultDevice_;
53 static std::vector<std::filesystem::path>
54 runtimeDir_;
57
58 private:
62 static std::vector<std::filesystem::path>
63 checkValidPaths(const std::vector<std::filesystem::path> &paths,
64 bool required = true);
65
66 public:
67 static void init();
68
69 static bool withMKL();
70 static bool withCUDA();
71 static bool withPyTorch();
72
73 static void setPrettyPrint(bool pretty = true) { prettyPrint_ = pretty; }
74 static bool prettyPrint() { return prettyPrint_; }
75
76 static void setPrintAllId(bool flag = true) { printAllId_ = flag; }
77 static bool printAllId() { return printAllId_; }
78
79 static void setPrintSourceLocation(bool flag = true) {
80 printSourceLocation_ = flag;
81 }
82 static bool printSourceLocation() { return printSourceLocation_; }
83
84 static void setFastMath(bool flag = true) { fastMath_ = flag; }
85 static bool fastMath() { return fastMath_; }
86
87 static void setWerror(bool flag = true) { werror_ = flag; }
88 static bool werror() { return werror_; }
89
90 static void setDebugBinary(bool flag = true) { debugBinary_ = flag; }
91 static bool debugBinary() { return debugBinary_; }
92
93 static void setDebugRuntimeCheck(bool flag = true) {
94 debugRuntimeCheck_ = flag;
95 }
96 static bool debugRuntimeCheck() { return debugRuntimeCheck_; }
97
98 static void setDebugCUDAWithUM(bool flag = true) {
99 debugCUDAWithUM_ = flag;
100 }
101 static bool debugCUDAWithUM() { return debugCUDAWithUM_; }
102
108 static void
109 setBackendCompilerCXX(const std::vector<std::filesystem::path> &paths) {
110 backendCompilerCXX_ = checkValidPaths(paths);
111 }
112 static const std::vector<std::filesystem::path> &backendCompilerCXX() {
113 return backendCompilerCXX_;
114 }
115
121 static void
122 setBackendCompilerNVCC(const std::vector<std::filesystem::path> &paths) {
123 backendCompilerNVCC_ = checkValidPaths(paths);
124 }
125 static const std::vector<std::filesystem::path> &backendCompilerNVCC() {
126 return backendCompilerNVCC_;
127 }
128
135 static void
136 setBackendOpenMP(const std::vector<std::filesystem::path> &path) {
137 backendOpenMP_ = path;
138 }
139 static const std::vector<std::filesystem::path> &backendOpenMP() {
140 return backendOpenMP_;
141 }
142
143 static void setDefaultTarget(const Ref<Target> &target) {
144 defaultTarget_ = target;
145 }
146 static Ref<Target> defaultTarget() { return defaultTarget_; }
147
148 static void setDefaultDevice(const Ref<Device> &dev) {
149 defaultDevice_ = dev;
150 }
151 static Ref<Device> defaultDevice() { return defaultDevice_; }
152
153 static void setRuntimeDir(const std::vector<std::filesystem::path> &paths) {
154 runtimeDir_ = checkValidPaths(paths);
155 }
156 static const std::vector<std::filesystem::path> &runtimeDir() {
157 return runtimeDir_;
158 }
159};
160
161} // namespace freetensor
162
163#endif // FREE_TENSOR_CONFIG_H
Definition: config.h:20
static void setPrintAllId(bool flag=true)
Definition: config.h:76
static bool printSourceLocation()
Definition: config.h:82
static Ref< Target > defaultTarget()
Definition: config.h:146
static void setDefaultDevice(const Ref< Device > &dev)
Definition: config.h:148
static bool debugRuntimeCheck()
Definition: config.h:96
static bool debugCUDAWithUM()
Definition: config.h:101
static void init()
Definition: config.cc:106
static void setDefaultTarget(const Ref< Target > &target)
Definition: config.h:143
static void setPrettyPrint(bool pretty=true)
Definition: config.h:73
static bool printAllId()
Definition: config.h:77
static void setBackendCompilerNVCC(const std::vector< std::filesystem::path > &paths)
Set the NVCC compiler for GPU backend.
Definition: config.h:122
static void setBackendOpenMP(const std::vector< std::filesystem::path > &path)
Set the OpenMP library linked to the compiled executable.
Definition: config.h:136
static void setWerror(bool flag=true)
Definition: config.h:87
static void setDebugBinary(bool flag=true)
Definition: config.h:90
static const std::vector< std::filesystem::path > & backendCompilerCXX()
Definition: config.h:112
static bool withPyTorch()
Definition: config.cc:192
static void setDebugRuntimeCheck(bool flag=true)
Definition: config.h:93
static const std::vector< std::filesystem::path > & backendCompilerNVCC()
Definition: config.h:125
static const std::vector< std::filesystem::path > & runtimeDir()
Definition: config.h:156
static bool withCUDA()
Definition: config.cc:184
static const std::vector< std::filesystem::path > & backendOpenMP()
Definition: config.h:139
static bool withMKL()
Called in src/ffi/config.cc.
Definition: config.cc:176
static void setRuntimeDir(const std::vector< std::filesystem::path > &paths)
Definition: config.h:153
static bool werror()
Definition: config.h:88
static void setFastMath(bool flag=true)
Definition: config.h:84
static bool debugBinary()
Definition: config.h:91
static bool prettyPrint()
Definition: config.h:74
static void setPrintSourceLocation(bool flag=true)
Definition: config.h:79
static bool fastMath()
Definition: config.h:85
static void setBackendCompilerCXX(const std::vector< std::filesystem::path > &paths)
Set the C++ compiler for CPU backend.
Definition: config.h:109
static Ref< Device > defaultDevice()
Definition: config.h:151
static void setDebugCUDAWithUM(bool flag=true)
Definition: config.h:98
Definition: ref.h:24
Definition: allocator.h:9