Search code examples
raspberry-pillvmnumballvmlite

numba RuntimeError: No available targets are compatible with triple "arm-unknown-linux-gnu"


I am running a Python application on a Raspberry Pi (Model 4B - 8GB) and I am getting a runtime error. I had a lot of trouble even getting numba to run in the first place, because the available binary distribution of LLVM was too old (version 11), so I had to build LLVM v14.0.0 from source. I am now able to run my application, but I'm getting a runtime error that no available targets are compatible with triple "arm-unknown-linux-gnu", but when I run llvm-config --targets-built I get AArch64 AMDGPU ARM AVR BPF Hexagon Lanai Mips MSP430 NVPTX PowerPC RISCV Sparc SystemZ VE WebAssembly X86 XCore, so it looks like it was built properly and should have the necessary targets?

Here is the traceback for my issue:

(.venv) user@raspberrypi:~/Documents/myapp $ python app.py
Traceback (most recent call last):
  File "/home/user/Documents/myapp/app.py", line 31, in <module>
    import MyClass as myclass
  File "/home/user/Documents/myapp/myclass.py", line 17, in <module>
    from model.utils import myfilter
  File "/home/user/Documents/myapp/model/utils.py", line 94, in <module>
    @njit
     ^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/decorators.py", line 287, in njit
    return jit(*args, **kws)
           ^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/decorators.py", line 201, in jit
    return wrapper(pyfunc)
           ^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/decorators.py", line 230, in wrapper
    disp = dispatcher(py_func=func, locals=locals,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/dispatcher.py", line 824, in __init__
    self.targetctx = self.targetdescr.target_context
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/registry.py", line 48, in target_context
    return self._toplevel_target_context
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/registry.py", line 32, in _toplevel_target_context
    return cpu.CPUContext(self.typing_context, self._target_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/cpu.py", line 42, in __init__
    super().__init__(typingctx, target)
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/base.py", line 254, in __init__
    self.init()
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/cpu.py", line 51, in init
    self._internal_codegen = codegen.JITCPUCodegen("numba.exec")
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/codegen.py", line 1171, in __init__
    self._init(self._llvm_module)
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/numba/core/codegen.py", line 1176, in _init
    target = ll.Target.from_triple(ll.get_process_triple())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/myapp/.venv/lib/python3.11/site-packages/llvmlite/binding/targets.py", line 197, in from_triple
    raise RuntimeError(str(outerr))
RuntimeError: No available targets are compatible with triple "arm-unknown-linux-gnu"
(.venv) user@raspberrypi:~/Documents/myapp $ 

I also opened a GitHub issue here: https://github.com/numba/llvmlite/issues/975


Solution

  • I got it to work! I followed similar steps to what was suggested in a related issue: https://github.com/numba/llvmlite/issues/497 I think that LLVM was getting built for a 64 bit architecture, even though the Raspberry Pi OS is a 32-bit OS, so I just had to update the cmake parameters to generate build files for a 32 bit version. Then I rebuilt it, reinstalled it, and reinstalled numba and llvmlite and it worked! Here are the cmake parameters that I ended up using that worked:

    cmake -DLLVM_DEFAULT_TARGET_TRIPLE=armv7l-linux-gnueabihf \
          -DLLVM_TARGET_ARCH=ARM \
          -DLLVM_TARGETS_TO_BUILD=ARM \
          -DCMAKE_BUILD_TYPE=Release \
          -DLLVM_ENABLE_ASSERTIONS=On \
          ../llvm