TVM uses LLVM to generate LLVM IR (
model.ll) and then compile it to object file (
After that the object file should be “linked” to a shared library.
TVM can run
clang++ command for you to link the object file (
model.o) to a shared library (
model.so) - it is implemented inside
Because the process of generating
model.so has two stages - LLVM stage and linking stage (g++/clang++), we need to make sure that both stages generate output for the same
# LLVM compilation for cpu sifive-u54 (llvm knows its arch rv64gc) and use lp64d ABI
target="llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=sifive-u54 -mabi=lp64d -device=arm_cpu"
# Linking for arch rv64gc and use lp64d ABI.
lib.export_library("model.so", cc="riscv64-unknown-linux-gnu-g++", options=["-march=rv64gc", "-mabi=lp64d", "-mcpu=sifive-u54"])
The linking process links not just your
model.o but other system libraries which
model.o needs (C Lib and C++ STL lib).
So, your cross-compilation toolchain should have pre-compiled system libraries for
mcpu/march/mabi which you are using in TVM. By default
riscv-gnu-toolchain only has lib64
rv64gc / lp64d system libraries.
Check what ABIs you have
To get pre-compiled system libraries for all ABIs use
--enable-multilib flag when building riscv-gnu-toolchain
./configure --prefix=/opt/riscv --enable-multilib
You can also use g++
--print-multi-lib flag to list pre-compiled system libraries which your toolchain has. (
-static-libstdc++ is a flag for the linker (g++/clang++) to include C++ STL functions into you shared library (
model.so). In that case the model (
model.so) will not need
libstdc++.so on the device.
If your device has C++ STL library
libstdc++.so then you do not need to use
readelf -d model.so | grep NEEDED