Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/bin/libint/dg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <cstdio>
#include <fstream>
#include <functional>
#include <set>
#include <utility>

using namespace std;
Expand Down Expand Up @@ -427,6 +428,7 @@ void DirectedGraph::reset() {
targets_.clear();
first_to_compute_.reset();
func_names_.clear();
hoisted_precomputed_.clear();
}

/// Apply a strategy to all vertices not yet computed (i.e. which do not have
Expand Down Expand Up @@ -1205,6 +1207,12 @@ void DirectedGraph::generate_code(
def << context->macro_endif();
}

// load the precomputed quantities that assign_symbols() hoisted
for (const auto& h : hoisted_precomputed_)
def << context->decldef(
context->const_modifier() + context->type_name<double>(), h.first,
h.second);

// now print out the code for this graph
print_def(context, def, dims, args);

Expand Down Expand Up @@ -1502,6 +1510,8 @@ void DirectedGraph::assign_symbols(
}

// then process all other symbols, EXCEPT operators
hoisted_precomputed_.clear();
std::set<std::string> hoisted_names;
for (iter v = stack_.begin(); v != stack_.end(); ++v) {
const ver_ptr& vptr = vertex_ptr(*v);
#if DEBUG
Expand All @@ -1528,10 +1538,22 @@ void DirectedGraph::assign_symbols(
// test if the vertex is precomputed runtime quantity, like a geometric
// parameter
if ((vptr)->precomputed()) {
std::string symbol("inteval->");
symbol += context->label_to_name((vptr)->label());
symbol += "[vi]";
(vptr)->set_symbol(symbol);
const std::string field =
"inteval->" + context->label_to_name((vptr)->label());
// in scalar code load each such quantity from inteval once, into a
// local declared by generate_code(): stores to the stack may alias
// inteval's fields, so the compiler cannot hoist these loads itself.
// a vertex that refers to another takes its symbol from the referred
// vertex, so do not hoist it
if (context->cparams()->max_vector_length() == 1 &&
!(vptr)->refers_to_another()) {
const std::string local =
"hv_" + context->label_to_name((vptr)->label());
(vptr)->set_symbol(local);
if (hoisted_names.insert(local).second)
hoisted_precomputed_.emplace_back(local, field + "[0]");
} else
(vptr)->set_symbol(field + "[vi]");
continue;
}

Expand Down
10 changes: 8 additions & 2 deletions src/bin/libint/dg.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ class DirectedGraph : public std::enable_shared_from_this<DirectedGraph> {
*/
FuncNameContainer func_names_;

/** precomputed quantities hoisted by assign_symbols() in scalar code, as
{local variable name, inteval field it is loaded from}, in the order
generate_code() declares them
*/
std::vector<std::pair<std::string, std::string>> hoisted_precomputed_;

#if !USE_ASSOCCONTAINER_BASED_DIRECTEDGRAPH
static const unsigned int default_size_ = 100;
#endif
Expand Down Expand Up @@ -427,7 +433,7 @@ class DirectedGraph : public std::enable_shared_from_this<DirectedGraph> {
/// graph
std::shared_ptr<DGVertex> insert_expr_at(
const std::shared_ptr<DGVertex>& where,
const std::shared_ptr<AlgebraicOperator<DGVertex> >& expr);
const std::shared_ptr<AlgebraicOperator<DGVertex>>& expr);
/// This function replaces RecurrenceRelations with concrete arithemtical
/// expressions
void replace_rr_with_expr();
Expand Down Expand Up @@ -529,7 +535,7 @@ void extract_symbols(const std::shared_ptr<DirectedGraph>& dg);

// use these functors with DirectedGraph::foreach
struct PrerequisitesExtractor {
std::deque<std::shared_ptr<DGVertex> > vertices;
std::deque<std::shared_ptr<DGVertex>> vertices;
void operator()(const std::shared_ptr<DGVertex>& v);
};
struct VertexPrinter {
Expand Down
Loading