tvm.relay.build_module

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

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

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

Parameters:
  • func (relay.Function) – The function to build.
  • 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.build_config(**kwargs)

Configure the build behavior by setting config variables.

Parameters:
  • opt_level (int, default=2) – Optimization level. See OPT_PASS_LEVEL for level of each pass.
  • add_pass (set of str) – Optimization pass to be added regardless of optimization level.
  • disable_pass (set of str) – Optimization pass to be disabled during optimization.
  • fallback_device (str or tvm.TVMContext) – The fallback device. It is also used as the default device for operators without specified device during heterogeneous execution.
Returns:

config – The build configuration

Return type:

BuildConfig

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.BuildConfig(**kwargs)

Configuration scope to set a build config option.

Parameters:kwargs – Keyword arguments of configurations to set.
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.