Code Generation
Types
ComputableDAGs.Tape
— TypeTape{INPUT}
TODO: update docs
INPUT
the input type of the problem instancecode::Vector{Expr}
: The julia expression containing the code for the whole graph.inputSymbols::Dict{String, Vector{Symbol}}
: A dictionary of symbols mapping the names of the input nodes of the graph to the symbols their inputs should be provided on.outputSymbol::Symbol
: The symbol of the final calculated value
Function Generation
Implementations for generation of a callable function. A function generated this way cannot immediately be called. One Julia World Age has to pass before this is possible, which happens when the global Julia scope advances. If the DAG and therefore the generated function becomes too large, use the tape machine instead, since compiling large functions becomes infeasible.
ComputableDAGs.execute
— Methodexecute(
graph::DAG,
instance,
machine::Machine,
input,
context_module::Module
)
Execute the code of the given graph
on the given input values.
This is essentially shorthand for
tape = gen_tape(graph, instance, machine, context_module)
return execute_tape(tape, input)
ComputableDAGs.get_compute_function
— Methodget_compute_function(
graph::DAG,
instance,
machine::Machine,
context_module::Module
)
Return a function of signature compute_<id>(input::input_type(instance))
, which will return the result of the DAG computation on the given input. The final argument context_module
should always be @__MODULE__
to be able to use functions defined in the caller's environment. For this to work, you need
using RuntimeGeneratedFunctions
RuntimeGeneratedFunctions.init(@__MODULE__)
in your top level.
Keyword Arguments
closures_size
(default=0 (off)): The size of closures to use in the main generated code. This specifies the size of code blocks across which the compiler cannot optimize. For sufficiently large functions, a larger value means longer compile times but potentially faster execution time.
Tape Machine
ComputableDAGs.call_fc
— Methodcall_fc(fc::FunctionCall, cache::Dict{Symbol, Any})
Execute the given FunctionCall
on the dictionary.
Several more specialized versions of this function exist to reduce vector unrolling work for common cases.
ComputableDAGs.execute_tape
— Methodexecute_tape(tape::Tape, input::Input) where {Input}
Execute the given tape with the given input.
This is very slow and might not work. This is to be majorly revamped.
ComputableDAGs.expr_from_fc
— Methodexpr_from_fc(fc::FunctionCall)
For a given function call, return an expression evaluating it.
ComputableDAGs.gen_function_body
— Methodgen_function_body(tape::Tape; closures_size)
Generate the function body from the given Tape
.
Keyword Arguments
closures_size
: The size of closures to generate (in lines of code). Closures introduce function barriers in the function body, preventing some optimizations by the compiler and therefore greatly reducing compile time. A value of 1 or less will disable the use of closures entirely.
ComputableDAGs.gen_input_assignment_code
— Methodgen_input_assignment_code(
input_symbols::Dict{String, Vector{Symbol}},
instance::AbstractProblemInstance,
machine::Machine,
context_module::Module
)
Return a Vector{Expr}
doing the input assignments from the given problem_input
onto the input_symbols
.
ComputableDAGs.gen_tape
— Functiongen_tape(
graph::DAG,
instance::AbstractProblemInstance,
machine::Machine,
context_module::Module,
scheduler::AbstractScheduler = GreedyScheduler()
)
Generate the code for a given graph. The return value is a Tape
.
See also: execute
, execute_tape