I know that you can get LLVM code with:
graph,lib,params = nnvm.compiler.build(sym,target,shape_dict,params=params)
lib.get_source()
But this code does not have a main function, so I can’t compile it for a specific backend with llc.
Is there a way that I can get it to put in a main function automatically?
Compiler here just build a library which packs functions for each operator in the model.
Main function here should be written by us which include initializing runtime, loading module, setting params and inputs …etc.
You may refer below doc for a sample.
# Deploy NNVM Modules
NNVM compiled modules are fully embedded in TVM runtime as long as ```GRAPH_RUNTIME``` option
is enabled in tvm runtime.
In a nutshell, we will need three items to deploy a compiled module.
Checkout our tutorials on getting started with NNVM compiler for more details.
- The graph json data which contains the execution graph.
- The tvm module library of compiled functions.
- The parameter blobs for stored parameters.
We can then use TVM's runtime API to deploy the compiled module.
Here is an example in python.
```python
import tvm
# tvm module for compiled functions.
loaded_lib = tvm.module.load("deploy.so")
This file has been truncated. show original
Would this require me to also compile the rest of TVM for the new target? I’m trying to get the model to run on a riscv simulator.
Also, I noticed that there’s a function that’s seems to do this,CodeGenCPU::AddMainFunction
that does execute but I’m not sure what it does.
Yes, you have to compile the tvm runtime for new target.
I wasn’t able to get the C++ example to build because of the include paths.