sync c928d21e6cc1
Browse filesFiles changed (4)
34 unmodified lines3536373839404134 unmodified linesreturn 1.0 / (1.0 + exp(-v));{% endif %}{% if actMode == "Tanh" %}return tanh(v);{% endif %}{% if actMode == "HardSigmoid" %}return clamp(f32({{ actA }}) * v + f32({{ actB }}), 0.0, 1.0);34 unmodified lines353637383940414243444534 unmodified linesreturn 1.0 / (1.0 + exp(-v));{% endif %}{% if actMode == "Tanh" %}// Clamp first: the hardware tanh evaluates (e^2v - 1)/(e^2v + 1), which is// Inf/Inf = NaN once e^2v overflows (v > ~44). A GEMM accumulator reaches that// easily because it grows with K. tanh is already +/-1 to full f32 precision by// |v| ~ 9, so the clamp changes no representable result.return tanh(clamp(v, -10.0, 10.0));{% endif %}{% if actMode == "HardSigmoid" %}return clamp(f32({{ actA }}) * v + f32({{ actB }}), 0.0, 1.0);
11 unmodified lines12131415161738 unmodified lines5657585960616295 unmodified lines15815916016116216316416541 unmodified lines2072082092102112122132142154 unmodified lines22022122222322422522622722817 unmodified lines24624724824925025125211 unmodified lines{% set operandScalar = mmaScalar %}{% set accScalar = "f32" %}{% set tileMValue = tileM if tileM is defined else 32 %}{% set tileNValue = tileN if tileN is defined else 64 %}{% set tileKValue = tileK if tileK is defined else 32 %}38 unmodified linesreturn 1.0 / (1.0 + exp(-v));{% endif %}{% if actMode == "Tanh" %}return tanh(v);{% endif %}{% if actMode == "HardSigmoid" %}return clamp(f32({{ actA }}) * v + f32({{ actB }}), 0.0, 1.0);95 unmodified linesfn storeOutput(offset: u32{% if needsColBase %}, col_base: u32{% endif %}, row: u32, col: u32, src_slot: u32, row_limit: i32) {if (row_limit > 0 && row < u32(row_limit)) {let col2: u32 = col + 1u;y[offset + row * OUT_F + col] = {{ yScalar }}({{ epiOpen }}scratch[src_slot][row * 8u + col]{{ BIAS_1 }}{{ epiClose }});y[offset + row * OUT_F + col2] = {{ yScalar }}({{ epiOpen }}scratch[src_slot][row * 8u + col2]{{ BIAS_2 }}{{ epiClose }});}}41 unmodified lines{% endif %}{% for m in range(dynamicATiles) %}{% if aTransposed %}var matA{{ m }}: subgroup_matrix_left<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_left<{{ operandScalar }}, 8, 8>>(&tile_A, matrix_a_offset + {{ m * 8 }}u, true, TILE_ROWS);{% else %}var matA{{ m }}: subgroup_matrix_left<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_left<{{ operandScalar }}, 8, 8>>(&tile_A, matrix_a_offset{% if m > 0 %} + {{ m * 8 }}u * TILE_K{% endif %}, false, TILE_K);{% endif %}{% endfor %}4 unmodified lines{% endif %}{% for n in range(bTilesPerSubgroup) %}{% if bTransposed %}var matB{{ n }}: subgroup_matrix_right<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_right<{{ operandScalar }}, 8, 8>>(&tile_B, matrix_b_offset + {{ n * 8 }}u, false, TILE_COLS);{% else %}var matB{{ n }}: subgroup_matrix_right<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_right<{{ operandScalar }}, 8, 8>>(&tile_B, matrix_b_offset + {{ n * 8 }}u * TILE_K, true, TILE_K);{% endif %}{% endfor %}17 unmodified lineslet bank: u32 = subtile_id * {{ aTilesPerSubgroup * bTilesPerSubgroup }}u;{% for m in range(aTilesPerSubgroup) %}{% for n in range(bTilesPerSubgroup) %}subgroupMatrixStore(&scratch[bank + {{ m * bTilesPerSubgroup + n }}u], 0u, matC{{ m }}{{ n }}, false, 8u);{% endfor %}{% endfor %}workgroupBarrier();11 unmodified lines121314151617181938 unmodified lines585960616263646566676895 unmodified lines16416516616716816917017141 unmodified lines2132142152162172182192202214 unmodified lines22622722822923023123223323417 unmodified lines25225325425525625725811 unmodified lines{% set operandScalar = mmaScalar %}{% set accScalar = "f32" %}{% set OUT = outputBuffer if outputBuffer is defined else "y" %}{% set OUT_SCALAR = outScalar if outScalar is defined else yScalar %}{% set tileMValue = tileM if tileM is defined else 32 %}{% set tileNValue = tileN if tileN is defined else 64 %}{% set tileKValue = tileK if tileK is defined else 32 %}38 unmodified linesreturn 1.0 / (1.0 + exp(-v));{% endif %}{% if actMode == "Tanh" %}// Clamp first: the hardware tanh evaluates (e^2v - 1)/(e^2v + 1), which is// Inf/Inf = NaN once e^2v overflows (v > ~44). A GEMM accumulator reaches that// easily because it grows with K. tanh is already +/-1 to full f32 precision by// |v| ~ 9, so the clamp changes no representable result.return tanh(clamp(v, -10.0, 10.0));{% endif %}{% if actMode == "HardSigmoid" %}return clamp(f32({{ actA }}) * v + f32({{ actB }}), 0.0, 1.0);95 unmodified linesfn storeOutput(offset: u32{% if needsColBase %}, col_base: u32{% endif %}, row: u32, col: u32, src_slot: u32, row_limit: i32) {if (row_limit > 0 && row < u32(row_limit)) {let col2: u32 = col + 1u;{{ OUT }}[offset + row * OUT_F + col] = {{ OUT_SCALAR }}({{ epiOpen }}scratch[src_slot][row * 8u + col]{{ BIAS_1 }}{{ epiClose }});{{ OUT }}[offset + row * OUT_F + col2] = {{ OUT_SCALAR }}({{ epiOpen }}scratch[src_slot][row * 8u + col2]{{ BIAS_2 }}{{ epiClose }});}}41 unmodified lines{% endif %}{% for m in range(dynamicATiles) %}{% if aTransposed %}var matA{{ m }}: subgroup_matrix_left<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_left<{{ operandScalar }}, 8, 8>, col_major>(&tile_A, matrix_a_offset + {{ m * 8 }}u, TILE_ROWS);{% else %}var matA{{ m }}: subgroup_matrix_left<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_left<{{ operandScalar }}, 8, 8>, row_major>(&tile_A, matrix_a_offset{% if m > 0 %} + {{ m * 8 }}u * TILE_K{% endif %}, TILE_K);{% endif %}{% endfor %}4 unmodified lines{% endif %}{% for n in range(bTilesPerSubgroup) %}{% if bTransposed %}var matB{{ n }}: subgroup_matrix_right<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_right<{{ operandScalar }}, 8, 8>, row_major>(&tile_B, matrix_b_offset + {{ n * 8 }}u, TILE_COLS);{% else %}var matB{{ n }}: subgroup_matrix_right<{{ operandScalar }}, 8, 8> = subgroupMatrixLoad<subgroup_matrix_right<{{ operandScalar }}, 8, 8>, col_major>(&tile_B, matrix_b_offset + {{ n * 8 }}u * TILE_K, TILE_K);{% endif %}{% endfor %}17 unmodified lineslet bank: u32 = subtile_id * {{ aTilesPerSubgroup * bTilesPerSubgroup }}u;{% for m in range(aTilesPerSubgroup) %}{% for n in range(bTilesPerSubgroup) %}subgroupMatrixStore<row_major>(&scratch[bank + {{ m * bTilesPerSubgroup + n }}u], 0u, matC{{ m }}{{ n }}, 8u);{% endfor %}{% endfor %}workgroupBarrier();
1234561 unmodified line8910111213141516171819{"name": "com.microsoft.FusedGemm","id": "_com_microsoft_fusedgemm_webgpu_afa4467","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },1 unmodified line"algorithm": "sha256","files": {"bench.json": "5+Pgon1ED+99xPL6smxxz2G47C5gDnfB0kJ+Zj2wZLc=","fused-gemm.wgsl.jinja": "IkB53JqVNn9Xezw0YcKYDvm9IwDvoZNnSeA/UY4Eci4=","gemm-subgroup-matrix.wgsl.jinja": "gk0C1ZhDuTerG8rDtHYjQp74zieMlGP6QeFm0XqRZSw=","manifest.json": "s7cSq5so+VQS0XTbiHalmSHGnQQA2ylTu524o3V815U=","test.json": "xyQ7rg3TZtQ7zZA5W25GP1jcfMvCLIWiBlk6ASHNmi0="}},"provenance": { "kernel": { "sha": "2e7068faf55e7f43df740015f6d1ee49391a41c5", "dirty": false } },"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/com.microsoft.FusedGemm" }}1234561 unmodified line8910111213141516171819{"name": "com.microsoft.FusedGemm","id": "_com_microsoft_fusedgemm_webgpu_61fbd6b","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },1 unmodified line"algorithm": "sha256","files": {"bench.json": "5+Pgon1ED+99xPL6smxxz2G47C5gDnfB0kJ+Zj2wZLc=","fused-gemm.wgsl.jinja": "XL5rMA9oUlUJZCMHq2PZAzmORxFZoz/xa5Mo05/aK3k=","gemm-subgroup-matrix.wgsl.jinja": "PF4rqax3Fvj0sfPRjj+0BeuUkfoJVM2Bt6r7yz4Q2y0=","manifest.json": "s7cSq5so+VQS0XTbiHalmSHGnQQA2ylTu524o3V815U=","test.json": "LRhFk3xI+8tnvhAwEvFnept0OjRWCvXhjpjQ31ZIK0E="}},"provenance": { "kernel": { "sha": "c928d21e6cc1310861cba3bafb75f5f679ecf5f3", "dirty": false } },"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/com.microsoft.FusedGemm" }}
522 unmodified lines523524525526527528522 unmodified lines},"outputs": { "Y": { "dtype": "float32", "shape": [64, 128], "tolerance": 0.00002, "relTolerance": 0.0002 } }},{"name": "sgmat_transa_rowbias_tanh","provenance": {522 unmodified lines523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578522 unmodified lines},"outputs": { "Y": { "dtype": "float32", "shape": [64, 128], "tolerance": 0.00002, "relTolerance": 0.0002 } }},{"name": "notrans_rowbias_tanh_saturating_preactivation","provenance": {"notes": "Saturating pre-activations: the row bias is large enough that most |alpha*A*B + beta*C| land past 44, where the hardware tanh's internal e^2v overflows and the quotient becomes Inf/Inf = NaN. The bias carries the magnitude rather than the operands so the accumulator stays small and well conditioned — large operands make the near-cancelling dot products disagree between accumulation orders, which is a property of the fixture rather than of the activation. Unaligned for the subgroup-matrix gate, so this covers the tiled store path."},"attrs": { "activation": "Tanh" },"inputs": {"A": {"dtype": "float32","shape": [48, 32],"data": { "kind": "fillFloat32", "scale": 0.8, "sinStep": 0.15, "cosStep": 0.27 }},"B": {"dtype": "float32","shape": [32, 24],"data": { "kind": "fillFloat32", "scale": 0.5, "sinStep": 0.19, "cosStep": 0.17 }},"C": {"dtype": "float32","shape": [24],"data": { "kind": "fillFloat32", "scale": 60.0, "sinStep": 0.11, "cosStep": 0.31 }}},"outputs": { "Y": { "dtype": "float32", "shape": [48, 24], "tolerance": 0.00002, "relTolerance": 0.0002 } }},{"name": "sgmat_notrans_rowbias_tanh_saturating_preactivation","provenance": {"notes": "The aligned twin of the saturating fixture above (M >= 32, K % 32 == 0, N % 64 == 0), so the subgroup-matrix route evaluates the same overflowing pre-activations through its own store sites."},"attrs": { "activation": "Tanh" },"inputs": {"A": {"dtype": "float32","shape": [64, 64],"data": { "kind": "fillFloat32", "scale": 0.8, "sinStep": 0.15, "cosStep": 0.27 }},"B": {"dtype": "float32","shape": [64, 128],"data": { "kind": "fillFloat32", "scale": 0.5, "sinStep": 0.19, "cosStep": 0.17 }},"C": {"dtype": "float32","shape": [128],"data": { "kind": "fillFloat32", "scale": 60.0, "sinStep": 0.11, "cosStep": 0.31 }}},"outputs": { "Y": { "dtype": "float32", "shape": [64, 128], "tolerance": 0.00002, "relTolerance": 0.0002 } }},{"name": "sgmat_transa_rowbias_tanh","provenance": {
build/webgpu/fused-gemm.wgsl.jinja+5-1
build/webgpu/gemm-subgroup-matrix.wgsl.jinja+14-8
build/webgpu/metadata.json+5-5
build/webgpu/test.json+50