From 8f14bdd66cb002b2f89265b2a578ad93249089c9 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 26 Mar 2026 07:03:01 +0100 Subject: feat(cnn_v3): upgrade architecture to enc_channels=[8,16] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Double encoder capacity: enc0 4→8ch, enc1 8→16ch, bottleneck 16→16ch, dec1 32→8ch, dec0 16→4ch. Total weights 2476→7828 f16 (~15.3 KB). FiLM MLP output 40→72 params (L1: 16×40→16×72). 16-ch textures split into _lo/_hi rgba32uint pairs (enc1, bottleneck). enc0 and dec1 textures changed from rgba16float to rgba32uint (8ch). GBUF_RGBA32UINT node gains CopySrc for parity test readback. - WGSL shaders: all 5 passes rewritten for new channel counts - C++ CNNv3Effect: new weight offsets/sizes, 8ch uniform structs - Web tool (shaders.js + tester.js): matching texture formats and bindings - Parity test: readback_rgba32uint_8ch helper, updated vector counts - Training scripts: default enc_channels=[8,16], updated docstrings - Docs + architecture PNG regenerated handoff(Gemini): CNN v3 [8,16] upgrade complete. All code, tests, web tool, training scripts, and docs updated. Next: run training pass. --- cnn_v3/shaders/cnn_v3_bottleneck.wgsl | 54 +++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'cnn_v3/shaders/cnn_v3_bottleneck.wgsl') 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 invalid in uniform + _pad0: u32, _pad1: u32, _pad2: u32, } -@group(0) @binding(0) var enc1_tex: texture_2d; -@group(0) @binding(1) var weights: array; -@group(0) @binding(2) var params: Params; -@group(0) @binding(3) var bottleneck_out: texture_storage_2d; +@group(0) @binding(0) var enc1_tex_lo: texture_2d; +@group(0) @binding(1) var enc1_tex_hi: texture_2d; +@group(0) @binding(2) var weights: array; +@group(0) @binding(3) var params: Params; +@group(0) @binding(4) var bn_out_lo: texture_storage_2d; +@group(0) @binding(5) var bn_out_hi: texture_storage_2d; -// 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 { +fn load_enc1_avg(qcoord: vec2i, half_dims: vec2i) -> array { 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(0., 0., 0., 0., 0., 0., 0., 0.); + return array(0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); } let base = qcoord * 2; var s: array; 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 { @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; 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])) + )); } -- cgit v1.2.3