Skip to content

[WebGPU EP] Reduce forward declaration boilerplate in kernel registration#27977

Merged
edgchen1 merged 3 commits into
mainfrom
edgchen1/webgpu_ep_refine_kernel_registration
Apr 16, 2026
Merged

[WebGPU EP] Reduce forward declaration boilerplate in kernel registration#27977
edgchen1 merged 3 commits into
mainfrom
edgchen1/webgpu_ep_refine_kernel_registration

Conversation

@edgchen1
Copy link
Copy Markdown
Contributor

@edgchen1 edgchen1 commented Apr 4, 2026

Description

Update WebGPU EP kernel registration to remove redundant forward declarations.

E.g., change from this:

class ONNX_OPERATOR_KERNEL_CLASS_NAME(kWebGpuExecutionProvider, kMSDomain, 1, Attention);

  static const BuildKernelCreateInfoFn function_table[] = {
      ...
      BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kWebGpuExecutionProvider, kMSDomain, 1, Attention)>,

to this:

static const BuildKernelCreateInfoFn function_table[] = {
    ...
    BuildKernelCreateInfo<class ONNX_OPERATOR_KERNEL_CLASS_NAME(kWebGpuExecutionProvider, kMSDomain, 1, Attention)>,

One subtlety is that the function table needs to be moved outside of the function now, since function-local (block scope) forward declarations would introduce names with no linkage. Those names should have external linkage.

We already do something similar here:

BuildKernelCreateInfo<class ONNX_OPERATOR_KERNEL_CLASS_NAME(kOnnxDomain, 14, Mul)>,

Motivation and Context

Reduce boilerplate.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Comment thread onnxruntime/contrib_ops/webgpu/webgpu_contrib_kernels.cc Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors WebGPU EP kernel registration to eliminate large blocks of redundant forward declarations by using elaborated type specifiers (class ...) directly in BuildKernelCreateInfo<...> entries, and moving the function pointer tables to namespace scope to ensure the introduced declarations have external linkage.

Changes:

  • Replace explicit forward-declaration lists with BuildKernelCreateInfo<class ONNX_OPERATOR_...> usage.
  • Move kernel create-info function tables out of function scope and reuse them in registration loops.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/providers/webgpu/webgpu_execution_provider.cc Moves WebGPU kernel create-info function table to namespace scope and removes forward-declaration boilerplate via class in template arguments.
onnxruntime/contrib_ops/webgpu/webgpu_contrib_kernels.cc Applies the same pattern for WebGPU contrib kernel registration by hoisting the function table and removing forward declarations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread onnxruntime/contrib_ops/webgpu/webgpu_contrib_kernels.cc
guschmue
guschmue previously approved these changes Apr 7, 2026
@edgchen1
Copy link
Copy Markdown
Contributor Author

edgchen1 commented Apr 7, 2026

will do this cleanup after 1.25

…larations

Use inline 'class' elaborated-type-specifiers in BuildKernelCreateInfo<> template arguments to combine forward declarations with table entries. Move function_table from function-local static to file scope and rename to build_kernel_create_info_function_table.

Affects webgpu_execution_provider.cc (~220 forward declarations removed) and webgpu_contrib_kernels.cc (~22 forward declarations removed).
@edgchen1 edgchen1 force-pushed the edgchen1/webgpu_ep_refine_kernel_registration branch from 1d3156d to caa13be Compare April 11, 2026 03:22
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Comment thread onnxruntime/contrib_ops/webgpu/webgpu_contrib_kernels.cc Outdated
@edgchen1 edgchen1 requested a review from guschmue April 11, 2026 03:27
@edgchen1 edgchen1 enabled auto-merge (squash) April 16, 2026 01:48
@edgchen1
Copy link
Copy Markdown
Contributor Author

/azp run Windows ARM64 QNN CI Pipeline

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@edgchen1 edgchen1 merged commit eb7a1bf into main Apr 16, 2026
96 checks passed
@edgchen1 edgchen1 deleted the edgchen1/webgpu_ep_refine_kernel_registration branch April 16, 2026 02:42
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