Files
FPGA-Neural/sim/neuron_parallel.vcd
T
micheleandClaude Sonnet 5 1a6f0ba2ef fix: guard neuron_parallel against invalid N_INPUTS/PARALLEL combos
Both Phase 2 findings (docs/FPGA-NeuralNetwork-Engine.md) shared one
root cause: GROUPS = N_INPUTS / PARALLEL is integer division. When
N_INPUTS is not an exact multiple of PARALLEL, the remainder inputs
were silently dropped from the accumulation (wrong result, no
error); when PARALLEL > N_INPUTS, GROUPS = 0 and the controller's
terminal condition was never met, hanging the neuron forever.

Added a single elaboration-time guard to rtl/neuron_parallel.v: a
`generate` block instantiates a deliberately undefined module when
N_INPUTS % PARALLEL != 0, forcing a hard failure in both simulation
and synthesis instead of a silent wrong answer or a deadlock. Valid
configurations are unaffected (the branch is never elaborated). The
validated datapath (mac8/mac_unit/accumulation/ReLU/saturation) is
untouched -- this is authorized as a scoped exception to the
"core is fixed, do not touch" project policy, for this guard only.

- sim/neuron_parallel_guard_negative_nonmultiple_tb.v and
  sim/neuron_parallel_guard_negative_degenerate_tb.v: negative tests
  that must fail to elaborate; verified both fail with the expected
  "Unknown module type" error.
- sim/parameter_sweep_tb.v: rewritten to valid-configs-only (the
  three configs that used to demonstrate truncation/hang no longer
  compile, by design); added PARALLEL=2 and PARALLEL=4 configs,
  the two best-performing values from
  docs/FPGA-Neural-Datapatch-Benchmark.md.
- Full regression re-run after the RTL change: all existing
  testbenches still pass unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WQV3vS9TXaGDJ5cRfnfidt
2026-09-02 14:41:49 +02:00

881 lines
16 KiB
Plaintext

$date
Wed Sep 2 14:41:17 2026
$end
$version
Icarus Verilog
$end
$timescale
1ps
$end
$scope module tb $end
$var wire 8 ! y [7:0] $end
$var wire 1 " done $end
$var wire 1 # busy $end
$var parameter 32 $ ACC_WIDTH $end
$var parameter 32 % DATA_WIDTH $end
$var parameter 32 & N_INPUTS $end
$var parameter 32 ' PARALLEL $end
$var reg 8 ( bias [7:0] $end
$var reg 1 ) clk $end
$var reg 1 * rst $end
$var reg 1 + start $end
$var reg 256 , w_bus [255:0] $end
$var reg 256 - x_bus [255:0] $end
$var integer 32 . errors [31:0] $end
$var integer 32 / i [31:0] $end
$scope module dut $end
$var wire 8 0 bias [7:0] $end
$var wire 1 ) clk $end
$var wire 1 * rst $end
$var wire 1 + start $end
$var wire 256 1 w_bus [255:0] $end
$var wire 256 2 x_bus [255:0] $end
$var wire 64 3 x_group [63:0] $end
$var wire 64 4 w_group [63:0] $end
$var wire 32 5 final_acc [31:0] $end
$var wire 32 6 bias_ext [31:0] $end
$var wire 32 7 acc_next [31:0] $end
$var parameter 32 8 ACC_WIDTH $end
$var parameter 32 9 DATA_WIDTH $end
$var parameter 32 : GROUPS $end
$var parameter 32 ; GROUP_INDEX_WIDTH $end
$var parameter 32 < N_INPUTS $end
$var parameter 32 = PARALLEL $end
$var reg 32 > acc [31:0] $end
$var reg 1 # busy $end
$var reg 1 " done $end
$var reg 2 ? group_index [1:0] $end
$var reg 8 @ y [7:0] $end
$scope module u_mac8 $end
$var wire 32 A acc_in [31:0] $end
$var wire 64 B w_bus [63:0] $end
$var wire 64 C x_bus [63:0] $end
$var wire 32 D acc_out [31:0] $end
$var parameter 32 E ACC_WIDTH $end
$var parameter 32 F DATA_WIDTH $end
$var parameter 32 G PARALLEL $end
$var parameter 32 H TREE_LEVELS $end
$scope begin GEN_MAC[0] $end
$var parameter 2 I i $end
$scope module u_mac $end
$var wire 32 J acc_in [31:0] $end
$var wire 8 K w [7:0] $end
$var wire 8 L x [7:0] $end
$var wire 32 M product_ext [31:0] $end
$var wire 16 N product [15:0] $end
$var wire 32 O acc_out [31:0] $end
$var parameter 32 P ACC_WIDTH $end
$var parameter 32 Q DATA_WIDTH $end
$var parameter 64 R PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[1] $end
$var parameter 2 S i $end
$scope module u_mac $end
$var wire 32 T acc_in [31:0] $end
$var wire 8 U w [7:0] $end
$var wire 8 V x [7:0] $end
$var wire 32 W product_ext [31:0] $end
$var wire 16 X product [15:0] $end
$var wire 32 Y acc_out [31:0] $end
$var parameter 32 Z ACC_WIDTH $end
$var parameter 32 [ DATA_WIDTH $end
$var parameter 64 \ PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[2] $end
$var parameter 3 ] i $end
$scope module u_mac $end
$var wire 32 ^ acc_in [31:0] $end
$var wire 8 _ w [7:0] $end
$var wire 8 ` x [7:0] $end
$var wire 32 a product_ext [31:0] $end
$var wire 16 b product [15:0] $end
$var wire 32 c acc_out [31:0] $end
$var parameter 32 d ACC_WIDTH $end
$var parameter 32 e DATA_WIDTH $end
$var parameter 64 f PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[3] $end
$var parameter 3 g i $end
$scope module u_mac $end
$var wire 32 h acc_in [31:0] $end
$var wire 8 i w [7:0] $end
$var wire 8 j x [7:0] $end
$var wire 32 k product_ext [31:0] $end
$var wire 16 l product [15:0] $end
$var wire 32 m acc_out [31:0] $end
$var parameter 32 n ACC_WIDTH $end
$var parameter 32 o DATA_WIDTH $end
$var parameter 64 p PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[4] $end
$var parameter 4 q i $end
$scope module u_mac $end
$var wire 32 r acc_in [31:0] $end
$var wire 8 s w [7:0] $end
$var wire 8 t x [7:0] $end
$var wire 32 u product_ext [31:0] $end
$var wire 16 v product [15:0] $end
$var wire 32 w acc_out [31:0] $end
$var parameter 32 x ACC_WIDTH $end
$var parameter 32 y DATA_WIDTH $end
$var parameter 64 z PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[5] $end
$var parameter 4 { i $end
$scope module u_mac $end
$var wire 32 | acc_in [31:0] $end
$var wire 8 } w [7:0] $end
$var wire 8 ~ x [7:0] $end
$var wire 32 !" product_ext [31:0] $end
$var wire 16 "" product [15:0] $end
$var wire 32 #" acc_out [31:0] $end
$var parameter 32 $" ACC_WIDTH $end
$var parameter 32 %" DATA_WIDTH $end
$var parameter 64 &" PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[6] $end
$var parameter 4 '" i $end
$scope module u_mac $end
$var wire 32 (" acc_in [31:0] $end
$var wire 8 )" w [7:0] $end
$var wire 8 *" x [7:0] $end
$var wire 32 +" product_ext [31:0] $end
$var wire 16 ," product [15:0] $end
$var wire 32 -" acc_out [31:0] $end
$var parameter 32 ." ACC_WIDTH $end
$var parameter 32 /" DATA_WIDTH $end
$var parameter 64 0" PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_MAC[7] $end
$var parameter 4 1" i $end
$scope module u_mac $end
$var wire 32 2" acc_in [31:0] $end
$var wire 8 3" w [7:0] $end
$var wire 8 4" x [7:0] $end
$var wire 32 5" product_ext [31:0] $end
$var wire 16 6" product [15:0] $end
$var wire 32 7" acc_out [31:0] $end
$var parameter 32 8" ACC_WIDTH $end
$var parameter 32 9" DATA_WIDTH $end
$var parameter 64 :" PROD_WIDTH $end
$upscope $end
$upscope $end
$scope begin GEN_TREE_INPUT[0] $end
$var parameter 2 ;" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[1] $end
$var parameter 2 <" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[2] $end
$var parameter 3 =" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[3] $end
$var parameter 3 >" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[4] $end
$var parameter 4 ?" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[5] $end
$var parameter 4 @" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[6] $end
$var parameter 4 A" i $end
$upscope $end
$scope begin GEN_TREE_INPUT[7] $end
$var parameter 4 B" i $end
$upscope $end
$scope begin GEN_TREE_LEVEL[0] $end
$var parameter 2 C" level $end
$scope begin GEN_TREE_NODE[0] $end
$var parameter 2 D" node $end
$upscope $end
$scope begin GEN_TREE_NODE[1] $end
$var parameter 2 E" node $end
$upscope $end
$scope begin GEN_TREE_NODE[2] $end
$var parameter 3 F" node $end
$upscope $end
$scope begin GEN_TREE_NODE[3] $end
$var parameter 3 G" node $end
$upscope $end
$upscope $end
$scope begin GEN_TREE_LEVEL[1] $end
$var parameter 2 H" level $end
$scope begin GEN_TREE_NODE[0] $end
$var parameter 2 I" node $end
$upscope $end
$scope begin GEN_TREE_NODE[1] $end
$var parameter 2 J" node $end
$upscope $end
$upscope $end
$scope begin GEN_TREE_LEVEL[2] $end
$var parameter 3 K" level $end
$scope begin GEN_TREE_NODE[0] $end
$var parameter 2 L" node $end
$upscope $end
$upscope $end
$upscope $end
$upscope $end
$scope task run_neuron $end
$upscope $end
$scope task test_1 $end
$upscope $end
$scope task test_2 $end
$upscope $end
$scope task test_3 $end
$upscope $end
$scope task test_4 $end
$upscope $end
$upscope $end
$enddefinitions $end
$comment Show the parameter values. $end
$dumpall
b0 L"
b10 K"
b1 J"
b0 I"
b1 H"
b11 G"
b10 F"
b1 E"
b0 D"
b0 C"
b111 B"
b110 A"
b101 @"
b100 ?"
b11 >"
b10 ="
b1 <"
b0 ;"
b10000 :"
b1000 9"
b100000 8"
b111 1"
b10000 0"
b1000 /"
b100000 ."
b110 '"
b10000 &"
b1000 %"
b100000 $"
b101 {
b10000 z
b1000 y
b100000 x
b100 q
b10000 p
b1000 o
b100000 n
b11 g
b10000 f
b1000 e
b100000 d
b10 ]
b10000 \
b1000 [
b100000 Z
b1 S
b10000 R
b1000 Q
b100000 P
b0 I
b11 H
b1000 G
b1000 F
b100000 E
b1000 =
b100000 <
b10 ;
b100 :
b1000 9
b100000 8
b1000 '
b100000 &
b1000 %
b100000 $
$end
#0
$dumpvars
bx 7"
bx 6"
bx 5"
bx 4"
bx 3"
b0 2"
bx -"
bx ,"
bx +"
bx *"
bx )"
b0 ("
bx #"
bx ""
bx !"
bx ~
bx }
b0 |
bx w
bx v
bx u
bx t
bx s
b0 r
bx m
bx l
bx k
bx j
bx i
b0 h
bx c
bx b
bx a
bx `
bx _
b0 ^
bx Y
bx X
bx W
bx V
bx U
b0 T
bx O
bx N
bx M
bx L
bx K
b0 J
bx D
bx C
bx B
bx A
bx @
bx ?
bx >
bx 7
b0 6
bx 5
bx 4
bx 3
b0 2
b0 1
b0 0
bx /
b0 .
b0 -
b0 ,
0+
1*
0)
b0 (
x#
x"
bx !
$end
#5000
b0 5
b0 7
b0 D
b0 O
b0 Y
b0 c
b0 m
b0 w
b0 #"
b0 -"
b0 7"
b0 M
b0 W
b0 a
b0 k
b0 u
b0 !"
b0 +"
b0 5"
b0 N
b0 L
b0 X
b0 V
b0 b
b0 `
b0 l
b0 j
b0 v
b0 t
b0 ""
b0 ~
b0 ,"
b0 *"
b0 6"
b0 4"
b0 K
b0 U
b0 _
b0 i
b0 s
b0 }
b0 )"
b0 3"
b0 3
b0 C
b0 4
b0 B
0"
0#
b0 !
b0 @
b0 >
b0 A
b0 ?
1)
#10000
0)
#15000
b10 c
b10 a
b11111111111111111111111111111100 Y
b11111111111111111111111111111100 W
b100 7
b100 D
b110 O
b110 M
b10 b
b1 _
b10 `
b1111111111111100 X
b11111111 U
b100 V
b110 N
b10 K
b11 L
b101 5
b1 6
b11111111100000010 4
b11111111100000010 B
b11111111100000010 ,
b11111111100000010 1
b100000010000000011 3
b100000010000000011 C
b100000010000000011 -
b100000010000000011 2
b1 (
b1 0
0*
1)
#20000
0)
#25000
1#
1+
1)
#30000
0)
#35000
b0 O
b0 M
b0 Y
b0 W
b0 c
b0 a
b0 L
b0 V
b0 `
b0 N
b0 K
b0 X
b0 U
b0 b
b0 _
b0 3
b0 C
b0 4
b0 B
b1 ?
b101 5
b100 7
b100 D
b100 >
b100 A
0+
1)
#40000
0)
#45000
b10 ?
1)
#50000
0)
#55000
b11 ?
1)
#60000
0)
#65000
1"
0#
b101 !
b101 @
b110 5
b101 7
b101 D
b101 >
b101 A
1)
#70000
0)
#75000
0"
b11111111111111111111111111111111 7"
b11111111111111111111111111111111 5"
b11111111111111111111111111111111 -"
b11111111111111111111111111111111 +"
b11111111111111111111111111111111 #"
b11111111111111111111111111111111 !"
b11111111111111111111111111111111 w
b11111111111111111111111111111111 u
b11111111111111111111111111111111 m
b11111111111111111111111111111111 k
b11111111111111111111111111111111 c
b11111111111111111111111111111111 a
b11111111111111111111111111111111 Y
b11111111111111111111111111111111 W
b11111111111111111111111111111101 7
b11111111111111111111111111111101 D
b11111111111111111111111111111111 O
b11111111111111111111111111111111 M
b1111111111111111 6"
b11111111 3"
b1 4"
b1111111111111111 ,"
b11111111 )"
b1 *"
b1111111111111111 ""
b11111111 }
b1 ~
b1111111111111111 v
b11111111 s
b1 t
b1111111111111111 l
b11111111 i
b1 j
b1111111111111111 b
b11111111 _
b1 `
b1111111111111111 X
b11111111 U
b1 V
b1111111111111111 N
b11111111 K
b1 L
b11111111111111111111111111111101 5
b0 6
b1111111111111111111111111111111111111111111111111111111111111111 4
b1111111111111111111111111111111111111111111111111111111111111111 B
b100000001000000010000000100000001000000010000000100000001 3
b100000001000000010000000100000001000000010000000100000001 C
b100000 /
b0 (
b0 0
b1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ,
b1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 1
b100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001 -
b100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001 2
1)
#80000
0)
#85000
1#
b11111111111111111111111111111000 5
b11111111111111111111111111111000 7
b11111111111111111111111111111000 D
b0 >
b0 A
b0 ?
1+
1)
#90000
0)
#95000
b1 ?
b11111111111111111111111111110000 5
b11111111111111111111111111110000 7
b11111111111111111111111111110000 D
b11111111111111111111111111111000 >
b11111111111111111111111111111000 A
0+
1)
#100000
0)
#105000
b10 ?
b11111111111111111111111111101000 5
b11111111111111111111111111101000 7
b11111111111111111111111111101000 D
b11111111111111111111111111110000 >
b11111111111111111111111111110000 A
1)
#110000
0)
#115000
b11 ?
b11111111111111111111111111100000 5
b11111111111111111111111111100000 7
b11111111111111111111111111100000 D
b11111111111111111111111111101000 >
b11111111111111111111111111101000 A
1)
#120000
0)
#125000
1"
0#
b0 !
b0 @
b11111111111111111111111111011000 5
b11111111111111111111111111011000 7
b11111111111111111111111111011000 D
b11111111111111111111111111100000 >
b11111111111111111111111111100000 A
1)
#130000
0)
#135000
0"
b11001000 O
b11001000 M
b11001000 Y
b11001000 W
b11001000 c
b11001000 a
b11001000 m
b11001000 k
b11001000 w
b11001000 u
b11001000 #"
b11001000 !"
b11001000 -"
b11001000 +"
b11000100000 5
b11000100000 7
b11000100000 D
b11001000 7"
b11001000 5"
b10 K
b10 U
b10 _
b10 i
b10 s
b10 }
b10 )"
b10 3"
b11001000 N
b1100100 L
b11001000 X
b1100100 V
b11001000 b
b1100100 `
b11001000 l
b1100100 j
b11001000 v
b1100100 t
b11001000 ""
b1100100 ~
b11001000 ,"
b1100100 *"
b11001000 6"
b1100100 4"
b100000 /
b1000000010000000100000001000000010000000100000001000000010 4
b1000000010000000100000001000000010000000100000001000000010 B
b1000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010 ,
b1000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010 1
b110010001100100011001000110010001100100011001000110010001100100 3
b110010001100100011001000110010001100100011001000110010001100100 C
b110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100 -
b110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100011001000110010001100100 2
1)
#140000
0)
#145000
1#
b11001000000 5
b11001000000 7
b11001000000 D
b0 >
b0 A
b0 ?
1+
1)
#150000
0)
#155000
b1 ?
b110010000000 5
b110010000000 7
b110010000000 D
b11001000000 >
b11001000000 A
0+
1)
#160000
0)
#165000
b10 ?
b1001011000000 5
b1001011000000 7
b1001011000000 D
b110010000000 >
b110010000000 A
1)
#170000
0)
#175000
b11 ?
b1100100000000 5
b1100100000000 7
b1100100000000 D
b1001011000000 >
b1001011000000 A
1)
#180000
0)
#185000
1"
0#
b1111111 !
b1111111 @
b1111101000000 5
b1111101000000 7
b1111101000000 D
b1100100000000 >
b1100100000000 A
1)
#190000
0)
#195000
0"
b10 O
b10 M
b11111111111111111111111111111111 Y
b11111111111111111111111111111111 W
b10 c
b10 a
b11111111111111111111111111111111 m
b11111111111111111111111111111111 k
b10 w
b10 u
b11111111111111111111111111111111 #"
b11111111111111111111111111111111 !"
b10 -"
b10 +"
b1100100000100 7
b1100100000100 D
b11111111111111111111111111111111 7"
b11111111111111111111111111111111 5"
b1100011110100 5
b11111111111111111111111111110000 6
b1 K
b1 U
b1 _
b1 i
b1 s
b1 }
b1 )"
b1 3"
b10 N
b10 L
b1111111111111111 X
b11111111 V
b10 b
b10 `
b1111111111111111 l
b11111111 j
b10 v
b10 t
b1111111111111111 ""
b11111111 ~
b10 ,"
b10 *"
b1111111111111111 6"
b11111111 4"
b100000 /
b11110000 (
b11110000 0
b100000001000000010000000100000001000000010000000100000001 4
b100000001000000010000000100000001000000010000000100000001 B
b100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001 ,
b100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001 1
b1111111100000010111111110000001011111111000000101111111100000010 3
b1111111100000010111111110000001011111111000000101111111100000010 C
b1111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010 -
b1111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010111111110000001011111111000000101111111100000010 2
1)
#200000
0)
#205000
1#
b11111111111111111111111111110100 5
b100 7
b100 D
b0 >
b0 A
b0 ?
1+
1)
#210000
0)
#215000
b1 ?
b11111111111111111111111111111000 5
b1000 7
b1000 D
b100 >
b100 A
0+
1)
#220000
0)
#225000
b10 ?
b11111111111111111111111111111100 5
b1100 7
b1100 D
b1000 >
b1000 A
1)
#230000
0)
#235000
b11 ?
b0 5
b10000 7
b10000 D
b1100 >
b1100 A
1)
#240000
0)
#245000
1"
0#
b0 !
b0 @
b11111111111111111111111111110100 5
b100 7
b100 D
b0 >
b0 A
1)
#250000
0)
#255000
0"
1)