LIBINT 2.9.0
default_params.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint compiler is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_defaultparams_h_
22#define _libint2_src_bin_libint_defaultparams_h_
23
24#include <smart_ptr.h>
25
26#include <climits>
27#include <map>
28#include <ostream>
29#include <string>
30#include <vector>
31
36namespace libint2 {
37
40 std::string default_task_name_;
41
42 public:
46
48 unsigned int max_am(std::string t = "", unsigned int c = 0) const;
50 unsigned int max_am_opt(std::string t = "") const;
52 unsigned int num_bf(std::string t = "") const;
54 unsigned int max_vector_length() const { return max_vector_length_; }
56 bool vectorize_by_line() const { return vectorize_by_line_; }
58 unsigned int unroll_threshold() const { return unroll_threshold_; }
60 unsigned int align_size() const { return align_size_; }
62 const std::string& source_directory() const { return source_directory_; }
64 const std::string& api_prefix() const { return api_prefix_; }
66 bool single_evaltype() const { return single_evaltype_; }
68 bool use_C_linking() const { return use_C_linking_; }
70 bool count_flops() const { return count_flops_; }
72 bool profile() const { return profile_; }
74 bool accumulate_targets() const { return accumulate_targets_; }
76 const std::string& realtype() const { return realtype_; }
78 bool contracted_targets() const { return contracted_targets_; }
80 const std::string& default_task_name() const { return default_task_name_; }
81
83 void max_am(const std::string& t, unsigned int a, unsigned int c = 0);
85 void max_am_opt(const std::string& t, unsigned int a);
87 void num_bf(const std::string& t, unsigned int a);
89 void max_vector_length(unsigned int a) { max_vector_length_ = a; }
91 void vectorize_by_line(bool flag) { vectorize_by_line_ = flag; }
93 void align_size(unsigned int a) { align_size_ = a; }
95 void unroll_threshold(unsigned int a) { unroll_threshold_ = a; }
97 void source_directory(const std::string& a) { source_directory_ = a; }
99 void api_prefix(const std::string& a) { api_prefix_ = a; }
101 void single_evaltype(bool se) { single_evaltype_ = se; }
103 void use_C_linking(bool a) { use_C_linking_ = a; }
105 void count_flops(bool a) { count_flops_ = a; }
107 void profile(bool a) { profile_ = a; }
109 void accumulate_targets(bool a) { accumulate_targets_ = a; }
111 void realtype(const std::string& realtype) { realtype_ = realtype; }
113 void contracted_targets(bool c) { contracted_targets_ = c; }
115 void default_task_name(const std::string& s) { default_task_name_ = s; }
116
118 void print(std::ostream& os) const;
119
120 private:
121 struct Defaults {
123 static const unsigned int max_am = 1;
125 static const unsigned int max_am_opt = 1;
127 static const unsigned int num_bf = 4;
129 static const unsigned int max_vector_length = 1;
131 static const bool vectorize_by_line = false;
133 static const unsigned int align_size = 0;
135 static const unsigned int unroll_threshold = 0;
137 static const std::string source_directory;
139 static const std::string api_prefix;
141 static const bool single_evaltype = true;
143 static const bool use_C_linking = true;
145 static const bool count_flops = false;
147 static const bool profile = false;
149 static const bool accumulate_targets = false;
151 static const std::string realtype;
153 static const bool contracted_targets = false;
155 static const std::string task_name;
156 };
157
158 struct TaskParameters {
160 std::vector<unsigned int> max_am;
162 unsigned int max_am_opt;
164 unsigned int num_bf;
165
166 TaskParameters() : max_am(1, 0u), max_am_opt(0u), num_bf(0u) {}
167 };
169 std::map<std::string, TaskParameters> task_params_;
172 void task_exists(const std::string& t) const;
174 void add_task(const std::string& t);
175
177 unsigned int max_vector_length_;
179 bool vectorize_by_line_;
184 unsigned int align_size_;
186 unsigned int unroll_threshold_;
188 std::string source_directory_;
190 std::string api_prefix_;
192 bool single_evaltype_;
194 bool use_C_linking_;
196 bool count_flops_;
198 bool profile_;
200 bool accumulate_targets_;
202 std::string realtype_;
204 bool contracted_targets_;
205};
206
212 public:
214 ~TaskParameters() {}
215
217 unsigned int max_ntarget() const { return max_ntarget_; }
219 unsigned int max_am() const { return max_stack_size_.size() - 1; }
221 unsigned int max_stack_size(unsigned int am) const {
222 return max_stack_size_.at(am);
223 }
229 unsigned int max_vector_stack_size(unsigned int am) const {
230 if (am + 1 > max_vector_stack_size_.size())
231 return 0;
232 else
233 return max_vector_stack_size_[am];
234 }
238 unsigned int max_hrr_hsrank(unsigned int am) const {
239 if (am + 1 > max_hrr_hsrank_.size())
240 return 0;
241 else
242 return max_hrr_hsrank_[am];
243 }
247 unsigned int max_hrr_lsrank(unsigned int am) const {
248 if (am + 1 > max_hrr_lsrank_.size())
249 return 0;
250 else
251 return max_hrr_lsrank_[am];
252 }
253
255 void max_ntarget(unsigned int ntarget) {
256 if (max_ntarget_ < ntarget) max_ntarget_ = ntarget;
257 }
258
260 void max_stack_size(unsigned int am, unsigned int size) {
261 extend_max_size(max_stack_size_, am, size);
262 }
263
265 void max_vector_stack_size(unsigned int am, unsigned int size) {
266 extend_max_size(max_vector_stack_size_, am, size);
267 }
268
270 void max_hrr_hsrank(unsigned int am, unsigned int rank) {
271 extend_max_size(max_hrr_hsrank_, am, rank);
272 }
273
275 void max_hrr_lsrank(unsigned int am, unsigned int rank) {
276 extend_max_size(max_hrr_lsrank_, am, rank);
277 }
278
279 private:
280 unsigned int max_ntarget_;
281 std::vector<unsigned int>
282 max_stack_size_; //< keeps track of stack size needed to compute
283 // integrals up to a given quantum number
284 std::vector<unsigned int> max_vector_stack_size_;
285 std::vector<unsigned int> max_hrr_hsrank_;
286 std::vector<unsigned int> max_hrr_lsrank_;
287
288 static void extend_max_size(std::vector<unsigned int>& max_size,
289 unsigned int am, unsigned int size) {
290 const int max_am = (int)max_size.size() - 1u;
291 if (max_am < (int)am) {
292 max_size.resize(am + 1);
293 for (int l = std::max(max_am + 1, 1); l <= (int)am; ++l)
294 max_size[l] = max_size[l - 1];
295 }
296 if (max_size[am] < size) max_size[am] = size;
297 }
298};
299
302std::string label_to_funcname(const std::string& label);
303
307bool condense_expr(unsigned int unroll_threshold, bool vectorize);
308}; // namespace libint2
309
310#endif
These are the parameters received by the compiler.
Definition default_params.h:39
void vectorize_by_line(bool flag)
set vectorize_by_line flag
Definition default_params.h:91
void unroll_threshold(unsigned int a)
set unroll threshold
Definition default_params.h:95
bool profile() const
whether profiling instrumentation is enabled
Definition default_params.h:72
void use_C_linking(bool a)
set whether to use C style linking
Definition default_params.h:103
unsigned int max_vector_length() const
returns max vector length
Definition default_params.h:54
bool count_flops() const
whether FLOP counting is enabled
Definition default_params.h:70
void align_size(unsigned int a)
set alignment size (in units of sizeof(LIBINT_FLOAT))
Definition default_params.h:93
unsigned int num_bf(std::string t="") const
returns number of basis functions in integrals for task t
Definition default_params.cc:123
bool single_evaltype() const
generate single evaluator type (i.e. not specific to each task)?
Definition default_params.h:66
bool use_C_linking() const
returns whether to use C-style linking
Definition default_params.h:68
void default_task_name(const std::string &s)
default task name
Definition default_params.h:115
void source_directory(const std::string &a)
set generated source directory
Definition default_params.h:97
bool vectorize_by_line() const
returns whether to vectorize line-by-line
Definition default_params.h:56
void api_prefix(const std::string &a)
API prefix.
Definition default_params.h:99
void accumulate_targets(bool a)
accumulate targets?
Definition default_params.h:109
void print(std::ostream &os) const
print params out
Definition default_params.cc:55
void profile(bool a)
set to instrument profiling
Definition default_params.h:107
unsigned int unroll_threshold() const
returns unroll threshold
Definition default_params.h:58
void count_flops(bool a)
set whether to count FLOPs
Definition default_params.h:105
const std::string & realtype() const
name of the floating-point type
Definition default_params.h:76
const std::string & api_prefix() const
the API prefix
Definition default_params.h:64
void realtype(const std::string &realtype)
which floating-point type to use
Definition default_params.h:111
const std::string & default_task_name() const
default task name
Definition default_params.h:80
const std::string & source_directory() const
returns directory path for the generated source
Definition default_params.h:62
unsigned int align_size() const
returns alignment size (in units of sizeof(LIBINT_FLOAT))
Definition default_params.h:60
bool accumulate_targets() const
whether target integrals are accumulated
Definition default_params.h:74
CompilationParameters()
Use default parameters.
Definition default_params.cc:35
bool contracted_targets() const
whether contracted targets are supported
Definition default_params.h:78
void contracted_targets(bool c)
support contracted targets?
Definition default_params.h:113
unsigned int max_am_opt(std::string t="") const
returns max AM for which to produce optimal code for task t
Definition default_params.cc:111
unsigned int max_am(std::string t="", unsigned int c=0) const
returns max AM for task t and center c
Definition default_params.cc:98
void max_vector_length(unsigned int a)
set max vector length
Definition default_params.h:89
void single_evaltype(bool se)
generate a single evaluator type (i.e. not specific to each task)?
Definition default_params.h:101
This class maintains various parameters for each task type which can only be determined during the so...
Definition default_params.h:211
unsigned int max_hrr_hsrank(unsigned int am) const
returns max rank of high-significance functions in a HRR call.
Definition default_params.h:238
void max_stack_size(unsigned int am, unsigned int size)
if max_stack_size_ < size then set max_stack_size_=size
Definition default_params.h:260
unsigned int max_vector_stack_size(unsigned int am) const
returns max vector stack size.
Definition default_params.h:229
void max_hrr_lsrank(unsigned int am, unsigned int rank)
if max_hrr_lsrank_ < rank then set max_hrr_lsrank_=rank
Definition default_params.h:275
unsigned int max_am() const
returns the max quantum number of targets
Definition default_params.h:219
void max_vector_stack_size(unsigned int am, unsigned int size)
if max_vector_stack_size_ < size then set max_vector_stack_size_=size
Definition default_params.h:265
unsigned int max_stack_size(unsigned int am) const
returns max stack size needed for quantum numbers up to am
Definition default_params.h:221
void max_ntarget(unsigned int ntarget)
if max_ntarget_ < ntarget then set max_ntarget_=ntarget
Definition default_params.h:255
void max_hrr_hsrank(unsigned int am, unsigned int rank)
if max_hrr_hsrank_ < rank then set max_hrr_hsrank_=rank
Definition default_params.h:270
unsigned int max_ntarget() const
returns the max number of targets
Definition default_params.h:217
unsigned int max_hrr_lsrank(unsigned int am) const
returns max rank of low-significance functions in a HRR call.
Definition default_params.h:247
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
std::string label_to_funcname(const std::string &label)
Converts a label, e.g.
Definition default_params.cc:201
bool condense_expr(unsigned int unroll_threshold, bool vectorize)
need to condense expressions? Makes sense if vectorizing the code or the compiler somehow prefers lon...
Definition default_params.cc:212