Segmentation fault on variable increment/update

Hi!

I am currently implementing a custom kernel in numba that at some point performs n increments on a local/register variable. However, the kernel produces a segmentation fault when I specify the number of increments as an argument, instead of at compile time. A minimal working example:

from numba import cuda
import numpy as np

from numba import cuda

@cuda.jit(debug=True)
def f(b, n):
    result = 0
    for i in range(n):
        result += b

f[1, 1](1, 2)

Alternatively, changing the increment to a reassignment: result = b works fine too.

I am reasonably new to numba, so I could be missing something dramatically obvious, but the behaviour feels a bit odd: either specifying n at compile time, or changing the update to a reassignment produces no issues.

It is a pretty basic problem, so I imagine it’s my understanding that is failing here. Any comments on why this produces a segmentation fault are appreciated!

Hi,

After trying a few more things, I managed to solve the issue by swapping the for loop for a while loop. It seems to me that shouldn’t have solved the issue, but it did! Perhaps this indicates a bug? Any comments on this issue are still appreciated!

Minimal working example that actually works (i.e. does not segfault):

from numba import cuda

@cuda.jit(debug=True)
def f(b, n):
    result = 0
    for while (n > 0):
        result += b
        n -= 1

f[1,1](1,2)

Hi @daniel_v

Thanks for reporting this, I think it is segfaulting nvvm. I’ve opened a ticket here: cuda segfault nvvm with opt+debug · Issue #7214 · numba/numba · GitHub.