Files
FPGA-Neural/sim/neuron_parallel_bug002_n_inputs_zero_tb.v
T
micheleandClaude Sonnet 5 07a48e401f fix: close 7 zero-value/mid-run guard gaps found in re-certification campaign
Fixes all 7 bugs found in the FPGA-Neural re-certification campaign
(docs/validation/bugs.md, CERTIFICATION.md), per campaign policy that
fixes land as a commit separate from the analysis work (commits
313a199..77e74db):

- BUG-005 (CRITICAL): layer_sequencer.v -- RUN_NETWORK(num_layers=0)
  ran through 256 fabricated layers reading arbitrary PSRAM data as
  descriptors. Now an immediate no-op.
- BUG-007 (CRITICAL): spi_engine.v -- SET_NET_TYPE received mid-run
  remapped the arbiter mux and hung the in-progress engine. Now
  rejected while graph_busy/seq_busy, verified not to partially apply.
- BUG-002 (MEDIA): neuron_parallel.v -- N_INPUTS=0 bypassed the
  elaboration-time guard, leaving x_bus/w_bus undriven. Guard extended
  to reject N_INPUTS==0.
- BUG-003 (MEDIA): neuron_parallel.v -- n_inputs_real=0 at runtime had
  inconsistent behavior across repeated runs. Now an explicit early-out
  via the existing "finishing" completion path.
- BUG-004 (BASSA): neuron_memory.v -- n_neurons_real=0 silently ignored
  the limit. Fixed at all three entry points into the vulnerable
  termination checks (STATE_READ_X, STATE_READ_W, and the X->W
  dispatch).
- BUG-006 (BASSA): graph_engine.v -- num_neurons_graph=0 relied on an
  incidental guard rather than a real one. Now an explicit no-op.
- BUG-001 (INFO): removed sim/top.v, confirmed dead code from the
  pre-INT8 Q8.8 era.

Every bug-reproduction testbench is rewritten from observe-only to
hard-assert the fixed behavior (sim/*_bug00[2-7]*_tb.v), verified
individually and via a full regression (44 testbenches, 43 PASS, 0
FAIL/ERROR, 1 benchmark by design). Re-verified on the real toolchain
(Yosys synth_ecp5 + nextpnr-ecp5): 0 constraint errors, Fmax 68.65 MHz
(was 67.91 MHz, within known placement noise), critical path
structurally unchanged (neuron_parallel/mac8 accumulator carry chain).

Updates docs/validation/bugs.md and CERTIFICATION.md to reflect the
resolved state, and docs/FPGA-NeuralNetwork-Engine.md + the LaTeX
datasheet (IT/EN) with inline notes on each fixed edge case, closing
the datasheet/RTL gap flagged in C.13 of the original certification.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013xXuuRUWZScuo1DeYJxs3v
2026-09-04 20:29:05 +02:00

51 lines
1.9 KiB
Verilog

`timescale 1ns/1ps
// ================================================================
// BUG-002 REGRESSION TEST (certification campaign, aspect C.1,
// docs/validation/bugs.md) -- N_INPUTS=0, now FIXED.
//
// Originally: rtl/neuron_parallel.v:71's guard was a single condition
// (`N_INPUTS % PARALLEL != 0`) that did NOT fire for N_INPUTS=0 (since
// `0 % PARALLEL == 0` for any PARALLEL != 0), yet GROUPS =
// N_INPUTS/PARALLEL = 0 -- the exact degenerate condition the guard's
// own header comment says causes a hang. Confirmed hang on both
// verification planes at the time (200-cycle simulation watchdog,
// `x_bus`/`w_bus` left undriven under real `yosys synth_ecp5`).
//
// Fix (rtl/neuron_parallel.v): the elaboration-time guard now also
// rejects N_INPUTS==0 explicitly:
// if (N_INPUTS == 0 || N_INPUTS % PARALLEL != 0) ...
// This file must now FAIL TO COMPILE/ELABORATE -- same pattern as the
// two deliberate negative tests, neuron_parallel_guard_negative_*_tb.v
// -- that failure IS the test, proving N_INPUTS=0 is rejected before
// it can ever reach runtime and hang.
//
// Verify with:
// iverilog -g2012 -o /tmp/out rtl/*.v \
// sim/neuron_parallel_bug002_n_inputs_zero_tb.v
//
// Expected: nonzero exit status and
// "error: Unknown module type:
// neuron_parallel_requires_N_INPUTS_multiple_of_PARALLEL"
//
// If BUG-002's guard is ever weakened or removed, this file will start
// compiling again -- do not "fix" that by deleting this test; restore
// the guard instead.
// ================================================================
module tb;
localparam DATA_WIDTH = 8;
localparam PARALLEL = 2;
localparam ACC_WIDTH = 32;
neuron_parallel #(
.DATA_WIDTH(DATA_WIDTH), .N_INPUTS(0), .PARALLEL(PARALLEL), .ACC_WIDTH(ACC_WIDTH)
) u_invalid (
.clk(1'b0), .rst(1'b0), .start(1'b0),
.x_bus(), .w_bus(), .bias(8'sd0),
.y(), .busy(), .done()
);
endmodule