Skip to content

Commit

Permalink
Change done_fill to single clock, for interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
Aba committed Aug 31, 2023
1 parent 38f9b33 commit 925a2e2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 105 deletions.
4 changes: 2 additions & 2 deletions rtl/dnn_engine.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module dnn_engine #(
input wire [(OUT_ADDR_WIDTH+2)-1:0] bram_addr_a,
output wire [ OUT_BITS -1:0] bram_rddata_a,
input wire bram_en_a,
output wire t_done_fill,
output wire done_fill,
input wire t_done_proc
);

Expand Down Expand Up @@ -122,7 +122,7 @@ module dnn_engine #(
.bram_addr_a (bram_addr_a ),
.bram_rddata_a(bram_rddata_a ),
.bram_en_a (bram_en_a ),
.t_done_fill (t_done_fill ),
.done_fill (done_fill ),
.t_done_proc (t_done_proc )
);
endmodule
Expand Down
9 changes: 5 additions & 4 deletions rtl/out_ram_switch.sv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module out_ram_switch #(
output logic [ WORD_WIDTH -1:0] bram_rddata_a,
input logic bram_en_a,

output logic t_done_fill,
output logic done_fill,
input logic t_done_proc
);

Expand Down Expand Up @@ -108,10 +108,11 @@ module out_ram_switch #(

assign ram_r_addr = bram_addr_a[(ADDR_WIDTH+2)-1:2];
assign bram_rddata_a = WORD_WIDTH'(signed'(ram_dout[i_read])); // pad to 32
assign done_fill = state_read == R_DONE_FILL_S; // one clock for interrupt

always_ff @(posedge clk)
if (!rstn) t_done_fill <= 0;
else if (state_read == R_DONE_FILL_S) t_done_fill <= !t_done_fill;
// always_ff @(posedge clk)
// if (!rstn) t_done_fill <= 0;
// else if (state_read == R_DONE_FILL_S) t_done_fill <= !t_done_fill;

always_ff @(posedge clk)
if (!rstn) dp_prev <= 0; // t_done_proc starts at 0
Expand Down
69 changes: 69 additions & 0 deletions test/sv/axis_dma_tb.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This was first written using classes: https://github.com/abarajithan11/dnn-engine/blob/1b7742d24c1ece4e47340f7402e51b54c6d087a3/rtl/tb/axis_tb.sv
// But iVerilog does not support {class, ref, break, rand}

`timescale 1ns/1ps

module AXIS_M2S #(
parameter WORD_WIDTH=8, BUS_WIDTH=8, PROB_VALID=20,
parameter MEM_DEPTH=1,
parameter WORDS_PER_BEAT = BUS_WIDTH/WORD_WIDTH
)(
input logic aclk, aresetn, s_ready,
output logic s_valid, s_last,
output logic [WORDS_PER_BEAT-1:0][WORD_WIDTH-1:0] s_data,
output logic [WORDS_PER_BEAT-1:0] s_keep,
ref bit [0:MEM_DEPTH-1][WORD_WIDTH-1:0] memory
);

logic s_last_val;
logic [WORDS_PER_BEAT-1:0][WORD_WIDTH-1:0] s_data_val;
logic [WORDS_PER_BEAT-1:0] s_keep_val;

int status, i_words=0;
bit prev_handshake=1; // data is released first
bit prev_slast=0;

task axis_push (input int START_ADDR, input int N_WORDS);
{s_valid, s_data, s_last, s_keep} = '0;

wait(aresetn); // wait for slave to begin

// iverilog doesnt support break. so the loop is rolled to have break at top
while (~prev_slast) begin // loop goes from (aresetn & s_ready) to s_last
if (prev_handshake) begin // change data
for (int i=0; i < WORDS_PER_BEAT; i++) begin
if(i_words >= N_WORDS) begin
$display(1, "finished at i_words=%d\n", i_words); // End, fill rest with zeros
s_data_val[i] = 0;
s_keep_val[i] = 0;
end
else begin
s_data_val[i] = memory[START_ADDR + i_words];
// $display("DMA: start:%d, i_words:%d, val:%d", START_ADDR, i_words, $signed(s_data_val[i]));
s_keep_val[i] = 1;
i_words += 1;
end
s_last_val = i_words >= N_WORDS;
end
end
s_valid = $urandom_range(0,999) < PROB_VALID; // randomize s_valid

// scrable data signals on every cycle if !valid to catch slave reading it at wrong time
s_data = s_valid ? s_data_val : 'x;
s_keep = s_valid ? s_keep_val : 'x;
s_last = s_valid ? s_last_val : 'x;

// -------------- LOOP BEGINS HERE -----------
@(posedge aclk);
prev_handshake = s_valid && s_ready; // read at posedge
prev_slast = s_valid && s_ready && s_last;

#10ps; // Delay before writing s_valid, s_data, s_keep
end

// Reset & close packet after done
{s_valid, s_data, s_keep, s_last, prev_slast, i_words} = '0;
prev_handshake = 1;
@(posedge aclk);
endtask
endmodule
10 changes: 3 additions & 7 deletions test/sv/dnn_engine_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module dnn_engine_tb;
logic [S_WEIGHTS_WIDTH_LF/K_BITS-1:0][K_BITS-1:0] s_axis_weights_tdata;
logic [S_WEIGHTS_WIDTH_LF/K_BITS-1:0] s_axis_weights_tkeep;

logic bram_en_a, t_done_fill, t_done_proc;
logic bram_en_a, done_fill, t_done_proc;
logic [(OUT_ADDR_WIDTH+2)-1:0] bram_addr_a;
logic [ OUT_BITS -1:0] bram_rddata_a;

Expand Down Expand Up @@ -94,7 +94,6 @@ module dnn_engine_tb;
`define RAND_DELAY repeat($urandom_range(1000/READY_PROB-1)) @(posedge aclk) #1;

int file, y_wpt, dout;
bit done_fill_prev=0; // t_done_fill starts at 0
initial begin
{bram_addr_a, bram_en_a, t_done_proc} = 0;
wait(aresetn);
Expand All @@ -118,12 +117,10 @@ module dnn_engine_tb;
// 5. fw loops to beginning, waits for t_done_fill to toggle


`RAND_DELAY
for (int i_nl=0; i_nl < bundles[ib].y_nl; i_nl++)
for (int i_w=0; i_w < bundles[ib].y_w; i_w++) begin

wait (t_done_fill != done_fill_prev);
done_fill_prev = t_done_fill;
wait (done_fill);

`RAND_DELAY
file = $fopen(y_path, "a");
Expand All @@ -136,9 +133,8 @@ module dnn_engine_tb;
$fdisplay(file, "%d", $signed(bram_rddata_a));
end
`RAND_DELAY
t_done_proc <= !t_done_proc;
$fclose(file);
`RAND_DELAY
t_done_proc <= !t_done_proc;
end
$display("done y: %0d_%0d_%0d_y_sim.txt", ib, ip, it);
end
Expand Down
99 changes: 7 additions & 92 deletions test/wave/dnn_engine_tb_behav.wcfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
</db_ref>
</db_ref_list>
<zoom_setting>
<ZoomStartTime time="816.350 ns"></ZoomStartTime>
<ZoomEndTime time="1,032.751 ns"></ZoomEndTime>
<Cursor1Time time="906.000 ns"></Cursor1Time>
<ZoomStartTime time="0.000000 us"></ZoomStartTime>
<ZoomEndTime time="434.000001 us"></ZoomEndTime>
<Cursor1Time time="1.000000 us"></Cursor1Time>
</zoom_setting>
<column_width_setting>
<NameColumnWidth column_width="476"></NameColumnWidth>
<ValueColumnWidth column_width="220"></ValueColumnWidth>
<ValueColumnWidth column_width="214"></ValueColumnWidth>
</column_width_setting>
<WVObjectSize size="2" />
<wave_markers>
Expand Down Expand Up @@ -1269,9 +1269,9 @@
<obj_property name="ElementShortName">done_fill</obj_property>
<obj_property name="ObjectShortName">done_fill</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/done_firmware" type="logic">
<obj_property name="ElementShortName">done_firmware</obj_property>
<obj_property name="ObjectShortName">done_firmware</obj_property>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/t_done_proc" type="logic">
<obj_property name="ElementShortName">t_done_proc</obj_property>
<obj_property name="ObjectShortName">t_done_proc</obj_property>
</wvobject>
</wvobject>
<wvobject fp_name="group1755" type="group">
Expand Down Expand Up @@ -1330,46 +1330,6 @@
<obj_property name="ObjectShortName">shift_reg[7:0][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
<obj_property name="isExpanded"></obj_property>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[7]" type="array">
<obj_property name="ElementShortName">[7][31:0]</obj_property>
<obj_property name="ObjectShortName">[7][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[6]" type="array">
<obj_property name="ElementShortName">[6][31:0]</obj_property>
<obj_property name="ObjectShortName">[6][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[5]" type="array">
<obj_property name="ElementShortName">[5][31:0]</obj_property>
<obj_property name="ObjectShortName">[5][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[4]" type="array">
<obj_property name="ElementShortName">[4][31:0]</obj_property>
<obj_property name="ObjectShortName">[4][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[3]" type="array">
<obj_property name="ElementShortName">[3][31:0]</obj_property>
<obj_property name="ObjectShortName">[3][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[2]" type="array">
<obj_property name="ElementShortName">[2][31:0]</obj_property>
<obj_property name="ObjectShortName">[2][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[1]" type="array">
<obj_property name="ElementShortName">[1][31:0]</obj_property>
<obj_property name="ObjectShortName">[1][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/shift_reg[0]" type="array">
<obj_property name="ElementShortName">[0][31:0]</obj_property>
<obj_property name="ObjectShortName">[0][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
</wvobject>
<wvobject fp_name="group1753" type="group">
<obj_property name="label">RAMS</obj_property>
Expand Down Expand Up @@ -1399,24 +1359,6 @@
<obj_property name="ObjectShortName">ram_addr[1:0][9:0]</obj_property>
<obj_property name="Radix">UNSIGNEDDECRADIX</obj_property>
<obj_property name="isExpanded"></obj_property>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_addr[1]" type="array">
<obj_property name="ElementShortName">[1][9:0]</obj_property>
<obj_property name="ObjectShortName">[1][9:0]</obj_property>
<obj_property name="Radix">UNSIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_addr[0]" type="array">
<obj_property name="ElementShortName">[0][9:0]</obj_property>
<obj_property name="ObjectShortName">[0][9:0]</obj_property>
<obj_property name="Radix">UNSIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_addr[1]" type="array">
<obj_property name="ElementShortName">[1][9:0]</obj_property>
<obj_property name="ObjectShortName">[1][9:0]</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_addr[0]" type="array">
<obj_property name="ElementShortName">[0][9:0]</obj_property>
<obj_property name="ObjectShortName">[0][9:0]</obj_property>
</wvobject>
</wvobject>
<wvobject fp_name="group607" type="group">
<obj_property name="label">ram0</obj_property>
Expand Down Expand Up @@ -1449,15 +1391,6 @@
<obj_property name="ObjectShortName">\genblk1.delay [0:0][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
<obj_property name="isExpanded"></obj_property>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/\I[0].RAM /RAM/\genblk1.delay [0]" type="array">
<obj_property name="ElementShortName">[0][31:0]</obj_property>
<obj_property name="ObjectShortName">[0][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/\I[0].RAM /RAM/\genblk1.delay [0]" type="array">
<obj_property name="ElementShortName">[0][31:0]</obj_property>
<obj_property name="ObjectShortName">[0][31:0]</obj_property>
</wvobject>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/\I[0].RAM /RAM/douta" type="array">
<obj_property name="DisplayName">FullPathName</obj_property>
Expand All @@ -1471,24 +1404,6 @@
<obj_property name="ObjectShortName">ram_dout[1:0][31:0]</obj_property>
<obj_property name="isExpanded"></obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_dout[1]" type="array">
<obj_property name="ElementShortName">[1][31:0]</obj_property>
<obj_property name="ObjectShortName">[1][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_dout[0]" type="array">
<obj_property name="ElementShortName">[0][31:0]</obj_property>
<obj_property name="ObjectShortName">[0][31:0]</obj_property>
<obj_property name="Radix">SIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_dout[1]" type="array">
<obj_property name="ElementShortName">[1][31:0]</obj_property>
<obj_property name="ObjectShortName">[1][31:0]</obj_property>
</wvobject>
<wvobject fp_name="/dnn_engine_tb/pipe/OUT_RAM/ram_dout[0]" type="array">
<obj_property name="ElementShortName">[0][31:0]</obj_property>
<obj_property name="ObjectShortName">[0][31:0]</obj_property>
</wvobject>
</wvobject>
</wvobject>
</wvobject>
Expand Down

0 comments on commit 925a2e2

Please sign in to comment.