Skip to content

[Kernel] Dispatch exp/sin/cos through dtype_trait - #19798

Merged
BBuf merged 1 commit into
sgl-project:mainfrom
xingsy97:feat/jit-math-type-traits
Mar 6, 2026
Merged

BBuf merged 1 commit into
sgl-project:mainfrom
xingsy97:feat/jit-math-type-traits

Conversation

@xingsy97

@xingsy97 xingsy97 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Motivation

exp/sin/cos in math.cuh are hardcoded with float signatures, while all other math functions (abs, sqrt, rsqrt, max, min) dispatch through dtype_trait<T>. This inconsistency allows silent implicit conversion when half/bfloat16 values are passed.

Addresses review feedback from #19770.

Modifications

  • Register exp/sin/cos as unary functions in dtype_trait<fp32_t> (type.cuh).
  • Convert exp/sin/cos in math.cuh from float-only to template<typename T> dispatching through dtype_trait<T>.

No behavioral change for existing callers (all pass float).

Accuracy Tests

N/A — no change to model outputs. Only the function signature changed from float to template<typename T>; all existing callers already pass float.

Benchmarking and Profiling

N/A — no change to inference speed. The generated PTX is identical for float callers.

Checklist

Route exp/sin/cos via dtype_trait<T> like the other math functions
(abs, sqrt, rsqrt) instead of hardcoding float signatures.
Prevents silent implicit conversion from half/bfloat16 to float.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@DarkSharpness

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@DarkSharpness DarkSharpness left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can merge after JIT kernel CI passes.

@github-actions github-actions Bot added the run-ci label Mar 4, 2026
@xingsy97
xingsy97 requested a review from DarkSharpness March 5, 2026 08:38
@xingsy97

xingsy97 commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

JIT Kernel CI passed. ready for merge

@HydraQYH HydraQYH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@DarkSharpness
DarkSharpness enabled auto-merge (squash) March 5, 2026 16:43
@xingsy97

xingsy97 commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @DarkSharpness , this PR seems ready for merge (required CI passed). Auto-merge is blocked by flaky and unrelated CI tests failure

@DarkSharpness

Copy link
Copy Markdown
Collaborator

cc @BBuf this PR is ready to merge

@DarkSharpness DarkSharpness added the ready-to-merge The PR is ready to merge after the CI is green. label Mar 6, 2026
@BBuf
BBuf disabled auto-merge March 6, 2026 14:57
@BBuf
BBuf merged commit 54634b9 into sgl-project:main Mar 6, 2026
153 of 170 checks passed
@xingsy97
xingsy97 deleted the feat/jit-math-type-traits branch March 6, 2026 15:05
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge The PR is ready to merge after the CI is green. run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants