21 #ifndef _libint2_src_bin_libint_buildtest_h_ 22 #define _libint2_src_bin_libint_buildtest_h_ 31 #include <integral_11_11.h> 35 #include <graph_registry.h> 40 void generate_rr_code(std::ostream& os,
const SafePtr<CompilationParameters>& cparams,
41 std::deque<std::string>& decl_filenames,
42 std::deque<std::string>& def_filenames);
47 const SafePtr<CodeContext>& context,
48 const SafePtr<CompilationParameters>& cparams,
49 const SafePtr<Strategy>& strat,
50 const SafePtr<Tactic>& tactic,
51 const SafePtr<MemoryManager>& memman,
52 std::deque<std::string>& decl_filenames,
53 std::deque<std::string>& def_filenames,
54 const std::string& prefix,
55 const std::string& label,
59 template <
unsigned int N>
65 const std::vector<unsigned int>& am()
const {
return am_; }
66 unsigned int size_to_unroll()
const {
return size_to_unroll_; }
67 unsigned int veclen()
const {
return veclen_; }
68 bool vectorize_by_line()
const {
return vectorize_by_line_; }
69 bool do_cse()
const {
return do_cse_; }
72 static const unsigned int max_am = 10;
73 std::vector<unsigned int> am_;
74 unsigned int size_to_unroll_;
76 bool vectorize_by_line_;
84 template <
class Integral,
bool GenAllCode>
85 void BuildTest(
const std::vector< SafePtr<Integral> >& targets,
unsigned int size_to_unroll,
unsigned int veclen,
86 bool vec_by_line,
bool do_cse,
const std::string& complabel =
"buildtest",
87 std::ostream& os = std::cout);
93 template <
class Integral,
bool GenAllCode>
94 void __BuildTest(
const std::vector< SafePtr<Integral> >& targets,
const SafePtr<CompilationParameters>& cparams,
95 unsigned int size_to_unroll, std::ostream& os = std::cout,
98 const std::string& complabel =
"general_integral");
100 template <
class Integral,
bool GenAllCode>
102 __BuildTest(
const std::vector< SafePtr<Integral> >& targets,
const SafePtr<CompilationParameters>& cparams,
103 unsigned int size_to_unroll, std::ostream& os,
104 const SafePtr<Tactic>& tactic,
const SafePtr<MemoryManager>& memman,
105 const std::string& complabel)
107 const std::string prefix(
"");
108 const std::string label = cparams->api_prefix() + complabel;
109 SafePtr<Strategy> strat(
new Strategy);
113 taskmgr.
add(complabel);
119 unsigned int max_am = 0;
120 for(
unsigned int t=0; t<targets.size(); ++t) {
121 const SafePtr<Integral>& target = targets[t];
122 const unsigned int np = target->bra().num_part();
124 for(
unsigned int p=0; p<np; p++) {
125 const unsigned int nf = target->bra().num_members(p);
126 for(
unsigned int f=0; f<nf; f++) {
128 const unsigned int am = target->bra(p,f).qn();
130 max_am = max(max_am,am);
134 for(
unsigned int p=0; p<np; p++) {
135 const unsigned int nf = target->ket().num_members(p);
136 for(
unsigned int f=0; f<nf; f++) {
138 const unsigned int am = target->ket(p,f).qn();
140 max_am = max(max_am,am);
144 const bool need_to_optimize = (max_am <= cparams->max_am_opt(complabel));
146 std::deque<std::string> decl_filenames;
147 std::deque<std::string> def_filenames;
149 os <<
"Building " << complabel << std::endl;
152 dg_xxxx->set_label(complabel);
155 dg_xxxx->registry()->do_cse(need_to_optimize);
156 dg_xxxx->registry()->condense_expr(
condense_expr(size_to_unroll,cparams->max_vector_length()>1));
158 dg_xxxx->registry()->accumulate_targets(cparams->accumulate_targets());
159 dg_xxxx->registry()->unroll_threshold(size_to_unroll);
161 for(
unsigned int t=0; t<targets.size(); ++t) {
162 const SafePtr<Integral>& target = targets[t];
163 SafePtr<DGVertex> target_ptr = dynamic_pointer_cast<DGVertex,Integral>(target);
164 assert(target_ptr != 0);
165 dg_xxxx->append_target(target_ptr);
169 GenerateCode(dg_xxxx, context, cparams, strat, tactic, memman,
170 decl_filenames, def_filenames,
171 prefix, label,
false);
174 taskmgr.
current().params()->max_stack_size(max_am, memman->max_memory_used());
175 taskmgr.
current().params()->max_ntarget(targets.size());
176 os <<
"Max memory used = " << memman->max_memory_used() << std::endl;
182 SafePtr<Libint2Iface> iface(
new Libint2Iface(cparams,icontext));
185 std::ostringstream oss;
186 for(std::deque<std::string>::const_iterator i = decl_filenames.begin(); i != decl_filenames.end(); ++i) {
187 oss <<
"#include <" << *i <<
">" << std::endl;
189 iface->to_int_iface(oss.str());
192 iface->to_params(iface->macro_define(
"CARTGAUSS_MAX_AM",LIBINT_CARTGAUSS_MAX_AM));
193 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING",LIBINT_CGSHELL_ORDERING));
194 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING_STANDARD",LIBINT_CGSHELL_ORDERING_STANDARD));
195 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING_INTV3",LIBINT_CGSHELL_ORDERING_INTV3));
196 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING_GAMESS",LIBINT_CGSHELL_ORDERING_GAMESS));
197 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING_ORCA",LIBINT_CGSHELL_ORDERING_ORCA));
198 iface->to_params(iface->macro_define(
"CGSHELL_ORDERING_BAGEL",LIBINT_CGSHELL_ORDERING_BAGEL));
199 iface->to_params(iface->macro_define(
"SHELLQUARTET_SET",LIBINT_SHELL_SET));
200 iface->to_params(iface->macro_define(
"SHELLQUARTET_SET_STANDARD",LIBINT_SHELL_SET_STANDARD));
201 iface->to_params(iface->macro_define(
"SHELLQUARTET_SET_ORCA",LIBINT_SHELL_SET_ORCA));
204 generate_rr_code(os,cparams,
205 decl_filenames, def_filenames);
208 std::cout <<
"Generated headers: ";
209 std::copy(decl_filenames.begin(), decl_filenames.end(), std::ostream_iterator<std::string>(std::cout,
" "));
210 std::cout << std::endl <<
"Generated sources: ";
211 std::copy(def_filenames.begin(), def_filenames.end(), std::ostream_iterator<std::string>(std::cout,
" "));
212 std::cout << std::endl <<
"Top compute function: " << context->label_to_name(
label_to_funcname(label)) << std::endl;
219 const SafePtr<CodeContext>& context,
220 const SafePtr<CompilationParameters>& cparams,
221 const SafePtr<Strategy>& strat,
222 const SafePtr<Tactic>& tactic,
223 const SafePtr<MemoryManager>& memman,
224 std::deque<std::string>& decl_filenames,
225 std::deque<std::string>& def_filenames,
226 const std::string& prefix,
227 const std::string& label,
230 dg->apply(strat,tactic);
231 #if PRINT_DAG_GRAPHVIZ 233 std::basic_ofstream<char> dotfile(dg->label() +
".strat.dot");
234 dg->print_to_dot(
false,dotfile);
237 dg->optimize_rr_out(context);
239 std::cout <<
"The number of vertices = " << dg->num_vertices() << std::endl;
244 if (dg->missing_prerequisites()) {
248 std::deque< SafePtr<DGVertex> > prereq_list = pe.vertices;
253 #if PRINT_DAG_GRAPHVIZ 255 std::basic_ofstream<char> dotfile(dg->label() +
".expr.dot");
256 dg->print_to_dot(
false,dotfile);
260 std::string decl_filename(prefix + context->label_to_name(label)); decl_filename +=
".h";
261 std::string def_filename(prefix + context->label_to_name(label)); def_filename +=
".cc";
262 std::basic_ofstream<char> declfile(decl_filename.c_str());
263 std::basic_ofstream<char> deffile(def_filename.c_str());
267 args->append_symbol(
"parent_stack");
269 label,declfile,deffile);
276 #if PRINT_DAG_GRAPHVIZ 278 std::basic_ofstream<char> dotfile(dg->label() +
".symb.dot");
279 dg->print_to_dot(
true,dotfile);
283 decl_filenames.push_back(decl_filename);
284 def_filenames.push_back(def_filename);
287 if (dg->missing_prerequisites()) {
291 dg_prereq->registry() = SafePtr<GraphRegistry>(dg->registry()->clone());
295 dg_prereq->registry()->uncontract(
true);
296 assert(cparams->contracted_targets() ==
true);
297 dg_prereq->registry()->return_targets(
false);
298 dg_prereq->registry()->accumulate_targets(
true);
299 dg_prereq->registry()->stack_name(
"stack");
300 if (dg->registry()->current_timer() >= 0) {
301 dg_prereq->registry()->current_timer( dg->registry()->current_timer() + 1 );
310 while (!prereq_list.empty()) {
311 dg_prereq->append_target(prereq_list.front());
312 prereq_list.pop_front();
315 const std::string label_prereq = label +
"_prereq";
316 GenerateCode(dg_prereq, context, cparams, strat, tactic, memman,
317 decl_filenames, def_filenames,
318 prefix, label_prereq,
true);
326 template <
class Integral,
bool GenAllCode>
327 void BuildTest(
const std::vector< SafePtr<Integral> >& targets,
unsigned int size_to_unroll,
unsigned int veclen,
328 bool vec_by_line,
bool do_cse,
const std::string& complabel,
331 const unsigned int max_am = 10;
332 os <<
"generating code to compute " << complabel << std::endl;
335 taskmgr.
add(complabel);
340 cparams->max_am(complabel,max_am);
341 cparams->num_bf(complabel,4u);
342 cparams->max_vector_length(veclen);
343 cparams->vectorize_by_line(vec_by_line);
344 #if LIBINT_ALIGN_SIZE 345 cparams->align_size(LIBINT_ALIGN_SIZE);
347 cparams->count_flops(
true);
348 #if LIBINT_ACCUM_INTS 349 cparams->accumulate_targets(
true);
351 cparams->accumulate_targets(
false);
353 #ifdef LIBINT_API_PREFIX 355 const std::string api_prefix(LIBINT_API_PREFIX);
356 cparams->api_prefix(api_prefix);
359 #if LIBINT_CONTRACTED_INTS 360 cparams->contracted_targets(
true);
362 cparams->contracted_targets(
false);
364 #ifdef LIBINT_USER_DEFINED_REAL 366 const std::string realtype(LIBINT_USER_DEFINED_REAL);
367 cparams->realtype(realtype);
372 cparams->max_am_opt(complabel,max_am);
375 cparams->max_am_opt(complabel,0);
377 cparams->default_task_name(complabel);
384 SafePtr<Tactic> tactic;
387 typename Integral::OperatorType,
388 typename Integral::AuxIndexType> genint_11_11_t;
389 SafePtr< genint_11_11_t > cast_ptr = dynamic_pointer_cast<genint_11_11_t>(targets.front());
391 const unsigned int la = cast_ptr->
bra(0, 0).norm();
392 const unsigned int lb = cast_ptr->ket(0, 0).norm();
393 const unsigned int lc = cast_ptr->bra(1, 0).norm();
394 const unsigned int ld = cast_ptr->ket(1, 0).norm();
402 __BuildTest<Integral,true>(targets,cparams,size_to_unroll,os,tactic,memman,complabel);
405 template <
unsigned int N>
406 TesterCmdLine<N>::TesterCmdLine(
int argc,
char* argv[])
409 throw ProgrammingError(
"TesterCmdLine<N>::TesterCmdLine but N is 0");
410 const int argc_min = N + 2;
411 const int argc_max = N + 5;
412 if (argc < argc_min || argc > argc_max) {
413 std::cerr <<
"Usage: " << argv[0] <<
" <am> size_to_unroll [vector_length] [vector_method] [do_cse]" << std::endl
414 <<
" <am> -- angular momenta on each center, e.g. 4 nonnegative integers for a 4-center ERI" << std::endl
415 <<
" size_to_unroll -- size of the largest integral set to be unrolled" << std::endl
416 <<
" vector_length -- (optional) max vector length. Defaults to 1." << std::endl
417 <<
" vector_method -- (optional) vectorization method. Valid choices are 0 (by-block) and 1 (by-line). Defaults to 0." << std::endl
418 <<
" do_cse -- (optional) do Common Subexpression Elimination? Valid choices are 0 (no) and 1 (yes). Defaults to 0." << std::endl << std::endl;
419 throw InputError(
"TesterCmdLine<N>::TesterCmdLine -- incorrect number of command-line arguments");
421 for(
unsigned int i=1; i<N+1; ++i) {
422 const unsigned int am = atoi(argv[i]);
424 throw InputError(
"TesterCmdLine<N>::TesterCmdLine -- angular momentum limit exceeded");
427 size_to_unroll_ = atoi(argv[N+1]);
431 veclen_ = atoi(argv[N+2]);
433 vectorize_by_line_ =
false;
435 vectorize_by_line_ = (1 == atoi(argv[N+3]));
439 do_cse_ = (1 == atoi(argv[N+4]));
FirstChoiceTactic simply chooses the first RR.
Definition: tactic.h:61
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:216
Manages tasks. This is a Singleton.
Definition: task.h:63
Libint2Iface is used to generate Libint2 interfaces.
Definition: iface.h:43
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:229
static SafePtr< ImplicitDimensions > default_dims()
Default ImplicitDimension object.
Definition: dims.cc:38
void __BuildTest(const std::vector< SafePtr< Integral > > &targets, const SafePtr< CompilationParameters > &cparams, unsigned int size_to_unroll, std::ostream &os=std::cout, const SafePtr< Tactic > &tactic=SafePtr< Tactic >(new FirstChoiceTactic< DummyRandomizePolicy >), const SafePtr< MemoryManager > &memman=SafePtr< MemoryManager >(new WorstFitMemoryManager), const std::string &complabel="general_integral")
This is a generic test of building an Integral using specified cparams, memman, size_to_unroll,...
Definition: buildtest.h:102
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
void extract_symbols(const SafePtr< DirectedGraph > &dg)
extracts external symbols and RRs from the graph
Definition: dg.cc:2357
Generic integral over a two-body operator with one bfs for each particle in bra and ket.
Definition: integral_11_11.h:33
void current(const std::string &task_label)
Makes this task current (must have been added already)
Definition: task.cc:76
Strategy specifies how to apply recurrence relations.
Definition: strategy.h:42
Command-line parser for the standard build tester – N is the number of centers, i....
Definition: buildtest.h:60
void BuildTest(const std::vector< SafePtr< Integral > > &targets, unsigned int size_to_unroll, unsigned int veclen, bool vec_by_line, bool do_cse, const std::string &complabel="buildtest", std::ostream &os=std::cout)
This is a user-friendly generic test of building an Integral using specified size_to_unroll,...
Definition: buildtest.h:327
CppCodeContext is an implementation of CodeContext for C++.
Definition: context.h:207
void add(const std::string &task_label)
Adds a new task. Do nothing if the task exists already.
Definition: task.cc:40
WorstFitMemoryManager allocates memory by trying to find the largest-possible free block.
Definition: src/bin/libint/memory.h:208
BraSetType::bfs_cref bra(unsigned int p, unsigned int i) const
Implementation of IntegralSet::bra() const.
Definition: integral.h:316
Class CodeSymbols specifies a set of symbols used in a code.
Definition: code.h:34
void GenerateCode(const SafePtr< DirectedGraph > &dg, const SafePtr< CodeContext > &context, const SafePtr< CompilationParameters > &cparams, const SafePtr< Strategy > &strat, const SafePtr< Tactic > &tactic, const SafePtr< MemoryManager > &memman, std::deque< std::string > &decl_filenames, std::deque< std::string > &def_filenames, const std::string &prefix, const std::string &label, bool have_parent)
defined below generates code for dg; dg and memman are reset at the end
Definition: buildtest.h:218
FourCenter_OS_Tactic decides graph build for (bra0 ket0| bra1 ket1) = <bra0 bra1|ket0 ket1>
Definition: tactic.h:164
static LibraryTaskManager & Instance()
LibraryTaskManager is a Singleton.
Definition: task.cc:34
static void set_default_dims(const SafePtr< CompilationParameters > &cparams)
Sets default ImplicitDimension object.
Definition: dims.cc:31
The shift parameter is computed as follows: delta = floor(nrrs*scale*random()/RAND_MAX) where nrrs is...
Definition: tactic.h:198
These are the parameters received by the compiler.
Definition: default_params.h:38
DirectedGraph is an implementation of a directed graph composed of vertices represented by DGVertex o...
Definition: dg.h:63