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 12 // 2^N
15#define STACK_KB 32
16
17enum class Arch {
18 CPU,
19 GPU,
20 HYBRID
21};
22
23enum class InputFormat {
24 XCSP3,
26};
27
28template<class Allocator>
30 using allocator_type = Allocator;
31 bool print_intermediate_solutions; // (only optimization problems).
32 size_t stop_after_n_solutions; // 0 for all solutions (satisfaction problems only).
33 size_t stop_after_n_nodes; // size_t MAX values for all nodes.
40 size_t timeout_ms;
41 size_t or_nodes;
42 size_t and_nodes; // (only for GPU)
44 size_t stack_kb;
46 battery::string<allocator_type> problem_path;
47 battery::string<allocator_type> version;
48 battery::string<allocator_type> hardware;
49
53 stop_after_n_nodes(std::numeric_limits<size_t>::max()),
54 free_search(false),
55 verbose_solving(false),
56 print_ast(false),
57 print_statistics(false),
58 only_global_memory(false),
59 noatomics(false),
60 timeout_ms(0),
61 and_nodes(0),
62 or_nodes(0),
65 arch(
66 #ifdef __CUDACC__
67 Arch::GPU
68 #else
69 Arch::CPU
70 #endif
71 ),
72 problem_path(alloc),
73 version(alloc),
74 hardware(alloc)
75 {}
76
79
80 template<class Alloc>
101
102 template <class Alloc2>
123
124 CUDA void print_commandline(const char* program_name) {
125 printf("%s -t %" PRIu64 " %s-n %" PRIu64 " %s%s%s%s%s",
126 program_name,
128 (print_intermediate_solutions ? "-a ": ""),
130 (print_intermediate_solutions ? "-i ": ""),
131 (free_search ? "-f " : ""),
132 (print_statistics ? "-s " : ""),
133 (verbose_solving ? "-v " : ""),
134 (print_ast ? "-ast " : "")
135 );
136 if(arch == Arch::GPU) {
137 printf("-arch gpu -or %" PRIu64 " -and %" PRIu64 " -sub %" PRIu64 " -stack %" PRIu64 " ", or_nodes, and_nodes, subproblems_power, stack_kb);
138 printf("%s%s",
139 (only_global_memory ? "-globalmem " : ""),
140 (noatomics ? "-noatomics " : ""));
141 }
142 else if(arch == Arch::HYBRID) {
143 printf("-arch hybrid -or %" PRIu64 " -and %" PRIu64 " ", or_nodes, and_nodes);
144 }
145 else {
146 printf("-arch cpu -p %" PRIu64 " ", or_nodes);
147 }
148 if(version.size() != 0) {
149 printf("-version %s ", version.data());
150 }
151 if(hardware.size() != 0) {
152 printf("-hardware \"%s\" ", hardware.data());
153 }
154 printf("-cutnodes %" PRIu64 " ", stop_after_n_nodes == std::numeric_limits<size_t>::max() ? 0 : stop_after_n_nodes);
155 printf("%s\n", problem_path.data());
156 }
157
158 CUDA const char* name_of_arch(Arch arch) const {
159 switch(arch) {
160 case Arch::CPU:
161 return "CPU";
162 case Arch::GPU:
163 return "GPU";
164 case Arch::HYBRID:
165 return "hybrid";
166 default:
167 assert(0);
168 return "Unknown";
169 }
170 }
171
172 CUDA void print_mzn_statistics() const {
173 printf("%%%%%%mzn-stat: problem_path=\"%s\"\n", problem_path.data());
174 printf("%%%%%%mzn-stat: solver=\"Turbo\"\n");
175 printf("%%%%%%mzn-stat: version=\"%s\"\n", (version.size() == 0) ? "1.2.3" : version.data());
176 printf("%%%%%%mzn-stat: hardware=\"%s\"\n", (hardware.size() == 0) ? "Intel Core i9-10900X@3.7GHz;24GO DDR4;NVIDIA RTX A5000" : hardware.data());
177 printf("%%%%%%mzn-stat: arch=\"%s\"\n", name_of_arch(arch));
178 printf("%%%%%%mzn-stat: free_search=\"%s\"\n", free_search ? "yes" : "no");
179 printf("%%%%%%mzn-stat: or_nodes=%" PRIu64 "\n", or_nodes);
180 printf("%%%%%%mzn-stat: timeout_ms=%" PRIu64 "\n", timeout_ms);
181 if(arch != Arch::CPU) {
182 printf("%%%%%%mzn-stat: and_nodes=%" PRIu64 "\n", and_nodes);
183 printf("%%%%%%mzn-stat: stack_size=%" PRIu64 "\n", stack_kb * 1000);
184 #ifdef CUDA_VERSION
185 printf("%%%%%%mzn-stat: cuda_version=%d\n", CUDA_VERSION);
186 #endif
187 #ifdef __CUDA_ARCH__
188 printf("%%%%%%mzn-stat: cuda_architecture=%d\n", __CUDA_ARCH__);
189 #endif
190 }
191 printf("%%%%%%mzn-stat: cutnodes=%" PRIu64 "\n", stop_after_n_nodes == std::numeric_limits<size_t>::max() ? 0 : stop_after_n_nodes);
192 }
193
195 if(problem_path.ends_with(".fzn")) {
197 }
198 else if(problem_path.ends_with(".xml")) {
199 return InputFormat::XCSP3;
200 }
201 else {
202 printf("ERROR: Unknown input format for the file %s [supported extension: .xml and .fzn].\n", problem_path.data());
203 exit(EXIT_FAILURE);
204 }
205 }
206};
207
208void usage_and_exit(const std::string& program_name);
210
211#endif
Arch
Definition config.hpp:17
@ HYBRID
Configuration< battery::standard_allocator > parse_args(int argc, char **argv)
#define STACK_KB
Definition config.hpp:15
#define SUBPROBLEMS_POWER
Definition config.hpp:14
InputFormat
Definition config.hpp:23
void usage_and_exit(const std::string &program_name)
Definition config.hpp:29
size_t stop_after_n_nodes
Definition config.hpp:33
battery::string< allocator_type > problem_path
Definition config.hpp:46
CUDA InputFormat input_format() const
Definition config.hpp:194
bool print_intermediate_solutions
Definition config.hpp:31
bool print_ast
Definition config.hpp:37
CUDA void print_mzn_statistics() const
Definition config.hpp:172
bool verbose_solving
Definition config.hpp:36
Arch arch
Definition config.hpp:45
size_t timeout_ms
Definition config.hpp:40
size_t or_nodes
Definition config.hpp:41
CUDA Configuration< allocator_type > & operator=(const Configuration< Alloc2 > &other)
Definition config.hpp:103
size_t stop_after_n_solutions
Definition config.hpp:32
size_t stack_kb
Definition config.hpp:44
CUDA Configuration(const allocator_type &alloc=allocator_type{})
Definition config.hpp:50
CUDA Configuration(const Configuration< Alloc > &other, const allocator_type &alloc=allocator_type{})
Definition config.hpp:81
Configuration(const Configuration< allocator_type > &)=default
bool noatomics
Definition config.hpp:39
bool free_search
Definition config.hpp:34
bool only_global_memory
Definition config.hpp:38
CUDA void print_commandline(const char *program_name)
Definition config.hpp:124
battery::string< allocator_type > hardware
Definition config.hpp:48
Allocator allocator_type
Definition config.hpp:30
bool print_statistics
Definition config.hpp:35
size_t and_nodes
Definition config.hpp:42
CUDA const char * name_of_arch(Arch arch) const
Definition config.hpp:158
Configuration(Configuration< allocator_type > &&)=default
battery::string< allocator_type > version
Definition config.hpp:47
size_t subproblems_power
Definition config.hpp:43