code wiki / (root) / nx_f32_groupnorm.nx

nx_f32_groupnorm.nx

buildroot/runtime/nx_f32_groupnorm.nx

6544 B146 linesdepth 4pulls 6 transitivereach 2 importersview sourcekind tooltopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_groupnorm.nx -- software-f32 Group Normalisation (Wu & He 2018), the R3 vision-op re-tier. sd-server -> Nishi migration, rung 3 ("unify the two numeric universes"): the existing diffusion GroupNorm `nx_groupnorm.nx` is i64 Q10 (10 fractional bits) and has only ever run on identity weights; this is the SAME math in the sovereign software-f32 tier (`nx_f32_*`, bit-exact IEEE-754 emulated in i64) so the REAL dequantized GGUF weights (`nx_q4k_to_f32` etc.) flow through it. GroupNorm(32) is the load-bearing norm in SD/Flux/Z-Image UNet + VAE ResBlocks. Tensor representation: a FLAT `*i64` whose every element is an f32 bit-pattern, laid out [N,C,H,W] row-major, with dims passed explicitly. This deliberately avoids `nx_tensor`'s F32 dtype, which is DTYPE_GATED / unusable today (TODO_COMPILER_F32_F64 parked) -- the flat-f32-bits convention is how the whole `nx_f32_*` stack already works. Composes ONLY gated primitives: nx_f32_add/sub/mul/sqrt (nx_f32.nx), nx_f32_div (nx_f32_div.nx), nx_i32_to_f32 (nx_f32_cvt.nx). No libm, no third-party. eps = 1e-5 (Z-Image norm_eps), built from cvt+div so there is no hand-coded float bit-pattern. Math (per group g of a sample n): mean,var over (C/G * H * W) elements; y = (x-mean)/sqrt(var+eps)*gamma+beta. license_tier: ORIGINAL

dependencies 4 imports · 1 importers

nx_syscalls.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f32_groupnorm.nx nx_f32_resblock.nx

imports: nx_syscalls.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nx

imported by: nx_f32_resblock.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nx_i32_to_f32 nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_groupnorm_forward nx_i32_to_f32 ↻ nx_f32gn_eps nx_f32_div ↻ nx_i32_to_f32 ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_div ↻ nx_f32_sub nx_f32_add ↻ nx_f32_neg nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_sqrt nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_exp_field ↻ nx_f32_mant_field ↻ _f32_isqrt nx_f32_sub ↻

structs

none

consts

24const NX_MAGIC_100000: i64 = 100000
26const NX_F32GN_OK: i64 = 0
27const NX_F32GN_ERR_BAD_GROUPS: i64 = 5

functions

30func nx_f32gn_eps() -> i64 { return nx_f32_div(nx_i32_to_f32(1), nx_i32_to_f32(NX_MAGIC_100000)) }
34func nx_f32_groupnorm_forward(x: *i64, N: i64, C: i64, H: i64, W: i64, n_groups: i64,
105func main() -> i64