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/quantized_linear/q4gsw_dW_wgsl .h>
12+ #include < executorch/backends/webgpu/runtime/ops/quantized_linear/linear_dW_wgsl .h>
1313
1414#include < webgpu/webgpu.h>
1515
@@ -21,16 +21,16 @@ namespace executorch::backends::webgpu {
2121
2222namespace {
2323
24- struct Q4gswDwParams {
24+ struct LinearDwParams {
2525 uint32_t M;
2626 uint32_t N;
2727 uint32_t K;
2828 uint32_t _pad;
2929};
30- static_assert (sizeof (Q4gswDwParams ) == 16 , " params must be 16 bytes" );
30+ static_assert (sizeof (LinearDwParams ) == 16 , " params must be 16 bytes" );
3131
3232// STE weight gradient d_W[N,K] = d_out^T @ x.
33- void q4gsw_dW_impl (WebGPUGraph& graph, const std::vector<int >& args) {
33+ void linear_dW_impl (WebGPUGraph& graph, const std::vector<int >& args) {
3434 const int dout_id = args.at (0 );
3535 const int x_id = args.at (1 );
3636 const int dw_id = args.at (2 );
@@ -41,12 +41,12 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
4141 const auto & dw = graph.get_tensor (dw_id);
4242
4343 if (dw.dims .size () != 2 || dout.dims .empty () || x.dims .empty ()) {
44- throw std::runtime_error (" q4gsw_dW : bad tensor ranks" );
44+ throw std::runtime_error (" linear_dW : bad tensor ranks" );
4545 }
4646 const uint32_t N = static_cast <uint32_t >(dw.dims [0 ]);
4747 const uint32_t K = static_cast <uint32_t >(dw.dims [1 ]);
4848 if (N == 0 || K == 0 ) {
49- throw std::runtime_error (" q4gsw_dW : N or K == 0" );
49+ throw std::runtime_error (" linear_dW : N or K == 0" );
5050 }
5151
5252 uint64_t dout_numel = 1 ;
@@ -59,42 +59,42 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
5959 }
6060 if (static_cast <uint32_t >(dout.dims .back ()) != N ||
6161 static_cast <uint32_t >(x.dims .back ()) != K) {
62- throw std::runtime_error (" q4gsw_dW : d_out/x last dim mismatch" );
62+ throw std::runtime_error (" linear_dW : d_out/x last dim mismatch" );
6363 }
6464 const uint32_t M = static_cast <uint32_t >(dout_numel / N);
6565 if (dout_numel % N != 0 || x_numel % K != 0 || x_numel / K != M) {
66- throw std::runtime_error (" q4gsw_dW : M mismatch across d_out/x" );
66+ throw std::runtime_error (" linear_dW : M mismatch across d_out/x" );
6767 }
6868
6969 // fp32-only byte-size guards (mirror the forward's byte checks).
7070 if (dw.nbytes != static_cast <uint64_t >(N) * K * sizeof (float ) ||
7171 dout.nbytes != dout_numel * sizeof (float ) ||
7272 x.nbytes != x_numel * sizeof (float )) {
73- throw std::runtime_error (" q4gsw_dW : fp32-only (byte-size mismatch)" );
73+ throw std::runtime_error (" linear_dW : fp32-only (byte-size mismatch)" );
7474 }
7575
76- Q4gswDwParams params = {};
76+ LinearDwParams params = {};
7777 params.M = M;
7878 params.N = N;
7979 params.K = K;
8080
8181 const uint32_t wg_size =
82- utils::clamp_workgroup_size (device, kQ4gswDwWorkgroupSizeX );
82+ utils::clamp_workgroup_size (device, kLinearDwWorkgroupSizeX );
8383 const uint64_t tiles =
8484 utils::div_up<uint64_t >(N, 4u ) * utils::div_up<uint64_t >(K, 4u );
8585 if (tiles > UINT32_MAX ) {
86- throw std::runtime_error (" q4gsw_dW : tile count exceeds u32" );
86+ throw std::runtime_error (" linear_dW : tile count exceeds u32" );
8787 }
8888 const uint32_t workgroup_count = utils::compute_1d_workgroup_count (
89- device, static_cast <uint32_t >(tiles), wg_size, " q4gsw_dW " );
89+ device, static_cast <uint32_t >(tiles), wg_size, " linear_dW " );
9090
9191 WGPUBuffer uniform_buffer =
9292 utils::make_uniform (device, ¶ms, sizeof (params));
9393 graph.add_uniform_buffer_bytes (sizeof (params));
9494
9595 WGPUShaderSourceWGSL wgsl_desc = {};
9696 wgsl_desc.chain .sType = WGPUSType_ShaderSourceWGSL;
97- wgsl_desc.code = {kQ4gswDwWGSL , WGPU_STRLEN };
97+ wgsl_desc.code = {kLinearDwWGSL , WGPU_STRLEN };
9898 WGPUShaderModuleDescriptor shader_desc = {};
9999 shader_desc.nextInChain = &wgsl_desc.chain ;
100100 WGPUShaderModule shader = wgpuDeviceCreateShaderModule (device, &shader_desc);
@@ -156,7 +156,7 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
156156 bg_desc.entries = bg_entries;
157157 WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup (device, &bg_desc);
158158
159- graph.add_dispatch ({pipeline, bind_group, workgroup_count, " q4gsw_dW " });
159+ graph.add_dispatch ({pipeline, bind_group, workgroup_count, " linear_dW " });
160160
161161 wgpuShaderModuleRelease (shader);
162162 wgpuBindGroupLayoutRelease (bgl);
@@ -167,7 +167,7 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
167167} // namespace
168168
169169WEBGPU_REGISTER_OPERATORS {
170- WEBGPU_REGISTER_OP (et_vk.linear_q4gsw_dW .default , q4gsw_dW_impl );
170+ WEBGPU_REGISTER_OP (et_vk.linear_dW .default , linear_dW_impl );
171171}
172172
173173} // namespace executorch::backends::webgpu
0 commit comments