Bug in `obj_involves_variable` when `Constraint` passed in as object to check
For the following kernel on e308d029:
from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2
import loopy as lp
lp.set_caching_enabled(False)
from loopy.kernel.data import temp_var_scope as scopes
import pyopencl as cl
import numpy as np
knl = lp.make_kernel([
'{[i]: 0 <= i < 12}',
'{[j]: 0 <= j < 3}',
'{[k, l]: start <= k < end and start2 <= l < end2}'],
"""
for i
for j
<> start = temp[j]
<> end = temp[j + 1]
<> start2 = temp2[j]
<> end2 = temp2[j + 1]
for k
for l
out[i] = out[i] + 1
end
end
end
end
""",
[lp.GlobalArg('out', shape=(12,)),
lp.TemporaryVariable('temp', initializer=np.arange(4, dtype=np.int),
read_only=True, scope=scopes.GLOBAL, shape=(4,)),
lp.TemporaryVariable('temp2', initializer=np.arange(5, dtype=np.int),
read_only=True, scope=scopes.GLOBAL, shape=(5,))]
)
knl = lp.split_iname(knl, 'i', 4, inner_tag='vec')
knl = lp.split_array_axis(knl, ['out'], 0, 4)
knl = lp.tag_array_axes(knl, ['out'], 'N0,vec')
print(lp.generate_code_v2(knl).device_code())
I get the following error:
Traceback (most recent call last):
File "/home/nick/miniconda3/envs/loopy/lib/python3.6/pdb.py", line 1667, in main
pdb._runscript(mainpyfile)
File "/home/nick/miniconda3/envs/loopy/lib/python3.6/pdb.py", line 1548, in _runscript
self.run(statement)
File "/home/nick/miniconda3/envs/loopy/lib/python3.6/bdb.py", line 434, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "/home/nick/loopy/test.py", line 1, in <module>
from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2
File "/home/nick/loopy/loopy/codegen/__init__.py", line 488, in generate_code_v2
schedule_index=0)
File "/home/nick/loopy/loopy/codegen/result.py", line 367, in generate_host_or_device_program
codegen_result = build_loop_nest(codegen_state, schedule_index)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 541, in build_insn_group
result = gen_code(new_codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 483, in gen_code
inner_codegen_state, i)
File "/home/nick/loopy/loopy/codegen/control.py", line 115, in generate_code_for_sched_index
new_codegen_state, sched_index)
File "/home/nick/loopy/loopy/codegen/result.py", line 365, in generate_host_or_device_program
schedule_index=schedule_index + 1))
File "/home/nick/loopy/loopy/codegen/loop.py", line 248, in set_up_hw_parallel_loops
return next_func(codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 541, in build_insn_group
result = gen_code(new_codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 483, in gen_code
inner_codegen_state, i)
File "/home/nick/loopy/loopy/codegen/control.py", line 154, in generate_code_for_sched_index
return func(codegen_state, sched_index)
File "/home/nick/loopy/loopy/codegen/loop.py", line 438, in generate_sequential_loop_dim_code
inner = build_loop_nest(new_codegen_state, sched_index+1)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 541, in build_insn_group
result = gen_code(new_codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 483, in gen_code
inner_codegen_state, i)
File "/home/nick/loopy/loopy/codegen/control.py", line 154, in generate_code_for_sched_index
return func(codegen_state, sched_index)
File "/home/nick/loopy/loopy/codegen/loop.py", line 438, in generate_sequential_loop_dim_code
inner = build_loop_nest(new_codegen_state, sched_index+1)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 541, in build_insn_group
result = gen_code(new_codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 483, in gen_code
inner_codegen_state, i)
File "/home/nick/loopy/loopy/codegen/control.py", line 154, in generate_code_for_sched_index
return func(codegen_state, sched_index)
File "/home/nick/loopy/loopy/codegen/loop.py", line 213, in generate_vectorize_loop
return build_loop_nest(new_codegen_state, sched_index+1)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 544, in build_insn_group
sched_index_info_entries[group_length:], codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 541, in build_insn_group
result = gen_code(new_codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 483, in gen_code
inner_codegen_state, i)
File "/home/nick/loopy/loopy/codegen/control.py", line 154, in generate_code_for_sched_index
return func(codegen_state, sched_index)
File "/home/nick/loopy/loopy/codegen/loop.py", line 438, in generate_sequential_loop_dim_code
inner = build_loop_nest(new_codegen_state, sched_index+1)
File "/home/nick/loopy/loopy/codegen/control.py", line 548, in build_loop_nest
insn_group = build_insn_group(sched_index_info_entries, codegen_state)
File "/home/nick/loopy/loopy/codegen/control.py", line 525, in build_insn_group
new_codegen_state.vectorization_info.iname):
File "/home/nick/loopy/loopy/isl_helpers.py", line 453, in obj_involves_variable
for idiv in obj.dim(dim_type.div):
AttributeError: 'Constraint' object has no attribute 'dim'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/nick/loopy/loopy/isl_helpers.py(453)obj_involves_variable()
-> for idiv in obj.dim(dim_type.div):
this appears to be because islpy.Constraint
doesn't define dim()
.
Note that if you eliminate either the k
or l
loops, or don't use explicit-SIMD, the issues disappears
You can convert the Constraint
to an Aff
via obj.get_aff()
to get around at least the first AttributeError
(i.e., obj.get_aff().dim(dim_type.div)
returns 0), but then ISL returns an error in the subsequent get_div
call:
(Pdb) p obj.get_aff().dim(dim_type.div)
0
(Pdb) idiv = obj.get_aff().dim(dim_type.div)
(Pdb) obj.get_div(idiv)
isl/isl_local_space.c:345: index out of bounds
*** islpy._isl.Error: call to isl_constraint_get_div failed: isl_error_invalid
(Pdb) obj.get_aff().get_div(idiv)
isl/isl_local_space.c:345: index out of bounds
*** islpy._isl.Error: call to isl_aff_get_div failed: isl_error_invalid
(Pdb)
One of these days I'm actually going to have to figure out what goes on under the ISL-hood!
Edited by Nick Curtis