Home > OS >  Python Numba - How to debug caching to see when compilation happens
Python Numba - How to debug caching to see when compilation happens

Time:03-03

I'm trying to determine when Numba is compiling or using a cached function.

Example:

import numpy as np
from numba import njit

@njit(cache=True)
def sq(x):
    return x**2

@njit(cache=True)
def f(x):
    return sq(x)*sq(x);

# scalar signature
x = 1
y = f(x)
# vector signature
x = np.asarray([1,2,3])
y = f(x)

Is there a way to have numba indicate when it compiles a function or uses the cache?

CodePudding user response:

You can set the environment variable NUMBA_DEBUG_CACHE to get more information, see https://numba.pydata.org/numba-doc/dev/reference/envvars.html#caching-options.

This could be done by adding

import os
os.environ['NUMBA_DEBUG_CACHE'] = "1"

in front of your script.

When running your script you will find output lines like:

[cache] index saved to '/path/to/cache/script_name.something.nbi'
[cache] data saved to '/path/to/cache/script_name.something.nbc'

Which is what you are looking for

  • Related