Hi Stan and Siu,
Good morning!
I am an author of mcvine, a Monte Carlo neutron ray tracing simulation package. We have been using numba to accelerate mcvine: mcvine.acc. We exchanged emails a couple years ago. Thanks for the help back then!
numba has been working quite well for us. Thank you again for the great work on numba. We encountered a problem recently that I think is likely related to variables in closure. The numba docsays that numba may or may not copy global variables. I think in our case it is copied and requires a lot of memory and eventually leads to failure of the code. The code in question is like this
def makeS(S_QxQy, Qx_min, Qx_max, Qy_min, Qy_max):
@cuda.jit(device=True)
def S(threadindex, rng_states, neutron):
# assume neutron velocity is mostly along z
v = neutron[3:6]
…
, where S_QxQy is a numpy float array while Qx_min, Qx_max, Qy_min, Qy_max are floating point numbers.
- If the shape of the array is (10, 10) the code works perfectly fine.
- If the shape of the array is (100, 100) the code fails with this error:
- File uses too much global constant data (0x13880 bytes, 0x10000 max)
- If the shape of the array is (1100, 1475), which is the typical use case, the code does not fail immediately but rather can be seen allocating a lot of memory until it crashes
I wonder if there is a way to make sure the array is not copied? I tried using cuda.to_device on S_QxQy before passing it into the closure, thinking that might tell numba to create references instead of copies, but it failed with the error
‘DeviceNDArray’ object has no attribute ‘tobytes’
Please advise how to make sure the array is not copied multiple times. Your help will be much appreciated.
Best,
Jiao