fix samples ntt bugs & set PLL & optimize matmul

This commit is contained in:
2026-07-15 10:36:38 +08:00
parent fc91511950
commit c4d36515cc
7 changed files with 274 additions and 120 deletions

View File

@@ -64,6 +64,7 @@ module cdma_matmul_bridge #(
output logic mat_done_clear,
output logic mat_crc_clear,
input logic mat_done,
input logic mat_crc_idle,
output logic seq_done_irq
);
@@ -102,10 +103,10 @@ module cdma_matmul_bridge #(
logic [31:0] load_next_dst_addr;
logic [31:0] bank_dst_addr [2];
logic rd_busy;
logic wr_busy;
logic rd_active_bank;
logic wr_active_bank;
logic [1:0] rd_outstanding_count;
logic [1:0] rd_bank_fifo;
logic [1:0] compute_q;
logic [1:0] compute_q_count;
logic mat_done_seen;
@@ -136,6 +137,7 @@ module cdma_matmul_bridge #(
wire retire_from_store = seq_busy && cdma_wr_req_done;
wire retire_from_compute = seq_busy && seq_skip_writeback && mat_done_event && (compute_q_count != 2'd0);
wire [31:0] retire_inc = {31'd0, retire_from_store} + {31'd0, retire_from_compute};
wire rd_req_fire = cdma_rd_req_valid && cdma_rd_req_ready;
function automatic logic [31:0] apply_wstrb(
input logic [31:0] old_val,
@@ -257,10 +259,10 @@ module cdma_matmul_bridge #(
load_next_dst_addr <= 32'd0;
bank_dst_addr[0] <= 32'd0;
bank_dst_addr[1] <= 32'd0;
rd_busy <= 1'b0;
wr_busy <= 1'b0;
rd_active_bank <= 1'b0;
wr_active_bank <= 1'b0;
rd_outstanding_count <= 2'd0;
rd_bank_fifo <= 2'b00;
compute_q <= 2'b00;
compute_q_count <= 2'd0;
mat_done_seen <= 1'b0;
@@ -290,7 +292,7 @@ module cdma_matmul_bridge #(
if (done_clear_req)
seq_done_flag <= 1'b0;
if (cdma_rd_req_valid && cdma_rd_req_ready)
if (rd_req_fire)
cdma_rd_req_valid <= 1'b0;
if (cdma_wr_req_valid && cdma_wr_req_ready)
@@ -313,8 +315,9 @@ module cdma_matmul_bridge #(
load_next_dst_addr <= seq_dst_base;
bank_dst_addr[0] <= 32'd0;
bank_dst_addr[1] <= 32'd0;
rd_busy <= 1'b0;
wr_busy <= 1'b0;
rd_outstanding_count <= 2'd0;
rd_bank_fifo <= 2'b00;
compute_q <= 2'b00;
compute_q_count <= 2'd0;
mat_done_seen <= 1'b1;
@@ -325,18 +328,50 @@ module cdma_matmul_bridge #(
end else if (seq_busy) begin
if (retire_inc != 32'd0) begin
groups_retired <= groups_retired + retire_inc;
if ((groups_retired + retire_inc) >= seq_groups) begin
seq_busy <= 1'b0;
seq_done_flag <= 1'b1;
end
end
if (cdma_rd_req_done) begin
rd_busy <= 1'b0;
bank_load_active[rd_active_bank] <= 1'b0;
bank_ab_valid[rd_active_bank] <= 1'b1;
// The final compute completion can precede the recursive CRC
// consumer. Do not expose sequence completion until it drains.
if ((groups_retired >= seq_groups) && mat_crc_idle) begin
seq_busy <= 1'b0;
seq_done_flag <= 1'b1;
end
if (cdma_rd_req_done && (rd_outstanding_count != 2'd0)) begin
bank_load_active[rd_bank_fifo[0]] <= 1'b0;
bank_ab_valid[rd_bank_fifo[0]] <= 1'b1;
end
// Track the active read and one prefetched read. Completion
// pulses are in request order, so a two-entry bank FIFO is
// sufficient to associate each RLAST with its destination.
case ({rd_req_fire, cdma_rd_req_done})
2'b10: begin
if (rd_outstanding_count == 2'd0)
rd_bank_fifo[0] <= cdma_rd_req_ep_bank[0];
else
rd_bank_fifo[1] <= cdma_rd_req_ep_bank[0];
rd_outstanding_count <= rd_outstanding_count + 2'd1;
end
2'b01: begin
if (rd_outstanding_count == 2'd2)
rd_bank_fifo[0] <= rd_bank_fifo[1];
if (rd_outstanding_count != 2'd0)
rd_outstanding_count <= rd_outstanding_count - 2'd1;
end
2'b11: begin
if (rd_outstanding_count == 2'd1) begin
rd_bank_fifo[0] <= cdma_rd_req_ep_bank[0];
end else begin
rd_bank_fifo[0] <= rd_bank_fifo[1];
rd_bank_fifo[1] <= cdma_rd_req_ep_bank[0];
end
end
default: begin
end
endcase
if (cdma_wr_req_done) begin
wr_busy <= 1'b0;
bank_store_active[wr_active_bank] <= 1'b0;
@@ -354,15 +389,14 @@ module cdma_matmul_bridge #(
compute_q_count <= compute_q_count - 2'd1;
end
if (!rd_busy && !cdma_rd_req_valid && (load_next_idx < seq_groups) && load_target_free) begin
if ((rd_outstanding_count < 2'd2) && !cdma_rd_req_valid &&
(load_next_idx < seq_groups) && load_target_free) begin
cdma_rd_req_src <= load_next_src_addr;
cdma_rd_req_bytes <= MAT_AB_BYTES;
cdma_rd_req_ep_id <= 4'd0;
cdma_rd_req_ep_bank <= {3'b000, load_target_bank};
cdma_rd_req_ep_word_off <= 8'd0;
cdma_rd_req_valid <= 1'b1;
rd_busy <= 1'b1;
rd_active_bank <= load_target_bank;
bank_load_active[load_target_bank] <= 1'b1;
bank_group_idx[load_target_bank] <= load_next_idx;
bank_dst_addr[load_target_bank] <= load_next_dst_addr;