Cross compile TVM on raspberry pi 4b

Hi,

I am trying to cross compile my code to run on raspberry pi 4b and it seems like I am getting errors from setting the compilation target incorrectly.

I currently have

target = tvm.target.Target(‘llvm -device=arm_cpu -model=bcm2835 -mtriple=armv7l-linux-gnueabihf -mattr=+neon’)

and running cat /proc/cpuinfo returns the following:

pi@raspberrypi:~ $ cat /proc/cpuinfo processor : 0 BogoMIPS : 108.00 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3

processor : 1 BogoMIPS : 108.00 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3

processor : 2 BogoMIPS : 108.00 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3

processor : 3 BogoMIPS : 108.00 Features : fp asimd evtstrm crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3

Hardware : BCM2835 Revision : c03115 Serial : 10000000602bee14 Model : Raspberry Pi 4 Model B Rev 1.5

For more information, below is the detailed error message:

Traceback (most recent call last): File “/home/xxx/relay_test/tvm_raspberry_pi.py”, line 89, in rlib = remote.load_module(“net.tar”)

File “/home/xxx/.local/lib/python3.8/site-packages/tvm/rpc/client.py”, line 159, in load_module return _ffi_api.LoadRemoteModule(self._sess, path)

File “/home/xxx/.local/lib/python3.8/site-packages/tvm/_ffi/_ctypes/packed_func.py”, line 237, in call raise get_last_ffi_error()

tvm.error.RPCError: Traceback (most recent call last):

File “/home/pi/tvm/python/tvm/_ffi/_ctypes/packed_func.py”, line 81, in cfun rv = local_pyfunc(*pyargs)

File “/home/pi/tvm/python/tvm/rpc/server.py”, line 79, in load_module m = _load_module(path)

File “/home/pi/tvm/python/tvm/runtime/module.py”, line 610, in load_module _cc.create_shared(path + “.so”, files)

File “/home/pi/tvm/python/tvm/contrib/cc.py”, line 79, in create_shared _linux_compile(output, objects, options, cc, compile_shared=True)

File “/home/pi/tvm/python/tvm/contrib/cc.py”, line 247, in _linux_compile raise RuntimeError(msg)

File “/workspace/tvm/src/runtime/rpc/rpc_endpoint.cc”, line 376 RPCError: Error caught from RPC call:

RuntimeError: Compilation error:

/usr/bin/ld: /tmp/tmpng790ld5/net/devc.o: error adding symbols: file in wrong format collect2: error: ld returned 1 exit status

Command line: /usr/bin/g++ -shared -fPIC -o /tmp/tmpng790ld5/net.tar.so /tmp/tmpng790ld5/net/devc.o /tmp/tmpng790ld5/net/lib0.o

What would be the correct way to set compilation target for Raspberry Pi 4b?

Looks like you are not setting the mcpu properly so the linker complains. While seeing that you are setting -mtriple=armv7l-linux-gnueabihf, which could be correct, would you like to double check if -mtriple=aarch64-linux-gnu and -mcpu=cortex-a72 could work?

1 Like

Thank you, it works now!

1 Like