Skip to content

Add BF16 support to CPU and CUDA Pad kernels - #34062

Merged
Tianlei Wu (tianleiwu) merged 4 commits into
mainfrom
copilot/pad-add-bfloat16-kernel
Nov 11, 2026
Merged

Tianlei Wu (tianleiwu) merged 4 commits into
mainfrom
copilot/pad-add-bfloat16-kernel

Conversation

Copilot AI commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Enable CPU BF16 Pad for opsets 21–25, including 16-bit constant-value dispatch.
  • Register and instantiate CUDA BF16 kernels, including the rank-2 optimized path.
  • Add provider-isolated coverage for 2D bottom padding.

Motivation and Context

BF16 Pad currently fails session initialization with CPU and CUDA providers, and CPU-only sessions report no implementation. Supporting it unblocks BF16 graphs that pad rotary caches without requiring a Concat workaround.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add bfloat16 kernel for Pad node Add BF16 support to CPU and CUDA Pad kernels Nov 10, 2026
@tianleiwu
Tianlei Wu (tianleiwu) marked this pull request as ready for review November 10, 2026 04:43
Copilot AI balanced review requested due to automatic review settings November 10, 2026 04:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated BF16 registrations are missing from generated kernel documentation, causing validation to fail, and the CUDA regression test can falsely pass through CPU fallback.

2 open issues
What changed in this PR

Adds BF16 support to ONNX Runtime’s CPU and CUDA Pad kernels, addressing the session-initialization failure reported in #33874 for BF16 graphs that pad rotary caches.

Changes:

  • Enables CPU BF16 Pad for opsets 21–25 with 16-bit constant-value handling.
  • Adds CUDA BF16 registrations and kernel instantiations, including the optimized rank-2 path.
  • Adds CPU- and CUDA-targeted tests for 2D bottom padding across opsets 21–25.
File Description
onnxruntime/​test/​providers/​cpu/​tensor/​pad_test.cc Adds BF16 padding regression tests for CPU and CUDA.
onnxruntime/​core/​providers/​cuda/​tensor/​pad.cc Instantiates BF16 Pad computation.
onnxruntime/​core/​providers/​cuda/​tensor/​pad_impl.cu Instantiates BF16 device kernels, including optimized padding.
onnxruntime/​core/​providers/​cuda/​cuda_execution_provider.cc Registers BF16 Pad kernels with the CUDA provider.
onnxruntime/​core/​providers/​cpu/​tensor/​pad.cc Enables BF16 types and 16-bit value and computation dispatch.

Review effort: Balanced

Add tensor(bfloat16) to the CPU Pad rows for opsets 21+ and to all CUDA Pad rows, matching the kernels registered by this PR. Generated with tools/python/gen_opkernel_doc.py (CPU and CUDA providers) on a local CUDA build and merged into the existing file; the DML and WebGPU sections are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RunCudaOnlyOnnxOpsetPadTest registered only the CUDA EP, but the CPU EP is always added implicitly, so the test could pass through CPU fallback when the CUDA kernel was missing. That became possible for BF16 now that the CPU EP also implements it. Set kOrtSessionOptionsDisableCPUEPFallback so a missing CUDA kernel fails session initialization instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@rui-ren Rui Ren (rui-ren) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@tianleiwu
Tianlei Wu (tianleiwu) merged commit adf4e97 into main Nov 11, 2026
102 of 103 checks passed
@tianleiwu
Tianlei Wu (tianleiwu) deleted the copilot/pad-add-bfloat16-kernel branch November 11, 2026 00:26
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.

Pad has no bfloat16 kernel (CPU or CUDA); session fails to initialize with an unclear error

4 participants