What I want to do is to compile the pretrained ResNet-50 v2 model on this RISC-V architecture.
For compilation I am using the tvmc tool and as target I am using the LLVM for RISC-V.
In your community I already found a thread about it, but I got the same error:
LLVM ERROR: CPU 'generic' is not supported. Use generic-rv64
My question is if anyone has already built it successfully with this approach, or whether this is possible at all with LLVM and RISC-V?
Or is this a completely wrong approach and I should use something a different approach like using microTVM?
In my code, I used this target target = tvm.target.Target( "llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=generic-rv64 -mabi=lp64d -mattr=+64bit,+m,+a,+f,+d,+c" )
but when I tried to use this target and your command in tvmc, I failed too. Maybe you can try to use this “target” in Python to build the model directly, instead of tvmc, and configure -mabi compilation instructions according to your hardware.
I am also interested on running a model on a RISCV (PicoRV32) implementation running on an FPGA on Replit. Do you know what would be best to start with? as in, is there an example somewhere of running a simple model based on a simple operation (say CONV2D)? before going all the way through ResNet?
Hi,
I tried the proposal of @alter-xp but I got the same issue. I basically did the step-by-step-guide but used a target you proposed.
My next attempt was to update LLVM - maybe there was an issue. So I rebuilded LLVM with version 15.0.0 (previously I was using 14.0.6), but now I am getting a different error:
/TVM_PYTHON_ENV/lib/python3.8/site-packages/tvm-0.10.dev531+g5dcf62288-py3.8-linux-x86_64.egg/tvm/driver/build_module.py:266: UserWarning: target_host parameter is going to be deprecated. Please pass in tvm.target.Target(target, host=target_host) instead.
warnings.warn(
[20:58:21] /TVM_INSTALL/src/target/llvm/codegen_llvm.cc:167: Warning: Set native vector bits to be 128 for riscv64
LLVM ERROR: Relocation type not implemented yet!
It crashes in that function and it seems that it doesn’t matter if I define a target or not.
I think I found my issue. I thought that I need to use a cross compiled LLVM (for RISC-V) instead of the standard one. So if I am using now the standard LLVM I am able to build it with the target that was proposed by @alter-xp.
Quick question @joschi2804 — how do you run that shared library (.so)? Do you install tvm on the board? or is there a way to call a function in that library?
Next step was to set up the runtime environment for riscv. I followed basically this straight forward instruction.
After the successful build of the runtime library I wrote a small C++ program that includes the tvm_runtime library and reads the model I’ve created before within python. I used the apps/howto_deploy example as reference. In principle I only had to adapt the makefile to my needs (Adapting the TVM root path, setting the riscv compiler) and compile it.
In the end I uploaded the compiled binary and the tvm_runtime library to my device, added the library to LD_LIBRARY_PATH and then executed the binary.