Skip to content

fix(parser): reject calls between Modules resolving different topology hierarchies #131

Open

Description

@zhen8838

Two Modules that resolve different topology hierarchies must not be able to call
each other. Today nothing stops that at construction; analysis rejects it
later, and schedule relies on the same late check.

Where it is caught today

src/tilefoundry/analysis/check.py validate_call_context:

if callee_owner.effective_topologies() != caller_owner.effective_topologies():
    raise AnalysisError(
        f"{caller_owner.name!r} calls {callee_owner.name!r}, which resolves a "
        f"different topology hierarchy ...; one kernel invocation runs one "
        f"hierarchy -- declare none on the child and inherit"
    )

Type inference does not and should not catch it: visitors.py _call_function
checks arity and each argument's shape/dtype against the callee's parameters.
Two Modules with different hierarchies can match on every one of those. Module
ownership and topology declaration are program structure, not types.

Why it belongs earlier

The check is a precondition of measurement, not of typing. Every analysis number
carries a per-unit denominator read off the topology:

compute-cost  flops=f32:524288@4096
traffic       gmem:r1048576/w0@r8192/w0
performance   predicted-ns=43552 waves=1

If the caller declares cta=132 and the callee cta=64, a "unit" means two
different things on the two sides, and no single denominator is right. The same
holds for schedule, which lays work out against one hierarchy.

So the program is not merely unanalysable -- it does not describe one kernel
invocation at all. That is a property of how it was written, which is what the
parser is for.

What this costs today

validate_call_context is reached through check_program, which has three
callers: analysis/api.py, schedule/api.py, and cli/analyze.py. Each pays
for a call-graph walk to re-establish something the program's own construction
could have settled once. An author also learns about it only when they ask for
an analysis, not when they write the call.

Note on wording

The current message reads as "you wrote this wrong". If nested launches with
their own hierarchy are ever modelled, the same shape becomes legal and the
check turns into a boundary to record rather than an edge to refuse. Worth
keeping in mind when choosing where the parser states it.

Branch refactor/analysis-architecture, d9108d8.

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