How to create compilable LLVM code from TVM?


#1

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?


#2

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.


#3

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.


#4

Yes, you have to compile the tvm runtime for new target.


#5

I wasn’t able to get the C++ example to build because of the include paths.