Initialize targets before everything

A whole day of wrestling with some code (from GitHub - mit-han-lab/bevfusion: BEVFusion: Multi-Task Multi-Sensor Fusion with Unified Bird's-Eye View Representation) and running into “RuntimeError: Unable to find target for this triple (no targets are registered)” (ultimately in llvmlite’s targets.py), I discovered that I just had to do this in the start of the code:

from llvmlite import binding
binding.initialize()
binding.initialize_all_targets()

Shouldn’t the library already do this for me? Anyway, I’m a noob so I haven’t looked too deep into this.

It shouldn’t, because initializing llvmlite has side-effects. See for example the warning from Numba’s __init__.py:

# ---------------------- WARNING WARNING WARNING ----------------------------
# The following imports occur below here (SVML init) because somewhere in their
# import sequence they have a `@njit` wrapped function. This triggers too early
# a bind to the underlying LLVM libraries which then irretrievably sets the LLVM
# SVML state to "no SVML". See https://github.com/numba/numba/issues/4689 for
# context.
# ---------------------- WARNING WARNING WARNING ----------------------------

From: numba/__init__.py at c61921276a0ae27d74c82126070014607d6bf460 · numba/numba · GitHub

But if I don’t initialize, the targets aren’t registered.

That’s right, you need to initialize the targets.