I’m experiencing a very strange behavior inside a while loop in the GPU.
I don’t get an error but I do get an unexpected result that makes no sense given the inside logic:
@cuda.jit(device=True)
def union(labels_matrix, p1, p2):
done = False
while not done:
p1_t, p2_t = find(labels_matrix, p1), find(labels_matrix, p2)
if p1_t[1] < p2_t[1]:
old = cuda.atomic.min(labels_matrix, p2_t[0], p1_t[1])
done = old == p2_t[1]
p2 = get_3d_index(labels_matrix.shape, old)
elif p2_t[1] < p1_t[1]:
old = cuda.atomic.min(labels_matrix, p1_t[0], p2_t[1])
done = old == p1_t[1]
p1 = get_3d_index(labels_matrix.shape, old)
else:
done = True
The only condition to exit the loop is for the variable done
to be true.
As an example and using some prints, p1_t = ((0, 2, 2), 1442) and p2_t = ((0,0,2), 2). It should exit the loop after only one iteration but, for some reason:
The same thing happens even if I add done = True
as the last instruction after the if/else sequence.
Can someone help me with this?