Code Generation

Types

ComputableDAGs.FunctionCallType
FunctionCall{VAL_T<:Tuple,FUNC_T<:Union{Function,Expr}}

Representation of a function call. Contains the function to call (or an expression of a value to assign), value arguments of type VAL_T, argument symbols, the return symbol(s) and type(s) and the device to execute on.

To support vectorization, i.e., calling the same function on multiple inputs (SIMD), the value arguments, arguments, and return symbols are each vectors of the actual inputs. In the non-vectorized case, these Vectors simply always have length 1. For this common case, a special constructor exists which automatically wraps each of these arguments in a Vector.

Type Arguments

  • VAL_T<:Tuple: A tuple of all the value arguments that are passed to the function when it's called.
  • FUNC_T<:Union{Function, Expr}: The type of the function. Function is the default, but in some cases, an Expr of a value can be necessary to assign to the return symbol. In this case, no arguments are allowed.

Fields

  • func::FUNC_T: The function to be called, or an expression containing a value to assign to the return_symbol.
  • value_arguments::Vector{VAL_T}: The value arguments for the function call. These are passed first to the function, in the order given here. The Vector contains the tuple of value arguments for each vectorization member.
  • arguments::Vector{Vector{Symbol}}: The first vector represents the vectorization, the second layer represents the symbols that will be passed as arguments to the function call.
  • return_symbols::Vector{Vector{Symbol}}: As with the arguments, the first vector level represents the vectorization, the second represents the symbols that the results of the function call are assigned to. For most function calls, there is only one return symbol. When using closures when generating a function body for a Tape, the option to have multiple return symbols is necessary.
  • device::AbstractDevice: The device that this function call is scheduled on.
source
ComputableDAGs.TapeType
Tape{INPUT}

Lowered representation of a computation, generated from a DAG through gen_tape.

  • INPUT the input type of the problem instance, see also the interface function input_type

Fields

  • input_assign_code::Vector{FunctionCall}: The FunctionCalls representing the input assignments, mapping part of the input of the computation to each DAG entry node. These functions are generated using the interface function input_expr.
  • schedule::Vector{FunctionCall}: The FunctionCalls representing the function body of the computation. There is one function call for each node in the DAG.
  • output_symbol::Symbol: The symbol of the final calculated value, which is returned.
  • instance::Any: The instance that this tape is generated for.
  • machine::Machine: The Machine that this tape is generated for.
source

Function Generation

ComputableDAGs.compute_functionFunction
compute_function(
    dag::DAG,
    instance,
    machine::Machine,
    context_module::Module,
    scheduler::AbstractScheduler = GreedyScheduler(),
)

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.

source

Tape Machine

ComputableDAGs.gen_input_assignment_codeMethod
gen_input_assignment_code(
    input_symbols::Dict{String, Vector{Symbol}},
    instance::Any,
    machine::Machine
)

Return a Vector{FunctionCall} doing the input assignments from the given problem_input onto the input_symbols.

source
ComputableDAGs.gen_tapeMethod
gen_tape(
    dag::DAG,
    instance::Any,
    machine::Machine,
    scheduler::AbstractScheduler,
)

Generate the code for a given graph. The return value is a Tape.

source