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",
)
| 70 | |
| 71 | |
| 72 | def 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) |
no test coverage detected
searching dependent graphs…