Skip to content

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

Open
edgchen1 wants to merge 5 commits intomainfrom
edgchen1/webgpu_ep_refine_kernel_registration
Open

[WebGPU EP] Reduce forward declaration boilerplate in kernel registration#27977
edgchen1 wants to merge 5 commits intomainfrom
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.

edgchen1 added 2 commits April 3, 2026 16:46
…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.

Affects webgpu_execution_provider.cc (~200 forward declarations removed) and webgpu_contrib_kernels.cc (~20 forward declarations removed).
More descriptive name now that it is at file scope instead of function-local.
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.

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.

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.

2 participants