summaryrefslogtreecommitdiff
path: root/cnn_v3/shaders/cnn_v3_bottleneck.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'cnn_v3/shaders/cnn_v3_bottleneck.wgsl')
-rw-r--r--cnn_v3/shaders/cnn_v3_bottleneck.wgsl54
1 files changed, 33 insertions, 21 deletions
diff --git a/cnn_v3/shaders/cnn_v3_bottleneck.wgsl b/cnn_v3/shaders/cnn_v3_bottleneck.wgsl
index e30682b..09819cc 100644
--- a/cnn_v3/shaders/cnn_v3_bottleneck.wgsl
+++ b/cnn_v3/shaders/cnn_v3_bottleneck.wgsl
@@ -1,43 +1,49 @@
// CNN v3 — Bottleneck
-// AvgPool2x2(enc1) + Conv(8->8, 3x3, dilation=2) + ReLU (no FiLM)
+// AvgPool2x2(enc1) + Conv(16->16, 3x3, dilation=2) + ReLU (no FiLM)
//
-// Input: enc1_tex (rgba32uint, 8xf16) half-res
-// Output: bottleneck_out (rgba32uint, 8xf16) quarter-res (dispatch at quarter-res dims)
+// Input: enc1_tex_lo (rgba32uint, 8xf16) half-res ch 0-7
+// enc1_tex_hi (rgba32uint, 8xf16) half-res ch 8-15
+// Output: bn_out_lo (rgba32uint, 8xf16) quarter-res
+// bn_out_hi (rgba32uint, 8xf16) quarter-res
//
// Weight layout (f16, OIHW + bias):
-// [0 .. 8*8*9) conv: w[out][in][ky*3+kx] (3x3 kernel, OIHW)
-// [576 .. +8) bias: b[out]
+// [0 .. 16*16*9) conv: w[out][in][ky*3+kx]
+// [2304 .. +16) bias: b[out]
#include "cnn_v3/common"
-const BN_IN: u32 = 8u;
-const BN_OUT: u32 = 8u;
+const BN_IN: u32 = 16u;
+const BN_OUT: u32 = 16u;
const BN_DILATION: i32 = 2;
struct Params {
weight_offset: u32,
- _pad0: u32, _pad1: u32, _pad2: u32, // 3 explicit pads: array<u32,3> invalid in uniform
+ _pad0: u32, _pad1: u32, _pad2: u32,
}
-@group(0) @binding(0) var enc1_tex: texture_2d<u32>;
-@group(0) @binding(1) var<storage, read> weights: array<u32>;
-@group(0) @binding(2) var<uniform> params: Params;
-@group(0) @binding(3) var bottleneck_out: texture_storage_2d<rgba32uint, write>;
+@group(0) @binding(0) var enc1_tex_lo: texture_2d<u32>;
+@group(0) @binding(1) var enc1_tex_hi: texture_2d<u32>;
+@group(0) @binding(2) var<storage, read> weights: array<u32>;
+@group(0) @binding(3) var<uniform> params: Params;
+@group(0) @binding(4) var bn_out_lo: texture_storage_2d<rgba32uint, write>;
+@group(0) @binding(5) var bn_out_hi: texture_storage_2d<rgba32uint, write>;
-// Avg-pool 2x2 from enc1_tex at quarter-res coord qcoord.
-// Returns zeros for OOB quarter-res coords (zero-padding for the 3x3 conv).
-fn load_enc1_avg(qcoord: vec2i, half_dims: vec2i) -> array<f32, 8> {
+fn load_enc1_avg(qcoord: vec2i, half_dims: vec2i) -> array<f32, 16> {
let quart_dims = half_dims / 2;
if (qcoord.x < 0 || qcoord.y < 0 || qcoord.x >= quart_dims.x || qcoord.y >= quart_dims.y) {
- return array<f32, 8>(0., 0., 0., 0., 0., 0., 0., 0.);
+ return array<f32, 16>(0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.);
}
let base = qcoord * 2;
var s: array<f32, BN_IN>;
for (var dy: i32 = 0; dy < 2; dy++) {
for (var dx: i32 = 0; dx < 2; dx++) {
let hc = clamp(base + vec2i(dx, dy), vec2i(0), half_dims - vec2i(1));
- let f = unpack_8ch(enc1_tex, hc);
- for (var i: u32 = 0u; i < BN_IN; i++) { s[i] += f[i]; }
+ let lo = unpack_8ch(enc1_tex_lo, hc);
+ let hi = unpack_8ch(enc1_tex_hi, hc);
+ for (var i: u32 = 0u; i < 8u; i++) {
+ s[i] += lo[i];
+ s[i + 8u] += hi[i];
+ }
}
}
for (var i: u32 = 0u; i < BN_IN; i++) { s[i] *= 0.25; }
@@ -46,7 +52,7 @@ fn load_enc1_avg(qcoord: vec2i, half_dims: vec2i) -> array<f32, 8> {
@compute @workgroup_size(8, 8)
fn bottleneck_main(@builtin(global_invocation_id) id: vec3u) {
- let half_dims = vec2i(textureDimensions(enc1_tex));
+ let half_dims = vec2i(textureDimensions(enc1_tex_lo));
let quart_dims = half_dims / 2;
let coord = vec2i(id.xy);
if (coord.x >= quart_dims.x || coord.y >= quart_dims.y) { return; }
@@ -55,7 +61,7 @@ fn bottleneck_main(@builtin(global_invocation_id) id: vec3u) {
var out: array<f32, BN_OUT>;
for (var o: u32 = 0u; o < BN_OUT; o++) {
- var sum = get_w(wo, BN_OUT * BN_IN * 9u + o); // bias (at end of 3x3 conv weights)
+ var sum = get_w(wo, BN_OUT * BN_IN * 9u + o); // bias
for (var ky: i32 = -1; ky <= 1; ky++) {
for (var kx: i32 = -1; kx <= 1; kx++) {
let feat = load_enc1_avg(coord + vec2i(kx, ky) * BN_DILATION, half_dims);
@@ -68,10 +74,16 @@ fn bottleneck_main(@builtin(global_invocation_id) id: vec3u) {
out[o] = max(0.0, sum);
}
- textureStore(bottleneck_out, coord, vec4u(
+ textureStore(bn_out_lo, coord, vec4u(
pack2x16float(vec2f(out[0], out[1])),
pack2x16float(vec2f(out[2], out[3])),
pack2x16float(vec2f(out[4], out[5])),
pack2x16float(vec2f(out[6], out[7]))
));
+ textureStore(bn_out_hi, coord, vec4u(
+ pack2x16float(vec2f(out[8], out[9])),
+ pack2x16float(vec2f(out[10], out[11])),
+ pack2x16float(vec2f(out[12], out[13])),
+ pack2x16float(vec2f(out[14], out[15]))
+ ));
}