// This file is auto-generated by wgsl-gen. Do not edit manually.
|
|
#pragma once
|
|
// Template implementation
|
// Source: tensor/pad.wgsl.template
|
|
template <>
|
Status ApplyTemplate<"tensor/pad.wgsl.template">(ShaderHelper& shader_helper, TemplateParameter<"tensor/pad.wgsl.template">::type params) {
|
[[maybe_unused]] auto& ss = shader_helper.AdditionalImplementation();
|
|
// Extract parameters
|
auto& __param_dim_value_zero = params.param_dim_value_zero;
|
auto& __param_is_float16 = params.param_is_float16;
|
auto& __param_pad_mode = params.param_pad_mode;
|
|
// Extract variables
|
auto* __var_output = params.var_output;
|
|
// 1 | #define PAD_MODE_CONSTANT 0
|
// 2 | #define PAD_MODE_REFLECT 1
|
// 3 | #define PAD_MODE_EDGE 2
|
// 4 | #define PAD_MODE_WRAP 3
|
// 5 |
|
// 6 | #use guardAgainstOutOfBoundsWorkgroupSizes
|
// 7 | #use getElementAt
|
// 8 | #use .offsetToIndices .setByOffset .rank
|
// 9 |
|
// 10 | #param dim_value_zero
|
// 11 | #param is_float16
|
// 12 | #param pad_mode
|
// 13 |
|
// 14 | $MAIN {
|
MainFunctionStart();
|
ss << __str_5;
|
// 15 | guardAgainstOutOfBoundsWorkgroupSizes(uniforms.output_size);
|
ss << __str_237;
|
ss << shader_helper.GuardAgainstOutOfBoundsWorkgroupSizes(__str_233);
|
ss << __str_25;
|
// 16 |
|
ss << __str_5;
|
// 17 | let constant_value =
|
ss << __str_363;
|
// 18 | #if is_float16
|
if (__param_is_float16) {
|
// 19 | bitcast<vec2<f16>>(uniforms.constant_value)[0];
|
ss << __str_364;
|
// 20 | #else
|
} else {
|
// 21 | bitcast<output_value_t>(uniforms.constant_value);
|
ss << __str_365;
|
// 22 | #endif
|
}
|
// 23 |
|
// 24 | #if dim_value_zero
|
if (__param_dim_value_zero) {
|
// 25 | output[global_idx] = constant_value;
|
ss << __str_366;
|
// 26 | #else
|
} else {
|
// 27 | let output_indices = output.offsetToIndices(global_idx);
|
ss << __str_367;
|
ss << __var_output->OffsetToIndices(__str_235);
|
ss << __str_25;
|
// 28 | var input_index = u32(0);
|
ss << __str_368;
|
// 29 | var use_pad_value = false;
|
ss << __str_369;
|
// 30 | var in_coord = i32(0);
|
ss << __str_370;
|
// 31 |
|
ss << __str_5;
|
// 32 | for (var dim = 0; dim < output.rank && !use_pad_value; dim++) {
|
ss << __str_371;
|
ss << __var_output->Rank();
|
ss << __str_372;
|
// 33 | let output_index = i32(getElementAt(output_indices, dim, output.rank));
|
ss << __str_373;
|
ss << GetElementAt(__str_357, __str_358, __var_output->Rank());
|
ss << __str_12;
|
// 34 | let lower_pads = getElementAt(uniforms.lower_pads, dim, output.rank);
|
ss << __str_374;
|
ss << GetElementAt(__str_359, __str_358, __var_output->Rank());
|
ss << __str_25;
|
// 35 | let data_shape = i32(getElementAt(uniforms.data_shape, dim, output.rank));
|
ss << __str_375;
|
ss << GetElementAt(__str_360, __str_358, __var_output->Rank());
|
ss << __str_12;
|
// 36 | #if pad_mode == PAD_MODE_CONSTANT
|
if (__param_pad_mode == 0) {
|
// 37 | if (output_index < lower_pads || output_index >= data_shape + lower_pads) {
|
ss << __str_376;
|
// 38 | use_pad_value = true;
|
ss << __str_377;
|
// 39 | #elif pad_mode == PAD_MODE_EDGE
|
} else if (__param_pad_mode == 2) {
|
// 40 | if (output_index < lower_pads) {
|
ss << __str_378;
|
// 41 | in_coord = 0;
|
ss << __str_379;
|
// 42 | } else if (output_index >= data_shape + lower_pads) {
|
ss << __str_380;
|
// 43 | in_coord = data_shape - 1;
|
ss << __str_381;
|
// 44 | #elif pad_mode == PAD_MODE_REFLECT
|
} else if (__param_pad_mode == 1) {
|
// 45 | if (output_index < lower_pads || output_index >= data_shape + lower_pads) {
|
ss << __str_376;
|
// 46 | in_coord = output_index - lower_pads;
|
ss << __str_382;
|
// 47 | if (in_coord < 0) {
|
ss << __str_383;
|
// 48 | in_coord = -in_coord;
|
ss << __str_384;
|
// 49 | }
|
ss << __str_314;
|
// 50 | let _2n_1 = 2 * (data_shape - 1);
|
ss << __str_385;
|
// 51 | in_coord = in_coord % _2n_1;
|
ss << __str_386;
|
// 52 | if (in_coord >= data_shape) {
|
ss << __str_387;
|
// 53 | in_coord = _2n_1 - in_coord;
|
ss << __str_388;
|
// 54 | }
|
ss << __str_314;
|
// 55 | #else // PAD_MODE_WRAP
|
} else {
|
// 56 | if (output_index < lower_pads) {
|
ss << __str_378;
|
// 57 | in_coord = data_shape + output_index - lower_pads;
|
ss << __str_389;
|
// 58 | } else if (output_index >= data_shape + lower_pads) {
|
ss << __str_380;
|
// 59 | in_coord = output_index - data_shape - lower_pads;
|
ss << __str_390;
|
// 60 | #endif // pad_mode
|
}
|
// 61 | } else {
|
ss << __str_391;
|
// 62 | in_coord = output_index - lower_pads;
|
ss << __str_392;
|
// 63 | }
|
ss << __str_15;
|
// 64 |
|
ss << __str_5;
|
// 65 | #if pad_mode == PAD_MODE_WRAP
|
if (__param_pad_mode == 3) {
|
// 66 | in_coord = ((in_coord % data_shape) + data_shape) % data_shape;
|
ss << __str_393;
|
// 67 | #endif
|
}
|
// 68 |
|
// 69 | input_index += select(u32(in_coord)
|
ss << __str_394;
|
// 70 | #if output.rank > 1
|
if (__var_output->Rank() > 1) {
|
// 71 | * getElementAt(uniforms.data_stride, dim, output.rank - 1)
|
ss << __str_395;
|
ss << GetElementAt(__str_361, __str_358, __var_output->Rank() - 1);
|
ss << __str_5;
|
// 72 | #endif
|
}
|
// 73 | , u32(in_coord), dim == output.rank - 1);
|
ss << __str_396;
|
ss << __var_output->Rank();
|
ss << __str_397;
|
// 74 | }
|
ss << __str_16;
|
// 75 |
|
ss << __str_5;
|
// 76 | output.setByOffset(global_idx, select(data[input_index], constant_value, use_pad_value));
|
ss << __str_237;
|
ss << __var_output->SetByOffset(__str_235, __str_362);
|
ss << __str_25;
|
// 77 | #endif
|
}
|
// 78 | } // MAIN
|
MainFunctionEnd();
|
ss << __str_5;
|
// 79 |
|
|
|
return Status::OK();
|
}
|