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