I have this simple MWE:
from numba import njit
@njit
def add(a, b):
return a + b
# Now let's inspect the assembly code for the 'add()' function.
for k, v in add.inspect_asm().items():
print(k)
when I run it I get no output. What is the right way to inspect the assembly?
You need to first compile the function to populate .inspect_asm()
, either by calling it or by specifying the signature. E.g.:
from numba import njit
@njit
def add(a, b):
return a + b
# first call add() to compile it
add(1, 2)
print(add.inspect_asm())
Prints:
{(int64, int64): '\t.text\n\t.file\t"<string>"\n\t.globl\t_ZN8__main__3addB2v1B38c8tJTIcFKzyF2ILShI4CrgQElQb6HczSBAA_3dExx\n\t.p2align\t4, ...
OR:
from numba import njit
# specify the signature first:
@njit("int64(int64, int64)")
def add(a, b):
return a + b
print(add.inspect_asm())