New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot lower setitem on a record in a parallel loop #6704
Comments
Many thanks for the issue report - I can reproduce this, with a minor change to the reproducer: import numba
import numpy as np
print(numba.__version__)
# => 0.52.0
state_dtype = np.dtype([
('var', np.int32)
])
@numba.njit(inline='always')
def inner_function(state):
state['var'] = 1
@numba.njit(parallel=True)
def outer_function(states):
for i in numba.prange(1):
inner_function(states[i])
outer_function(np.ones(shape=1, dtype=state_dtype)) This is because setting
so I changed it to As a workaround, you can spell the setitem as a setattr, at least for this reproducer: import numba
import numpy as np
print(numba.__version__)
# => 0.52.0
state_dtype = np.dtype([
('var', np.int32)
])
@numba.njit(inline='always')
def inner_function(state):
state.var = 2
@numba.njit(parallel=True)
def outer_function(states):
for i in numba.prange(1):
inner_function(states[i])
data = np.ones(shape=1, dtype=state_dtype)
outer_function(data)
print(data) I edited the setting of data from
|
I don't think this has anything to do with the inliner. from numba import njit, prange
import numpy as np
state_dtype = np.dtype([
('var', np.int32)
])
def outer_function(states):
for i in prange(1):
states[i]['var'] = 1
print("interpreter", outer_function(np.ones(shape=1, dtype=state_dtype)))
print("njit", njit(outer_function)(np.ones(shape=1, dtype=state_dtype)))
print("parallel accelerator", njit(parallel=True)(outer_function)(np.ones(shape=1, dtype=state_dtype))) it's just the last line that fails, same way as above. |
CC @DrTodd13 ^ thanks. |
That's weird because on my machine having inline='never' compiles and run fine |
The parallel transforms can't "look" through a function call, so if the function remains as a As an aside, what's the reasoning behing inlining this function at the Numba IR level? If it's performance, LLVM would probably inline it anyway, there's some notes on what Numba inlining does and its uses here: https://numba.readthedocs.io/en/stable/developer/inlining.html#notes-on-inlining . |
Thanks for the explanation @stuartarchibald it makes sense now! Yeah it is performance. In some instances I've seen up to 30% difference. However I only benchmarked without the |
@stuartarchibald I guess StaticSetItem is supported for record array writes and not SetItem? |
Reporting a bug
When running this code:
numba yields
No definition for lowering <built-in function setitem>(Record(var[type=int32;offset=0];4;False), Literal[str](var), Literal[int](1)) -> none
, which seems to be the correct signature and I'm not so sure why there is no lowering available for that situation.When disabling parallel or inlining the code compiles and produces correct results.
visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
i.e. it's possible to run as 'python bug.py'.
The text was updated successfully, but these errors were encountered: