Skip to content

feat(kernel): Add batch matmul API#668

Merged
lightseek-bot merged 2 commits into
lightseekorg:mainfrom
qedawkins:qedawkins/batch-matmul-api
Jul 17, 2026
Merged

feat(kernel): Add batch matmul API#668
lightseek-bot merged 2 commits into
lightseekorg:mainfrom
qedawkins:qedawkins/batch-matmul-api

Conversation

@qedawkins

Copy link
Copy Markdown
Contributor

Add a public gemm.bmm API matching the GEMM dispatch style for true batched inputs. The API is for true batched GEMMs only and is kept distinct from typical GEMM as implementations can vary in non-trivial ways depending on the size of the batch. Currently registers the torch reference implementation while performant backend implementations are left for follow-up work.

Also add out= plumbing to mm and bmm with torch reference dense GEMM/BMM write through native torch out= paths when possible. Triton GEMM paths that already store through explicit output strides write directly into out=. Gluon GEMM paths were updated to do the same as well. This is motivated by bmm callsites needing to write directly into concatenated outputs in ways that wasn't yet encountered for normal GEMM. Bias and enable_pdl handling now follow the same ownership model for mm and bmm: kernels that opt in receive those kwargs, and dispatch only applies bias for kernels without bias support.

Share the GEMM and BMM numerics input generation paths so shape/layout handling stays consistent, and add shape presets, throughput accounting, API selection coverage, generator coverage, and focused API correctness tests.

Testing: pytest tokenspeed-kernel/test/ops/test_bmm.py tokenspeed-kernel/test/ops/test_gemm.py; pytest tokenspeed-kernel/test/test_kernel_api_selection.py; pytest tokenspeed-kernel/test/test_numerics.py; pytest tokenspeed-kernel/test/test_benchmark.py -q -k 'bmm_throughput'.

@qedawkins
qedawkins marked this pull request as ready for review July 14, 2026 14:46
@qedawkins
qedawkins requested review from a team as code owners July 14, 2026 14:46
@qedawkins qedawkins changed the title feat: Add batch matmul API feat(kernel): Add batch matmul API Jul 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ceb451dc62

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py Outdated
@qedawkins
qedawkins force-pushed the qedawkins/batch-matmul-api branch from ceb451d to 0d34978 Compare July 15, 2026 15:27

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d349780f3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/numerics/reference/gemm.py Outdated
Comment thread tokenspeed-kernel/test/ops/test_gemm.py
Comment thread tokenspeed-kernel/test/ops/test_bmm.py Outdated
Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py
@qedawkins
qedawkins force-pushed the qedawkins/batch-matmul-api branch 2 times, most recently from 0148a86 to ba250a5 Compare July 16, 2026 14:37
@borontion

Copy link
Copy Markdown
Contributor

@qedawkins the gluon bf16 gemm registration has been removed in #689 due to performance issue in decode. can we also follow it to make sure not registering it until performance is fixed? just for normal mm not batch mm

@qedawkins
qedawkins force-pushed the qedawkins/batch-matmul-api branch from ba250a5 to 99d1eb0 Compare July 16, 2026 18:37
@qedawkins

Copy link
Copy Markdown
Contributor Author

@qedawkins the gluon bf16 gemm registration has been removed in #689 due to performance issue in decode. can we also follow it to make sure not registering it until performance is fixed? just for normal mm not batch mm

I kept bmm disabled too for consistency. The situations where we're faster are quite narrow for bmm also so fine to enable slowly there as well.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99d1eb057c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 459b46a9a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py Outdated
Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99327b138e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py Outdated
@qedawkins
qedawkins force-pushed the qedawkins/batch-matmul-api branch 2 times, most recently from cb3e56a to d6d5ca3 Compare July 16, 2026 23:11
Add a public gemm.bmm API matching the GEMM dispatch style for true batched inputs. The API is for true batched GEMMs only and is kept distinct from typical GEMM as implementations can vary in non-trivial ways depending on the size of the batch. Currently registers the torch reference implementation while performant backend implementations are left for follow-up work.

Also add out= plumbing to mm and bmm with torch reference dense GEMM/BMM write through native torch out= paths when possible. Triton GEMM paths that already store through explicit output strides write directly into out=. Gluon GEMM paths were updated to do the same as well. This is motivated by bmm callsites needing to write directly into concatenated outputs in ways that wasn't yet encountered for normal GEMM. Bias and enable_pdl handling now follow the same ownership model for mm and bmm: kernels that opt in receive those kwargs, and dispatch only applies bias for kernels without bias support.

Share the GEMM and BMM numerics input generation paths so shape/layout handling stays consistent, and add shape presets, throughput accounting, API selection coverage, generator coverage, and focused API correctness tests.

Testing: pytest tokenspeed-kernel/test/ops/test_bmm.py tokenspeed-kernel/test/ops/test_gemm.py; pytest tokenspeed-kernel/test/test_kernel_api_selection.py; pytest tokenspeed-kernel/test/test_numerics.py; pytest tokenspeed-kernel/test/test_benchmark.py -q -k 'bmm_throughput'.

Signed-off-by: Quinn Dawkins <quinn.dawkins@gmail.com>
@qedawkins
qedawkins force-pushed the qedawkins/batch-matmul-api branch from d6d5ca3 to cc76cfb Compare July 16, 2026 23:33

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc76cfb967

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py
Signed-off-by: Quinn Dawkins <quinn.dawkins@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 801ad47a7c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tokenspeed-kernel/python/tokenspeed_kernel/ops/gemm/__init__.py
@lightseek-bot
lightseek-bot merged commit 11da7c3 into lightseekorg:main Jul 17, 2026
66 of 81 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