fix: rewrite layer_tb and neuron_parallel_tb for current INT8 architecture

Both testbenches instantiated their DUTs with a FRAC_BITS parameter and
Q8.8 fixed-point 16-bit values, which no longer exist in rtl/neuron_parallel.v
(now plain INT8, DATA_WIDTH=8, hardcoded +127 saturation, ReLU-only clamp).
This made both tests fail elaboration ("parameter FRAC_BITS not found").

Rewrote both benches with integer INT8 stimuli and expectations matching
the current core (no RTL changes): neuron_parallel_tb covers a mixed
vector, ReLU, positive saturation, and mixed values with a boundary
negative bias; layer_tb covers 8 neurons exercising scale, ReLU,
saturation, bias-only, and a sparse weight pattern across groups.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WQV3vS9TXaGDJ5cRfnfidt
This commit is contained in:
2026-09-02 14:16:34 +02:00
co-authored by Claude Sonnet 5
parent 896f56c675
commit 4b5cd4e558
7 changed files with 17623 additions and 8338 deletions
+25
View File
@@ -22,3 +22,28 @@
- neuron_parallel_tb: FALLISCE in elaborazione — stesso errore, `parameter FRAC_BITS not found in tb.dut`, riferito a rtl/neuron_parallel.v. - neuron_parallel_tb: FALLISCE in elaborazione — stesso errore, `parameter FRAC_BITS not found in tb.dut`, riferito a rtl/neuron_parallel.v.
- NOTA: questi due fallimenti sono preesistenti e non toccano i file modificati in questa sessione (sim/neuron_memory_tb.v). Non risolti in questa sessione perché fuori scope dichiarato (debug neuron_memory); da segnalare all'utente. - NOTA: questi due fallimenti sono preesistenti e non toccano i file modificati in questa sessione (sim/neuron_memory_tb.v). Non risolti in questa sessione perché fuori scope dichiarato (debug neuron_memory); da segnalare all'utente.
- 2026-09-02T00:20 — [FASE 3] — CONCLUSIONE: il bug indirizzamento byte/word nei task preload_vector/preload_weights di sim/neuron_memory_tb.v era l'unico difetto riscontrato nel percorso neuron_memory; risulta già corretto nel working tree e validato con successo da tutti e 5 i test (incl. il nuovo test PATTERN aggiunto). Nessun bug residuo individuato in rtl/neuron_memory.v o rtl/int8_memory_access.v per il caso N_NEURONS=1. Procedo al commit del fix sul branch `fix/neuron-memory-debug`. - 2026-09-02T00:20 — [FASE 3] — CONCLUSIONE: il bug indirizzamento byte/word nei task preload_vector/preload_weights di sim/neuron_memory_tb.v era l'unico difetto riscontrato nel percorso neuron_memory; risulta già corretto nel working tree e validato con successo da tutti e 5 i test (incl. il nuovo test PATTERN aggiunto). Nessun bug residuo individuato in rtl/neuron_memory.v o rtl/int8_memory_access.v per il caso N_NEURONS=1. Procedo al commit del fix sul branch `fix/neuron-memory-debug`.
- 2026-09-02T00:21 — [FASE 4] — Committato (896f56c) il fix di sim/neuron_memory_tb.v + artefatti sim/neuron_memory_sim, sim/neuron_memory.vcd + WORKLOG.md sul branch fix/neuron-memory-debug. Ripristinati con `git checkout --` i .vcd di altri testbench (int8_memory_access, int8_psram_integration, memory_interface, parametric, psram_controller) rigenerati per errore durante la regressione, per non introdurre diff non pertinenti.
- 2026-09-02T00:25 — [FASE 5] — Contesto hardware fornito dall'utente durante la sessione (per riferimento futuro, non ancora usato in RTL/sim): FPGA target = Lattice ECP5 LFE5U-45F-8BG381C; PSRAM = ISSI IS66WVE4M16EBLL-70BLI; il controller esterno pilota il sistema FPGA+RAM via SPI, e accede alla RAM solo tramite la FPGA (mai in accesso diretto).
- 2026-09-02T00:26 — [FASE 6] — Richiesta utente: "sistema i due test e così chiudiamo" — riferito a sim/layer_tb.v e sim/neuron_parallel_tb.v, che fallivano in elaborazione con `parameter FRAC_BITS not found in tb.dut`.
- 2026-09-02T00:27 — [FASE 6] — Letto rtl/neuron_parallel.v per intero: DATA_WIDTH default 8, nessun parametro FRAC_BITS, ReLU (final_acc<=0 -> y=0) e saturazione positiva HARDCODED a `8'sd127` indipendentemente da DATA_WIDTH (nessuna saturazione negativa esplicita, solo ReLU). Confermato che il modulo non supporta più (e non ha mai realmente supportato in questa versione) il formato fixed-point Q8.8 a 16 bit assunto dai due testbench.
- 2026-09-02T00:28 — [FASE 6] — Letto rtl/layer.v per intero: parametrico, instanzia N_NEURONS x neuron_parallel con layout pesi neuron-major; nessun riferimento a FRAC_BITS.
- 2026-09-02T00:29 — [FASE 6] — Letto per intero sim/neuron_parallel_tb.v e sim/layer_tb.v (versioni obsolete, DATA_WIDTH=16, FRAC_BITS=8, valori Q8.8 via funzione q8_8(), saturazione attesa a ±32767): confermato che sono residui di una precedente architettura fixed-point a 16 bit, incompatibile con neuron_parallel.v attuale (core validato, da NON modificare).
- 2026-09-02T00:30 — [FASE 6] — Letto sim/parametric_tb.v (test già passante) come riferimento di stile/parametri corretti per l'architettura INT8 attuale (DATA_WIDTH=8, valori interi, saturazione a 127).
- 2026-09-02T00:35 — [FASE 6] — Riscritto interamente sim/neuron_parallel_tb.v: rimosso FRAC_BITS e funzione q8_8; parametri allineati ai default di rtl/neuron_parallel.v (DATA_WIDTH=8, N_INPUTS=32, PARALLEL=8, ACC_WIDTH=32); 4 test ridisegnati con valori interi INT8 mantenendo lo stesso intento dei test originali:
- TEST 1 DIVERSE VECTOR: x0=3,w0=2 / x1=4,w1=-1 / x2=2,w2=1 / bias=1 -> atteso 5.
- TEST 2 RELU: tutti i prodotti negativi (x=1,w=-1 su 32 input) -> atteso 0.
- TEST 3 POSITIVE SATURATION: x=100,w=2 su 32 input -> somma 6400, satura a 127.
- TEST 4 MIXED + NEGATIVE BIAS: 16 input pari (x=2,w=1) + 16 dispari (x=-1,w=1), bias=-16 -> somma esattamente 0 -> ReLU -> atteso 0.
- 2026-09-02T00:40 — [FASE 6] — Riscritto interamente sim/layer_tb.v: rimosso FRAC_BITS; parametri DATA_WIDTH=8, N_INPUTS=32, N_NEURONS=8, PARALLEL=8, ACC_WIDTH=32; input vettore tutti =1; 8 neuroni con scenari distinti (pattern ispirato a parametric_tb.v):
- N0 w=1,bias=0 -> 32
- N1 w=3,bias=0 -> 96
- N2 w=-1 -> ReLU -> 0
- N3 w=8 -> somma 256 -> satura 127
- N4 w=0,bias=+5 -> 5
- N5 w=0,bias=-5 -> ReLU -> 0
- N6 w=1,bias=-10 -> 32-10=22
- N7 primi 16 pesi=1 resto 0, bias=+5 -> 16+5=21 (verifica pattern di pesi sparso su più gruppi, PARALLEL=8 -> GROUPS=4)
- 2026-09-02T00:42 — [FASE 6] — Compilato ed eseguito `sim/neuron_parallel_tb.v`: `iverilog -g2012 -o <tmp> rtl/*.v sim/neuron_parallel_tb.v` + `vvp`. Risultato: TUTTI I 4 TEST PASSANO (TEST1=5, TEST2=0, TEST3=127, TEST4=0).
- 2026-09-02T00:43 — [FASE 6] — Compilato ed eseguito `sim/layer_tb.v`: `iverilog -g2012 -o <tmp> rtl/*.v sim/layer_tb.v` + `vvp`. Risultato: TUTTI GLI 8 NEURONI PASSANO (32,96,0,127,5,0,22,21), busy=0, done=1 a fine test.
- 2026-09-02T00:44 — [FASE 6] — Rigenerati gli artefatti tracciati in git `sim/neuron_sim` (da neuron_parallel_tb.v) e `sim/layer_sim` (da layer_tb.v) con i relativi `.vcd`, per coerenza con la convenzione del repo di committare i binari di simulazione insieme alle sorgenti.
- 2026-09-02T00:45 — [FASE 7] — Nessuna modifica a rtl/ in questa fase: root cause dei due fallimenti era esclusivamente nei testbench (riferimento a un parametro FRAC_BITS rimosso da tempo dall'RTL), non nel core di calcolo. Sessione di debug neuron_memory + fix dei due test residui considerata chiusa.
+3360 -3212
View File
File diff suppressed because one or more lines are too long
+6285 -3456
View File
File diff suppressed because it is too large Load Diff
+55 -60
View File
@@ -1,11 +1,12 @@
`timescale 1ns/1ps
module tb; module tb;
parameter DATA_WIDTH = 16; parameter DATA_WIDTH = 8;
parameter FRAC_BITS = 8; parameter N_INPUTS = 32;
parameter N_INPUTS = 64;
parameter N_NEURONS = 8; parameter N_NEURONS = 8;
parameter PARALLEL = 8; parameter PARALLEL = 8;
parameter ACC_WIDTH = 40; parameter ACC_WIDTH = 32;
reg clk; reg clk;
reg rst; reg rst;
@@ -26,12 +27,10 @@ module tb;
wire done; wire done;
integer i; integer i;
integer n;
integer errors; integer errors;
layer #( layer #(
.DATA_WIDTH(DATA_WIDTH), .DATA_WIDTH(DATA_WIDTH),
.FRAC_BITS(FRAC_BITS),
.N_INPUTS(N_INPUTS), .N_INPUTS(N_INPUTS),
.N_NEURONS(N_NEURONS), .N_NEURONS(N_NEURONS),
.PARALLEL(PARALLEL), .PARALLEL(PARALLEL),
@@ -53,13 +52,6 @@ module tb;
forever #5 clk = ~clk; forever #5 clk = ~clk;
end end
function signed [15:0] q8_8;
input real value;
begin
q8_8 = $rtoi(value * 256.0);
end
endfunction
task run_layer; task run_layer;
begin begin
@(posedge clk); @(posedge clk);
@@ -92,41 +84,41 @@ module tb;
/* /*
* Input vector: * Input vector:
* all inputs = 1.0 * all inputs = 1
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
x_bus[i*DATA_WIDTH +: DATA_WIDTH] = q8_8(1.0); x_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd1;
/* /*
* Neuron 0: * Neuron 0:
* weights = 1.0 * weights = 1
* bias = 0 * bias = 0
* result = 64 * result = 32
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
weights_bus[ weights_bus[
0*N_INPUTS*DATA_WIDTH + 0*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(1.0); ] = 8'sd1;
bias_bus[0*DATA_WIDTH +: DATA_WIDTH] = q8_8(0.0); bias_bus[0*DATA_WIDTH +: DATA_WIDTH] = 8'sd0;
/* /*
* Neuron 1: * Neuron 1:
* weights = 0.5 * weights = 3
* result = 32 * result = 96
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
weights_bus[ weights_bus[
1*N_INPUTS*DATA_WIDTH + 1*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(0.5); ] = 8'sd3;
/* /*
* Neuron 2: * Neuron 2:
* weights = -0.5 * weights = -1
* result = -32 -> ReLU = 0 * result = -32 -> ReLU = 0
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
@@ -134,90 +126,93 @@ module tb;
2*N_INPUTS*DATA_WIDTH + 2*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(-0.5); ] = -8'sd1;
/* /*
* Neuron 3: * Neuron 3:
* weights = 2.0 * weights = 8
* result = 128 -> saturation = 127.996... * result = 256 -> INT8 saturation = 127
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
weights_bus[ weights_bus[
3*N_INPUTS*DATA_WIDTH + 3*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(2.0); ] = 8'sd8;
/* /*
* Neuron 4: * Neuron 4:
* weights = 0 * weights = 0
* bias = +1 * bias = +5
* result = 1 * result = 5
*/ */
bias_bus[4*DATA_WIDTH +: DATA_WIDTH] = q8_8(1.0); bias_bus[4*DATA_WIDTH +: DATA_WIDTH] = 8'sd5;
/* /*
* Neuron 5: * Neuron 5:
* weights = 0 * weights = 0
* bias = -1 * bias = -5
* ReLU = 0 * ReLU = 0
*/ */
bias_bus[5*DATA_WIDTH +: DATA_WIDTH] = q8_8(-1.0); bias_bus[5*DATA_WIDTH +: DATA_WIDTH] = -8'sd5;
/* /*
* Neuron 6: * Neuron 6:
* weights = 1.0 * weights = 1
* bias = -1.0 * bias = -10
* result = 63 * result = 32 - 10 = 22
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
weights_bus[ weights_bus[
6*N_INPUTS*DATA_WIDTH + 6*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(1.0); ] = 8'sd1;
bias_bus[6*DATA_WIDTH +: DATA_WIDTH] = q8_8(-1.0); bias_bus[6*DATA_WIDTH +: DATA_WIDTH] = -8'sd10;
/* /*
* Neuron 7: * Neuron 7:
* weights = 0.25 * first 16 weights = 1, remaining 16 = 0
* bias = +1 * bias = +5
* result = 16 + 1 = 17 * result = 16 + 5 = 21
*
* Exercises a sparse weight pattern across groups
* (PARALLEL = 8 -> GROUPS = 4).
*/ */
for (i = 0; i < N_INPUTS; i = i + 1) for (i = 0; i < N_INPUTS; i = i + 1)
weights_bus[ weights_bus[
7*N_INPUTS*DATA_WIDTH + 7*N_INPUTS*DATA_WIDTH +
i*DATA_WIDTH +: i*DATA_WIDTH +:
DATA_WIDTH DATA_WIDTH
] = q8_8(0.25); ] = (i < 16) ? 8'sd1 : 8'sd0;
bias_bus[7*DATA_WIDTH +: DATA_WIDTH] = q8_8(1.0); bias_bus[7*DATA_WIDTH +: DATA_WIDTH] = 8'sd5;
$display(""); $display("");
$display("=============================="); $display("==============================");
$display("LAYER TEST"); $display("LAYER TEST (INT8)");
$display("=============================="); $display("==============================");
run_layer; run_layer;
$display("Neuron 0 = %5d expected = 16384", y_bus[0*16 +: 16]); $display("Neuron 0 = %5d expected = 32", $signed(y_bus[0*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 1 = %5d expected = 8192", y_bus[1*16 +: 16]); $display("Neuron 1 = %5d expected = 96", $signed(y_bus[1*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 2 = %5d expected = 0", y_bus[2*16 +: 16]); $display("Neuron 2 = %5d expected = 0", $signed(y_bus[2*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 3 = %5d expected = 32767", y_bus[3*16 +: 16]); $display("Neuron 3 = %5d expected = 127", $signed(y_bus[3*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 4 = %5d expected = 256", y_bus[4*16 +: 16]); $display("Neuron 4 = %5d expected = 5", $signed(y_bus[4*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 5 = %5d expected = 0", y_bus[5*16 +: 16]); $display("Neuron 5 = %5d expected = 0", $signed(y_bus[5*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 6 = %5d expected = 16128", y_bus[6*16 +: 16]); $display("Neuron 6 = %5d expected = 22", $signed(y_bus[6*DATA_WIDTH +: DATA_WIDTH]));
$display("Neuron 7 = %5d expected = 4352", y_bus[7*16 +: 16]); $display("Neuron 7 = %5d expected = 21", $signed(y_bus[7*DATA_WIDTH +: DATA_WIDTH]));
if (y_bus[0*16 +: 16] !== 16'sd16384) errors = errors + 1; if ($signed(y_bus[0*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd32) errors = errors + 1;
if (y_bus[1*16 +: 16] !== 16'sd8192) errors = errors + 1; if ($signed(y_bus[1*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd96) errors = errors + 1;
if (y_bus[2*16 +: 16] !== 16'sd0) errors = errors + 1; if ($signed(y_bus[2*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd0) errors = errors + 1;
if (y_bus[3*16 +: 16] !== 16'sd32767) errors = errors + 1; if ($signed(y_bus[3*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd127) errors = errors + 1;
if (y_bus[4*16 +: 16] !== 16'sd256) errors = errors + 1; if ($signed(y_bus[4*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd5) errors = errors + 1;
if (y_bus[5*16 +: 16] !== 16'sd0) errors = errors + 1; if ($signed(y_bus[5*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd0) errors = errors + 1;
if (y_bus[6*16 +: 16] !== 16'sd16128) errors = errors + 1; if ($signed(y_bus[6*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd22) errors = errors + 1;
if (y_bus[7*16 +: 16] !== 16'sd4352) errors = errors + 1; if ($signed(y_bus[7*DATA_WIDTH +: DATA_WIDTH]) !== 8'sd21) errors = errors + 1;
$display("busy = %0d", busy); $display("busy = %0d", busy);
$display("done = %0d", done); $display("done = %0d", done);
@@ -237,4 +232,4 @@ module tb;
$finish; $finish;
end end
endmodule endmodule
+780 -927
View File
File diff suppressed because it is too large Load Diff
+38 -51
View File
@@ -2,11 +2,10 @@
module tb; module tb;
parameter DATA_WIDTH = 16; parameter DATA_WIDTH = 8;
parameter FRAC_BITS = 8; parameter N_INPUTS = 32;
parameter N_INPUTS = 64;
parameter PARALLEL = 8; parameter PARALLEL = 8;
parameter ACC_WIDTH = 40; parameter ACC_WIDTH = 32;
reg clk; reg clk;
reg rst; reg rst;
@@ -25,7 +24,6 @@ module tb;
neuron_parallel #( neuron_parallel #(
.DATA_WIDTH(DATA_WIDTH), .DATA_WIDTH(DATA_WIDTH),
.FRAC_BITS(FRAC_BITS),
.N_INPUTS(N_INPUTS), .N_INPUTS(N_INPUTS),
.PARALLEL(PARALLEL), .PARALLEL(PARALLEL),
.ACC_WIDTH(ACC_WIDTH) .ACC_WIDTH(ACC_WIDTH)
@@ -47,16 +45,6 @@ module tb;
forever #5 clk = ~clk; forever #5 clk = ~clk;
end end
// ------------------------------------------------------------
// Helper: convert real value to Q8.8
// ------------------------------------------------------------
function signed [15:0] q8_8;
input real value;
begin
q8_8 = $rtoi(value * 256.0);
end
endfunction
// ------------------------------------------------------------ // ------------------------------------------------------------
// Start neuron and wait for completion // Start neuron and wait for completion
// ------------------------------------------------------------ // ------------------------------------------------------------
@@ -79,14 +67,13 @@ module tb;
// //
// Diverse vector: // Diverse vector:
// //
// x0 = 1.5 w0 = 2.0 -> 3.0 // x0 = 3 w0 = 2 -> 6
// x1 = 2.0 w1 = -1.0 -> -2.0 // x1 = 4 w1 = -1 -> -4
// x2 = 0.5 w2 = 0.25 -> 0.125 // x2 = 2 w2 = 1 -> 2
// //
// bias = 0.609375 // bias = 1
// //
// total = 1.734375 // total = 6 - 4 + 2 + 1 = 5
// Q8.8 = 444
// ------------------------------------------------------------ // ------------------------------------------------------------
task test_1; task test_1;
begin begin
@@ -95,23 +82,23 @@ module tb;
x_bus = 0; x_bus = 0;
w_bus = 0; w_bus = 0;
bias = q8_8(0.609375); bias = 8'sd1;
x_bus[0*16 +: 16] = q8_8(1.5); x_bus[0*DATA_WIDTH +: DATA_WIDTH] = 8'sd3;
w_bus[0*16 +: 16] = q8_8(2.0); w_bus[0*DATA_WIDTH +: DATA_WIDTH] = 8'sd2;
x_bus[1*16 +: 16] = q8_8(2.0); x_bus[1*DATA_WIDTH +: DATA_WIDTH] = 8'sd4;
w_bus[1*16 +: 16] = q8_8(-1.0); w_bus[1*DATA_WIDTH +: DATA_WIDTH] = -8'sd1;
x_bus[2*16 +: 16] = q8_8(0.5); x_bus[2*DATA_WIDTH +: DATA_WIDTH] = 8'sd2;
w_bus[2*16 +: 16] = q8_8(0.25); w_bus[2*DATA_WIDTH +: DATA_WIDTH] = 8'sd1;
run_neuron; run_neuron;
$display("RTL = %0d", y); $display("RTL = %0d", y);
$display("EXPECTED = 444"); $display("EXPECTED = 5");
if (y !== 16'sd444) begin if (y !== 8'sd5) begin
$display("FAIL - TEST 1"); $display("FAIL - TEST 1");
errors = errors + 1; errors = errors + 1;
end end
@@ -137,8 +124,8 @@ module tb;
bias = 0; bias = 0;
for (i = 0; i < N_INPUTS; i = i + 1) begin for (i = 0; i < N_INPUTS; i = i + 1) begin
x_bus[i*16 +: 16] = q8_8(1.0); x_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd1;
w_bus[i*16 +: 16] = q8_8(-1.0); w_bus[i*DATA_WIDTH +: DATA_WIDTH] = -8'sd1;
end end
run_neuron; run_neuron;
@@ -146,7 +133,7 @@ module tb;
$display("RTL = %0d", y); $display("RTL = %0d", y);
$display("EXPECTED = 0"); $display("EXPECTED = 0");
if (y !== 16'sd0) begin if (y !== 8'sd0) begin
$display("FAIL - TEST 2"); $display("FAIL - TEST 2");
errors = errors + 1; errors = errors + 1;
end end
@@ -160,7 +147,7 @@ module tb;
// TEST 3 // TEST 3
// //
// Large positive result. // Large positive result.
// Must saturate to +32767. // Must saturate to +127 (INT8).
// ------------------------------------------------------------ // ------------------------------------------------------------
task test_3; task test_3;
begin begin
@@ -172,16 +159,16 @@ module tb;
bias = 0; bias = 0;
for (i = 0; i < N_INPUTS; i = i + 1) begin for (i = 0; i < N_INPUTS; i = i + 1) begin
x_bus[i*16 +: 16] = q8_8(127.0); x_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd100;
w_bus[i*16 +: 16] = q8_8(2.0); w_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd2;
end end
run_neuron; run_neuron;
$display("RTL = %0d", y); $display("RTL = %0d", y);
$display("EXPECTED = 32767"); $display("EXPECTED = 127");
if (y !== 16'sd32767) begin if (y !== 8'sd127) begin
$display("FAIL - TEST 3"); $display("FAIL - TEST 3");
errors = errors + 1; errors = errors + 1;
end end
@@ -196,12 +183,12 @@ module tb;
// //
// Mixed positive/negative products. // Mixed positive/negative products.
// //
// 32 x (+1) // 16 x (2 * 1) = 32
// 32 x (-1) // 16 x (-1 * 1) = -16
// sum = 0 // sum = 16
// bias = -1 // bias = -16
// //
// ReLU -> 0 // total = 0 -> ReLU boundary -> 0
// ------------------------------------------------------------ // ------------------------------------------------------------
task test_4; task test_4;
begin begin
@@ -210,16 +197,16 @@ module tb;
x_bus = 0; x_bus = 0;
w_bus = 0; w_bus = 0;
bias = q8_8(-1.0); bias = -8'sd16;
for (i = 0; i < N_INPUTS; i = i + 1) begin for (i = 0; i < N_INPUTS; i = i + 1) begin
if ((i % 2) == 0) begin if ((i % 2) == 0) begin
x_bus[i*16 +: 16] = q8_8(2.0); x_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd2;
w_bus[i*16 +: 16] = q8_8(0.5); w_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd1;
end end
else begin else begin
x_bus[i*16 +: 16] = q8_8(-1.0); x_bus[i*DATA_WIDTH +: DATA_WIDTH] = -8'sd1;
w_bus[i*16 +: 16] = q8_8(1.0); w_bus[i*DATA_WIDTH +: DATA_WIDTH] = 8'sd1;
end end
end end
@@ -228,7 +215,7 @@ module tb;
$display("RTL = %0d", y); $display("RTL = %0d", y);
$display("EXPECTED = 0"); $display("EXPECTED = 0");
if (y !== 16'sd0) begin if (y !== 8'sd0) begin
$display("FAIL - TEST 4"); $display("FAIL - TEST 4");
errors = errors + 1; errors = errors + 1;
end end
@@ -259,7 +246,7 @@ module tb;
$display(""); $display("");
$display("=============================="); $display("==============================");
$display("NEURON_PARALLEL TESTBENCH"); $display("NEURON_PARALLEL TESTBENCH (INT8)");
$display("=============================="); $display("==============================");
test_1; test_1;
@@ -283,4 +270,4 @@ module tb;
$finish; $finish;
end end
endmodule endmodule
+7080 -632
View File
File diff suppressed because one or more lines are too long