LIBINT  2.1.0-stable
default_params.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see http://www.gnu.org/licenses/.
17  *
18  */
19 
20 #ifndef _libint2_src_bin_libint_defaultparams_h_
21 #define _libint2_src_bin_libint_defaultparams_h_
22 
23 #include <ostream>
24 #include <string>
25 #include <map>
26 #include <vector>
27 #include <climits>
28 #include <smart_ptr.h>
29 
34 namespace libint2 {
35 
38  std::string default_task_name_;
39 
40  public:
41 
45 
47  unsigned int max_am(std::string t = "", unsigned int c = 0) const;
49  unsigned int max_am_opt(std::string t = "") const;
51  unsigned int num_bf(std::string t = "") const;
53  unsigned int max_vector_length() const {
54  return max_vector_length_;
55  }
57  bool vectorize_by_line() const {
58  return vectorize_by_line_;
59  }
61  unsigned int unroll_threshold() const {
62  return unroll_threshold_;
63  }
65  unsigned int align_size() const {
66  return align_size_;
67  }
69  const std::string& source_directory() const {
70  return source_directory_;
71  }
73  const std::string& api_prefix() const {
74  return api_prefix_;
75  }
77  bool single_evaltype() const {
78  return single_evaltype_;
79  }
81  bool use_C_linking() const {
82  return use_C_linking_;
83  }
85  bool count_flops() const {
86  return count_flops_;
87  }
89  bool profile() const {
90  return profile_;
91  }
93  bool accumulate_targets() const {
94  return accumulate_targets_;
95  }
97  const std::string& realtype() const {
98  return realtype_;
99  }
101  bool contracted_targets() const {
102  return contracted_targets_;
103  }
105  const std::string& default_task_name() const {
106  return default_task_name_;
107  }
108 
110  void max_am(const std::string& t, unsigned int a, unsigned int c=0);
112  void max_am_opt(const std::string& t, unsigned int a);
114  void num_bf(const std::string& t, unsigned int a);
116  void max_vector_length(unsigned int a) {
117  max_vector_length_ = a;
118  }
120  void vectorize_by_line(bool flag) {
121  vectorize_by_line_ = flag;
122  }
124  void align_size(unsigned int a) {
125  align_size_ = a;
126  }
128  void unroll_threshold(unsigned int a) {
129  unroll_threshold_ = a;
130  }
132  void source_directory(const std::string& a) {
133  source_directory_ = a;
134  }
136  void api_prefix(const std::string& a) {
137  api_prefix_ = a;
138  }
140  void single_evaltype(bool se) {
141  single_evaltype_ = se;
142  }
144  void use_C_linking(bool a) {
145  use_C_linking_ = a;
146  }
148  void count_flops(bool a) {
149  count_flops_ = a;
150  }
152  void profile(bool a) {
153  profile_ = a;
154  }
156  void accumulate_targets(bool a) {
157  accumulate_targets_ = a;
158  }
160  void realtype(const std::string& realtype) {
161  realtype_ = realtype;
162  }
164  void contracted_targets(bool c) {
165  contracted_targets_ = c;
166  }
168  void default_task_name(const std::string& s) {
169  default_task_name_ = s;
170  }
171 
173  void print(std::ostream& os) const;
174 
175  private:
176  struct Defaults {
178  static const unsigned int max_am = 1;
180  static const unsigned int max_am_opt = 1;
182  static const unsigned int num_bf = 4;
184  static const unsigned int max_vector_length = 1;
186  static const bool vectorize_by_line = false;
188  static const unsigned int align_size = 0;
190  static const unsigned int unroll_threshold = 1;
192  static const std::string source_directory;
194  static const std::string api_prefix;
196  static const bool single_evaltype = true;
198  static const bool use_C_linking = true;
200  static const bool count_flops = false;
202  static const bool profile = false;
204  static const bool accumulate_targets = false;
206  static const std::string realtype;
208  static const bool contracted_targets = false;
210  static const std::string task_name;
211  };
212 
213  struct TaskParameters {
215  std::vector<unsigned int> max_am;
217  unsigned int max_am_opt;
219  unsigned int num_bf;
220 
221  TaskParameters() : max_am(1, 0u), max_am_opt(0u), num_bf(0u) {}
222  };
224  std::map<std::string,TaskParameters> task_params_;
226  void task_exists(const std::string& t) const;
228  void add_task(const std::string& t);
229 
231  unsigned int max_vector_length_;
233  bool vectorize_by_line_;
237  unsigned int align_size_;
239  unsigned int unroll_threshold_;
241  std::string source_directory_;
243  std::string api_prefix_;
245  bool single_evaltype_;
247  bool use_C_linking_;
249  bool count_flops_;
251  bool profile_;
253  bool accumulate_targets_;
255  std::string realtype_;
257  bool contracted_targets_;
258  };
259 
265  public:
266  TaskParameters();
267  ~TaskParameters() {}
268 
270  unsigned int max_ntarget() const {
271  return max_ntarget_;
272  }
274  unsigned int max_am() const {
275  return max_stack_size_.size() - 1;
276  }
278  unsigned int max_stack_size(unsigned int am) const {
279  return max_stack_size_.at(am);
280  }
285  unsigned int max_vector_stack_size(unsigned int am) const {
286  if (am + 1 > max_vector_stack_size_.size())
287  return 0;
288  else
289  return max_vector_stack_size_[am];
290  }
294  unsigned int max_hrr_hsrank(unsigned int am) const {
295  if (am + 1 > max_hrr_hsrank_.size())
296  return 0;
297  else
298  return max_hrr_hsrank_[am];
299  }
303  unsigned int max_hrr_lsrank(unsigned int am) const {
304  if (am + 1 > max_hrr_lsrank_.size())
305  return 0;
306  else
307  return max_hrr_lsrank_[am];
308  }
309 
311  void max_ntarget(unsigned int ntarget) {
312  if (max_ntarget_ < ntarget)
313  max_ntarget_ = ntarget;
314  }
315 
317  void max_stack_size(unsigned int am, unsigned int size) {
318  extend_max_size(max_stack_size_, am, size);
319  }
320 
322  void max_vector_stack_size(unsigned int am, unsigned int size) {
323  extend_max_size(max_vector_stack_size_, am, size);
324  }
325 
327  void max_hrr_hsrank(unsigned int am, unsigned int rank) {
328  extend_max_size(max_hrr_hsrank_, am, rank);
329  }
330 
332  void max_hrr_lsrank(unsigned int am, unsigned int rank) {
333  extend_max_size(max_hrr_lsrank_, am, rank);
334  }
335 
336  private:
337  unsigned int max_ntarget_;
338  std::vector<unsigned int> max_stack_size_; //< keeps track of stack size needed to compute integrals up to a given quantum number
339  std::vector<unsigned int> max_vector_stack_size_;
340  std::vector<unsigned int> max_hrr_hsrank_;
341  std::vector<unsigned int> max_hrr_lsrank_;
342 
343  static void extend_max_size(std::vector<unsigned int>& max_size, unsigned int am, unsigned int size) {
344  const int max_am = (int)max_size.size() - 1u;
345  if (max_am < (int)am) {
346  max_size.resize(am + 1);
347  for(int l = std::max(max_am+1,1); l<=(int)am; ++l)
348  max_size[l] = max_size[l-1];
349  }
350  if (max_size[am] < size)
351  max_size[am] = size;
352  }
353  };
354 
360  static const unsigned int num_am_letters = 10;
362  static const char am_letters[num_am_letters+1];
363  };
364 
366  std::string label_to_funcname(const std::string& label);
367 
370  bool condense_expr(unsigned int unroll_threshold, bool vectorize);
371 };
372 
373 #endif
374 
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:332
void source_directory(const std::string &a)
set generated source directory
Definition: default_params.h:132
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:317
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:322
void vectorize_by_line(bool flag)
set vectorize_by_line flag
Definition: default_params.h:120
const std::string & default_task_name() const
default task name
Definition: default_params.h:105
Static parameters.
Definition: default_params.h:356
std::string label_to_funcname(const std::string &label)
Converts a label, e.g. name of the target node, to the name of the function to compute it...
Definition: default_params.cc:215
unsigned int align_size() const
returns alignment size (in units of sizeof(LIBINT_FLOAT))
Definition: default_params.h:65
void unroll_threshold(unsigned int a)
set unroll threshold
Definition: default_params.h:128
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:228
void single_evaltype(bool se)
generate a single evaluator type (i.e. not specific to each task)?
Definition: default_params.h:140
bool profile() const
whether profiling instrumentation is enabled
Definition: default_params.h:89
void contracted_targets(bool c)
support contracted targets?
Definition: default_params.h:164
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
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:327
unsigned int max_vector_length() const
returns max vector length
Definition: default_params.h:53
void realtype(const std::string &realtype)
which floating-point type to use
Definition: default_params.h:160
This class maintains various parameters for each task type which can only be determined during the so...
Definition: default_params.h:264
unsigned int unroll_threshold() const
returns unroll threshold
Definition: default_params.h:61
void print(std::ostream &os) const
print params out
Definition: default_params.cc:55
const std::string & source_directory() const
returns directory path for the generated source
Definition: default_params.h:69
unsigned int max_ntarget() const
returns the max number of targets
Definition: default_params.h:270
void accumulate_targets(bool a)
accumulate targets?
Definition: default_params.h:156
const std::string & api_prefix() const
the API prefix
Definition: default_params.h:73
const std::string & realtype() const
name of the floating-point type
Definition: default_params.h:97
void max_vector_length(unsigned int a)
set max vector length
Definition: default_params.h:116
void default_task_name(const std::string &s)
default task name
Definition: default_params.h:168
unsigned int max_am() const
returns the max quantum number of targets
Definition: default_params.h:274
CompilationParameters()
Use default parameters.
Definition: default_params.cc:33
unsigned int max_hrr_hsrank(unsigned int am) const
returns max rank of high-significance functions in a HRR call.
Definition: default_params.h:294
bool single_evaltype() const
generate single evaluator type (i.e. not specific to each task)?
Definition: default_params.h:77
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:99
void use_C_linking(bool a)
set whether to use C style linking
Definition: default_params.h:144
bool accumulate_targets() const
whether target integrals are accumulated
Definition: default_params.h:93
void profile(bool a)
set to instrument profiling
Definition: default_params.h:152
bool contracted_targets() const
whether contracted targets are supported
Definition: default_params.h:101
unsigned int max_vector_stack_size(unsigned int am) const
returns max vector stack size.
Definition: default_params.h:285
bool count_flops() const
whether FLOP counting is enabled
Definition: default_params.h:85
void align_size(unsigned int a)
set alignment size (in units of sizeof(LIBINT_FLOAT))
Definition: default_params.h:124
unsigned int max_hrr_lsrank(unsigned int am) const
returns max rank of low-significance functions in a HRR call.
Definition: default_params.h:303
unsigned int num_bf(std::string t="") const
returns number of basis functions in integrals for task t
Definition: default_params.cc:127
void api_prefix(const std::string &a)
API prefix.
Definition: default_params.h:136
bool use_C_linking() const
returns whether to use C-style linking
Definition: default_params.h:81
void count_flops(bool a)
set whether to count FLOPs
Definition: default_params.h:148
These are the parameters received by the compiler.
Definition: default_params.h:37
bool vectorize_by_line() const
returns whether to vectorize line-by-line
Definition: default_params.h:57
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:113
void max_ntarget(unsigned int ntarget)
if max_ntarget_ < ntarget then set max_ntarget_=ntarget
Definition: default_params.h:311
unsigned int max_stack_size(unsigned int am) const
returns max stack size needed for quantum numbers up to am
Definition: default_params.h:278