Nested substitution rules in instructions aren't expanded
If calls to substitution rules (in actual instructions) are nested within each other, expand_subst
will only expand the outermost rule. All rules are removed from the substitution rule list, but the calls to the nested rules remain in the kernel
import loopy as lp
knl = lp.make_kernel(
"{[i]: 0<=i<n}",
"""
a(x) := 2 * x
b(x) := x**2
f[i] = b(a(i))
"""
)
knl = lp.expand_subst(knl)
print(knl)
yields
---------------------------------------------------------------------------
KERNEL: loopy_kernel
---------------------------------------------------------------------------
ARGUMENTS:
f: type: <auto/runtime>, shape: (n), dim_tags: (N0:stride:1) aspace: global
n: ValueArg, type: <auto/runtime>
---------------------------------------------------------------------------
DOMAINS:
[n] -> { [i] : 0 <= i < n }
---------------------------------------------------------------------------
INAME IMPLEMENTATION TAGS:
i: None
---------------------------------------------------------------------------
INSTRUCTIONS:
for i
f[i] = a(i)**2 {id=insn}
end i
---------------------------------------------------------------------------
Trying to run the kernel fails catastrophically at clBuildProgram
, of course.
Note that if the nesting is done within the actual definition of the rule, the expansion is correct, e.g. the following instruction body correctly:
a(x) := 2 * x
b(x) := a(x)**2
f[i] = b(i)
Edited by Zach Weiner