Skip to content

[Language] Fix gemm syntax highlight#1476

Merged
LeiWang1999 merged 3 commits intotile-ai:mainfrom
SiriusNEO:chaofan/fix3
Dec 23, 2025
Merged

[Language] Fix gemm syntax highlight#1476
LeiWang1999 merged 3 commits intotile-ai:mainfrom
SiriusNEO:chaofan/fix3

Conversation

@SiriusNEO
Copy link
Collaborator

@SiriusNEO SiriusNEO commented Dec 19, 2025

Following #1466, this PR fixes the highlight problem of T.gemm

Summary by CodeRabbit

  • Refactor
    • GEMM entry now uses a runtime-dispatching callable wrapper instead of a static alias, preserving behavior while enabling runtime selection.
    • Loop helpers Serial and Unroll now expose explicit, typed function signatures for clearer argument handling while forwarding to the same underlying implementations.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link

👋 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
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

Replaced the module-level gemm alias with a public gemm(...) function that dispatches at call time to gemm_v1 or gemm_v2 based on _env.use_gemm_v1() (previous alias left commented). Expanded public wrappers Serial and Unroll from var-arg passthroughs to explicit, typed signatures forwarding to internal serial/unroll.

Changes

Cohort / File(s) Change Summary
GEMM dispatch
tilelang/language/gemm_op.py
Added a public function def gemm(A, B, C, transpose_A=False, transpose_B=False, policy=GemmWarpPolicy.Square, clear_accum=False, k_pack=1, wg_wait=0, mbar=None) that at call time selects gemm_v1(...) if _env.use_gemm_v1() else gemm_v2(...). The previous module-level alias is commented. No changes to gemm_v1/gemm_v2 internals.
Loop wrappers
tilelang/language/loop.py
Replaced varargs wrappers with explicit typed public functions: `Serial(start: tir.PrimExpr, stop: tir.PrimExpr

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to 'Fix gemm syntax highlight' but the actual changes add typed wrapper functions for gemm, Serial, and Unroll that dispatch to underlying implementations—these are structural/API changes, not syntax highlighting fixes. Update the title to accurately reflect the main changes, such as '[Language] Add typed wrapper functions for gemm, Serial, and Unroll' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tilelang/language/gemm_op.py (1)

187-188: Consider removing commented-out code.

The commented-out static alias is no longer needed since the new dynamic dispatch function replaces it. Keeping dead code can clutter the codebase.

🔎 Proposed cleanup
-# gemm = gemm_v1 if _env.use_gemm_v1() else gemm_v2
-
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2217eb7 and b0b0804.

📒 Files selected for processing (1)
  • tilelang/language/gemm_op.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tilelang/language/gemm_op.py (1)
tilelang/env.py (1)
  • use_gemm_v1 (284-290)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)

# gemm = gemm_v1 if _env.use_gemm_v1() else gemm_v2


def gemm(*args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

one small question, if we replace the alias with function proxy, can lint still tell us the arguments of gemm is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we should explicit add arguments in the sigature

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tilelang/language/loop.py (2)

181-184: Consider adding return type hint and docstring for public API consistency.

The Serial wrapper correctly forwards all parameters to serial. However, as a public API function, it would benefit from:

  1. A return type hint (-> frame.ForFrame) matching the underlying serial function
  2. A docstring explaining its purpose and relationship to serial
🔎 Suggested improvements
 def Serial(
     start: tir.PrimExpr, stop: tir.PrimExpr | None = None, step: tir.PrimExpr | None = None, *, annotations: dict[str, Any] | None = None
-):
+) -> frame.ForFrame:
+    """Serial for loop (tile-level wrapper).
+    
+    Uppercase alias of serial() to emphasize tile-level loop semantics.
+    See serial() for parameter details.
+    """
     return serial(start, stop, step, annotations=annotations)

187-196: Consider adding return type hint and docstring for public API consistency.

The Unroll wrapper correctly forwards all parameters to unroll, including the explicit and unroll_factor keyword arguments. However, as a public API function, it would benefit from:

  1. A return type hint (-> frame.ForFrame) matching the underlying unroll function
  2. A docstring explaining its purpose and relationship to unroll (the underlying function already has comprehensive documentation at lines 122-148)
🔎 Suggested improvements
 def Unroll(
     start: tir.PrimExpr,
     stop: tir.PrimExpr | None = None,
     step: tir.PrimExpr | None = None,
     *,
     explicit: bool = False,
     unroll_factor: int | None = None,
     annotations: dict[str, Any] | None = None,
-):
+) -> frame.ForFrame:
+    """Unrolled for loop (tile-level wrapper).
+    
+    Uppercase alias of unroll() to emphasize tile-level loop semantics.
+    See unroll() for parameter details.
+    """
     return unroll(start, stop, step, explicit=explicit, unroll_factor=unroll_factor, annotations=annotations)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbe0e61 and 694969e.

📒 Files selected for processing (2)
  • tilelang/language/gemm_op.py
  • tilelang/language/loop.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tilelang/language/gemm_op.py
🧰 Additional context used
🧬 Code graph analysis (1)
tilelang/language/loop.py (1)
tilelang/language/tir/ir.py (2)
  • serial (9-28)
  • unroll (75-101)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
  • GitHub Check: Test for Python 3.12 with CUDA-12.8 (on self-hosted-nvidia)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)

@LeiWang1999
Copy link
Member

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tilelang/language/gemm_op.py (2)

188-189: Consider removing the commented-out alias.

The commented-out code serves as a reference for the old implementation pattern, but once the new function is stable, this comment could be removed to keep the codebase clean.


191-222: Excellent refactoring that addresses all previous concerns.

The implementation correctly:

  • Calls _env.use_gemm_v1() without arguments (fixing the previous critical bug)
  • Uses the implementation-selection pattern suggested in past reviews
  • Provides an explicit signature that enables proper IDE support and syntax highlighting (the PR objective)
  • Forwards all parameters correctly to the selected implementation

The dispatch now happens at call time rather than module load time, which is appropriate here since it enables better tooling support and allows runtime configuration changes if needed.


Minor: Fix docstring typo.

Line 214: "Int identifier" should be "Integer identifier" for consistency with standard documentation style.

🔎 Suggested fix
-        wg_wait (int): Int identifier of the warpgroup MMA batch to wait on.. Defaults to 0.
+        wg_wait (int): Integer identifier of the warpgroup MMA batch to wait on. Defaults to 0.

Note: Also fixes the double period ("..") typo.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 694969e and 546f783.

📒 Files selected for processing (2)
  • tilelang/language/gemm_op.py
  • tilelang/language/loop.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tilelang/language/loop.py
🧰 Additional context used
🧬 Code graph analysis (1)
tilelang/language/gemm_op.py (3)
tilelang/language/v2/annot.py (1)
  • Buffer (562-585)
tilelang/tileop/gemm/gemm_base.py (1)
  • mbar (128-129)
tilelang/env.py (1)
  • use_gemm_v1 (284-290)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)

@LeiWang1999 LeiWang1999 merged commit e79bbcc into tile-ai:main Dec 23, 2025
5 of 6 checks passed
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.

2 participants