Commit 506d1e4a for whisper.cpp
commit 506d1e4a1e10d701f242e31a878c8b1ac855b11d
Author: Leon <118652405+LeON-Nie-code@users.noreply.github.com>
Date: Wed Nov 11 18:11:06 2026 +0800
webgpu: add PAD_REFLECT_1D support (llama/31877)
* webgpu : add PAD_REFLECT_1D support
* webgpu: remove redundant PAD_REFLECT_1D contiguity check
* tests: simplify PAD_REFLECT_1D setup
diff --git a/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp b/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
index 92ec03fb..3cc6a70c 100644
--- a/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
+++ b/ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp
@@ -333,14 +333,18 @@ struct ggml_webgpu_rms_norm_mul_shader_decisions {
/** Pad **/
struct ggml_webgpu_pad_pipeline_key {
bool circular;
+ bool reflect;
- bool operator==(const ggml_webgpu_pad_pipeline_key & other) const { return circular == other.circular; }
+ bool operator==(const ggml_webgpu_pad_pipeline_key & other) const {
+ return circular == other.circular && reflect == other.reflect;
+ }
};
struct ggml_webgpu_pad_pipeline_key_hash {
size_t operator()(const ggml_webgpu_pad_pipeline_key & key) const {
size_t seed = 0;
ggml_webgpu_hash_combine(seed, key.circular);
+ ggml_webgpu_hash_combine(seed, key.reflect);
return seed;
}
};
@@ -2047,7 +2051,8 @@ class ggml_webgpu_shader_lib {
webgpu_pipeline get_pad_pipeline(const ggml_webgpu_shader_lib_context & context) {
ggml_webgpu_pad_pipeline_key key = {};
- key.circular = ggml_get_op_params_i32(context.dst, 8) != 0;
+ key.reflect = context.dst->op == GGML_OP_PAD_REFLECT_1D;
+ key.circular = !key.reflect && ggml_get_op_params_i32(context.dst, 8) != 0;
auto it = pad_pipelines.find(key);
if (it != pad_pipelines.end()) {
@@ -2057,6 +2062,10 @@ class ggml_webgpu_shader_lib {
std::vector<std::string> defines;
std::string variant = "pad";
+ if (key.reflect) {
+ defines.push_back("REFLECT");
+ variant += "_reflect";
+ }
if (key.circular) {
defines.push_back("CIRCULAR");
variant += "_circular";
diff --git a/ggml/src/ggml-webgpu/ggml-webgpu.cpp b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
index b827e3d4..c08aa415 100644
--- a/ggml/src/ggml-webgpu/ggml-webgpu.cpp
+++ b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
@@ -3625,6 +3625,7 @@ static std::optional<webgpu_encoded_op> ggml_webgpu_encode(webgpu_context ctx,
}
case GGML_OP_ARANGE:
return ggml_webgpu_arange(ctx, node);
+ case GGML_OP_PAD_REFLECT_1D:
case GGML_OP_PAD:
return ggml_webgpu_pad(ctx, src0, node);
case GGML_OP_COUNT_EQUAL:
@@ -5165,6 +5166,9 @@ static bool ggml_backend_webgpu_device_supports_op(ggml_backend_dev_t dev, const
case GGML_OP_ARANGE:
supports_op = op->type == GGML_TYPE_F32 && ggml_is_contiguous(op);
break;
+ case GGML_OP_PAD_REFLECT_1D:
+ supports_op = op->type == GGML_TYPE_F32 && src0->type == GGML_TYPE_F32;
+ break;
case GGML_OP_PAD:
supports_op = op->type == GGML_TYPE_F32 && src0->type == GGML_TYPE_F32;
break;
diff --git a/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl b/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl
index 2cb999be..6c7b2e0a 100644
--- a/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl
+++ b/ggml/src/ggml-webgpu/wgsl-shaders/pad.wgsl
@@ -64,6 +64,18 @@ fn main(@builtin(num_workgroups) num_wg: vec3<u32>,
var value: f32 = 0.0;
+#ifdef REFLECT
+ var x: u32;
+ if (i0 < params.lp0) {
+ x = params.lp0 - i0;
+ } else if (i0 < params.lp0 + params.src_ne0) {
+ x = i0 - params.lp0;
+ } else {
+ x = params.src_ne0 - 2 - (i0 - params.lp0 - params.src_ne0);
+ }
+ value = src[params.offset_src + x * params.stride_src0 + i1 * params.stride_src1 +
+ i2 * params.stride_src2 + i3 * params.stride_src3];
+#else
#ifdef CIRCULAR
let ci0 = wrap_around(i32(i0) - i32(params.lp0), params.src_ne0);
let ci1 = wrap_around(i32(i1) - i32(params.lp1), params.src_ne1);
@@ -85,5 +97,6 @@ fn main(@builtin(num_workgroups) num_wg: vec3<u32>,
}
#endif
+#endif
dst[params.offset_dst + gid_i] = value;
}