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 exampleadd,stackortwo_body_decay_com, listed below), wire the results to the outputs withoutput, then callfunctionto obtain the finished Function. The instruction methods are generated frommadspace/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.
-
ValueVec input_range(int start_index, int end_index) const¶
The graph inputs in the half-open range [
start_index,end_index).
-
void output_range(int start_index, const ValueVec &values)¶
Wire
valuesto the graph outputs starting atstart_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
namewith argumentsargs; returns its outputs.
-
ValueVec instruction(InstructionPtr instruction, const ValueVec &args)¶
Append
instructionwith argumentsargs; 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.
-
FunctionBuilder(const NamedVector<Type> &_input_types, const NamedVector<Type> &_output_types)¶