Skip to content

Conversation

@lucifer1004
Copy link
Collaborator

@lucifer1004 lucifer1004 commented Jan 4, 2026

Summary by CodeRabbit

  • New Features
    • Added support for the tanh (hyperbolic tangent) function in the math interface.
    • Introduced a fastmath-optimized tanh variant for faster approximate evaluation when fast-math optimizations are enabled, offering improved performance with minimal precision trade-offs.

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

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

👋 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 Jan 4, 2026

📝 Walkthrough

Walkthrough

Adds tanh/tanhf fastmath canonicalization to CuTeDSL codegen and a fastmath-backed tanh user-op in the CuTeDSL math DSL, enabling selection of an inline-assembly fastmath tanh path.

Changes

Cohort / File(s) Summary
CuTeDSL fastmath mapping
src/target/codegen_cutedsl.cc
Added tanh and tanhf entries to kFastMathMap inside CanonicalizeFastmathFunctionName_, enabling canonicalization of tanh with fastmath.
CuTeDSL math DSL
tilelang/contrib/cutedsl/math.py
Added __tanhf DSL user-op (inline-assembly fastmath tanh) and public tanh(x, fastmath=False) that dispatches to the fastmath path when requested; updated imports and typing to support the new op.

Sequence Diagram(s)

(omitted — changes are localized and do not introduce multi-component sequential flows)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 I hopped through bytes and tiny tags,
I stitched a fastmath path in fabled flags.
Tanh now darts with nimble cheer,
A rabbit’s tweak—precision near! ✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding tanh/tanhf support to CuteDSL, and references the related issue.
✨ Finishing touches
  • 📝 Generate docstrings

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

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5d8451 and 3142f8a.

📒 Files selected for processing (1)
  • tilelang/contrib/cutedsl/math.py
🧰 Additional context used
🪛 Ruff (0.14.10)
tilelang/contrib/cutedsl/math.py

5-5: Unused noqa directive (non-enabled: F401)

Remove unused noqa directive

(RUF100)


15-15: Unused function argument: fastmath

(ARG001)

🔇 Additional comments (2)
tilelang/contrib/cutedsl/math.py (2)

4-4: LGTM! Imports are appropriate.

All added imports are utilized in the new tanh implementation.

Also applies to: 7-9


30-32: LGTM! The fastmath delegation logic is correct.

The function correctly delegates to __tanhf for fast approximation when fastmath=True, or to math.tanh for standard precision when fastmath=False. Passing False as the second parameter to _math_op is appropriate since the operation choice already encodes the fast/slow decision.

@LeiWang1999 LeiWang1999 changed the title fix: add support for tanh/tanhf (fixes #1595) [Fix][CuteDSL] add support for tanh/tanhf (fixes #1595) Jan 4, 2026
@LeiWang1999 LeiWang1999 merged commit ebf3b68 into tile-ai:main Jan 4, 2026
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.

3 participants