[TVM] C++ api to print lowered funcs

Dear all,

Hi, I’m trying to make a example code that shows how Relay IR becomes LLVM IR.

I managed to get LLVM IR, but can’t understand the relationship between Relay IR and TensorExpression IR.

I’m following the tvm/tests/relay_build_module_test.cc with adding some Relay optimization passes.

In order to understand the relation between those two, I want to obtain lowered funcs.

auto pfb = tvm::runtime::Registry::Get("relay.build_module._BuildModule");
tvm::runtime::Module build_mod = (*pfb)();

// Bool for query_imports
auto build_f = build_mod.GetFunction("build", false);
auto json_f = build_mod.GetFunction("get_graph_json", false);
auto mod_f = build_mod.GetFunction("get_module", false);
// (TODO) Retrieve lowered functions

Is there anyone who have gone through this?

Thanks,

Jake

there is a WIP in progress to support this in the unified IR refactor. at the moment, you can do LOG(INFO) << lowerd_func->body

Dear @tqchen,

Thanks for quick response.

With a wonderful doc codebase_walkthrough and reading tutorials, I am close to understanding the full flow of TVM.

However, I am still confused with few parts.

By the way, I’m targeting VTA (LLVM).

As you mentioned on the RPC, flows can be described as following:

By going through some diggings, I concluded the flow as following:

Vision model -> Relay IR -> [Relay Passes] -> Relay IR -> sch -> [InferBound] -> stmt -> [ir pass] -> stmt -> LLVM IR

Looking through graph_runtime_codegen.cc, it seems GraphRuntimeCodegen is responsible for making LoweredFunc. (Correct me if I’m wrong)

There are two things that I’m confused.

  1. graph_runtime

          with vta.build_config():
             graph, lib, params = relay.build(
                 relay_prog, target=target,
                 params=params, target_host=env.target_host)
                     ...
     temp = util.tempdir()
     lib.save(temp.relpath("graphlib.o"))
     remote.upload(temp.relpath("graphlib.o"))
     lib = remote.load_module("graphlib.o")
    
     m = graph_runtime.create(graph, lib, ctx)
    

I’m confused with graph_runtime because graph_runtime_codegen.cc is placed at relay/backend and graph_runtime.py is at contrib folder.

Is former like graph_runtime_for_relay and latter like grap_runtime_for_hardware?

  1. runtime::Module

In case of VTA, where does LoweredFunc becomes runtime::Module?

I’m aware that src/codegen/build_module.cc is responsible for heterogeneous execution, but not sure how GraphRuntimeCodegen meets with this file or codegen_llvm.cc or codegen_arm.cc

Due to my lack of knowledge, my wordings could be awkward.

Thanks for reading such a long question.

Regrads,

Jake

1 Like