Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ParallelAccelerator will no more convert StaticSetItem to SetItem due…
… to record handling requiring StaticSetItem.
  • Loading branch information
DrTodd13 committed Mar 5, 2021
commit 095c58b45903cb3bccabe8e656ca37e4e599ddb0
12 changes: 3 additions & 9 deletions numba/parfors/array_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,13 @@ def get_or_set(d, k):
def set_shape_setitem(self, obj, shape):
"""remember shapes of SetItem IR nodes.
"""
assert isinstance(obj, ir.StaticSetItem) or isinstance(obj, ir.SetItem)
assert isinstance(obj, (ir.StaticSetItem, ir.SetItem))
self.ext_shapes[obj] = shape

def _get_shape(self, obj):
"""Overload _get_shape to retrieve the shape of SetItem IR nodes.
"""
if isinstance(obj, ir.StaticSetItem) or isinstance(obj, ir.SetItem):
if isinstance(obj, (ir.StaticSetItem, ir.SetItem)):
require(obj in self.ext_shapes)
return self.ext_shapes[obj]
else:
Expand Down Expand Up @@ -1252,12 +1252,6 @@ def _determine_transform(self, cfg, block, label, scope, init_equiv_set):
pending_transforms = []
for inst in block.body:
redefined = set()
if isinstance(inst, ir.StaticSetItem):
orig_calltype = self.calltypes[inst]
inst = ir.SetItem(
inst.target, inst.index_var, inst.value, inst.loc
)
self.calltypes[inst] = orig_calltype
pre, post = self._analyze_inst(
label, scope, equiv_set, inst, redefined
)
Expand Down Expand Up @@ -1403,7 +1397,7 @@ def _analyze_inst(self, label, scope, equiv_set, inst, redefined):
if not result:
return [], []
if result[0] is not None:
assert isinstance(inst, ir.SetItem)
assert isinstance(inst, (ir.StaticSetItem, ir.SetItem))
inst.index = result[0]
result = result[1]
target_shape = result.kwargs['shape']
Expand Down
23 changes: 13 additions & 10 deletions numba/parfors/parfor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,9 @@ def _type_getitem(self, args):
return self.pass_states.typingctx.resolve_function_type(fnty, tuple(args), {})


def get_index_var(x):
return x.index if isinstance(x, ir.SetItem) else x.index_var

Comment thread
DrTodd13 marked this conversation as resolved.
Resolved
class ConvertSetItemPass:
"""Parfor subpass to convert setitem on Arrays
"""
Expand All @@ -1713,11 +1716,10 @@ def run(self, blocks):
new_body = []
equiv_set = pass_states.array_analysis.get_equiv_set(label)
for instr in block.body:
if isinstance(instr, ir.StaticSetItem) or isinstance(instr, ir.SetItem):
if isinstance(instr, (ir.StaticSetItem, ir.SetItem)):
loc = instr.loc
>
index = (instr.index if isinstance(instr, ir.SetItem)
else instr.index_var)
index = get_index_var(instr)
value = instr.value
target_typ = pass_states.typemap[target.name]
index_typ = pass_states.typemap[index.name]
Expand Down Expand Up @@ -3435,9 +3437,9 @@ def get_parfor_outputs(parfor, parfor_params):
outputs = []
for blk in parfor.loop_body.values():
for stmt in blk.body:
if isinstance(stmt, ir.SetItem):
if stmt.index.name == parfor.index_var.name:
outputs.append(stmt.target.name)
if (isinstance(stmt, (ir.StaticSetItem, ir.SetItem)) and
get_index_var(stmt).name == parfor.index_var.name):
outputs.append(stmt.target.name)
# make sure these written arrays are in parfor parameters (live coming in)
outputs = list(set(outputs) & set(parfor_params))
return sorted(outputs)
Expand Down Expand Up @@ -4135,8 +4137,8 @@ def remove_dead_parfor(parfor, lives, lives_n_aliases, arg_aliases, alias_map, f
alias_lives = in_lives & alias_set
for v in alias_lives:
in_lives |= alias_map[v]
if (isinstance(stmt, ir.SetItem) and
stmt.index.name == parfor.index_var.name and
if (isinstance(stmt, (ir.StaticSetItem, ir.SetItem)) and
get_index_var(stmt).name == parfor.index_var.name and
stmt.target.name not in in_lives and
stmt.target.name not in arg_aliases):
continue
Expand Down Expand Up @@ -4173,8 +4175,9 @@ def _update_parfor_get_setitems(block_body, index_var, alias_map,
replace getitems of a previously set array in a block of parfor loop body
"""
for stmt in block_body:
if (isinstance(stmt, ir.SetItem) and stmt.index.name ==
index_var.name and stmt.target.name not in lives):
if (isinstance(stmt, (ir.StaticSetItem, ir.SetItem)) and
get_index_var(stmt).name == index_var.name and
stmt.target.name not in lives):
# saved values of aliases of SetItem target array are invalid
for w in alias_map.get(stmt.target.name, []):
saved_values.pop(w, None)
Expand Down
2 changes: 1 addition & 1 deletion numba/parfors/parfor_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def _hoist_internal(inst, dep_on_param, call_table, hoisted, not_hoisted,

def find_setitems_block(setitems, itemsset, block, typemap):
for inst in block.body:
if isinstance(inst, ir.StaticSetItem) or isinstance(inst, ir.SetItem):
if isinstance(inst, (ir.StaticSetItem, ir.SetItem)):
setitems.add(inst.target.name)
# If we store a non-mutable object into an array then that is safe to hoist.
# If the stored object is mutable and you hoist then multiple entries in the
Expand Down