Hello, all.
I have the following code where the assertion is wrong but the code will still run as usual. Finally, it gives an incorrect result.
It took me a long time to identify the problem and after removing the assert line the code is working fine.
I’m wondering if failing the assertion the code would still run and give a random result is normal behavior for numba cuda? It seems that assert support doesn’t make any sense.
@cuda.jit()
def add_tile(a, b):
'''
a: [tile_size, tile_size, 3]
b: [tile_size, tile_size, 3]
'''
TILE_SIZE = 16
# This assertion is wrong, I forgot that the first dimension is the block dimension
# But the code still runs, just the result is wrong
assert a.shape[0] == TILE_SIZE
tile_ix, tile_iy = cuda.threadIdx.x, cuda.threadIdx.y
tile_id = cuda.blockIdx.x
for i in range(3):
a[tile_id, tile_ix, tile_iy, i] += b[tile_id, tile_ix, tile_iy, i]
# some random test
blocks = 32
threads = (TILE_SIZE, TILE_SIZE)
a = np.random.randn(blocks, threads[0], threads[1], 3).astype(np.float32)
b = np.random.randn(blocks, threads[0], threads[1], 3).astype(np.float32)
print((a + b)[1, 1, 1, :])
device_a = cuda.to_device(a)
device_b = cuda.to_device(b)
add_tile[blocks, threads](device_a, device_b)
print(device_a.copy_to_host()[1, 1, 1, :])