Skip to content

parser: tile() bound cta.x * (M // BX) recurses until RecursionError (dim_to_isl_expr <-> dim_range) #182

Description

@zhen8838

Summary

A unit-dependent tile() bound that multiplies a mesh coordinate by a constant floor-division, e.g. cta.x * (M // BX), makes parsing recurse until RecursionError. The same bound written with the quotient precomputed (cta.x * CHUNK_M, CHUNK_M = M // BX) or as a literal (cta.x * 128) parses fine. All three are the same program.

Reproduction

Start from the repository's own fixture tests/fixtures/placed/persistent_gemm_tiled.py (added in #175) and change only line 38:

# original: parses
for mi in tile(cta.x * CHUNK_M, (cta.x + 1) * CHUNK_M, BM):
# changed: RecursionError
for mi in tile(cta.x * (M // BX), (cta.x + 1) * (M // BX), BM):
# also parses
for mi in tile(cta.x * 128, (cta.x + 1) * 128, BM):
from tilefoundry.cli.source import load_namespace
load_namespace("persistent_gemm_tiled_inline.py")   # RecursionError: maximum recursion depth exceeded

M and BX are module-level Python ints (512 and 4), so M // BX is the constant 128.

Traceback (tail, deduplicated)

src/tilefoundry/parser/ast_pattern.py, line 1402, in construct
src/tilefoundry/parser/pattern_nodes.py, line 4076, in construct
src/tilefoundry/ir/isl_interop.py, line 238, in normalize_dim
src/tilefoundry/ir/isl_interop.py, line 172, in dim_to_isl_expr
src/tilefoundry/ir/visitor.py, line 202, in visit
src/tilefoundry/ir/visitor.py, line 271, in dispatch_visit
src/tilefoundry/ir/isl_interop.py, line 127, in visit_Call
src/tilefoundry/ir/isl_interop.py, line 332, in dim_range
src/tilefoundry/ir/isl_interop.py, line 302, in visit_Call
RecursionError: maximum recursion depth exceeded

The cycle is dim_to_isl_expr → visit_Call (isl_interop.py:127) → dim_range (:332) → _DimRangeVisitor.visit_Call (:302, which calls dim_to_isl_expr on the same value) → …, apparently without folding the constant DimFloorDiv first.

Expected

The constant quotient folds (or is bounded) and the loop parses exactly like the CHUNK_M form. If some form is genuinely unsupported, a parse error naming the bound rather than an unbounded recursion.

Workaround

Precompute the quotient at module level (CHUNK_M = M // BX) and use the name in the bound.

Version

TileFoundry main at 53c739d (after #176).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions