Skip to content

[MACA] Expand GEMM regression benchmark shapes#106

Open
VitalyAnkh wants to merge 6 commits into
tile-ai:devfrom
VitalyAnkh:vitalyr/bench-gemm-regression
Open

[MACA] Expand GEMM regression benchmark shapes#106
VitalyAnkh wants to merge 6 commits into
tile-ai:devfrom
VitalyAnkh:vitalyr/bench-gemm-regression

Conversation

@VitalyAnkh

@VitalyAnkh VitalyAnkh commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a benchmark-shape table to the existing GEMM regression driver
  • keep all benchmark shape coverage in examples/gemm/regression_example_gemm.py
  • preserve the current-base intrinsics/base GEMM regression wrappers and module entrypoint
  • add long-K plus representative production GEMM shapes:
    • bench_gemm_m1664_n1024_k262144
    • bench_gemm_m4096_n1024_k8192
    • bench_gemm_m4096_n8192_k8192
    • bench_gemm_m4096_n28672_k8192
    • bench_gemm_m4096_n8192_k28672
    • bench_gemm_m8192_n1024_k8192
    • bench_gemm_m8192_n8192_k8192
    • bench_gemm_m8192_n28672_k8192
    • bench_gemm_m8192_n8192_k28672

Validation

  • transient AST/source check for benchmark cases, wrappers, and no separate shape test file
  • python -m py_compile examples/gemm/regression_example_gemm.py
  • ruff check examples/gemm/regression_example_gemm.py
  • ruff format --check examples/gemm/regression_example_gemm.py
  • git diff --check origin/dev...HEAD

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a GEMM regression harness: centralized benchmark config/cases, a JIT-compiled tiled GEMM kernel with optional K-pipelining, runner helpers that profile via CUPTI, and nine public regression entrypoints to run named (M,N,K) cases.

Changes

GEMM Regression Benchmark

Layer / File(s) Summary
Benchmark configuration
examples/gemm/regression_example_gemm.py
Defines _BENCH_GEMM_CONFIG and _BENCH_GEMM_CASES enumerating named (M,N,K) benchmark cases.
JIT GEMM kernel
examples/gemm/regression_example_gemm.py
Implements _bench_gemm_matmul: shared-memory A/B tiles, C fragment allocation/clear, T.use_swizzle, pipelined K-loop (T.Pipelined), tiled T.gemm, and writes C back to global memory.
Runner and wiring
examples/gemm/regression_example_gemm.py
Adds _run_bench_gemm to compile and call profiler.do_bench(backend="cupti"), _process_bench_gemm_case to route cases via tilelang.testing.process_func, and _get_bench_gemm_case for case lookup.
Public regression wrappers
examples/gemm/regression_example_gemm.py
Adds nine new regression_bench_gemm_* entrypoints that look up a named case and invoke the processing pipeline.
Existing regression entrypoints
examples/gemm/regression_example_gemm.py
Retains prior regression_example_gemm_intrinsics, regression_example_gemm, and the __main__ runner unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tiny hare compiles and hops,
Tiled A and B in memory crops,
Pipelines hum through K so deep,
Nine cases wake from JIT-compiled sleep,
Profiler beeps — the matrix hops!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[MACA] Expand GEMM regression benchmark shapes' accurately describes the main change: adding new GEMM regression benchmark functions with expanded shape configurations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/maca/gemm/regression_example_gemm.py (1)

94-107: ⚠️ Potential issue | 🟡 Minor

Fix the incorrect refactor summary (functions/entrypoint still present)

examples/maca/gemm/regression_example_gemm.py still contains regression_example_gemm_autotune(), regression_example_gemm_intrinsics(), regression_example_gemm(), and the if __name__ == "__main__": tilelang.testing.regression() block (lines 94-107), so the summary claiming they were removed is incorrect.

Repo-wide search found no call sites to these maca functions outside this file (only their definitions), so clarify whether these wrappers/entrypoint are intended to remain for compatibility/manual use or should be removed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/maca/gemm/regression_example_gemm.py` around lines 94 - 107, The
file still defines unused wrapper entrypoints regression_example_gemm_autotune,
regression_example_gemm_intrinsics, regression_example_gemm and the if __name__
== "__main__": tilelang.testing.regression() block; either remove these symbols
and the module-level main block if they are truly unused, or keep them but mark
as deprecated and update the PR summary to state they remain for
compatibility/manual use—ensure you search for any callers before deleting and
update the file-level comment/README and the PR description accordingly;
reference the exact names regression_example_gemm_autotune,
regression_example_gemm_intrinsics, regression_example_gemm, and the main
entrypoint when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@examples/maca/gemm/regression_example_gemm.py`:
- Around line 94-107: The file still defines unused wrapper entrypoints
regression_example_gemm_autotune, regression_example_gemm_intrinsics,
regression_example_gemm and the if __name__ == "__main__":
tilelang.testing.regression() block; either remove these symbols and the
module-level main block if they are truly unused, or keep them but mark as
deprecated and update the PR summary to state they remain for
compatibility/manual use—ensure you search for any callers before deleting and
update the file-level comment/README and the PR description accordingly;
reference the exact names regression_example_gemm_autotune,
regression_example_gemm_intrinsics, regression_example_gemm, and the main
entrypoint when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f491111f-5efe-4a32-bb34-5640eecea43e

📥 Commits

Reviewing files that changed from the base of the PR and between 2a34480 and 510b058.

📒 Files selected for processing (2)
  • examples/maca/gemm/regression_example_gemm.py
  • testing/maca/test_regression_example_gemm_shapes.py

@VitalyAnkh VitalyAnkh changed the title [MACA] Add long-K GEMM regression benchmark [MACA] Expand GEMM regression benchmark shapes Jun 9, 2026
# Conflicts:
#	examples/gemm/regression_example_gemm.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/gemm/regression_example_gemm.py`:
- Around line 76-89: The wrapper functions
regression_bench_gemm_m1664_n1024_k262144,
regression_bench_gemm_m4096_n8192_k8192,
regression_bench_gemm_m4096_n8192_k28672, and
regression_bench_gemm_m8192_n1024_k8192 must not hard-code numeric indices into
_BENCH_GEMM_CASES; instead, locate the correct case by matching its "name" (the
same string used to build the wrapper name) against entries in _BENCH_GEMM_CASES
and call _process_bench_gemm_case(found_case); update each wrapper to search
_BENCH_GEMM_CASES for case["name"] == "<case name>" (or compute name
dynamically) and raise a clear error if not found so reordering of
_BENCH_GEMM_CASES cannot swap shapes silently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 870c4aed-7f8c-4e58-bc5e-287a7b82b380

📥 Commits

Reviewing files that changed from the base of the PR and between 510b058 and 953e7fc.

📒 Files selected for processing (1)
  • examples/gemm/regression_example_gemm.py

Comment thread examples/gemm/regression_example_gemm.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
examples/gemm/regression_example_gemm.py (2)

81-85: 💤 Low value

Consider pre-building a lookup dict if _BENCH_GEMM_CASES grows.

The current O(n) linear search is fine for 9 cases, but if the benchmark suite expands significantly, converting _BENCH_GEMM_CASES to a dict keyed by name would give O(1) lookup.

♻️ Optional refactor to dict-based lookup
-_BENCH_GEMM_CASES = (
+_BENCH_GEMM_CASES = {
+    "bench_gemm_m1664_n1024_k262144": {"name": "bench_gemm_m1664_n1024_k262144", "M": 1664, "N": 1024, "K": 262144},
-    {"name": "bench_gemm_m1664_n1024_k262144", "M": 1664, "N": 1024, "K": 262144},
     # ... (repeat for all cases)
-)
+}

 def _get_bench_gemm_case(name):
-    for case in _BENCH_GEMM_CASES:
-        if case["name"] == name:
-            return case
-    raise KeyError(f"unknown GEMM benchmark case: {name}")
+    if name not in _BENCH_GEMM_CASES:
+        raise KeyError(f"unknown GEMM benchmark case: {name}")
+    return _BENCH_GEMM_CASES[name]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/gemm/regression_example_gemm.py` around lines 81 - 85, The linear
search in _get_bench_gemm_case over _BENCH_GEMM_CASES should be replaced with an
O(1) lookup: build a dict mapping case["name"] to the case (e.g.,
_BENCH_GEMM_CASES_BY_NAME) at module load time and have
_get_bench_gemm_case(name) return _BENCH_GEMM_CASES_BY_NAME[name] (raising
KeyError if missing); update any code that mutates or constructs
_BENCH_GEMM_CASES to keep the dict in sync or construct the dict from the list
once to avoid repeat scans.

88-121: ⚖️ Poor tradeoff

Optional: Derive case name from wrapper function name to reduce string repetition.

All nine wrappers follow the pattern regression_bench_gemm_*bench_gemm_*. You could eliminate the hard-coded case name strings by deriving them from the function's own __name__:

def regression_bench_gemm_m1664_n1024_k262144():
    import sys
    fn_name = sys._getframe().f_code.co_name
    case_name = fn_name.replace("regression_", "", 1)
    _process_bench_gemm_case(_get_bench_gemm_case(case_name))

This eliminates typo risk and enforces the naming convention. However, the current explicit approach is more readable and grep-friendly, so this is purely optional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/gemm/regression_example_gemm.py` around lines 88 - 121, Nine wrapper
functions repeat the bench case string; change each regression_bench_gemm_*
wrapper to derive the case name from the function's own name (fn_name =
sys._getframe().f_code.co_name or equivalent) by stripping the "regression_"
prefix and pass that derived case_name into _get_bench_gemm_case and then to
_process_bench_gemm_case to remove hard-coded strings while keeping behavior of
functions like regression_bench_gemm_m1664_n1024_k262144 and the helpers
_get_bench_gemm_case/_process_bench_gemm_case unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/gemm/regression_example_gemm.py`:
- Around line 81-85: The linear search in _get_bench_gemm_case over
_BENCH_GEMM_CASES should be replaced with an O(1) lookup: build a dict mapping
case["name"] to the case (e.g., _BENCH_GEMM_CASES_BY_NAME) at module load time
and have _get_bench_gemm_case(name) return _BENCH_GEMM_CASES_BY_NAME[name]
(raising KeyError if missing); update any code that mutates or constructs
_BENCH_GEMM_CASES to keep the dict in sync or construct the dict from the list
once to avoid repeat scans.
- Around line 88-121: Nine wrapper functions repeat the bench case string;
change each regression_bench_gemm_* wrapper to derive the case name from the
function's own name (fn_name = sys._getframe().f_code.co_name or equivalent) by
stripping the "regression_" prefix and pass that derived case_name into
_get_bench_gemm_case and then to _process_bench_gemm_case to remove hard-coded
strings while keeping behavior of functions like
regression_bench_gemm_m1664_n1024_k262144 and the helpers
_get_bench_gemm_case/_process_bench_gemm_case unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c73aecf-c6b1-4d6e-9ba9-04a647df1faa

📥 Commits

Reviewing files that changed from the base of the PR and between 953e7fc and c6083a4.

📒 Files selected for processing (1)
  • examples/gemm/regression_example_gemm.py

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant