MCPcopy Create free account
hub / github.com/apache/tvm / compile

Function compile

python/tvm/driver/build_module.py:72–112  ·  view source on GitHub ↗

Compile an IRModule to a runtime executable. This function serves as a unified entry point for compiling both TIR and Relax modules. It automatically detects the module type and routes to the appropriate build function. Parameters ---------- mod : Union[PrimFunc, IRModule]

(  # pylint: disable=redefined-builtin
    mod: PrimFunc | IRModule,
    target: Target | None = None,
    *,
    relax_pipeline: tvm.transform.Pass | Callable | str | None = "default",
    tir_pipeline: tvm.transform.Pass | Callable | str | None = "default",
)

Source from the content-addressed store, hash-verified

70
71
72def compile( # pylint: disable=redefined-builtin
73 mod: PrimFunc | IRModule,
74 target: Target | None = None,
75 *,
76 relax_pipeline: tvm.transform.Pass | Callable | str | None = "default",
77 tir_pipeline: tvm.transform.Pass | Callable | str | None = "default",
78) -> Executable:
79 """
80 Compile an IRModule to a runtime executable.
81
82 This function serves as a unified entry point for compiling both TIR and Relax modules.
83 It automatically detects the module type and routes to the appropriate build function.
84
85 Parameters
86 ----------
87 mod : Union[PrimFunc, IRModule]
88 The input module to be compiled. Can be a PrimFunc or an IRModule containing
89 TIR or Relax functions.
90 target : Optional[Target]
91 The target platform to compile for.
92 relax_pipeline : Optional[Union[tvm.transform.Pass, Callable, str]]
93 The compilation pipeline to use for Relax functions.
94 Only used if the module contains Relax functions.
95 tir_pipeline : Optional[Union[tvm.transform.Pass, Callable, str]]
96 The compilation pipeline to use for TIR functions.
97
98 Returns
99 -------
100 Executable
101 A runtime executable that can be loaded and executed.
102 """
103 # TODO(tvm-team): combine two path into unified one
104 if _contains_relax(mod):
105 return tvm.relax.build(
106 mod,
107 target,
108 relax_pipeline=relax_pipeline,
109 tir_pipeline=tir_pipeline,
110 )
111 lib = tvm.tirx.build(mod, target, pipeline=tir_pipeline)
112 return Executable(lib)

Callers 4

_eval_shapeFunction · 0.50
_eval_exprFunction · 0.50
_eval_assignFunction · 0.50
get_funcFunction · 0.50

Calls 3

ExecutableClass · 0.90
_contains_relaxFunction · 0.85
buildMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…