FunctionBuilder

class FunctionBuilder

Records instructions and freezes them into a Function.

Construct it with the input and output types, read the graph inputs with input, add nodes by calling the instruction methods (for example add, stack or two_body_decay_com, listed below), wire the results to the outputs with output, then call function to obtain the finished Function. The instruction methods are generated from madspace/instruction_set.yaml.

Public Functions

FunctionBuilder(const NamedVector<Type> &_input_types, const NamedVector<Type> &_output_types)

Start an empty builder with the given input and output types.

FunctionBuilder(const Function &function)

Start a builder pre-populated with an existing function.

Value input(int index) const

The graph input at position index.

ValueVec input_range(int start_index, int end_index) const

The graph inputs in the half-open range [start_index, end_index).

void output(int index, Value value)

Wire value to the graph output at position index.

void output_range(int start_index, const ValueVec &values)

Wire values to the graph outputs starting at start_index.

Value global(const std::string &name, DataType dtype, const std::vector<int> &shape)

Declare a named global tensor and return a value reading it.

Parameters:
  • name – global name

  • dtype – element data type

  • shape – static shape, without the batch dimension

ValueVec instruction(const std::string &name, const ValueVec &args)

Append the instruction name with arguments args; returns its outputs.

ValueVec instruction(InstructionPtr instruction, const ValueVec &args)

Append instruction with arguments args; returns its outputs.

inline std::size_t current_stream() const

Index of the execution stream new instructions are added to.

inline void set_current_stream(std::size_t stream_index)

Select the execution stream new instructions are added to.

Function function()

Freeze the recorded graph into an immutable Function.

Value sum(const ValueVec &values)

Sum of values, element by element.

Value product(const ValueVec &values)

Product of values, element by element.