pythonlinuxllvmnumballvmlite

How can I get LLVM loop vectorization debug output in Numba?


I'm trying to view LLVM debug messages for loop vectorization using Numba and llvmlite. I want to see the loop vectorization "LV:" debug output (e.g., messages like LV: Checking a loop in ...) so I can analyze the vectorization decisions made by LLVM. https://numba.readthedocs.io/en/stable/user/faq.html#does-numba-vectorize-array-computations-simd

I'm using a conda environment with the following YAML file. This makes sure I’m using the llvmlite build from the numba channel (which should have LLVM built with assertions enabled):

name: numbadev

channels:
  - defaults
  - numba

dependencies:
  - python>=3.12.9
  - numba::numba
  - numba::llvmlite
  - intel-cmplr-lib-rt

Running conda list shows:

# Name      Version     Build                               Channel
python      3.13.2      hf623796_100_cp313
llvmlite    0.44.0      py313h84b9e52_0                     numba
numba       0.61.2      np2.1py3.13hf94e718_g1e70d8ceb_0    numba
...

This is my script debug_loop_vectorization.py:

import llvmlite.binding as llvm
llvm.set_option('', '--debug-only=loop-vectorize')

import numpy as np
from numba import jit

@jit(nopython=True, fastmath=True)
def test_func(a):
    result = 0.0
    for i in range(a.shape[0]):
        result += a[i] * 2.0
    return result

# Trigger compilation.
a = np.arange(1000, dtype=np.float64)
test_func(a)

# Print the LLVM IR
print(test_func.inspect_llvm(test_func.signatures[0]))

When I run the script from a Linux terminal I see the LLVM-IR but no lines starting with "LV:...".

How can I get LLVM loop vectorization debug output?

Edit:

I've tried to call the script from the Linux terminal like this:

conda activate numbadev
cd /PathToMyFile/
python debug_loop_vectorization.py

or like this:

LLVM_DEBUG=1 python debug_loop_vectorization.py 2>&1 | grep '^LV:'

Edit:

In llvmlite/conda-recipes/llvmdev,

bld.bat contains a cmake argument "DLLVM_ENABLE_ASSERTIONS=ON".

https://github.com/numba/llvmlite/blob/main/conda-recipes/llvmdev/bld.bat#L32

build.sh doesn't contain "_cmake_config+=(-DLLVM_ENABLE_ASSERTIONS:BOOL=ON)" anymore.

https://github.com/numba/llvmlite/blob/main/conda-recipes/llvmdev/build.sh

Edit:

LLVM debug messages have been disabled in the Linux build unintentionally and should be enabled in LLVMlite v0.45.0 on the Numba channel.


Solution

  • On Linux, a workaround solution for tests is to use Numba 0.60.0. Indeed, it is based on LLVMlite v0.43.0 which is build with an LLVM version having assertions.

    On Linux, newer versions (e.g. Numba 0.61.2 and LLVMlite v0.44.0) do not embed an LLVM supporting assertions (apparently due to a code cleaning). Thus it must be build manually with . One solution with newer version is to recompile LLVMlite and its embedded LLVM locally so assertions are enabled. This can be done by setting -DLLVM_ENABLE_ASSERTIONS:BOOL=ON in CMAKE_ARGS before the build. Alternatively, you can add this line in the conda-recipes/llvmdev/build.sh file.

    On Windows, this works well by default so far. There is nothing to do.