Template Class PreprocessVisitor

Class Documentation

template<typename T>
class PreprocessVisitor

Preprocesses the provided binary tree by

  • removing explicit appearances of scalar leafs. We don’t want them to be represented in the tree. Instead, we keep track of them in a different way in order to be able to give scalar factors alongside the actual tensor contraction they are supposed to scale (this is necessary as there are backends which only support scaling in this context)

  • rebalance the tree such that for any given non-leaf node, its left subtree is always larger (or equally large) than its right one. This ensures that we have to have the least amount of tensors loaded at the same time, when generating code for a backend which only supports stack-like memory allocations (e.g. when A is allocated before B, B must be deleted before A can be deleted).

  • Rename intermediate tensors that have the same name and describe the same tensor block, which are required as two separate entities at the same time when evaluating the tree (thus a single tensor object is insufficient). While doing so, we also collect meta information about the expression(s) encoded in this tree.

Public Functions

inline PreprocessVisitor(PreprocessResult &result, ExportContext &ctx, PrunableScalars prunable)
inline void operator()(ExportNode<T> &tree, TreeTraversal context)
inline void prune_scalar_factors(ExportNode<T> &tree)
inline void preprocess_node_content(ExportNode<T> &node)
inline void rebalance_tree(ExportNode<T> &tree)
inline void set_compute_selection(ExportNode<T> &node)
inline void release_used_terms(ExportNode<T> &node)