// This file is auto-generated by wgsl-gen. Do not edit manually. #pragma once // Template implementation // Source: math/matmul_gemv.wgsl.template template <> Status ApplyTemplate<"math/matmul_gemv.wgsl.template">(ShaderHelper& shader_helper, TemplateParameter<"math/matmul_gemv.wgsl.template">::type params) { [[maybe_unused]] auto& ss = shader_helper.AdditionalImplementation(); // Extract variables auto* __var_a = params.var_a; auto* __var_b = params.var_b; auto* __var_output = params.var_output; // 1 | // Copyright (c) Microsoft Corporation. All rights reserved. // 2 | // Licensed under the MIT License. // 3 | // 4 | #use .getByOffset .setByOffset // 5 | // 6 | var partials: array, workgroup_size_x * workgroup_size_y>; ss << __str_4; // 7 | ss << __str_5; // 8 | $MAIN { MainFunctionStart(); ss << __str_5; // 9 | let n_vec = workgroup_idx * workgroup_size_x + local_id.x; ss << __str_6; // 10 | let n_vec_count = uniforms.N / 4u; ss << __str_7; // 11 | var acc = vec4(0); ss << __str_8; // 12 | if (n_vec < n_vec_count) { ss << __str_9; // 13 | for (var k = local_id.y; k < uniforms.K; k += workgroup_size_y) { ss << __str_10; // 14 | let av = f32(a.getByOffset(k)); ss << __str_11; ss << __var_a->GetByOffset(__str_0); ss << __str_12; // 15 | let bv = vec4(b.getByOffset(k * n_vec_count + n_vec)); ss << __str_13; ss << __var_b->GetByOffset(__str_1); ss << __str_12; // 16 | acc = fma(vec4(av), bv, acc); ss << __str_14; // 17 | } ss << __str_15; // 18 | } ss << __str_16; // 19 | partials[local_idx] = acc; ss << __str_17; // 20 | workgroupBarrier(); ss << __str_18; // 21 | ss << __str_5; // 22 | // All lanes participate in the barriers, including a partial N tile. // 23 | for (var stride = workgroup_size_y / 2u; stride > 0u; stride /= 2u) { ss << __str_19; // 24 | if (local_id.y < stride) { ss << __str_20; // 25 | partials[local_idx] += partials[local_idx + stride * workgroup_size_x]; ss << __str_21; // 26 | } ss << __str_15; // 27 | workgroupBarrier(); ss << __str_22; // 28 | } ss << __str_16; // 29 | if (local_id.y == 0u && n_vec < n_vec_count) { ss << __str_23; // 30 | output.setByOffset(n_vec, output_value_t(partials[local_idx])); ss << __str_24; ss << __var_output->SetByOffset(__str_2, __str_3); ss << __str_25; // 31 | } ss << __str_16; // 32 | } MainFunctionEnd(); ss << __str_5; // 33 | return Status::OK(); }