Template Class Generator¶
Defined in File generator.hpp
Inheritance Relationships¶
Derived Types¶
public sequant::JuliaTensorOperationsGenerator< JuliaITensorGeneratorContext >(Template Class JuliaTensorOperationsGenerator)public sequant::JuliaTensorOperationsGenerator< JuliaTensorKitGeneratorContext >(Template Class JuliaTensorOperationsGenerator)public sequant::PythonEinsumGeneratorBase< NumPyEinsumGeneratorContext >(Template Class PythonEinsumGeneratorBase)public sequant::PythonEinsumGeneratorBase< PyTorchEinsumGeneratorContext >(Template Class PythonEinsumGeneratorBase)public sequant::GenerationOptimizer< MainGenerator, MainContext >(Template Class GenerationOptimizer)public sequant::ItfGenerator< Context >(Template Class ItfGenerator)public sequant::JuliaTensorOperationsGenerator< Context >(Template Class JuliaTensorOperationsGenerator)public sequant::TextGenerator< Context >(Template Class TextGenerator)
Class Documentation¶
-
template<typename C>
class Generator¶ Abstract base class for all (code) generators. These work by implementing callbacks for semantic actions and their job is to perform (piecewise) translation of those semantic actions into the corresponding code.
Subclassed by sequant::JuliaTensorOperationsGenerator< JuliaITensorGeneratorContext >, sequant::JuliaTensorOperationsGenerator< JuliaTensorKitGeneratorContext >, sequant::PythonEinsumGeneratorBase< NumPyEinsumGeneratorContext >, sequant::PythonEinsumGeneratorBase< PyTorchEinsumGeneratorContext >, sequant::GenerationOptimizer< MainGenerator, MainContext >, sequant::ItfGenerator< Context >, sequant::JuliaTensorOperationsGenerator< Context >, sequant::TextGenerator< Context >
Public Functions
-
virtual ~Generator() = default¶
-
virtual std::string get_format_name() const = 0¶
- Returns:
The name of the format this generator will produce (i.e. the name of the programming language and/or framework)
-
virtual bool supports_named_sections() const = 0¶
- Returns:
Whether this generator supports named sections
-
virtual bool requires_named_sections() const = 0¶
- Returns:
Whether this generator requires names (that is, it can’t deal with code outside of named sections)
-
virtual DeclarationScope index_declaration_scope() const = 0¶
- Returns:
The scope at which this generator would like declare indices
-
virtual DeclarationScope variable_declaration_scope() const = 0¶
- Returns:
The scope at which this generator would like declare variables
-
virtual DeclarationScope tensor_declaration_scope() const = 0¶
- Returns:
The scope at which this generator would like declare tensors
-
virtual PrunableScalars prunable_scalars() const = 0¶
- Returns:
What kinds of scalars may be pruned from the expression tree in order to avoid binary computation steps for them. Instead, all pruned scalars will be multiplied with whatever binary expression remains after pruning. This means that scalar pruning may lead to non-binary expressions that need to be exported by this generator.
-
virtual std::string represent(const Index &idx, const Context &ctx) const = 0¶
- Returns:
A backend-specific string representation of the given Index
-
virtual std::string represent(const Tensor &tensor, const Context &ctx) const = 0¶
- Returns:
A backend-specific string representation of the given Tensor
-
virtual std::string represent(const Variable &variable, const Context &ctx) const = 0¶
- Returns:
A backend-specific string representation of the given Variable
-
virtual std::string represent(const Constant &constant, const Context &ctx) const = 0¶
- Returns:
A backend-specific string representation of the given Constant
-
virtual void create(const Tensor &tensor, bool zero_init, const Context &ctx) = 0¶
Semantic callback for creating the given tensor. This is expected to make the created tensor available for further use.
-
virtual void load(const Tensor &tensor, bool set_to_zero, const Context &ctx) = 0¶
Semantic callback for loading the given tensor. Loading implies making the tensor available for subsequent use (e.g. by reading it from disk in order to bring it into RAM).
-
virtual void set_to_zero(const Tensor &tensor, const Context &ctx) = 0¶
Semantic callback for setting the given tensor to zero.
-
virtual void unload(const Tensor &tensor, const Context &ctx) = 0¶
Semantic callback for unloading the given tensor. This is expected to discard the tensor without saving its current value. However, the tensor must still be loadable afterwards.
-
virtual void destroy(const Tensor &tensor, const Context &ctx) = 0¶
Semantic callback for destroying the given tensor. Destroying means that this tensor will never be needed again and is no longer required to be loadable.
-
virtual void persist(const Tensor &tensor, const Context &ctx) = 0¶
Semantic callback for persisting the given tensor. Persisting means that the current value of the tensor is stored in some way that makes its value available at a later time.
-
virtual void create(const Variable &variable, bool zero_init, const Context &ctx) = 0¶
Semantic callback for creating the given variable. This is expected to make the created variable available for further use.
-
virtual void load(const Variable &variable, bool set_to_zero, const Context &ctx) = 0¶
Semantic callback for loading the given variable. Loading implies making the variable available for subsequent use (e.g. by reading it from disk in order to bring it into RAM).
-
virtual void set_to_zero(const Variable &variable, const Context &ctx) = 0¶
Semantic callback for setting the given variable to zero.
-
virtual void unload(const Variable &variable, const Context &ctx) = 0¶
Semantic callback for unloading the given variable. This is expected to discard the variable without saving its current value. However, the variable must still be loadable afterwards.
-
virtual void destroy(const Variable &variable, const Context &ctx) = 0¶
Semantic callback for destroying the given variable. Destroying means that this variable will never be needed again and is no longer required to be loadable.
-
virtual void persist(const Variable &tensor, const Context &ctx) = 0¶
Semantic callback for persisting the given variable. Persisting means that the current value of the variable is stored in some way that makes its value available at a later time.
-
virtual void compute(const Expr &expression, const Tensor &result, const Context &ctx) = 0¶
Semantic callback for encoding the computation of the given expression. The result is expected to be written into the provided Tensor.
-
virtual void compute(const Expr &expression, const Variable &result, const Context &ctx) = 0¶
Semantic callback for encoding the computation of the given expression. The result is expected to be written into the provided Variable.
-
virtual void declare(const Index &idx, const Context &ctx) = 0¶
Semantic callback for declaring the provided Index.
-
virtual void declare(const Variable &variable, UsageSet usage, const Context &ctx) = 0¶
Semantic callback for declaring the provided Variable
-
virtual void declare(const Tensor &tensor, UsageSet usage, const Context &ctx) = 0¶
Semantic callback for declaring the provided Tensor
-
virtual void all_indices_declared(std::size_t amount, const Context &ctx) = 0¶
Callback signalling that all indices have been declared
- Parameters:
amount – The amount of indices that have been declared
-
virtual void all_variables_declared(std::size_t amount, const Context &ctx) = 0¶
Callback signalling that all variables have been declared
- Parameters:
amount – The amount of variables that have been declared
-
virtual void all_tensors_declared(std::size_t amount, const Context &ctx) = 0¶
Callback signalling that all tensors have been declared
- Parameters:
amount – The amount of tensors that have been declared
-
virtual void begin_declarations(DeclarationScope scope, const Context &ctx) = 0¶
Callback signalling that we now start declarations for the given scope.
-
virtual void end_declarations(DeclarationScope scope, const Context &ctx) = 0¶
Callback signalling that all declarations for the given scope have been performed
-
virtual void insert_comment(const std::string &comment, const Context &ctx) = 0¶
Semantic callback for inserting a comment at the current position in the generated code
- Parameters:
comment – The comment to insert
-
virtual void begin_named_section(std::string_view name, const Context &ctx) = 0¶
Semantic callback that we are starting a new named section
- Parameters:
name – The name of the named section
-
virtual void end_named_section(std::string_view name, const Context &ctx) = 0¶
Semantic callback to signal that we have reached the end of the current named section
- Parameters:
name – The name of the named section that is ending now
-
virtual void begin_expression(const Context &ctx) = 0¶
Callback signalling that we now begin export of a new (high-level) expression
-
virtual void end_expression(const Context &ctx) = 0¶
Callback signalling that the export of the current (high-level) expression is finished
-
virtual void begin_export(const Context &ctx) = 0¶
Callback signalling that we now begin with the export process.
-
virtual void end_export(const Context &ctx) = 0¶
Callback signalling that the export process is finished.
-
virtual std::string get_generated_code() const = 0¶
- Returns:
The generated code that corresponds to all semantic actions encountered during the current export
Protected Functions
-
Generator() = default¶
-
virtual ~Generator() = default¶