Skip to content

Commit d80feec

Browse files
MaxFreedomPollardclaude
authored andcommitted
Fix ISPC code generation for subscripted private temporaries
ExprToISPCExprMapper.map_subscript calls get_grid_size_upper_bounds_as_exprs() without the callables table, which has been a required argument since the 2021 kernel callables work. Any kernel that subscripts a private temporary therefore fails ISPC code generation with "TypeError: LoopKernel.get_grid_size_upper_bounds_as_exprs() missing 1 required positional argument: 'callables_table'". That includes ordinary uses of an "ilp" iname, which privatizes temporaries into arrays. The other three calls in loopy/target/ispc.py were updated over time (map_variable in fbdda4d for gh-763, the temporary declarator in 34c7344); this one was missed. Pass self.codegen_state.callables_table, as map_variable does. test_ispc_private_array is the subscripted counterpart of test_ispc_private_var. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5bd3945 commit d80feec

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎loopy/target/ispc.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def map_subscript(self, expr, type_context):
169169
and ary.address_space == AddressSpace.PRIVATE):
170170
# generate access code for access to private-index temporaries
171171

172-
_gsize, lsize = self.kernel.get_grid_size_upper_bounds_as_exprs()
172+
_gsize, lsize = self.kernel.get_grid_size_upper_bounds_as_exprs(
173+
self.codegen_state.callables_table)
173174
if lsize:
174175
lsize, = lsize
175176
from pymbolic import evaluate

‎test/test_target.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,29 @@ def test_ispc_private_var():
799799
print(cg_result.device_code())
800800

801801

802+
def test_ispc_private_array():
803+
# Like test_ispc_private_var, but for a private temporary that is
804+
# subscripted, which takes a separate code path in the expression mapper.
805+
knl = lp.make_kernel(
806+
"{ [i, j]: 0<=i<n and 0<=j<4 }",
807+
"""
808+
<> tmp[j] = 2*a[i, j]
809+
out[i, j] = tmp[3-j]
810+
""", [lp.GlobalArg("a,out", np.float32, shape=("n", 4)),
811+
lp.ValueArg("n", np.int32)],
812+
target=lp.ISPCTarget())
813+
814+
knl = lp.split_iname(knl, "i", 8, inner_tag="l.0", outer_tag="g.0")
815+
knl = lp.set_temporary_address_space(knl, "tmp", "private")
816+
817+
code = lp.generate_code_v2(knl).device_code()
818+
819+
# Each of the 8 program instances gets its own copy of 'tmp'.
820+
assert "float tmp[8 * 4];" in code
821+
# One store and one load, both offset by programIndex.
822+
assert code.count("tmp[programIndex + 8 * ") == 2
823+
824+
802825
def test_to_complex_casts(ctx_factory: cl.CtxFactory):
803826
arith_dtypes = "bhilqpBHILQPfdFD"
804827

0 commit comments

Comments
 (0)