feat: MILESTONE - real activation-fetch engine, full N=2 system verified on real DDR3 (EXP-0079)
Closes the last major disclosed functional gap: packed_slot.v's activation data was read through a combinational stand-in since EXP-0062. New act_tile_fetch.v reads activation tiles directly from DDR3 (no on-chip buffering needed, unlike weights -- activation data has no reuse), sharing each slot's existing ctrl port with its own weight-prefetch engine. Real memory layout: one full BURST_LEN=8-word burst per tile, deliberately avoiding any runtime-indexed part-select given this project's thin P&R timing margin (EXP-0078). Verified at three levels: act_tile_fetch.v alone (6/6), packed_slot.v with real preloaded activation data (9/9), and the full N=2 system against real DDR3 via xsim (8/8, 0 errors) -- the first time this project's compute path has been verified end-to-end with real DDR3 for both weights and activations. Retired hardware/v3/rtl/n2_system_top.v and its testbench (pre-DDR3 SDR-placeholder era, fully superseded by n2_system_ddr3_top.v). Also: docs/PHYSICAL_REALIZATION.md (real pinout/parts/timing/protocol reference for the physical board) and CLAUDE.md (persistent project instructions for future Claude Code sessions). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUG92aM9m68TRc4rG55BcC
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
// ============================================================
|
||||
// V3 -- act_tile_fetch.v: REAL activation-tile fetch engine, closing
|
||||
// the gap packed_slot.v's own header has disclosed since EXP-0062
|
||||
// ("a real activation fetch engine ... is a separate, later
|
||||
// deliverable, NOT built here"). This is that deliverable.
|
||||
//
|
||||
// WHY A SEPARATE, SIMPLE ENGINE (not a prefetch/buffer pair like the
|
||||
// weight path): weights are reused across M reuse-positions per
|
||||
// Director-dispatched pair, so prefetching them once into an on-chip
|
||||
// buffer (layer_prefetch_ctrl.v/layer_weight_buffer.v) amortizes real
|
||||
// DDR3 latency across many reads. Activation data has NO such reuse
|
||||
// -- each position's activation tile is read exactly once per job --
|
||||
// so buffering it on-chip would only add complexity for zero benefit.
|
||||
// This engine reads DIRECTLY from DDR3 per tile instead.
|
||||
//
|
||||
// MEMORY LAYOUT CONVENTION (real, disclosed, and REQUIRED of whoever
|
||||
// prepares activation data in DDR3 -- documented in the physical
|
||||
// realization doc too): each activation tile (P_IN=8 INT8 values)
|
||||
// occupies its OWN full BURST_LEN=8-word (128-bit) burst slot, in the
|
||||
// LOW 64 bits, upper 64 bits unused padding. Tile index t's word
|
||||
// address is therefore `base + t*BURST_LEN`, always burst-aligned by
|
||||
// construction. This is DELIBERATELY wasteful of DDR3 capacity (2x)
|
||||
// in exchange for AVOIDING a runtime-indexed part-select to pick
|
||||
// which half of a shared burst holds the tile -- weight_tile_gather.v
|
||||
// already established (EXP-0061) that pattern is a real Fmax risk,
|
||||
// and this project's own P&R margin is currently thin (EXP-0078,
|
||||
// WNS +0.013ns) -- not the moment to introduce a new critical path.
|
||||
// A future denser packing (2 tiles/burst, real part-select) is a
|
||||
// disclosed, deliberate follow-up, not done here.
|
||||
//
|
||||
// PROTOCOL: one request (`req` pulse + base_a/base_b/tcnt) triggers
|
||||
// TWO SEQUENTIAL burst reads (lane A then lane B) over the SAME
|
||||
// shared ctrl port packed_slot.v already owns -- reusing the EXACT
|
||||
// port layer_prefetch_ctrl.v uses during S_PREFETCH, since that
|
||||
// phase has already finished (weight data is on-chip by the time
|
||||
// this engine runs) and the port is genuinely free. Follows the same
|
||||
// combinational-first-grant discipline as every other one-shot-pulse
|
||||
// requester in this project (EXP-0066): `mem_active` must be visible
|
||||
// to the arbiter the SAME cycle it asserts, `ctrl_req` is only issued
|
||||
// after `mem_grant` is observed, never blind.
|
||||
// ============================================================
|
||||
module act_tile_fetch #(
|
||||
parameter DATA_WIDTH = 8,
|
||||
parameter P_IN = 8,
|
||||
parameter BURST_LEN = 8,
|
||||
parameter ADDR_WIDTH = 25 // word address, matches the shared ctrl port's own convention
|
||||
)(
|
||||
input wire clk,
|
||||
input wire rst,
|
||||
|
||||
input wire req, // one-shot pulse
|
||||
input wire [ADDR_WIDTH-1:0] base_a,
|
||||
input wire [ADDR_WIDTH-1:0] base_b,
|
||||
input wire [15:0] tcnt,
|
||||
output reg valid, // one-cycle pulse, data_a/data_b valid
|
||||
output reg signed [DATA_WIDTH*P_IN-1:0] data_a,
|
||||
output reg signed [DATA_WIDTH*P_IN-1:0] data_b,
|
||||
|
||||
output wire mem_active,
|
||||
input wire mem_grant,
|
||||
|
||||
output reg ctrl_req,
|
||||
output reg ctrl_wr,
|
||||
output reg [ADDR_WIDTH-1:0] ctrl_addr,
|
||||
output wire [16*BURST_LEN-1:0] ctrl_wdata,
|
||||
output wire [2*BURST_LEN-1:0] ctrl_wmask,
|
||||
input wire [16*BURST_LEN-1:0] ctrl_rdata,
|
||||
input wire ctrl_ready,
|
||||
input wire ctrl_busy
|
||||
);
|
||||
assign ctrl_wdata = {(16*BURST_LEN){1'b0}};
|
||||
assign ctrl_wmask = {(2*BURST_LEN){1'b0}}; // read-only engine, mask unused
|
||||
|
||||
localparam S_IDLE = 3'd0,
|
||||
S_MEMWAIT = 3'd1,
|
||||
S_REQ_A = 3'd2,
|
||||
S_GAP = 3'd3, // wait for ctrl_busy to clear before firing lane B's request
|
||||
S_REQ_B = 3'd4;
|
||||
|
||||
reg [2:0] state;
|
||||
reg [ADDR_WIDTH-1:0] base_a_lat, base_b_lat;
|
||||
reg [15:0] tcnt_lat;
|
||||
|
||||
assign mem_active = (state != S_IDLE);
|
||||
|
||||
wire [ADDR_WIDTH-1:0] tile_offset = {{(ADDR_WIDTH-16){1'b0}}, tcnt_lat} * BURST_LEN[ADDR_WIDTH-1:0];
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (rst) begin
|
||||
state <= S_IDLE;
|
||||
ctrl_req <= 1'b0; ctrl_wr <= 1'b0; ctrl_addr <= {ADDR_WIDTH{1'b0}};
|
||||
valid <= 1'b0; data_a <= {(DATA_WIDTH*P_IN){1'b0}}; data_b <= {(DATA_WIDTH*P_IN){1'b0}};
|
||||
base_a_lat <= {ADDR_WIDTH{1'b0}}; base_b_lat <= {ADDR_WIDTH{1'b0}}; tcnt_lat <= 16'd0;
|
||||
end else begin
|
||||
ctrl_req <= 1'b0;
|
||||
valid <= 1'b0;
|
||||
|
||||
case (state)
|
||||
S_IDLE: begin
|
||||
if (req) begin
|
||||
base_a_lat <= base_a;
|
||||
base_b_lat <= base_b;
|
||||
tcnt_lat <= tcnt;
|
||||
state <= S_MEMWAIT;
|
||||
end
|
||||
end
|
||||
|
||||
S_MEMWAIT: begin
|
||||
if (mem_grant) begin
|
||||
ctrl_addr <= base_a_lat + tile_offset;
|
||||
ctrl_wr <= 1'b0;
|
||||
ctrl_req <= 1'b1;
|
||||
state <= S_REQ_A;
|
||||
end
|
||||
end
|
||||
|
||||
S_REQ_A: begin
|
||||
if (ctrl_ready) begin
|
||||
data_a <= ctrl_rdata[0 +: DATA_WIDTH*P_IN];
|
||||
ctrl_addr <= base_b_lat + tile_offset;
|
||||
ctrl_wr <= 1'b0;
|
||||
state <= S_GAP;
|
||||
end
|
||||
end
|
||||
|
||||
S_GAP: begin
|
||||
// the shared controller may still be finishing its
|
||||
// own internal completion sequence for lane A's
|
||||
// request for one more cycle after ctrl_ready
|
||||
// pulsed (mig_native_adapter.v's own S_DONE state
|
||||
// keeps `busy` asserted through it) -- wait for
|
||||
// !ctrl_busy before firing lane B's request,
|
||||
// instead of assuming back-to-back is safe.
|
||||
if (!ctrl_busy) begin
|
||||
ctrl_req <= 1'b1;
|
||||
state <= S_REQ_B;
|
||||
end
|
||||
end
|
||||
|
||||
S_REQ_B: begin
|
||||
if (ctrl_ready) begin
|
||||
data_b <= ctrl_rdata[0 +: DATA_WIDTH*P_IN];
|
||||
valid <= 1'b1;
|
||||
state <= S_IDLE;
|
||||
end
|
||||
end
|
||||
|
||||
default: state <= S_IDLE;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -260,30 +260,14 @@ module n2_system_ddr3_top #(
|
||||
wire [15:0] s0_nid_a, s0_nid_b, s1_nid_a, s1_nid_b;
|
||||
wire [JOB_ADDR_WIDTH-1:0] s0_raddr_a, s0_raddr_b, s1_raddr_a, s1_raddr_b;
|
||||
|
||||
// ---- activation-fetch STUB (disclosed gap, see packed_slot.v's
|
||||
// own header: no real activation-fetch engine exists yet). Kept
|
||||
// fully INTERNAL rather than exposed as top-level chip pins --
|
||||
// exposing act_addr/act_data literally as pins was a real mistake
|
||||
// caught by this same P&R run: s0/s1's act_addr_a/b (JOB_ADDR_
|
||||
// WIDTH=26 bits x4) + act_data_a/b (DATA_WIDTH*P_IN=64 bits x4)
|
||||
// alone demand ~360 I/O, but XC7A100T-CSG324 has only 324 pins
|
||||
// total (DDR3 alone already uses ~53) -- place_design failed with
|
||||
// "IO Clock Placer failed" for exactly this reason. A free-
|
||||
// running counter-addressed pattern stands in for real activation
|
||||
// data until a real fetch engine (DDR3-backed, like the weight
|
||||
// path) is built; this keeps real timing/placement meaningful for
|
||||
// everything else in this P&R run without claiming activation
|
||||
// fetch is solved.
|
||||
wire [JOB_ADDR_WIDTH-1:0] s0_act_addr_a, s0_act_addr_b, s1_act_addr_a, s1_act_addr_b;
|
||||
reg [DATA_WIDTH*P_IN-1:0] act_stub_reg;
|
||||
always @(posedge ui_clk)
|
||||
if (ui_clk_sync_rst) act_stub_reg <= {(DATA_WIDTH*P_IN){1'b0}};
|
||||
else act_stub_reg <= act_stub_reg + 1'b1;
|
||||
wire signed [DATA_WIDTH*P_IN-1:0] s0_act_data_a = act_stub_reg;
|
||||
wire signed [DATA_WIDTH*P_IN-1:0] s0_act_data_b = act_stub_reg;
|
||||
wire signed [DATA_WIDTH*P_IN-1:0] s1_act_data_a = act_stub_reg;
|
||||
wire signed [DATA_WIDTH*P_IN-1:0] s1_act_data_b = act_stub_reg;
|
||||
|
||||
// ---- activation fetch: REAL now (EXP-0079) -- each packed_slot
|
||||
// instance owns its own act_tile_fetch.v internally, sharing that
|
||||
// SAME slot's existing ctrl_req/addr/etc port (already wired to
|
||||
// the arbiter below) with its own weight-prefetch engine. No
|
||||
// top-level activation ports exist any more -- the old stand-in
|
||||
// (act_tile_addr_a/b -> act_tile_data_a/b, and before that, a
|
||||
// free-running counter stub that nearly blew the package's whole
|
||||
// I/O budget, see git history) is gone; this is fully internal.
|
||||
packed_slot #(
|
||||
.DATA_WIDTH(DATA_WIDTH), .P_IN(P_IN), .ACC_WIDTH(ACC_WIDTH),
|
||||
.BURST_LEN(BURST_LEN), .ADDR_WIDTH(JOB_ADDR_WIDTH), .LAYER_BYTES(LAYER_BYTES)
|
||||
@@ -302,8 +286,6 @@ module n2_system_ddr3_top #(
|
||||
.result_node_id_a(s0_nid_a), .result_node_id_b(s0_nid_b),
|
||||
.result_addr_a_out(s0_raddr_a), .result_addr_b_out(s0_raddr_b),
|
||||
.mem_active(req_active[0]), .mem_grant(req_grant[0]),
|
||||
.act_tile_addr_a(s0_act_addr_a), .act_tile_addr_b(s0_act_addr_b),
|
||||
.act_tile_data_a(s0_act_data_a), .act_tile_data_b(s0_act_data_b),
|
||||
.ctrl_req(req_req[0]), .ctrl_wr(req_wr[0]),
|
||||
.ctrl_addr(req_addr[0*MEM_ADDR_WIDTH +: MEM_ADDR_WIDTH]),
|
||||
.ctrl_wdata(req_wdata[0*16*BURST_LEN +: 16*BURST_LEN]),
|
||||
@@ -330,8 +312,6 @@ module n2_system_ddr3_top #(
|
||||
.result_node_id_a(s1_nid_a), .result_node_id_b(s1_nid_b),
|
||||
.result_addr_a_out(s1_raddr_a), .result_addr_b_out(s1_raddr_b),
|
||||
.mem_active(req_active[1]), .mem_grant(req_grant[1]),
|
||||
.act_tile_addr_a(s1_act_addr_a), .act_tile_addr_b(s1_act_addr_b),
|
||||
.act_tile_data_a(s1_act_data_a), .act_tile_data_b(s1_act_data_b),
|
||||
.ctrl_req(req_req[1]), .ctrl_wr(req_wr[1]),
|
||||
.ctrl_addr(req_addr[1*MEM_ADDR_WIDTH +: MEM_ADDR_WIDTH]),
|
||||
.ctrl_wdata(req_wdata[1*16*BURST_LEN +: 16*BURST_LEN]),
|
||||
|
||||
@@ -1,192 +0,0 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
// ============================================================
|
||||
// V3 -- synthesis top for the EXP-0066 verified N=2 multi-core
|
||||
// system: neural_director_packed.v + 2 real packed_slot.v instances
|
||||
// + sdram_slot_arbiter2.v + real sdram_controller.v, flat structural
|
||||
// wiring, for a real P&R resource/timing check (same out-of-context
|
||||
// methodology as EXP-0059/0063).
|
||||
//
|
||||
// Activation stand-in ports (see packed_slot.v's own header) are
|
||||
// exposed per-slot at the top level, matching this module's own
|
||||
// still-declared scope limit (no real activation fetch engine yet).
|
||||
// ============================================================
|
||||
module n2_system_top #(
|
||||
parameter DATA_WIDTH = 8,
|
||||
parameter P_IN = 8,
|
||||
parameter ACC_WIDTH = 32,
|
||||
parameter BURST_LEN = 8,
|
||||
parameter ROW_BITS = 13,
|
||||
parameter COL_BITS = 10,
|
||||
parameter BANK_BITS = 2,
|
||||
parameter SDRAM_ADDR_WIDTH = BANK_BITS + ROW_BITS + COL_BITS,
|
||||
parameter ADDR_WIDTH = 26,
|
||||
parameter LAYER_BYTES = 128,
|
||||
parameter N_SLOTS = 2,
|
||||
parameter QUEUE_DEPTH = 8
|
||||
)(
|
||||
input wire clk,
|
||||
input wire rst,
|
||||
|
||||
// ---- Director job submission ----
|
||||
input wire job_in_valid,
|
||||
output wire job_in_ready,
|
||||
input wire [ADDR_WIDTH-1:0] job_in_x_base,
|
||||
input wire [ADDR_WIDTH-1:0] job_in_w_base,
|
||||
input wire [15:0] job_in_n_tiles,
|
||||
input wire [ADDR_WIDTH-1:0] job_in_result_addr,
|
||||
input wire [15:0] job_in_node_id,
|
||||
output wire job_out_done,
|
||||
output wire [$clog2(N_SLOTS)-1:0] job_out_slot,
|
||||
|
||||
// ---- activation stand-ins, slot 0 ----
|
||||
output wire [ADDR_WIDTH-1:0] s0_act_addr_a,
|
||||
output wire [ADDR_WIDTH-1:0] s0_act_addr_b,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] s0_act_data_a,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] s0_act_data_b,
|
||||
output wire signed [DATA_WIDTH-1:0] s0_result_data_a,
|
||||
output wire signed [DATA_WIDTH-1:0] s0_result_data_b,
|
||||
|
||||
// ---- activation stand-ins, slot 1 ----
|
||||
output wire [ADDR_WIDTH-1:0] s1_act_addr_a,
|
||||
output wire [ADDR_WIDTH-1:0] s1_act_addr_b,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] s1_act_data_a,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] s1_act_data_b,
|
||||
output wire signed [DATA_WIDTH-1:0] s1_result_data_a,
|
||||
output wire signed [DATA_WIDTH-1:0] s1_result_data_b,
|
||||
|
||||
// ---- real SDRAM pins ----
|
||||
output wire sdram_cke,
|
||||
output wire sdram_cs_n,
|
||||
output wire sdram_ras_n,
|
||||
output wire sdram_cas_n,
|
||||
output wire sdram_we_n,
|
||||
output wire [BANK_BITS-1:0] sdram_ba,
|
||||
output wire [ROW_BITS-1:0] sdram_a,
|
||||
inout wire [15:0] sdram_dq,
|
||||
output wire [1:0] sdram_dqm
|
||||
);
|
||||
localparam BUFADDRW = $clog2(LAYER_BYTES);
|
||||
|
||||
wire [N_SLOTS-1:0] slot_job_start;
|
||||
wire [ADDR_WIDTH*N_SLOTS-1:0] slot_x_base_a, slot_x_base_b, slot_w_base;
|
||||
wire [ADDR_WIDTH*N_SLOTS-1:0] slot_result_addr_a, slot_result_addr_b;
|
||||
wire [16*N_SLOTS-1:0] slot_n_tiles, slot_node_id_a, slot_node_id_b;
|
||||
wire [N_SLOTS-1:0] slot_job_done;
|
||||
wire [3:0] dir_state;
|
||||
wire dir_error;
|
||||
wire queue_empty;
|
||||
|
||||
neural_director_packed #(
|
||||
.ADDR_WIDTH(ADDR_WIDTH), .N_SLOTS(N_SLOTS), .QUEUE_DEPTH(QUEUE_DEPTH)
|
||||
) u_dir (
|
||||
.clk(clk), .rst(rst),
|
||||
.job_in_valid(job_in_valid), .job_in_ready(job_in_ready),
|
||||
.job_in_x_base(job_in_x_base), .job_in_w_base(job_in_w_base),
|
||||
.job_in_n_tiles(job_in_n_tiles), .job_in_result_addr(job_in_result_addr),
|
||||
.job_in_node_id(job_in_node_id),
|
||||
.slot_job_start(slot_job_start),
|
||||
.slot_x_base_a(slot_x_base_a), .slot_x_base_b(slot_x_base_b),
|
||||
.slot_w_base(slot_w_base), .slot_n_tiles(slot_n_tiles),
|
||||
.slot_result_addr_a(slot_result_addr_a), .slot_result_addr_b(slot_result_addr_b),
|
||||
.slot_node_id_a(slot_node_id_a), .slot_node_id_b(slot_node_id_b),
|
||||
.slot_job_done(slot_job_done),
|
||||
.job_out_done(job_out_done), .job_out_slot(job_out_slot),
|
||||
.dir_state(dir_state), .dir_error(dir_error), .queue_empty(queue_empty)
|
||||
);
|
||||
|
||||
wire [1:0] mem_active, mem_grant;
|
||||
wire [1:0] s_ctrl_req, s_ctrl_wr;
|
||||
wire [SDRAM_ADDR_WIDTH-1:0] s0_ctrl_addr, s1_ctrl_addr;
|
||||
wire [16*BURST_LEN-1:0] s0_ctrl_wdata, s1_ctrl_wdata;
|
||||
wire [2*BURST_LEN-1:0] s0_ctrl_wmask, s1_ctrl_wmask;
|
||||
wire [16*BURST_LEN-1:0] s0_ctrl_rdata, s1_ctrl_rdata;
|
||||
wire [1:0] s_ctrl_ready, s_ctrl_busy;
|
||||
|
||||
wire ctrl_req, ctrl_wr;
|
||||
wire [SDRAM_ADDR_WIDTH-1:0] ctrl_addr;
|
||||
wire [16*BURST_LEN-1:0] ctrl_wdata, ctrl_rdata;
|
||||
wire [2*BURST_LEN-1:0] ctrl_wmask;
|
||||
wire ctrl_ready, ctrl_busy;
|
||||
|
||||
sdram_slot_arbiter2 #(.ADDR_WIDTH(SDRAM_ADDR_WIDTH), .BURST_LEN(BURST_LEN)) u_arb (
|
||||
.clk(clk), .rst(rst),
|
||||
.slot0_active(mem_active[0]), .slot0_grant(mem_grant[0]),
|
||||
.slot0_req(s_ctrl_req[0]), .slot0_wr(s_ctrl_wr[0]),
|
||||
.slot0_addr(s0_ctrl_addr), .slot0_wdata(s0_ctrl_wdata), .slot0_wmask(s0_ctrl_wmask),
|
||||
.slot0_rdata(s0_ctrl_rdata), .slot0_ready(s_ctrl_ready[0]), .slot0_busy(s_ctrl_busy[0]),
|
||||
.slot1_active(mem_active[1]), .slot1_grant(mem_grant[1]),
|
||||
.slot1_req(s_ctrl_req[1]), .slot1_wr(s_ctrl_wr[1]),
|
||||
.slot1_addr(s1_ctrl_addr), .slot1_wdata(s1_ctrl_wdata), .slot1_wmask(s1_ctrl_wmask),
|
||||
.slot1_rdata(s1_ctrl_rdata), .slot1_ready(s_ctrl_ready[1]), .slot1_busy(s_ctrl_busy[1]),
|
||||
.ctrl_req(ctrl_req), .ctrl_wr(ctrl_wr), .ctrl_addr(ctrl_addr),
|
||||
.ctrl_wdata(ctrl_wdata), .ctrl_wmask(ctrl_wmask),
|
||||
.ctrl_rdata(ctrl_rdata), .ctrl_ready(ctrl_ready), .ctrl_busy(ctrl_busy)
|
||||
);
|
||||
|
||||
sdram_controller #(
|
||||
.CLK_FREQ_MHZ(64), .BURST_LEN(BURST_LEN),
|
||||
.ROW_BITS(ROW_BITS), .COL_BITS(COL_BITS), .BANK_BITS(BANK_BITS)
|
||||
) u_ctrl (
|
||||
.clk(clk), .rst(rst),
|
||||
.req(ctrl_req), .wr(ctrl_wr), .addr(ctrl_addr),
|
||||
.wdata(ctrl_wdata), .wmask(ctrl_wmask),
|
||||
.rdata(ctrl_rdata), .ready(ctrl_ready), .busy(ctrl_busy),
|
||||
.sdram_cke(sdram_cke), .sdram_cs_n(sdram_cs_n), .sdram_ras_n(sdram_ras_n),
|
||||
.sdram_cas_n(sdram_cas_n), .sdram_we_n(sdram_we_n),
|
||||
.sdram_ba(sdram_ba), .sdram_a(sdram_a), .sdram_dq(sdram_dq), .sdram_dqm(sdram_dqm)
|
||||
);
|
||||
|
||||
wire [15:0] s0_nid_a, s0_nid_b, s1_nid_a, s1_nid_b;
|
||||
wire [ADDR_WIDTH-1:0] s0_raddr_a, s0_raddr_b, s1_raddr_a, s1_raddr_b;
|
||||
|
||||
packed_slot #(
|
||||
.DATA_WIDTH(DATA_WIDTH), .P_IN(P_IN), .ACC_WIDTH(ACC_WIDTH),
|
||||
.BURST_LEN(BURST_LEN), .ADDR_WIDTH(ADDR_WIDTH), .LAYER_BYTES(LAYER_BYTES)
|
||||
) u_slot0 (
|
||||
.clk(clk), .rst(rst),
|
||||
.job_start(slot_job_start[0]),
|
||||
.x_base_a(slot_x_base_a[0*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.x_base_b(slot_x_base_b[0*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.w_base(slot_w_base[0*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.n_tiles(slot_n_tiles[0*16 +: 16]),
|
||||
.result_addr_a(slot_result_addr_a[0*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.result_addr_b(slot_result_addr_b[0*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.node_id_a(slot_node_id_a[0*16 +: 16]), .node_id_b(slot_node_id_b[0*16 +: 16]),
|
||||
.job_done(slot_job_done[0]),
|
||||
.result_data_a(s0_result_data_a), .result_data_b(s0_result_data_b),
|
||||
.result_node_id_a(s0_nid_a), .result_node_id_b(s0_nid_b),
|
||||
.result_addr_a_out(s0_raddr_a), .result_addr_b_out(s0_raddr_b),
|
||||
.mem_active(mem_active[0]), .mem_grant(mem_grant[0]),
|
||||
.act_tile_addr_a(s0_act_addr_a), .act_tile_addr_b(s0_act_addr_b),
|
||||
.act_tile_data_a(s0_act_data_a), .act_tile_data_b(s0_act_data_b),
|
||||
.ctrl_req(s_ctrl_req[0]), .ctrl_wr(s_ctrl_wr[0]), .ctrl_addr(s0_ctrl_addr),
|
||||
.ctrl_wdata(s0_ctrl_wdata), .ctrl_wmask(s0_ctrl_wmask),
|
||||
.ctrl_rdata(s0_ctrl_rdata), .ctrl_ready(s_ctrl_ready[0]), .ctrl_busy(s_ctrl_busy[0])
|
||||
);
|
||||
|
||||
packed_slot #(
|
||||
.DATA_WIDTH(DATA_WIDTH), .P_IN(P_IN), .ACC_WIDTH(ACC_WIDTH),
|
||||
.BURST_LEN(BURST_LEN), .ADDR_WIDTH(ADDR_WIDTH), .LAYER_BYTES(LAYER_BYTES)
|
||||
) u_slot1 (
|
||||
.clk(clk), .rst(rst),
|
||||
.job_start(slot_job_start[1]),
|
||||
.x_base_a(slot_x_base_a[1*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.x_base_b(slot_x_base_b[1*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.w_base(slot_w_base[1*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.n_tiles(slot_n_tiles[1*16 +: 16]),
|
||||
.result_addr_a(slot_result_addr_a[1*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.result_addr_b(slot_result_addr_b[1*ADDR_WIDTH +: ADDR_WIDTH]),
|
||||
.node_id_a(slot_node_id_a[1*16 +: 16]), .node_id_b(slot_node_id_b[1*16 +: 16]),
|
||||
.job_done(slot_job_done[1]),
|
||||
.result_data_a(s1_result_data_a), .result_data_b(s1_result_data_b),
|
||||
.result_node_id_a(s1_nid_a), .result_node_id_b(s1_nid_b),
|
||||
.result_addr_a_out(s1_raddr_a), .result_addr_b_out(s1_raddr_b),
|
||||
.mem_active(mem_active[1]), .mem_grant(mem_grant[1]),
|
||||
.act_tile_addr_a(s1_act_addr_a), .act_tile_addr_b(s1_act_addr_b),
|
||||
.act_tile_data_a(s1_act_data_a), .act_tile_data_b(s1_act_data_b),
|
||||
.ctrl_req(s_ctrl_req[1]), .ctrl_wr(s_ctrl_wr[1]), .ctrl_addr(s1_ctrl_addr),
|
||||
.ctrl_wdata(s1_ctrl_wdata), .ctrl_wmask(s1_ctrl_wmask),
|
||||
.ctrl_rdata(s1_ctrl_rdata), .ctrl_ready(s_ctrl_ready[1]), .ctrl_busy(s_ctrl_busy[1])
|
||||
);
|
||||
endmodule
|
||||
@@ -14,17 +14,30 @@
|
||||
// packed.v already expects (job_start/x_base_a/b/w_base/n_tiles/
|
||||
// node_id_a/b -> job_done/result_data_a/b/result_node_id_a/b).
|
||||
//
|
||||
// SCOPE LIMITATION (disclosed, matches this project's own established
|
||||
// precedent -- EXP-0058/0062's own header comments: "activation data
|
||||
// ... representing the activation/sliding-window path, which is a
|
||||
// separate, already-existing memory path not the subject of this
|
||||
// test"): activations are read through a WIDE, per-tile, combinational
|
||||
// stand-in port (act_tile_addr_a/b -> act_tile_data_a/b), mirroring
|
||||
// this project's own earlier ideal_memory_model.v-style staging
|
||||
// (establish the architectural contract before committing to a
|
||||
// specific real fetch engine). A real activation fetch engine
|
||||
// (analogous to weight_tile_gather.v, but for the sliding-window/
|
||||
// activation path) is a separate, later deliverable, NOT built here.
|
||||
// ACTIVATION FETCH (EXP-0079, real, closes the gap this header used to
|
||||
// disclose as deferred): act_tile_fetch.v reads each tile's activation
|
||||
// data DIRECTLY from the shared DDR3 bus, one tile at a time -- no
|
||||
// on-chip buffering/prefetch (unlike weights, activation data is read
|
||||
// exactly once per job, so buffering it would add complexity for zero
|
||||
// reuse benefit). It shares THIS slot's own single ctrl_req/addr/etc
|
||||
// port with layer_prefetch_ctrl.v (u_pf): the two are mutually
|
||||
// exclusive in time by FSM construction (weight prefetch always fully
|
||||
// completes, including its own consume_done, before the tile loop
|
||||
// that needs activation data ever starts), muxed below on act_mem_
|
||||
// active. The outer arbiter's grant (mem_active/mem_grant, this
|
||||
// module's own top-level ports) is now also needed during activation
|
||||
// fetch, not just weight prefetch -- held PER TILE (one 2-burst fetch,
|
||||
// lane A then lane B), released between tiles, matching this
|
||||
// project's own established "lock the grant for one whole logical
|
||||
// fetch, not longer" discipline (avoids starving the other slot for
|
||||
// the whole tile loop's duration).
|
||||
//
|
||||
// MEMORY LAYOUT this requires of activation data in DDR3: each tile
|
||||
// occupies its own full BURST_LEN=8-word burst slot (see act_tile_
|
||||
// fetch.v's own header for why -- avoiding a runtime-indexed part-
|
||||
// select, a known Fmax risk this project's already-thin P&R margin,
|
||||
// EXP-0078, can't afford right now). Documented for whoever prepares
|
||||
// host-side data layout in the physical realization doc.
|
||||
//
|
||||
// Also disclosed: no result-writeback engine exists yet either --
|
||||
// result_addr_a/b are passed through unused, for a future writeback
|
||||
@@ -72,18 +85,11 @@ module packed_slot #(
|
||||
output reg [ADDR_WIDTH-1:0] result_addr_b_out,
|
||||
|
||||
// high exactly while this slot needs exclusive access to the
|
||||
// shared SDRAM controller (its own weight-fetch phase) -- a
|
||||
// shared-controller arbiter uses this to lock a grant for the
|
||||
// whole multi-burst fetch, not just one transaction.
|
||||
// shared SDRAM controller (its own weight-fetch OR activation-
|
||||
// fetch phase) -- a shared-controller arbiter uses this to lock a
|
||||
// grant for the whole multi-burst fetch, not just one transaction.
|
||||
output wire mem_active,
|
||||
|
||||
// ---- activation stand-in port (see header -- real fetch engine
|
||||
// deferred) ----
|
||||
output reg [ADDR_WIDTH-1:0] act_tile_addr_a,
|
||||
output reg [ADDR_WIDTH-1:0] act_tile_addr_b,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] act_tile_data_a,
|
||||
input wire signed [DATA_WIDTH*P_IN-1:0] act_tile_data_b,
|
||||
|
||||
// grant from a shared-controller arbiter (see mem_active's own
|
||||
// comment): must be asserted before this slot may pulse its own
|
||||
// layer_prefetch_ctrl.v start, since that module's ctrl_req is a
|
||||
@@ -118,7 +124,6 @@ module packed_slot #(
|
||||
S_DONE = 4'd9;
|
||||
|
||||
reg [3:0] state;
|
||||
assign mem_active = (state == S_MEMWAIT) || (state == S_PREFETCH);
|
||||
reg [ADDR_WIDTH-1:0] w_base_lat, x_base_a_lat, x_base_b_lat;
|
||||
reg [15:0] n_tiles_lat;
|
||||
reg [ADDR_WIDTH-1:0] result_addr_a_lat, result_addr_b_lat;
|
||||
@@ -132,17 +137,58 @@ module packed_slot #(
|
||||
wire [BUFADDRW-1:0] pf_fill_addr;
|
||||
wire [DATA_WIDTH-1:0] pf_fill_data;
|
||||
|
||||
wire pf_ctrl_req, pf_ctrl_wr;
|
||||
wire [ADDR_WIDTH-2:0] pf_ctrl_addr;
|
||||
wire [16*BURST_LEN-1:0] pf_ctrl_wdata;
|
||||
wire [2*BURST_LEN-1:0] pf_ctrl_wmask;
|
||||
|
||||
layer_prefetch_ctrl #(
|
||||
.DATA_WIDTH(DATA_WIDTH), .LAYER_BYTES(LAYER_BYTES), .BURST_LEN(BURST_LEN), .ADDR_WIDTH(ADDR_WIDTH-1)
|
||||
) u_pf (
|
||||
.clk(clk), .rst(rst),
|
||||
.start(pf_start), .layer_base(w_base_lat[ADDR_WIDTH-2:0]), .busy(pf_busy), .done(pf_done),
|
||||
.fill_we(pf_fill_we), .fill_addr(pf_fill_addr), .fill_data(pf_fill_data),
|
||||
.ctrl_req(ctrl_req), .ctrl_wr(ctrl_wr), .ctrl_addr(ctrl_addr),
|
||||
.ctrl_wdata(ctrl_wdata), .ctrl_wmask(ctrl_wmask),
|
||||
.ctrl_req(pf_ctrl_req), .ctrl_wr(pf_ctrl_wr), .ctrl_addr(pf_ctrl_addr),
|
||||
.ctrl_wdata(pf_ctrl_wdata), .ctrl_wmask(pf_ctrl_wmask),
|
||||
.ctrl_rdata(ctrl_rdata), .ctrl_ready(ctrl_ready), .ctrl_busy(ctrl_busy)
|
||||
);
|
||||
|
||||
// ---- act_tile_fetch.v (EXP-0079): real activation fetch, shares
|
||||
// this slot's own ctrl port with u_pf above (mutually exclusive in
|
||||
// time -- see header) ----
|
||||
reg act_req;
|
||||
wire act_valid;
|
||||
wire signed [DATA_WIDTH*P_IN-1:0] act_data_a_w, act_data_b_w;
|
||||
wire act_mem_active;
|
||||
|
||||
wire act_ctrl_req, act_ctrl_wr;
|
||||
wire [ADDR_WIDTH-2:0] act_ctrl_addr;
|
||||
wire [16*BURST_LEN-1:0] act_ctrl_wdata;
|
||||
wire [2*BURST_LEN-1:0] act_ctrl_wmask;
|
||||
|
||||
act_tile_fetch #(
|
||||
.DATA_WIDTH(DATA_WIDTH), .P_IN(P_IN), .BURST_LEN(BURST_LEN), .ADDR_WIDTH(ADDR_WIDTH-1)
|
||||
) u_act (
|
||||
.clk(clk), .rst(rst),
|
||||
.req(act_req), .base_a(x_base_a_lat[ADDR_WIDTH-2:0]), .base_b(x_base_b_lat[ADDR_WIDTH-2:0]),
|
||||
.tcnt(tcnt), .valid(act_valid), .data_a(act_data_a_w), .data_b(act_data_b_w),
|
||||
.mem_active(act_mem_active), .mem_grant(mem_grant),
|
||||
.ctrl_req(act_ctrl_req), .ctrl_wr(act_ctrl_wr), .ctrl_addr(act_ctrl_addr),
|
||||
.ctrl_wdata(act_ctrl_wdata), .ctrl_wmask(act_ctrl_wmask),
|
||||
.ctrl_rdata(ctrl_rdata), .ctrl_ready(ctrl_ready), .ctrl_busy(ctrl_busy)
|
||||
);
|
||||
|
||||
// mutually exclusive by FSM construction (weight prefetch always
|
||||
// fully completes, incl. consume_done, before the tile loop that
|
||||
// triggers act_req ever starts) -- safe to select on act_mem_active alone.
|
||||
assign ctrl_req = act_mem_active ? act_ctrl_req : pf_ctrl_req;
|
||||
assign ctrl_wr = act_mem_active ? act_ctrl_wr : pf_ctrl_wr;
|
||||
assign ctrl_addr = act_mem_active ? act_ctrl_addr : pf_ctrl_addr;
|
||||
assign ctrl_wdata = act_mem_active ? act_ctrl_wdata : pf_ctrl_wdata;
|
||||
assign ctrl_wmask = act_mem_active ? act_ctrl_wmask : pf_ctrl_wmask;
|
||||
|
||||
assign mem_active = (state == S_MEMWAIT) || (state == S_PREFETCH) || act_mem_active;
|
||||
|
||||
// ---- layer_weight_buffer.v ----
|
||||
wire [BUFADDRW-1:0] lwb_rd_addr;
|
||||
wire [DATA_WIDTH-1:0] lwb_rd_data;
|
||||
@@ -158,6 +204,7 @@ module packed_slot #(
|
||||
// ---- weight_tile_gather.v ----
|
||||
reg tile_req;
|
||||
reg [BUFADDRW-1:0] tile_base;
|
||||
reg tile_seen, act_seen; // S_TILEWAIT join latches (weight vs activation, see header)
|
||||
wire tile_valid;
|
||||
wire [DATA_WIDTH*P_IN-1:0] tile_data;
|
||||
|
||||
@@ -214,6 +261,9 @@ module packed_slot #(
|
||||
pf_start <= 1'b0;
|
||||
consume_done <= 1'b0;
|
||||
tile_req <= 1'b0;
|
||||
act_req <= 1'b0;
|
||||
tile_seen <= 1'b0;
|
||||
act_seen <= 1'b0;
|
||||
job_valid_np <= 1'b0;
|
||||
operand_valid<= 1'b0;
|
||||
tile_last <= 1'b0;
|
||||
@@ -226,6 +276,7 @@ module packed_slot #(
|
||||
pf_start <= 1'b0;
|
||||
consume_done <= 1'b0;
|
||||
tile_req <= 1'b0;
|
||||
act_req <= 1'b0;
|
||||
|
||||
case (state)
|
||||
S_IDLE: begin
|
||||
@@ -278,19 +329,33 @@ module packed_slot #(
|
||||
S_TILEREQ: begin
|
||||
tile_req <= 1'b1;
|
||||
tile_base <= tcnt[BUFADDRW-1:0]*P_IN[BUFADDRW-1:0];
|
||||
act_tile_addr_a <= x_base_a_lat + {{(ADDR_WIDTH-16){1'b0}}, tcnt};
|
||||
act_tile_addr_b <= x_base_b_lat + {{(ADDR_WIDTH-16){1'b0}}, tcnt};
|
||||
act_req <= 1'b1;
|
||||
tile_seen <= 1'b0;
|
||||
act_seen <= 1'b0;
|
||||
state <= S_TILEWAIT;
|
||||
end
|
||||
|
||||
// Real join: weight_tile_gather.v's tile_valid (fast,
|
||||
// on-chip) and act_tile_fetch.v's act_valid (real
|
||||
// DDR3 latency, 2 bursts) do NOT arrive on the same
|
||||
// cycle in general -- latch whichever comes first,
|
||||
// proceed only once BOTH have been seen. Handles
|
||||
// either arrival order correctly, not just the
|
||||
// expected-common one (weight first).
|
||||
S_TILEWAIT: begin
|
||||
if (tile_valid) begin
|
||||
weight_data_r <= tile_data;
|
||||
input_data_a_r <= act_tile_data_a;
|
||||
input_data_b_r <= act_tile_data_b;
|
||||
tile_last <= (tcnt == n_tiles_lat - 16'd1);
|
||||
operand_valid <= 1'b1;
|
||||
state <= S_OPERAND;
|
||||
weight_data_r <= tile_data;
|
||||
tile_seen <= 1'b1;
|
||||
end
|
||||
if (act_valid) begin
|
||||
input_data_a_r <= act_data_a_w;
|
||||
input_data_b_r <= act_data_b_w;
|
||||
act_seen <= 1'b1;
|
||||
end
|
||||
if ((tile_valid || tile_seen) && (act_valid || act_seen)) begin
|
||||
tile_last <= (tcnt == n_tiles_lat - 16'd1);
|
||||
operand_valid <= 1'b1;
|
||||
state <= S_OPERAND;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user