Level 3 API

Essentials

enum [anonymous]

Values:

enumerator CCV_NNC_TENSOR_SYMBOL_INIT_ZEROS

Initialize underlying tensor for the symbol with zeros

enumerator CCV_NNC_TENSOR_SYMBOL_INIT_ONES

Initialize underlying tensor for the symbol with ones

enumerator CCV_NNC_TENSOR_SYMBOL_TAPE_VAR

Mark this as a tape variable (it cannot be folded, will contain flag CCV_TAPE_ALLOC)

enumerator CCV_NNC_TENSOR_SYMBOL_DEAD

Mark this tensor symbol as dead, any future usage will cause assertion

enum [anonymous]

Values:

enumerator CCV_NNC_GRAPH_EXEC_DEAD

Mark this node as dead.

enumerator CCV_NNC_GRAPH_EXEC_P_WHILE

Mark this node keyword is while

enumerator CCV_NNC_GRAPH_EXEC_CASE_OF

Mark this node keyword is case_of

enumerator CCV_NNC_GRAPH_EXEC_DISABLE_OPT

Mark this node to avoid optimization pass.

enum [anonymous]

Values:

enumerator CCV_NNC_NO_TENSOR_SYMBOL

Special symbol reference for no tensor symbol.

enumerator CCV_NNC_WHILE_COUNT_TENSOR_SYMBOL

Special symbol reference for while loop count tensor.

enum [anonymous]

Values:

enumerator CCV_NNC_NO_GRAPH_EXEC_SYMBOL

Special symbol reference for no exec symbol.

enum [anonymous]

Values:

enumerator CCV_NNC_SYMBOL_TENSOR

Identifier for tensor symbol

enumerator CCV_NNC_SYMBOL_TENSOR_ALIAS

Identifier for tensor alias symbol

enumerator CCV_NNC_SYMBOL_GRAPH_EXEC

Identifier for exec symbol

enum [anonymous]

Values:

enumerator CCV_NNC_AUTOGEN_ALL_EXECS

Automatic concatenation for all execution nodes

enumerator CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS

Automatically find all source and destination nodes.

typedef struct ccv_nnc_symbolic_graph_s ccv_nnc_symbolic_graph_t

Opaque pointer to the symbolic graph object.

typedef struct ccv_nnc_tensor_arena_s ccv_nnc_tensor_arena_t

Opaque pointer to an arena of allocated tensors.

typedef struct ccv_nnc_graph_exec_arena_s ccv_nnc_graph_exec_arena_t

Opaque pointer to an arena of allocated execs.

typedef void (*ccv_nnc_symbolic_graph_format_f)(const ccv_nnc_symbolic_graph_t *const graph, const int node, const char *const name, const ccv_nnc_cmd_t cmd, const int flags, const int *const incomings, const int incoming_size, const int *const outgoings, const int outgoing_size, const int *const inputs, const int input_size, const int *const outputs, const int output_size, void *const context)

The format callback function. Note that these are all integer ids. They can be filled to ccv_nnc_graph_exec_symbol_t.d or ccv_nnc_tensor_symbol_t.d.

Param graph:

The symbolic graph.

Param node:

The id for the node. It is unique in the graph.

Param name:

The name for the node. It is either NULL or \0 terminated string.

Param cmd:

The associated command for this node.

Param flags:

The flag that help to identify if it is a sub-graph, which type it is (P_WHILE or CASE_OF)

Param incomings:

The incoming nodes for execution.

Param incoming_size:

The number of incoming nodes for execution.

Param outgoings:

The outgoing nodes for execution.

Param outgoing_size:

The number of outgoing nodes for execution.

Param inputs:

The input tensor symbols.

Param input_size:

The number of the input tensor symbols.

Param outputs:

The output tensor symbols.

Param output_size:

The number of the output tensor symbols.

Param context:

The context passed through ccv_nnc_symbolic_graph_format.

ccv_nnc_symbolic_graph_new(void)

Create a new empty symbolic graph. It is an opaque data structure that maintains the whole graph of computation in its symbolic form. Note that all graph mutation methods are not thread-safe. You should only operate the graph in serial fashion.

ccv_nnc_tensor_symbol_new(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_param_t info, const char *const name)

Create an tensor symbol (thus, with no actual memory space allocation) in a symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • info – The tensor parameters.

  • name – The name of the tensor symbol, it is optional.

Returns:

A tensor symbol reference.

ccv_nnc_tensor_symbol_alias_new(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor_symbol, const int ofs[CCV_NNC_MAX_DIM_ALLOC], const int stride[CCV_NNC_MAX_DIM_ALLOC], const ccv_nnc_tensor_param_t info, const char *const name)

Create an alias to the tensor symbol as tensor view (thus, pointing to the same memory region, but with a different header info and offset).

Parameters:
  • graph – The symbolic graph.

  • tensor_symbol – The tensor symbol we are going to reference to.

  • ofs – The offset on each of the dimension.

  • stride – The stride of each dimension.

  • info – The tensor parameters for the new alias.

  • name – The name of the tensor symbol alias, it is optional.

Returns:

A tensor symbol alias reference.

void ccv_nnc_tensor_symbol_free(ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_tensor_symbol_t tensor)

Manually delete a tensor symbol off the symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

ccv_nnc_graph_exec_symbol_t ccv_nnc_graph_exec_symbol_new(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_cmd_t cmd, const ccv_nnc_tensor_symbol_t *const inputs, const int input_size, const ccv_nnc_tensor_symbol_t *const outputs, const int output_size, const char *const name)

Create a graph execution node (an operation that takes a set of inputs and generates a set of outputs).

Parameters:
  • graph – The symbolic graph.

  • cmd – The wrapped command.

  • inputs – The input tensor symbols array.

  • input_size – The size of input tensor symbols array.

  • outputs – The output tensor symbols array.

  • output_size – The size of output tensor symbols array.

  • name – The name of this execution node, optional.

Returns:

The execution node symbol reference.

void ccv_nnc_graph_exec_symbol_set_hint(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec, const ccv_nnc_hint_t hint)

ccv_nnc_graph_exec_symbol_new defaults to use `ccv_nnc_hint_auto` find the best hints for a set of inputs / outputs. However, you can also set your own hints.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

  • hint – The hint for the command.

void ccv_nnc_graph_exec_symbol_free(ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_graph_exec_symbol_t symbol)

Manually delete a exec symbol off the symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • symbol – The execution node symbol reference.

int ccv_nnc_graph_exec_symbol_autogen(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const execs, const int exec_size, const int flags)

Automatic concatenate these nodes together based on its inputs / outputs. Imagining this is to generate the execution flow based on input tensors and output tensors. nil for execs and 0 for exec_size means to loop over all the execs on the graph and autogen.

Parameters:
  • graph – The symbolic graph.

  • execs – The execution nodes array.

  • exec_size – The size of execution nodes array.

  • flags – The flags determines what operations to perform when concatenating.

Returns:

non-zero if cannot figure out.

void ccv_nnc_symbolic_graph_set_sources(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const sources, const int source_size)

Set the default sources for a symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • sources – The source execution nodes array.

  • source_size – The size of source execution nodes array.

void ccv_nnc_symbolic_graph_add_source(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t source)

Add one node to the default sources for a symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • source – The source execution node.

ccv_nnc_graph_exec_symbol_t *ccv_nnc_symbolic_graph_sources(const ccv_nnc_symbolic_graph_t *const graph)

Get the pointer to the default sources.

Parameters:

graph – The symbolic graph.

Returns:

The pointer to the source execution nodes array.

int ccv_nnc_symbolic_graph_source_size(const ccv_nnc_symbolic_graph_t *const graph)

Get the size of the default source nodes array.

Parameters:

graph – The symbolic graph.

Returns:

The size of the default source nodes array.

void ccv_nnc_symbolic_graph_set_destinations(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const destinations, const int destination_size)

Set the default destinations for a symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • destinations – The destination execution nodes array.

  • destination_size – The size of destination execution nodes array.

void ccv_nnc_symbolic_graph_add_destination(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t destination)

Add one node to the default destinations for a symbolic graph.

Parameters:
  • graph – The symbolic graph.

  • destination – The destination execution node.

ccv_nnc_graph_exec_symbol_t *ccv_nnc_symbolic_graph_destinations(const ccv_nnc_symbolic_graph_t *const graph)

Get the pointer to the default destinations.

Parameters:

graph – The symbolic graph.

Returns:

The pointer to the destinationsexecution nodes array.

int ccv_nnc_symbolic_graph_destination_size(const ccv_nnc_symbolic_graph_t *const graph)

Get the size of the default destination nodes array.

Parameters:

graph – The symbolic graph.

Returns:

The size of the default destination nodes array.

void ccv_nnc_symbolic_graph_dot(const ccv_nnc_symbolic_graph_t *const graph, const int flags, FILE *out)

Generate output that can be parsed by GraphViz (DOT language).

Parameters:
  • graph – The symbolic graph.

  • flags – Either CCV_NNC_SHORT_DOT_GRAPH or CCV_NNC_LONG_DOT_GRAPH

  • out – The output file stream.

void ccv_nnc_symbolic_graph_compile(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_symbolic_graph_compile_param_t compile_params, const ccv_nnc_tensor_bind_t *const tensor_binds, const int tensor_bind_size, const ccv_nnc_tensor_symbol_t *const outputs, const int output_size, const ccv_nnc_graph_exec_symbol_t *const sources, const int source_size, const ccv_nnc_graph_exec_symbol_t *const destinations, const int destination_size, ccv_nnc_graph_t **const graph_ref, ccv_nnc_tensor_arena_t **const tensor_arena_ref, ccv_nnc_graph_exec_arena_t **const graph_exec_arena_ref)

Compile a symbolic graph into a graph that can be executed, and a set of tensors (opaque data structure tensor arena) are allocated based on which tensor symbols are the input and which are the outputs. The tensor allocation is done to minimize the required storage. tensor_binds provide custom binding for these tensors. You still responsible to manage the life-time of these tensors. outputs marks the tensor symbols that need to be kept til the end of the graph.

Parameters:
  • graph – The symbolic graph.

  • compile_params – A ccv_nnc_symbolic_graph_compile_param_t struct defines compilation parameters.

  • tensor_binds – The binding array (a tensor symbol and a concrete tensor). We replace everywhere that uses the tensor symbol with the concrete tensor.

  • tensor_bind_size – The size of the binding array.

  • outputs – The output tensor symbols that we want to keep the value.

  • output_size – The size of the output tensor symbols array.

  • sources – The sources for the graph.

  • source_size – The size of the sources array. 0 to use default sources.

  • destinations – The destinations for the graph.

  • destination_size – The size of the destinations array. 0 to use default destinations.

  • graph_ref – The pointer to store the generated concrete graph.

  • tensor_arena_ref – The pointer to store ccv_nnc_tensor_arena_t.

  • graph_exec_arena_ref – The pointer to store ccv_nnc_graph_exec_arena_t.

void ccv_nnc_symbolic_graph_free(ccv_nnc_symbolic_graph_t *const graph)

Free the symbolic graph and its associated memory. Note that if you compiled a graph / tensor arena out of this symbolic graph, these won’t be free’d.

Parameters:

graph – The symbolic graph.

ccv_nnc_tensor_from_symbol(const ccv_nnc_tensor_arena_t *const tensor_arena, const ccv_nnc_tensor_symbol_t symbol)

Find corresponding tensor by a symbol from the tensor arena.

Parameters:
  • tensor_arena – The tensor arena object generated through compilation,

  • symbol – The tensor symbol reference. Because tensor symbol reference is on stack. It can still be used even the original symbolic graph is free’d.

Returns:

A concrete tensor from the tensor arena.

void ccv_nnc_tensor_bind_symbol(ccv_nnc_tensor_arena_t *const tensor_arena, const ccv_nnc_tensor_symbol_t symbol, const ccv_nnc_tensor_t *const tensor)

Bind a tensor to a symbol. You still responsible to manage the life-time of the tensor to make sure it is not freed until everything is done.

Parameters:
  • tensor_arena – The tensor arena object generated through compilation.

  • symbol – The tensor symbol reference. Because tensor symbol reference is on stack. It can still be used even the original symbolic graph is free’d.

  • tensor – The new tensor to bind to.

void ccv_nnc_tensor_arena_clear_bindings(ccv_nnc_tensor_arena_t *const tensor_arena)

Clear existing bindings on the tensor arena.

Parameters:

tensor_arena – The tensor arena object generated through compilation to clear bindings.

void ccv_nnc_tensor_arena_buffer_free(ccv_nnc_tensor_arena_t *const tensor_arena)

Free the data buffer of the tensor arena.

Parameters:

tensor_arena – The tensor arena object generated through compilation.

void ccv_nnc_tensor_arena_free(ccv_nnc_tensor_arena_t *const tensor_arena)

Free the opaque tensor arena structure.

Parameters:

tensor_arena – The tensor arena object generated through compilation.

ccv_nnc_graph_exec_from_symbol(const ccv_nnc_graph_exec_arena_t *const graph_exec_arena, const ccv_nnc_graph_exec_symbol_t symbol)

Find corresponding graph exec by a exec symbol from graph exec arena.

Parameters:
  • graph_exec_arena – The graph execution node arena object generated through compilation,

  • symbol – The execution node symbol reference. Because execution node symbol reference is on stack. It can still be used even the original symbolic graph is free’d.

Returns:

A execution node reference to the concrete graph.

ccv_nnc_graph_exec_source(const ccv_nnc_graph_exec_arena_t *const graph_exec_arena)

Return the node that can drive all the source nodes from the compilation.

Parameters:

graph_exec_arena – The graph execution node arena object generated through compilation,

Returns:

A execution node reference that is the source.

ccv_nnc_graph_exec_destination(const ccv_nnc_graph_exec_arena_t *const graph_exec_arena)

Return the node that can drain all the destination nodes from the compilation.

Parameters:

graph_exec_arena – The graph execution node arena object generated through compilation,

Returns:

A execution node reference that is the destination.

void ccv_nnc_graph_exec_arena_free(ccv_nnc_graph_exec_arena_t *const graph_exec_arena)

Free the opaque graph exec arena structure.

Parameters:

graph_exec_arena – The graph execution node arena object generated through compilation,

void ccv_nnc_symbolic_graph_write(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_bind_t *const tensor_binds, const int tensor_bind_size, const char *const fn)

Write symbolic graph to disk, along with some binding tensors.

Parameters:
  • graph – The symbolic graph.

  • tensor_binds – The binding array (pair of tensor symbol and concrete tensor).

  • tensor_bind_size – The size of the binding array.

  • fn – The file name.

void ccv_nnc_symbolic_graph_read(const char *const fn, ccv_nnc_symbolic_graph_t **const graph_ref, ccv_nnc_tensor_bind_t **const tensor_binds_ref, int *const tensor_bind_size_ref)

Read symbolic graph from disk, with some binding tensors.

Parameters:
  • fn – The file name.

  • graph_ref – The pointer to store symbolic graph.

  • tensor_binds_ref – The pointer to store the binding array.

  • tensor_bind_size_ref – The pointer to store the size of the binding array.

void ccv_nnc_symbolic_graph_format(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const sources, const int source_size, const ccv_nnc_graph_exec_symbol_t *const destinations, const int destination_size, const ccv_nnc_symbolic_graph_format_f format_fn, void *const context)

Provide a hook for upper level to do custom formatting of a given symbolic graph. You can implement logic to format the graph into protobuf, or json, or doing persistence. However, this is not the method for you to visit the graph, and do mutations on it. This function doesn’t recurse into sub-graphs. You need to inspect each node to know if these are sub-graphs and handle accordingly.

Parameters:
  • graph – The symbolic graph.

  • sources – The sources for the graph.

  • source_size – The size of the sources array. 0 to use default sources.

  • destinations – The destinations for the graph.

  • destination_size – The size of the destinations array. 0 to use default destinations.

  • format_fn – The format callback to be called on every node.

  • context – The context that will be passed to the callback.

CCV_NNC_TENSOR_SYMBOL_IS_DEAD(x)
CCV_NNC_GRAPH_EXEC_IS_DEAD(x)
CCV_NNC_GRAPH_REF(x)
CCV_NNC_IS_WHILE_COUNT_TENSOR_SYMBOL(d)
struct ccv_nnc_tensor_symbol_t
#include <ccv_nnc.h>

On stack object references a tensor symbol in the symbolic graph.

struct ccv_nnc_graph_exec_symbol_t
#include <ccv_nnc.h>

On stack object references a execution node symbol in the symbolic graph.

struct ccv_nnc_tensor_symbol_map_t
#include <ccv_nnc.h>

A data structure to pass in a pair of tensor symbols.

Public Members

ccv_nnc_tensor_symbol_t source

The ‘from’ tensor symbol.

ccv_nnc_tensor_symbol_t destination

The ‘to’ tensor symbol.

struct ccv_nnc_tensor_bind_t
#include <ccv_nnc.h>

The data structure to wrap a tensor symbol and a concrete tensor together.

struct ccv_nnc_symbolic_graph_compile_allocator_vtab_t
struct ccv_nnc_symbolic_graph_compile_allocator_t
struct ccv_nnc_symbolic_graph_compile_param_t

Others

typedef ccv_nnc_cmd_t (*ccv_nnc_symbolic_graph_subst_f)(const ccv_nnc_graph_exec_symbol_t symbol, const ccv_nnc_cmd_t cmd)

Substitution function. Given an execution node symbol and a command, return a new command.

typedef void (*ccv_nnc_tensor_symbol_new_hook_f)(void *context, const ccv_nnc_tensor_symbol_t symbol, const ccv_nnc_tensor_param_t info, const char *const name)

Function prototype for tensor symbol creation callback.

typedef void (*ccv_nnc_tensor_symbol_alias_new_hook_f)(void *context, const ccv_nnc_tensor_symbol_t symbol, const ccv_nnc_tensor_symbol_t from_symbol, const int ofs[CCV_NNC_MAX_DIM_ALLOC], const int stride[CCV_NNC_MAX_DIM_ALLOC], const ccv_nnc_tensor_param_t info, const char *const name)

Function prototype for tensor symbol alias creation callback.

typedef void (*ccv_nnc_graph_exec_symbol_new_hook_f)(void *context, const ccv_nnc_graph_exec_symbol_t symbol, const ccv_nnc_cmd_t cmd, const ccv_nnc_tensor_symbol_t *const inputs, const int input_size, const ccv_nnc_tensor_symbol_t *const outputs, const int output_size, const char *const name)

Function prototype for execution node symbol creation callback.

ccv_nnc_tensor_symbol_alias_to(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor_symbol)

Return the symbol it alias to.

Parameters:
  • graph – The symbolic graph.

  • tensor_symbol – The tensor symbol alias.

Returns:

A tensor symbol reference to the original tensor symbol. If this symbol has no reference, return NO_SYMBOL (.graph = 0)

int ccv_nnc_tensor_symbol_set(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor, const ccv_nnc_tensor_param_t info)

Set the tensor symbol parameters.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

  • info – The new tensor parameters.

Returns:

non-zero if encountered errors.

ccv_nnc_tensor_symbol_params(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor)

Get the parameters for a tensor symbol.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

Returns:

The tensor parameters.

ccv_nnc_tensor_symbol_name(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor)

Get the name for a tensor symbol.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

Returns:

The tensor name if available. Otherwise 0. The memory is managed by the graph.

int ccv_nnc_tensor_symbol_alias_set(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor, const int ofs[CCV_NNC_MAX_DIM_ALLOC], const int stride[CCV_NNC_MAX_DIM_ALLOC])

Set the tensor symbol alias parameters.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

  • ofs – The offset on each of the dimension.

  • stride – The stride of each dimension.

Returns:

non-zero if it is not a tensor alias.

int ccv_nnc_tensor_symbol_alias_params(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor, int ofs[CCV_NNC_MAX_DIM_ALLOC], int stride[CCV_NNC_MAX_DIM_ALLOC])

Get the parameters for a tensor symbol.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

  • ofs – The offset on each of the dimension.

  • stride – The stride of each dimension.

Returns:

non-zero if it is not a tensor alias.

int ccv_nnc_tensor_symbol_set_flags(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor, const int flags)

Set the flags for this tensor symbol. The flags are only used for symbol, not for tensor.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

  • flags – A reserved field for flags.

ccv_nnc_tensor_symbol_flags(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor)

Get all the flags for a tensor.

Parameters:
  • graph – The symbolic graph.

  • tensor – The tensor symbol reference.

void ccv_nnc_graph_exec_symbol_set(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec, const ccv_nnc_cmd_t cmd)

Set the cmd of this exec symbol.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

  • cmd – The new wrapped command.

void ccv_nnc_graph_exec_symbol_set_flags(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec, const int flags)

Set the flags for this exec symbol. The flags are only used for symbol. We can only set higher 16-bit.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

  • flags – A reserved field for flags.

ccv_nnc_graph_exec_symbol_flags(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec)

Get the flags for a tensor. We can only retrieve the higher 16-bit.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

ccv_nnc_graph_exec_symbol_cmd(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec)

Return the command on this exec symbol.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

Returns:

The wrapped command.

ccv_nnc_graph_exec_symbol_name(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec)

Return the command on this exec symbol.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

Returns:

The name for the exec symbol if available. The memory is managed by the graph.

void ccv_nnc_graph_exec_symbol_set_io(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec, const ccv_nnc_tensor_symbol_t *const inputs, const int input_size, const ccv_nnc_tensor_symbol_t *const outputs, const int output_size)

Set the inputs / outputs for a exec symbol.

Parameters:
  • graph – The symbolic graph.

  • exec – The execution node symbol reference.

  • inputs – The input tensor symbols array.

  • input_size – The size of input tensor symbols array.

  • outputs – The output tensor symbols array.

  • output_size – The size of output tensor symbols array.

int ccv_nnc_graph_exec_symbol_concat(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t source, const ccv_nnc_graph_exec_symbol_t destination)

Manually concatenate input node with an output graph node.

Parameters:
  • graph – The symbolic graph.

  • source – The source execution node symbol to connect.

  • destination – The destination execution node symbol connect to.

Returns:

non-zero if cannot concat successfully.

int ccv_nnc_graph_exec_symbol_disjoin(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t source, const ccv_nnc_graph_exec_symbol_t destination)

Manually disconnect input node with an output graph node for this graph.

Parameters:
  • graph – The symbolic graph.

  • source – The source execution node symbol to disconnect.

  • destination – The destination execution node symbol disconnect to.

Returns:

non-zero if cannot disjoin successfully.

ccv_nnc_graph_exec_symbol_count(const ccv_nnc_symbolic_graph_t *const graph)

Number of exec symbols.

Parameters:

graph – The symbolic graph.

ccv_nnc_symbolic_graph_active_symbol_count(const ccv_nnc_symbolic_graph_t *const graph, const int type)

Number of active exec symbols.

Parameters:
  • graph – The symbolic graph.

  • type – The type of op, can be CCV_NNC_SYMBOL_TENSOR, CCV_NNC_SYMBOL_GRAPH_EXEC (will error out on CCV_NNC_SYMBOL_TENSOR_ALIAS)

ccv_nnc_symbolic_graph_dup(const ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_symbolic_graph_subst_f subst)

Generate a duplicate of the provided graph. While generating the duplicate, it calls the function pointer to re-process the node type.

Parameters:
  • graph – The symbolic graph.

  • subst – The substitution function.

Returns:

The duplicated symbolic graph.

ccv_nnc_tensor_symbol_count(const ccv_nnc_symbolic_graph_t *const graph)

Number of tensor symbols.

Parameters:

graph – The symbolic graph.

void ccv_nnc_symbolic_graph_tensor_auto(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const sources, const int source_size, const ccv_nnc_graph_exec_symbol_t *const destinations, const int destination_size)

Compute all the tensor shapes within this graph.

Parameters:
  • graph – The symbolic graph.

  • sources – The sources for the graph.

  • source_size – The size of the sources array. 0 to use default sources.

  • destinations – The destinations for the graph.

  • destination_size – The size of the destinations array. 0 to use default destinations.

ccv_nnc_tensor_symbol_resolve(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor_symbol)

For a given tensor symbol, this method resolves to its local reference inside the given graph. This is related to the sub-graph of symbolic graphs. A tensor symbol in the sub-graph can still have a representation in the parent graph. This method used to find the local reference in any graph.

Parameters:
  • graph – The symbolic graph.

  • tensor_symbol – The tensor symbol we want to resolve.

Returns:

A tensor symbol reference in the given graph.

void ccv_nnc_tensor_symbol_hookup(ccv_nnc_symbolic_graph_t *const src_graph, ccv_nnc_symbolic_graph_t *const dest_graph, const ccv_nnc_tensor_symbol_t src_tensor_symbol, const ccv_nnc_tensor_symbol_t dest_tensor_symbol)

Pass graph’s tensor symbol into its sub graph. We will make the connection that the source tensor symbol in the source symbolic graph is the destination tensor symbol in the destination symbolic graph. The reason to do this inference is because a tensor symbol is local to a symbolic graph under the hood. Although you can use tensor symbols from different graphs directly (it calls this method or the resolve method above when create an execution node symbol), sometimes you need this method to do it manually.

Parameters:
  • src_graph – The source symbolic graph.

  • dest_graph – The destination symbolic graph.

  • src_tensor_symbol – The tensor symbol we want to resolve.

  • dest_tensor_symbol – The tensor symbol we want to resolve.

void ccv_nnc_tensor_symbol_set_bypasses(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_map_t *const symbol_map, const int symbol_map_size)

Set bypasses for a tensor symbol. For case..of graphs, if the condition doesn’t meet, we will skip the execution of a sub-graph. However, in that case, we cannot express easily which output tensor corresponds to which input tensor. This methods provides the way.

Parameters:
  • graph – The symbolic graph.

  • symbol_map – The pair of tensors array, source is the input tensor, destination is the output tensor.

  • symbol_map_size – The size of the tensor pairs array.

void ccv_nnc_graph_exec_symbol_io(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t symbol, const int **const inputs, int *const input_size, const int **const outputs, int *const output_size)

Fetch input / output for an exec symbol. For efficiency consideration, this returns pointer directly.

Parameters:
  • graph – The symbolic graph.

  • symbol – The execution node symbol reference.

  • inputs – The pointer to store input tensor symbols array.

  • input_size – The pointer to store the size of input tensor symbols array.

  • outputs – The pointer to store output tensor symbols array.

  • output_size – The pointer to store the size of output tensor symbols array.

void ccv_nnc_graph_exec_symbol_replace_io(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t symbol, const ccv_nnc_tensor_symbol_t old_symbol, const ccv_nnc_tensor_symbol_t new_symbol)

Replace a input / output tensor symbol on an exec symbol.

Parameters:
  • graph – The symbolic graph.

  • symbol – The execution node symbol reference.

  • old_symbol – The old tensor symbol to be replaced.

  • new_symbol – The new tensor symbol on input / output.

void ccv_nnc_graph_exec_symbol_to(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t symbol, const int **const tos, int *const to_size)

Which exec symbol this is connected to. For efficiency consideration, this returns pointer directly.

Parameters:
  • graph – The symbolic graph.

  • symbol – The execution node symbol reference.

  • tos – The pointer to store outgoing indexes of the execution nodes.

  • to_size – the pointer to store the number of outgoing indexes.

ccv_nnc_tensor_arena_size(const ccv_nnc_tensor_arena_t *const tensor_arena)

Find the size allocated on the opaque tensor arena structure.

Parameters:

tensor_arena – The tensor arena object generated through compilation.

Returns:

The total allocated size in bytes.

void ccv_nnc_symbolic_graph_sources_to_destinations(const ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t *const sources, const int source_size, const ccv_nnc_graph_exec_symbol_t *const destinations, const int destination_size, uint64_t *const bitmask)

Query whether a set of sources are the ancestors to a set of destination nodes.

Parameters:
  • graph – The symbolic graph.

  • sources – The exec sources to check whether they can reach some of the destinations.

  • source_size – How many sources in the source list.

  • destinations – The exec destinations to check whether sources can reach.

  • destination_size – How many destinations in the destination list.

  • bitmask – Bit return value, each bit represents a source, and 1 meant it can reach some of the destinations.

int ccv_nnc_tensor_arena_reinit(ccv_nnc_tensor_arena_t *const tensor_arena, const ccv_nnc_symbolic_graph_t *const graph)

Re-init the tensor arena with updated symbolic graph. This won’t work if the symbolic graph requires larger tensors than what’s available. Use this method properly, you can avoid re-compile a graph just because some tensor shape changed.

Parameters:
  • tensor_arena – The tensor arena object generated through compilation.

  • graph – The updated symbolic graph with different tensor shape.

Returns:

0 if successful, -1 if the tensor arena doesn’t have enough space to just re-init.

void ccv_nnc_graph_exec_reinit(ccv_nnc_graph_exec_arena_t *const graph_exec_arena, ccv_nnc_graph_t *const graph, const ccv_nnc_symbolic_graph_t *const symbolic_graph)

Re-init the graph exec arena with updated symbolic graph. This updated some hyper-parameters of executions to match the updated symbolic graph. Note that this will try to keep the backend / algorithm selection from previous graph if possible (meaning if the command still match).

Parameters:
  • graph_exec_arena – The graph exec arena object provided mapping between symbolic and concrete graph.

  • graph – The concrete graph generated through compile method.

  • symbolic_graph – The updated symbolic graph.

void *ccv_nnc_tensor_symbol_new_hook(ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_tensor_symbol_new_hook_f hook, void *context, ccv_nnc_tensor_symbol_new_hook_f *previous_hook)

Hook into the call to ccv_nnc_tensor_symbol_new, return previous provided context if call into this method.

Parameters:
  • graph – The symbolic graph.

  • hook – The function to be called if a new tensor symbol created.

  • context – The context associated with the callback function.

  • previous_hook – Return the previous hook if provided.

Returns:

The previous context associated with the previous hook function.

void *ccv_nnc_tensor_symbol_alias_new_hook(ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_tensor_symbol_alias_new_hook_f hook, void *context, ccv_nnc_tensor_symbol_alias_new_hook_f *previous_hook)

Hook into the call to ccv_nnc_tensor_symbol_alias_new, return previous provided context if call into this method.

Parameters:
  • graph – The symbolic graph.

  • hook – The function to be called if a new tensor symbol alias created.

  • context – The context associated with the callback function.

  • previous_hook – The function to be called if a new tensor symbol alias created.

Returns:

The previous context associated with the previous hook function.

void ccv_nnc_tensor_symbol_pair_with(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_tensor_symbol_t tensor_symbol, const ccv_nnc_tensor_symbol_t pair_tensor_symbol)

Set the pair reference for tensor symbols. Peer reference for tensor symbols has very specific meanings. For a backward pass involves sub-graphs. The commands in the sub-graph could reference to tensor symbols of a different graph (its forward pass graph). That is not allowed (two graph has no ancestral relationship cannot share a tensor symbol). So we create a new tensor symbol, but set the pair reference.

Parameters:
  • graph – The symbolic graph.

  • tensor_symbol – The tensor symbol in the current graph.

  • pair_tensor_symbol – The tensor symbol in the pair graph.

void *ccv_nnc_graph_exec_symbol_new_hook(ccv_nnc_symbolic_graph_t *const graph, ccv_nnc_graph_exec_symbol_new_hook_f hook, void *context, ccv_nnc_graph_exec_symbol_new_hook_f *previous_hook)

Hook into the call to ccv_nnc_graph_exec_symbol_new, return previous provided context if call into this method.

Parameters:
  • graph – The symbolic graph.

  • hook – The function to be called if a new execution node symbol created.

  • context – The context associated with the callback function.

  • previous_hook – The previous hook function associated with this operation.

Returns:

The previous context associated with the previous hook function.

void ccv_nnc_graph_exec_symbol_pair_with(ccv_nnc_symbolic_graph_t *const graph, const ccv_nnc_graph_exec_symbol_t exec_symbol, const ccv_nnc_graph_exec_symbol_t pair_exec_symbol)

Set the pair reference for exec. This is very similar to the one for concrete graph. A pair reference of a backward pass execution node is its forward pass counterpart.

Parameters:
  • graph – The symbolic graph.

  • exec_symbol – The execution node symbol in the current graph.

  • pair_exec_symbol – The pairing execution node symbol.