// This file is auto-generated by wgsl-gen. Do not edit manually. #pragma once // Template implementation // Source: nn/conv_transpose3d.wgsl.template template <> Status ApplyTemplate<"nn/conv_transpose3d.wgsl.template">(ShaderHelper& shader_helper, TemplateParameter<"nn/conv_transpose3d.wgsl.template">::type params) { [[maybe_unused]] auto& ss = shader_helper.AdditionalImplementation(); // Extract parameters auto& __param_components = params.param_components; auto& __param_has_bias = params.param_has_bias; auto& __param_is_channels_last = params.param_is_channels_last; auto& __param_is_prepacked = params.param_is_prepacked; // Extract variables auto* __var_bias = params.var_bias; auto* __var_output = params.var_output; auto* __var_w = params.var_w; auto* __var_x = params.var_x; // 1 | // Copyright (c) Microsoft Corporation. All rights reserved. // 2 | // Licensed under the MIT License. // 3 | // 4 | #param has_bias // 5 | #param is_channels_last // 6 | #param is_prepacked // 7 | #param components // 8 | // 9 | #use guardAgainstOutOfBoundsWorkgroupSizes getElementAt // 10 | #use .rank .offsetToIndices .indicesGet .getByIndices .getByOffset .setByOffset // 11 | // 12 | #if components == 4 if (__param_components == 4) { // 13 | alias Accumulator = vec4; ss << __str_412; // 14 | #elif components == 2 } else if (__param_components == 2) { // 15 | alias Accumulator = vec2; ss << __str_413; // 16 | #else } else { // 17 | alias Accumulator = f32; ss << __str_414; // 18 | #endif } // 19 | // 20 | $MAIN { MainFunctionStart(); ss << __str_5; // 21 | guardAgainstOutOfBoundsWorkgroupSizes(uniforms.output_size); ss << __str_237; ss << shader_helper.GuardAgainstOutOfBoundsWorkgroupSizes(__str_233); ss << __str_25; // 22 | let output_indices = output.offsetToIndices(global_idx); ss << __str_367; ss << __var_output->OffsetToIndices(__str_235); ss << __str_25; // 23 | let batch = output.indicesGet(output_indices, 0); ss << __str_415; ss << __var_output->IndicesGet(__str_357, __str_398); ss << __str_25; // 24 | #if is_channels_last if (__param_is_channels_last) { // 25 | let output_channel = output.indicesGet(output_indices, 4); ss << __str_416; ss << __var_output->IndicesGet(__str_357, __str_399); ss << __str_25; // 26 | let spatial_dim = 1u; ss << __str_417; // 27 | #else } else { // 28 | let output_channel = output.indicesGet(output_indices, 1); ss << __str_416; ss << __var_output->IndicesGet(__str_357, __str_400); ss << __str_25; // 29 | let spatial_dim = 2u; ss << __str_418; // 30 | #endif } // 31 | #if is_prepacked if (__param_is_prepacked) { // 32 | let output_channels_per_group = getElementAt(uniforms.w_shape, 3, w.rank); ss << __str_419; ss << GetElementAt(__str_401, __str_402, __var_w->Rank()); ss << __str_25; // 33 | let kernel_shape = vec3(getElementAt(uniforms.w_shape, 0, w.rank), ss << __str_420; ss << GetElementAt(__str_401, __str_398, __var_w->Rank()); ss << __str_421; // 34 | getElementAt(uniforms.w_shape, 1, w.rank), ss << __str_422; ss << GetElementAt(__str_401, __str_400, __var_w->Rank()); ss << __str_421; // 35 | getElementAt(uniforms.w_shape, 2, w.rank)); ss << __str_422; ss << GetElementAt(__str_401, __str_403, __var_w->Rank()); ss << __str_12; // 36 | #else } else { // 37 | let output_channels_per_group = getElementAt(uniforms.w_shape, 1, w.rank); ss << __str_419; ss << GetElementAt(__str_401, __str_400, __var_w->Rank()); ss << __str_25; // 38 | let kernel_shape = vec3(getElementAt(uniforms.w_shape, 2, w.rank), ss << __str_420; ss << GetElementAt(__str_401, __str_403, __var_w->Rank()); ss << __str_421; // 39 | getElementAt(uniforms.w_shape, 3, w.rank), ss << __str_422; ss << GetElementAt(__str_401, __str_402, __var_w->Rank()); ss << __str_421; // 40 | getElementAt(uniforms.w_shape, 4, w.rank)); ss << __str_422; ss << GetElementAt(__str_401, __str_399, __var_w->Rank()); ss << __str_12; // 41 | #endif } // 42 | let group = output_channel / output_channels_per_group; ss << __str_423; // 43 | let w_channel = output_channel % output_channels_per_group; ss << __str_424; // 44 | let corner = vec3( ss << __str_425; // 45 | i32(output.indicesGet(output_indices, spatial_dim)), ss << __str_426; ss << __var_output->IndicesGet(__str_357, __str_404); ss << __str_427; // 46 | i32(output.indicesGet(output_indices, spatial_dim + 1u)), ss << __str_426; ss << __var_output->IndicesGet(__str_357, __str_405); ss << __str_427; // 47 | i32(output.indicesGet(output_indices, spatial_dim + 2u))) + vec3(uniforms.pads); ss << __str_426; ss << __var_output->IndicesGet(__str_357, __str_406); ss << __str_428; // 48 | var value = Accumulator(0); ss << __str_429; // 49 | ss << __str_5; // 50 | // Gather input positions using signed integer coordinates so padding and stride // 51 | // alignment remain exact even for float16 tensors with large spatial dimensions. // 52 | for (var kd = 0u; kd < kernel_shape.x; kd++) { ss << __str_430; // 53 | let pos_d = corner.x - i32(kd) * i32(uniforms.dilations.x); ss << __str_431; // 54 | if (pos_d < 0 || pos_d % i32(uniforms.strides.x) != 0) { ss << __str_432; // 55 | continue; ss << __str_433; // 56 | } ss << __str_15; // 57 | let id = u32(pos_d) / uniforms.strides.x; ss << __str_434; // 58 | if (id >= getElementAt(uniforms.x_shape, spatial_dim, x.rank)) { ss << __str_435; ss << GetElementAt(__str_407, __str_404, __var_x->Rank()); ss << __str_272; // 59 | continue; ss << __str_433; // 60 | } ss << __str_15; // 61 | for (var kh = 0u; kh < kernel_shape.y; kh++) { ss << __str_436; // 62 | let pos_h = corner.y - i32(kh) * i32(uniforms.dilations.y); ss << __str_437; // 63 | if (pos_h < 0 || pos_h % i32(uniforms.strides.y) != 0) { ss << __str_438; // 64 | continue; ss << __str_439; // 65 | } ss << __str_314; // 66 | let ih = u32(pos_h) / uniforms.strides.y; ss << __str_440; // 67 | if (ih >= getElementAt(uniforms.x_shape, spatial_dim + 1u, x.rank)) { ss << __str_441; ss << GetElementAt(__str_407, __str_405, __var_x->Rank()); ss << __str_272; // 68 | continue; ss << __str_439; // 69 | } ss << __str_314; // 70 | for (var kw = 0u; kw < kernel_shape.z; kw++) { ss << __str_442; // 71 | let pos_w = corner.z - i32(kw) * i32(uniforms.dilations.z); ss << __str_443; // 72 | if (pos_w < 0 || pos_w % i32(uniforms.strides.z) != 0) { ss << __str_444; // 73 | continue; ss << __str_445; // 74 | } ss << __str_200; // 75 | let iw = u32(pos_w) / uniforms.strides.z; ss << __str_446; // 76 | if (iw >= getElementAt(uniforms.x_shape, spatial_dim + 2u, x.rank)) { ss << __str_447; ss << GetElementAt(__str_407, __str_406, __var_x->Rank()); ss << __str_272; // 77 | continue; ss << __str_445; // 78 | } ss << __str_200; // 79 | for (var c = 0u; c < uniforms.input_channels_per_group; c += components) { ss << __str_448; ss << __param_components; ss << __str_272; // 80 | let input_channel = group * uniforms.input_channels_per_group + c; ss << __str_449; // 81 | #if is_channels_last if (__param_is_channels_last) { // 82 | let x_indices = x_indices_t(batch, id, ih, iw, input_channel / components); ss << __str_450; ss << __param_components; ss << __str_12; // 83 | let x_value = Accumulator(x.getByIndices(x_indices)); ss << __str_451; ss << __var_x->GetByIndices(__str_408); ss << __str_12; // 84 | #else } else { // 85 | #if components > 1 if (__param_components > 1) { // 86 | var x_value = Accumulator(0); ss << __str_452; // 87 | for (var lane = 0u; lane < components; lane++) { ss << __str_453; ss << __param_components; ss << __str_454; // 88 | let x_indices = x_indices_t(batch, input_channel + lane, id, ih, iw); ss << __str_455; // 89 | x_value[lane] = f32(x.getByIndices(x_indices)); ss << __str_456; ss << __var_x->GetByIndices(__str_408); ss << __str_12; // 90 | } ss << __str_457; // 91 | #else } else { // 92 | let x_indices = x_indices_t(batch, input_channel, id, ih, iw); ss << __str_458; // 93 | let x_value = f32(x.getByIndices(x_indices)); ss << __str_459; ss << __var_x->GetByIndices(__str_408); ss << __str_12; // 94 | #endif } // 95 | #endif } // 96 | #if is_prepacked if (__param_is_prepacked) { // 97 | let w_indices = w_indices_t(kd, kh, kw, w_channel, input_channel / components); ss << __str_460; ss << __param_components; ss << __str_12; // 98 | #else } else { // 99 | let w_indices = w_indices_t(input_channel, w_channel, kd, kh, kw); ss << __str_461; // 100 | #endif } // 101 | value += x_value * Accumulator(w.getByIndices(w_indices)); ss << __str_462; ss << __var_w->GetByIndices(__str_409); ss << __str_12; // 102 | } ss << __str_200; // 103 | } ss << __str_314; // 104 | } ss << __str_15; // 105 | } ss << __str_16; // 106 | #if components > 1 if (__param_components > 1) { // 107 | var result = dot(value, Accumulator(1)); ss << __str_463; // 108 | #else } else { // 109 | var result = value; ss << __str_464; // 110 | #endif } // 111 | #if has_bias if (__param_has_bias) { // 112 | result += f32(bias.getByOffset(output_channel)); ss << __str_465; ss << __var_bias->GetByOffset(__str_410); ss << __str_12; // 113 | #endif } // 114 | output.setByOffset(global_idx, output_value_t(result)); ss << __str_237; ss << __var_output->SetByOffset(__str_235, __str_411); ss << __str_25; // 115 | } MainFunctionEnd(); ss << __str_5; // 116 | return Status::OK(); }