tvm.relay.build_module

Construct the necessary state for the TVM graph runtime from a Relay expression.

tvm.relay.build_module.build(mod, target=None, target_host=None, params=None)

Helper function that builds a Relay function to run on TVM graph runtime.

Parameters
  • mod (relay.Module) – The module to build. Using relay.Function is deprecated.

  • target (str, tvm.target.Target, or dict of str(i.e. device/context) –

  • to str/tvm.target.Target, optional (name)) – For heterogeneous compilation, it is a dictionary indicating context to target mapping. For homogeneous compilation, it is a build target.

  • target_host (str or tvm.target.Target, optional) – Host compilation target, if target is device. When TVM compiles device specific program such as CUDA, we also need host(CPU) side code to interact with the driver setup the dimensions and parameters correctly. target_host is used to specify the host side codegen target. By default, llvm is used if it is enabled, otherwise a stackvm intepreter is used.

  • params (dict of str to NDArray) – Input parameters to the graph that do not change during inference time. Used for constant folding.

Returns

  • graph_json (str) – The json string that can be accepted by graph runtime.

  • mod (tvm.Module) – The module containing necessary libraries.

  • params (dict) – The parameters of the final graph.

tvm.relay.build_module.create_executor(kind='debug', mod=None, ctx=None, target='llvm')

Factory function to create an executor.

Parameters
  • kind (str) – The type of executor

  • mod (Module) – The Relay module containing collection of functions

  • ctx (tvm.TVMContext) – The context to execute the code.

  • target (tvm.Target) – The corresponding context

class tvm.relay.build_module.GraphExecutor(mod, ctx, target)

Wrapper around Executor interface.

This executor is used for debug and testing purpoes.

Parameters
  • mod (Module) – The module to support the execution.

  • ctx (TVMContext) – The runtime context to run the code on.

  • target (Target) – The target option to build the function.