Turbo Constraint Solver
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1// Copyright 2022 Pierre Talbot
2
3#ifndef TURBO_CONFIG_HPP
4#define TURBO_CONFIG_HPP
5
6#include "battery/allocator.hpp"
7#include "battery/string.hpp"
8#include <cinttypes>
9
10#ifdef __CUDACC__
11 #include <cuda.h>
12#endif
13
14#define SUBPROBLEMS_POWER 15 // 2^N
15
16enum class Arch {
17 CPU,
18 GPU,
20 HYBRID
21};
22
23enum class FixpointKind {
24 AC1,
25 WAC1
26};
27
28enum class InputFormat {
29 XCSP3,
31};
32
33template<class Allocator>
35 using allocator_type = Allocator;
36 bool print_intermediate_solutions; // (only optimization problems).
37 size_t stop_after_n_solutions; // 0 for all solutions (satisfaction problems only).
38 size_t stop_after_n_nodes; // size_t MAX values for all nodes.
47 size_t timeout_ms;
48 size_t or_nodes;
50 size_t stack_kb;
54 battery::string<allocator_type> problem_path;
55 battery::string<allocator_type> version;
56 battery::string<allocator_type> hardware;
57
61 stop_after_n_nodes(std::numeric_limits<size_t>::max()),
62 free_search(false),
64 print_ast(false),
65 print_statistics(false),
66 only_global_memory(false),
67 force_ternarize(false),
68 disable_simplify(false),
69 network_analysis(false),
70 timeout_ms(0),
71 or_nodes(0),
74 #ifdef TURBO_IPC_ABSTRACT_DOMAIN
75 32
76 #else
77 0
78 #endif
79 ),
80 arch(
81 #ifdef __CUDACC__
83 #else
84 Arch::CPU
85 #endif
86 ),
88 #ifdef __CUDACC__
90 #else
92 #endif
93 ),
94 wac1_threshold(4096),
95 problem_path(alloc),
96 version(alloc),
97 hardware(alloc)
98 {}
99
102
103 template<class Alloc>
127
128 template <class Alloc2>
152
153 CUDA void print_commandline(const char* program_name) {
154 printf("%s -t %" PRIu64 " %s-n %" PRIu64 " %s%s%s%s",
155 program_name,
157 (print_intermediate_solutions ? "-a ": ""),
159 (print_intermediate_solutions ? "-i ": ""),
160 (free_search ? "-f " : ""),
161 (print_statistics ? "-s " : ""),
162 (print_ast ? "-ast " : "")
163 );
164 for(int i = 0; i < verbose_solving; ++i) {
165 printf("-v ");
166 }
167 if(arch != Arch::CPU) {
168 printf("-arch %s -or %" PRIu64 " -sub %" PRIu64 " -stack %" PRIu64 " ", name_of_arch(arch), or_nodes, subproblems_power, stack_kb);
169 if(only_global_memory) { printf("-globalmem "); }
170 }
171 else {
172 printf("-arch cpu -p %" PRIu64 " ", or_nodes);
173 }
174 if(disable_simplify) { printf("-disable_simplify "); }
175 if(force_ternarize) { printf("-force_ternarize "); }
176 if(network_analysis) { printf("-network_analysis "); }
177 printf("-fp %s ", name_of_fixpoint(fixpoint));
179 printf("-wac1_threshold %" PRIu64 " ", wac1_threshold);
180 }
181 if(version.size() != 0) {
182 printf("-version %s ", version.data());
183 }
184 if(hardware.size() != 0) {
185 printf("-hardware \'%s\' ", hardware.data());
186 }
187 printf("-cutnodes %" PRIu64 " ", stop_after_n_nodes == std::numeric_limits<size_t>::max() ? 0 : stop_after_n_nodes);
188 printf("%s", problem_path.data());
189 }
190
191 CUDA const char* name_of_fixpoint(FixpointKind fixpoint) const {
192 switch(fixpoint) {
194 return "ac1";
196 return "wac1";
197 default:
198 assert(0);
199 return "Unknown";
200 }
201 }
202
203 CUDA const char* name_of_arch(Arch arch) const {
204 switch(arch) {
205 case Arch::CPU:
206 return "cpu";
207 case Arch::GPU:
208 return "gpu";
209 case Arch::BAREBONES:
210 return "barebones";
211 case Arch::HYBRID:
212 return "hybrid";
213 default:
214 assert(0);
215 return "Unknown";
216 }
217 }
218
219 CUDA void print_mzn_statistics() const {
220 printf("%%%%%%mzn-stat: problem_path=\"%s\"\n", problem_path.data());
221 printf("%%%%%%mzn-stat: solver=\"Turbo\"\n");
222 printf("%%%%%%mzn-stat: version=\"%s\"\n", (version.size() == 0) ? "1.2.8" : version.data());
223 printf("%%%%%%mzn-stat: hardware=\"%s\"\n", (hardware.size() == 0) ? "unspecified" : hardware.data());
224 printf("%%%%%%mzn-stat: arch=\"%s\"\n", name_of_arch(arch));
225 printf("%%%%%%mzn-stat: fixpoint=\"%s\"\n", name_of_fixpoint(fixpoint));
227 printf("%%%%%%mzn-stat: wac1_threshold=%" PRIu64 "\n", wac1_threshold);
228 }
229 printf("%%%%%%mzn-stat: free_search=\"%s\"\n", free_search ? "yes" : "no");
230 printf("%%%%%%mzn-stat: or_nodes=%" PRIu64 "\n", or_nodes);
231 printf("%%%%%%mzn-stat: timeout_ms=%" PRIu64 "\n", timeout_ms);
232 if(arch != Arch::CPU) {
233 printf("%%%%%%mzn-stat: threads_per_block=%d\n", CUDA_THREADS_PER_BLOCK);
234 printf("%%%%%%mzn-stat: stack_size=%" PRIu64 "\n", stack_kb * 1000);
235 #ifdef CUDA_VERSION
236 printf("%%%%%%mzn-stat: cuda_version=%d\n", CUDA_VERSION);
237 #endif
238 #ifdef __CUDA_ARCH__
239 printf("%%%%%%mzn-stat: cuda_architecture=%d\n", __CUDA_ARCH__);
240 #endif
241 }
242 printf("%%%%%%mzn-stat: cutnodes=%" PRIu64 "\n", stop_after_n_nodes == std::numeric_limits<size_t>::max() ? 0 : stop_after_n_nodes);
243 }
244
246 if(problem_path.ends_with(".fzn")) {
248 }
249 else if(problem_path.ends_with(".xml")) {
250 return InputFormat::XCSP3;
251 }
252 else {
253 printf("ERROR: Unknown input format for the file %s [supported extension: .xml and .fzn].\n", problem_path.data());
254 exit(EXIT_FAILURE);
255 }
256 }
257};
258
259void usage_and_exit(const std::string& program_name);
261
262#endif
Arch
Definition config.hpp:16
@ HYBRID
@ BAREBONES
Configuration< battery::standard_allocator > parse_args(int argc, char **argv)
FixpointKind
Definition config.hpp:23
#define SUBPROBLEMS_POWER
Definition config.hpp:14
InputFormat
Definition config.hpp:28
void usage_and_exit(const std::string &program_name)
Definition config.hpp:34
size_t stop_after_n_nodes
Definition config.hpp:38
battery::string< allocator_type > problem_path
Definition config.hpp:54
CUDA InputFormat input_format() const
Definition config.hpp:245
bool print_intermediate_solutions
Definition config.hpp:36
bool disable_simplify
Definition config.hpp:45
bool print_ast
Definition config.hpp:42
CUDA void print_mzn_statistics() const
Definition config.hpp:219
Arch arch
Definition config.hpp:51
size_t timeout_ms
Definition config.hpp:47
size_t or_nodes
Definition config.hpp:48
CUDA Configuration< allocator_type > & operator=(const Configuration< Alloc2 > &other)
Definition config.hpp:129
size_t stop_after_n_solutions
Definition config.hpp:37
size_t stack_kb
Definition config.hpp:50
CUDA Configuration(const allocator_type &alloc=allocator_type{})
Definition config.hpp:58
CUDA Configuration(const Configuration< Alloc > &other, const allocator_type &alloc=allocator_type{})
Definition config.hpp:104
Configuration(const Configuration< allocator_type > &)=default
bool force_ternarize
Definition config.hpp:44
bool free_search
Definition config.hpp:39
bool only_global_memory
Definition config.hpp:43
CUDA void print_commandline(const char *program_name)
Definition config.hpp:153
battery::string< allocator_type > hardware
Definition config.hpp:56
bool network_analysis
Definition config.hpp:46
Allocator allocator_type
Definition config.hpp:35
CUDA const char * name_of_fixpoint(FixpointKind fixpoint) const
Definition config.hpp:191
bool print_statistics
Definition config.hpp:40
FixpointKind fixpoint
Definition config.hpp:52
int verbose_solving
Definition config.hpp:41
size_t wac1_threshold
Definition config.hpp:53
CUDA const char * name_of_arch(Arch arch) const
Definition config.hpp:203
Configuration(Configuration< allocator_type > &&)=default
battery::string< allocator_type > version
Definition config.hpp:55
size_t subproblems_power
Definition config.hpp:49