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
Bad Parfor loop fusion side-effects? #6920
Comments
The problem seems to be coming from Line 2827 in 835e56c
The The one after that statement: I highlighted the (CC @DrTodd13) |
Think this might fix it: diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py
index cf2080c..68b1cbd 100644
--- a/numba/core/ir_utils.py
+++ b/numba/core/ir_utils.py
@@ -727,6 +727,8 @@ def has_no_side_effect(rhs, lives, call_table):
return False
if isinstance(rhs, ir.Expr) and rhs.op == 'inplace_binop':
return rhs.lhs.name not in lives
+ if isinstance(rhs, ir.Expr) and rhs.op in ('static_getitem', 'getitem'):
+ return rhs.value.name not in lives
if isinstance(rhs, ir.Yield):
return False
if isinstance(rhs, ir.Expr) and rhs.op == 'pair_first':
diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py
index 89a582e..a798475 100644
--- a/numba/parfors/parfor.py
+++ b/numba/parfors/parfor.py
@@ -3855,7 +3855,7 @@ def _can_reorder_stmts(stmt, next_stmt, func_ir, call_table,
and not isinstance(next_stmt, Parfor)
and not isinstance(next_stmt, ir.Print)
and (not isinstance(next_stmt, ir.Assign)
- or has_no_side_effect(next_stmt.value, set(), call_table)
+ or has_no_side_effect(next_stmt.value, [x.name for x in next_stmt.list_vars()], call_table)
or guard(is_assert_equiv, func_ir, next_stmt.value))):
stmt_accesses = expand_aliases({v.name for v in stmt.list_vars()},
alias_map, arg_aliases) |
Assuming getitems have side-effect doesn't match the semantics. |
Ah yes, this is true, it fixes the effect and not the cause. Any idea where in parfors the write association can be expressed? |
I think |
Yes, this is the correct approach.
|
Reporting a bug
released versionHEAD (476d192) ( of Numba (most recent isvisible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
i.e. it's possible to run as 'python bug.py'.
Example:
This always print
0
whenfusion=True
and print other values (random due to race condition) whenfusion=False
. The code has no valid fusion because the loop domain innp.zeros(1, ...)
is not equivalent to thefor i in prange(arr.size)
.FYI, what I am trying to do is adding an atomic add intrinsic: https://gist.github.com/sklam/e5496e412fccac6acc0e96b4413ed977
The text was updated successfully, but these errors were encountered: