The in-progress representation of an AnvlGraph during tracing. This is
a mutable class.
While trace_fn() runs a function, every primitive call is recorded as a
GraphStatement into the current descriptor (see graph_desc_add() and
current_descriptor()). The descriptor also does the book-keeping the
trace needs: which GraphValue an AnvlArray or GraphBox stands
for, the constants and devices encountered, and the default data types the
trace is pinned to. Once tracing finishes, it is converted to an
AnvlGraph, which only keeps what is needed to lower and run the
program.
Usage
GraphDescriptor(
statements = list(),
array_to_gval = NULL,
gval_to_box = NULL,
constants = list(),
in_tree = NULL,
out_tree = NULL,
inputs = list(),
outputs = list(),
is_static_flat = NULL,
static_args_flat = NULL,
devices = character(),
default_dtypes = NULL,
backend,
side_effects_mode = NULL,
parent = NULL
)Arguments
- statements
(
list(GraphStatement))
The statements that make up the graph.- array_to_gval
(
hashtab)
Mapping:AnvlArray->GraphValue- gval_to_box
(
hashtab)
Mapping:GraphValue->GraphBox- constants
(
list(GraphValue))
The constants of the graph.- in_tree
(
NULL|RTree)
The tree of inputs. May contain leaves for both array inputs and static (non-array) arguments. Only the array leaves correspond to entries ininputs; useis_static_flatto distinguish them.- out_tree
(
NULL|RTree)
The tree of outputs.- inputs
(
list(GraphValue))
The inputs to the graph (array arguments only).- outputs
(
list(GraphValue))
The outputs of the graph.- is_static_flat
(
NULL | logical())
Boolean mask indicating which flat positions inin_treeare static (non-array) args.NULLwhen all args are array inputs.- static_args_flat
(
NULL | list())
Flattened traced values for the static arguments indicated byis_static_flat.- devices
(
list())
Devices encountered during tracing: the device of every concrete array registered in the graph, plus the ones declared bygraph_desc_add().- default_dtypes
(
NULL|list(float, int))
The data types every R value in this trace materializes at when nothing else decides one (seedefault_dtypes()).- backend
(
character(1))
The backend this trace is compiled for. Required: it decides which entry of theanvl.default_dtypesoption applies to the trace, so switching the active backend inside a traced body changes nothing.local_descriptor()fills it in fromactive_backend(), so only a direct call has to name it.- side_effects_mode
(
NULL|character(1))
Where the trace's view of a side effect starts on its first use:"program": where the side effect says: an implicit input of the program, which the graph records in itsside_effectsrather than among its inputs, an argument, or a value the program creates. The top level ofjit()andtrace_fn()takes side effects this way."loop": as fresh inputs of the graph, which the graph also returns there. The bodies ofnv_while()andnv_scan()take side effects this way, and hand them on to the next iteration."capture": as the value ofparent's view, which the graph closes over and continues. The branches ofnv_if()and the functiongradient()differentiates take side effects this way.NULL: not at all. Such a trace cannot hand back what it did, so using a side effect there is an error.
- parent
(
NULL|GraphDescriptor)
The trace this one is opened in, orNULLfor a trace at the top level.local_descriptor()fills it in.