Skip to content

Commit 17219f8

Browse files
committed
Update (base update)
[ghstack-poisoned]
1 parent 51b811e commit 17219f8

5 files changed

Lines changed: 18 additions & 45 deletions

File tree

backends/webgpu/runtime/ops/log_softmax/LogSoftmax.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/log_softmax/log_softmax_wgsl.h>
12+
#include <executorch/backends/webgpu/runtime/ops/softmax/log_softmax_wgsl.h>
1313

1414
#include <webgpu/webgpu.h>
1515

backends/webgpu/runtime/ops/log_softmax/log_softmax.wgsl

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

backends/webgpu/runtime/ops/log_softmax/log_softmax_wgsl.h renamed to backends/webgpu/runtime/ops/softmax/log_softmax_wgsl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
namespace executorch::backends::webgpu {
1414

15-
// @generated from log_softmax.wgsl - DO NOT EDIT.
16-
// wgsl-sha256: 0f6d1e9eea8d0ec8246c2c4f0b0be5c03deb4a73790896b8a0b093fc5be16114
15+
// @generated from softmax.wgsl - DO NOT EDIT.
16+
// wgsl-sha256: 3e5550d3bf913a4e9e871b1474934278f81b4d635504aceb8ab4e096ef18889a
1717
inline constexpr const char* kLogSoftmaxWGSL = R"(
1818
struct Params {
1919
outer_: u32,
@@ -38,7 +38,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
3838
let oo = t / params.inner_;
3939
let ii = t % params.inner_;
4040
let base = oo * params.r_ * params.inner_ + ii;
41-
// Online flash-style softmax; -3.4e38 seeds max (Tint overflows -FLT_MAX).
41+
// Online (flash-style) softmax; -3.4e38 seeds max (Tint overflows -FLT_MAX).
4242
var mx: f32 = -3.4e38;
4343
var ssum: f32 = 0.0;
4444
for (var r: u32 = 0u; r < params.r_; r = r + 1u) {

backends/webgpu/runtime/ops/softmax/softmax.wgsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
3232
}
3333
ssum = ssum + exp(v - mx);
3434
}
35+
$if LOG:
36+
let log_sum = log(ssum);
3537
for (var r: u32 = 0u; r < params.r_; r = r + 1u) {
3638
let idx = base + r * params.inner_;
37-
out[idx] = exp(inp[idx] - mx) / ssum;
39+
$if LOG:
40+
out[idx] = (inp[idx] - mx) - log_sum;
41+
$else:
42+
out[idx] = exp(inp[idx] - mx) / ssum;
3843
}
3944
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
softmax:
2+
parameter_names_with_default_values:
3+
LOG: 0
4+
shader_variants:
5+
- NAME: softmax
6+
LOG: 0
7+
- NAME: log_softmax
8+
LOG: 1

0 commit comments

Comments
 (0)