We have already merged the codegen and runtime PRs for “Bring Your Own Codegen to TVM”. Another piece of this work is allowing users to conveniently annotate the given Relay program and then partition it into regions (sub-functions) that will be handled by various compilers (i.e. the default ones in the TVM stack and external ones), https://github.com/apache/incubator-tvm/pull/4570.
In order to do this, we mainly have two passes, one for annotation and the other for partitioning. Annotation allows users to annotate Relay expressions with boundaries (i.e. compiler_begin and compiler_end). It indicates that this annotated region (i.e. it could a single CallNode contains an operator) should be handled by the provided compiler. After annotation, we invoke the partitioning pass to clean the annotation, extracts the annotated regions and packs them into sub-functions that will use external codegen.
Here, we’d like to get some thoughts/comments from the community about some of the naming and API designs.
-
The API for annotation and partitioning, there are a few design choices
-
Directly invoke the passes
mod = relay.transform.AnnotateExternalCompiler("xx")(mod) mod = relay.transform.PartitionGraph()(mod) graph, lib, params = relay.build(mod, target="llvm")
Of course, these two passes could be packed as a SequentialPass and applied together.
-
Have a separate build pipeline for such a case
def build_external_compiler(target="xx"): mod = relay.transform.AnnotateExternalCompiler("xx")(mod) mod = relay.transform.PartitionGraph()(mod) return mod mod = relay.build_external_compiler(target="xx") graph, lib, params = relay.build(mod, target="llvm")
-
Let users set the attribute of a function and invoke annotate with no parameters
func = func.set_func_attr("compiler", "xx") mod["func"] = func mod = relay.transform.AnnotateExternalCompiler()(mod) mod = relay.transform.PartitionGraph()(mod) graph, lib, params = relay.build(mod, target="llvm")
-
Among these three options, option 1 seems most obvious, option 2 hides the external pipeline to users, and option 3 seems more extensible than the others (i.e. if we want to have multiple external compilers), please share your opinion. Or if you have other options, please bring them up.
-
Naming
-
AnnotateExternalComipler
. seems not very good, what are other good names? AnnotateCompilationBoundaries? AnnotateCodegenRegion? AnnotateCompiler? -
PartitionGraph. We know @jared doesn’t like this. We kept it because this term is also widely adopted by other frameworks.
-
Please share your thoughts.
@tqchen @jroesch @yzhliu @haichen @comaniac @masahi @ramana-arm @jonso