Code Generation

Types

ComputableDAGs.TapeType
Tape{INPUT}

TODO: update docs

  • INPUT the input type of the problem instance

  • code::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

source

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.executeMethod
execute(
    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)
source
ComputableDAGs.get_compute_functionMethod
get_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.

source

Tape Machine

ComputableDAGs.call_fcMethod
call_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.

source
ComputableDAGs.execute_tapeMethod
execute_tape(tape::Tape, input::Input) where {Input}

Execute the given tape with the given input.

Warning

This is very slow and might not work. This is to be majorly revamped.

source
ComputableDAGs.gen_function_bodyMethod
gen_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.

source
ComputableDAGs.gen_input_assignment_codeMethod
gen_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.

source
ComputableDAGs.gen_tapeFunction
gen_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

source