Skip to content

Commit cbd0294

Browse files
committed
[ExecuTorch][WebGPU] Generate extrema and unary shader variants
Pull Request resolved: #21450 **Generate extrema and unary shader families** The extrema reductions and ten no-parameter unary kernels duplicated shader skeletons that could drift independently. This consolidates amax/amin behind one extrema template and abs/cos/exp/hardswish/neg/round/rsqrt/sin/sqrt/tanh behind one unary template while preserving the generated runtime payloads. Key changes: - Generate amax/amin from one extrema manifest. - Generate ten unary payloads from one operator-expression manifest. - Lock expanded bytes, registry entries, delegation, and boundary numerics. The attempted Unary lifecycle migration is intentionally not part of the stack: its performance campaign did not produce an authoritative passing result, so the Unary builder, interface, and activation/sigmoid call sites are restored to their pre-migration bytes. Co-authored-with: Claude Code. ghstack-source-id: 411961475 @exported-using-ghexport Differential Revision: [D113979760](https://our.internmc.facebook.com/intern/diff/D113979760/)
1 parent 0954161 commit cbd0294

33 files changed

Lines changed: 397 additions & 283 deletions

backends/webgpu/runtime/WebGPUShaderRegistry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <executorch/backends/webgpu/runtime/ops/adamw/adamw_step_wgsl.h>
1414
#include <executorch/backends/webgpu/runtime/ops/add/binary_add_wgsl.h>
1515
#include <executorch/backends/webgpu/runtime/ops/addmm/addmm_tiled_wgsl.h>
16-
#include <executorch/backends/webgpu/runtime/ops/amax/amax_wgsl.h>
17-
#include <executorch/backends/webgpu/runtime/ops/amin/amin_wgsl.h>
1816
#include <executorch/backends/webgpu/runtime/ops/argmax/arg_reduce_wgsl.h>
1917
#include <executorch/backends/webgpu/runtime/ops/avg_pool2d/avg_pool2d_wgsl.h>
2018
#include <executorch/backends/webgpu/runtime/ops/batch_norm/batch_norm_wgsl.h>
@@ -48,6 +46,8 @@
4846
#include <executorch/backends/webgpu/runtime/ops/et_vk_sdpa/et_vk_sdpa_qk_entry_wgsl.h>
4947
#include <executorch/backends/webgpu/runtime/ops/et_vk_sdpa/et_vk_sdpa_qk_wgsl.h>
5048
#include <executorch/backends/webgpu/runtime/ops/expand_copy/expand_copy_wgsl.h>
49+
#include <executorch/backends/webgpu/runtime/ops/extrema/amax_wgsl.h>
50+
#include <executorch/backends/webgpu/runtime/ops/extrema/amin_wgsl.h>
5151
#include <executorch/backends/webgpu/runtime/ops/fill/fill_wgsl.h>
5252
#include <executorch/backends/webgpu/runtime/ops/flip/flip_wgsl.h>
5353
#include <executorch/backends/webgpu/runtime/ops/floor_divide/binary_floor_divide_wgsl.h>

backends/webgpu/runtime/ops/amax/Reduce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <executorch/backends/webgpu/runtime/WebGPUGraph.h>
1010
#include <executorch/backends/webgpu/runtime/WebGPUUtils.h>
1111
#include <executorch/backends/webgpu/runtime/ops/OperatorRegistry.h>
12-
#include <executorch/backends/webgpu/runtime/ops/amax/amax_wgsl.h>
12+
#include <executorch/backends/webgpu/runtime/ops/extrema/amax_wgsl.h>
1313

1414
#include <webgpu/webgpu.h>
1515

backends/webgpu/runtime/ops/amin/Reduce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <executorch/backends/webgpu/runtime/WebGPUGraph.h>
1010
#include <executorch/backends/webgpu/runtime/WebGPUUtils.h>
1111
#include <executorch/backends/webgpu/runtime/ops/OperatorRegistry.h>
12-
#include <executorch/backends/webgpu/runtime/ops/amin/amin_wgsl.h>
12+
#include <executorch/backends/webgpu/runtime/ops/extrema/amin_wgsl.h>
1313

1414
#include <webgpu/webgpu.h>
1515

backends/webgpu/runtime/ops/amin/amin.wgsl

Lines changed: 0 additions & 49 deletions
This file was deleted.

backends/webgpu/runtime/ops/amax/amax_wgsl.h renamed to backends/webgpu/runtime/ops/extrema/amax_wgsl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace executorch::backends::webgpu {
1414

15-
// @generated from amax.wgsl - DO NOT EDIT.
15+
// @generated from extrema.wgsl - DO NOT EDIT.
1616
// wgsl-sha256: 35fc059d7c72caa17f9cb1128823ecfd8f75be4ce24b6cd4f9629a97b52f64c0
1717
inline constexpr const char* kAmaxWGSL = R"(
1818
@group(0) @binding(0) var<storage, read> input: array<f32>;

backends/webgpu/runtime/ops/amin/amin_wgsl.h renamed to backends/webgpu/runtime/ops/extrema/amin_wgsl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace executorch::backends::webgpu {
1414

15-
// @generated from amin.wgsl - DO NOT EDIT.
15+
// @generated from extrema.wgsl - DO NOT EDIT.
1616
// wgsl-sha256: 8cb6035ae4d34eb2a6cc973d93d9847905722e967239c96033fccfe3a1943cb2
1717
inline constexpr const char* kAminWGSL = R"(
1818
@group(0) @binding(0) var<storage, read> input: array<f32>;

backends/webgpu/runtime/ops/amax/amax.wgsl renamed to backends/webgpu/runtime/ops/extrema/extrema.wgsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main(
3232
var acc = input[base];
3333
var i = lid.x;
3434
while (i < params.reduce_size) {
35-
acc = max(acc, input[base + i]);
35+
acc = ${REDUCE_FN}(acc, input[base + i]);
3636
i = i + wg_size;
3737
}
3838
partials[lid.x] = acc;
@@ -42,7 +42,7 @@ fn main(
4242
if (lid.x == 0u) {
4343
var m = partials[0];
4444
for (var t = 1u; t < wg_size; t = t + 1u) {
45-
m = max(m, partials[t]);
45+
m = ${REDUCE_FN}(m, partials[t]);
4646
}
4747
output[row] = m;
4848
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
extrema:
8+
parameter_names_with_default_values:
9+
REDUCE_FN: max
10+
shader_variants:
11+
- NAME: amax
12+
- NAME: amin
13+
REDUCE_FN: min

backends/webgpu/runtime/ops/unary/abs.wgsl

Lines changed: 0 additions & 21 deletions
This file was deleted.

backends/webgpu/runtime/ops/unary/abs_wgsl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace executorch::backends::webgpu {
1414

15-
// @generated from abs.wgsl - DO NOT EDIT.
15+
// @generated from unary.wgsl - DO NOT EDIT.
1616
// wgsl-sha256: 39d3c163fdf6a92286828f4b3217e00294e3ca5634a878ed5fd34e3b1cdf0a27
1717
inline constexpr const char* kAbsWGSL = R"(
1818
@group(0) @binding(0) var<storage, read> input: array<f32>;

0 commit comments

Comments
 (0)