diff --git a/ci/baselines/perf/dxa.json b/ci/baselines/perf/dxa.json index 9c42109c5f..f8b2d3ce3a 100644 --- a/ci/baselines/perf/dxa.json +++ b/ci/baselines/perf/dxa.json @@ -76,6 +76,17 @@ "configs": "-DVX_CFG_EXT_DXA_ENABLE -DVX_CFG_NUM_THREADS=4", "driver": "rtlsim" }, + "dxa:perf_gate-wgmma-dxa-lsu2:rtlsim": { + "32": { + "cycles": 39426, + "instrs": 6840 + }, + "app": "sgemm_tcu_wg_dxa", + "args": "-m 128 -n 128 -k 64", + "config_hash": "f49d8ef4553b4dca", + "configs": "-DVX_CFG_ISSUE_WIDTH=2 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=32 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=2 -DVX_CFG_NUM_FPU_BLOCKS=1 -DVX_CFG_NUM_WARPS=8 -DVX_CFG_NUM_THREADS=32", + "driver": "rtlsim" + }, "dxa:perf_gate-wgmma-dxa-mcast-nt16:rtlsim": { "32": { "cycles": 81041, diff --git a/ci/baselines/synthesis/beacon/core.json b/ci/baselines/synthesis/beacon/core.json index 3f207c971a..66ef039802 100644 --- a/ci/baselines/synthesis/beacon/core.json +++ b/ci/baselines/synthesis/beacon/core.json @@ -266,7 +266,7 @@ "dut": "lmem", "result": { "bram": 16.0, - "build_time_s": 15, + "build_time_s": 25, "deep_endpoints": 0, "deepest_paths": [ "9 lmem_unit/g_data_store_0.bank/g_amo.amo_old_r[0] -> lmem_unit/g_data_store_0.bank/g_dual_port.lmem_store/g_bram.g_wren.ram.wd[0]", @@ -281,27 +281,27 @@ "9 lmem_unit/g_data_store_0.bank/g_amo.amo_old_r[0] -> lmem_unit/g_data_store_0.bank/g_dual_port.lmem_store/g_bram.g_wren.ram.wd[9]" ], "dsp": 0, - "endpoints": 17366, + "endpoints": 17390, "env": { "beacon": "beacon 134d03b9e", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 14361, + "ff": 14407, "fix_levels": 12, "interfaces": {}, - "lut": 18880, + "lut": 18949, "lutram": 726, "max_levels": 9, - "pred_fmax_mhz": 324.3, + "pred_fmax_mhz": 326.2, "risk_endpoints": 0, "tied_bits": 17, "tied_ports": [ { "bits": 17, - "port": "dma_req_buf.data_in", - "width": 607 + "port": "dma_rd_buf.data_in", + "width": 31 } ], "units": { diff --git a/ci/baselines/synthesis/beacon/tensor.json b/ci/baselines/synthesis/beacon/tensor.json index cdec9428b7..f7586ba6e4 100644 --- a/ci/baselines/synthesis/beacon/tensor.json +++ b/ci/baselines/synthesis/beacon/tensor.json @@ -68,7 +68,7 @@ "dut": "tensor", "result": { "bram": 114.5, - "build_time_s": 115, + "build_time_s": 150, "deep_endpoints": 3267, "deepest_paths": [ "24 g_cores_0.tcu_unit/g_blocks_0.tcu_block/tcu_core/g_i_0.g_j_0.pe/fedp/pipe_acc/g_pipe.g_no_reset.pipe[39] -> g_cores_0.tcu_unit/g_blocks_0.tcu_block/tcu_core/g_i_0.g_j_0.pe/fedp/pipe_norm_round/g_pipe.g_no_reset.pipe.d[0]", @@ -83,21 +83,21 @@ "24 g_cores_0.tcu_unit/g_blocks_0.tcu_block/tcu_core/g_i_0.g_j_0.pe/fedp/pipe_acc/g_pipe.g_no_reset.pipe[39] -> g_cores_0.tcu_unit/g_blocks_0.tcu_block/tcu_core/g_i_0.g_j_0.pe/fedp/pipe_norm_round/g_pipe.g_no_reset.pipe.d[9]" ], "dsp": 267, - "endpoints": 170268, + "endpoints": 170251, "env": { "beacon": "beacon 134d03b9e", "circt": "CIRCT 90c5fd313", "device": "xcu55c-fsvh2892-2L-e", "xlen": 32 }, - "ff": 161727, + "ff": 161725, "fix_levels": 12, "interfaces": {}, - "lut": 260500, + "lut": 260100, "lutram": 12675, "max_levels": 24, "pred_fmax_mhz": 261.3, - "risk_endpoints": 200, + "risk_endpoints": 201, "tied_bits": 4, "tied_ports": [ { @@ -139,7 +139,7 @@ "g_cores_*_g_lsu_mem_path_*_mem_path/g_coalescing_mem_coalescer/req_ibuf/allocator": 11, "g_cores_*_g_lsu_mem_path_*_mem_path/lsu_scheduler/mem_scheduler/g_req_queue_rw_req_queue/g_ebN_fifo_queue": 9, "g_cores_*_g_lsu_mem_path_*_mem_path/lsu_scheduler/mem_scheduler/req_ibuf/allocator": 10, - "g_cores_*_mem_unit/g_lmem_dma_dxa_completion_detect/compl_fifo/pending_size": 8, + "g_cores_*_mem_unit/dxa_completion_detect/compl_fifo/pending_size": 8, "g_cores_*_mem_unit/lmem_unit/g_data_store_*_bank/g_single_port_lmem_store": 9, "g_cores_*_tcu_shared/wgmma": 9, "g_cores_*_tcu_shared/wgmma/tbuf/bbuf": 16, diff --git a/ci/baselines/synthesis/beacon_asic/core.json b/ci/baselines/synthesis/beacon_asic/core.json index ccb2e346c8..ffd31c4848 100644 --- a/ci/baselines/synthesis/beacon_asic/core.json +++ b/ci/baselines/synthesis/beacon_asic/core.json @@ -68,16 +68,16 @@ "configs": "-DVX_CFG_NUM_THREADS=16 -DVX_CFG_ISSUE_WIDTH=2 -DVX_CFG_EXT_A_ENABLE", "dut": "lmem", "result": { - "build_time_s": 15, - "cells": 120296, - "endpoints": 18134, + "build_time_s": 25, + "cells": 120509, + "endpoints": 18158, "env": { "beacon": "beacon 134d03b9e", "circt": "CIRCT 90c5fd313", "pdk": "asap7", "xlen": 32 }, - "ff": 23721, + "ff": 23767, "fmax_mhz": 1692.0, "macros": 32, "max_stages": 15, @@ -88,8 +88,8 @@ "tied_ports": [ { "bits": 17, - "port": "dma_req_buf.data_in", - "width": 607 + "port": "dma_rd_buf.data_in", + "width": 31 } ] } diff --git a/ci/baselines/synthesis/beacon_asic/tensor.json b/ci/baselines/synthesis/beacon_asic/tensor.json index a3142ff674..24e05c23eb 100644 --- a/ci/baselines/synthesis/beacon_asic/tensor.json +++ b/ci/baselines/synthesis/beacon_asic/tensor.json @@ -31,16 +31,16 @@ "configs": "-DVX_CFG_NUM_THREADS=8 -DVX_CFG_NUM_WARPS=8", "dut": "tensor", "result": { - "build_time_s": 85, - "cells": 838075, - "endpoints": 89487, + "build_time_s": 130, + "cells": 837473, + "endpoints": 89470, "env": { "beacon": "beacon 134d03b9e", "circt": "CIRCT 90c5fd313", "pdk": "asap7", "xlen": 32 }, - "ff": 166953, + "ff": 166951, "fmax_mhz": 977.5, "macros": 34, "max_stages": 33, diff --git a/ci/testcases/dxa.yaml b/ci/testcases/dxa.yaml index cc7e8e33fc..9f3aeadc58 100644 --- a/ci/testcases/dxa.yaml +++ b/ci/testcases/dxa.yaml @@ -662,6 +662,22 @@ tests: configs: -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=16 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=1 -DVX_CFG_NUM_FPU_BLOCKS=1 # Not warp-width swept: a warp-group MMA is defined over a 32-lane warp. shape: {threads: 32, warps: 8} +# Two LSU blocks: the TCU's operand reads use the local memory's second bank +# port and run beside the DXA's writes. +- id: model_parity-wgmma-dxa-lsu2 + check: model_parity + via: blackbox + app: sgemm_tcu_wg_dxa + args: -m 128 -n 128 -k 64 + configs: -DVX_CFG_ISSUE_WIDTH=2 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=32 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=2 -DVX_CFG_NUM_FPU_BLOCKS=1 + shape: {threads: 32, warps: 8} +- id: perf_gate-wgmma-dxa-lsu2 + check: perf_gate + via: blackbox + app: sgemm_tcu_wg_dxa + args: -m 128 -n 128 -k 64 + configs: -DVX_CFG_ISSUE_WIDTH=2 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=32 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=2 -DVX_CFG_NUM_FPU_BLOCKS=1 + shape: {threads: 32, warps: 8} # Sparse WGMMA consumer fed by a DXA producer pipeline. - id: model_parity-wgmma-sp-dxa check: model_parity @@ -672,6 +688,13 @@ tests: # several times the size, and a hosted CI runner cannot build it in a job. configs: -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_TCU_SPARSE_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=32 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=1 -DVX_CFG_NUM_FPU_BLOCKS=1 shape: {threads: 32, warps: 8} +- id: model_parity-wgmma-sp-dxa-lsu2 + check: model_parity + via: blackbox + app: sgemm_tcu_wg_sp_dxa + args: -m 128 -n 128 -k 128 + configs: -DVX_CFG_ISSUE_WIDTH=2 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DVX_CFG_TCU_SPARSE_ENABLE -DVX_CFG_EXT_DXA_ENABLE -DWGMMA_NRC=32 -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=2 -DVX_CFG_NUM_FPU_BLOCKS=1 + shape: {threads: 32, warps: 8} - id: perf_gate-wgmma-sp-dxa check: perf_gate via: blackbox diff --git a/docs/designs/dxa_async_copy_multicast.md b/docs/designs/dxa_async_copy_multicast.md index 2e4f9a2270..f23282f48d 100644 --- a/docs/designs/dxa_async_copy_multicast.md +++ b/docs/designs/dxa_async_copy_multicast.md @@ -135,14 +135,14 @@ queue out to `NUM_DXA_UNITS` workers. walk replays each receiver's writes at `+r·smem_stride` — **serial**, `popcount(mask)` beats/word — and the last write per receiver sets `attr = {notify, bar_addr + (idx< 0) begin : g_lmem_dma - - VX_mem_bus_if #( - .DATA_SIZE (LMEM_DMA_DATA_SIZE), - .TAG_WIDTH (LMEM_DMA_IN_TAG_W), - .ATTR_WIDTH (LMEM_DMA_ATTR_W), - .ADDR_WIDTH (LMEM_DMA_ADDR_WIDTH) - ) dma_arb_in_if[LMEM_DMA_INPUTS](); - - VX_mem_bus_if #( - .DATA_SIZE (LMEM_DMA_DATA_SIZE), - .TAG_WIDTH (LMEM_DMA_TAG_WIDTH), - .ATTR_WIDTH (LMEM_DMA_ATTR_W), - .ADDR_WIDTH (LMEM_DMA_ADDR_WIDTH) - ) dma_arb_out_if[1](); - - // Wire DXA and/or TCU into the arbiter input array. - `ifdef VX_CFG_EXT_DXA_ENABLE - // DXA issues LMEM-relative word addresses directly (issuer_lmem_base + intra, - // with multicast replay adding r×smem_stride per beat), so no per-slot - // address translation is needed here. - VX_mem_bus_connect dma_arb_in_lmem_dma_dxa_idx_connect ( - .bus_in_if (dxa_lmem_bus_if), - .bus_out_if (dma_arb_in_if[LMEM_DMA_DXA_IDX]) - ); - `endif - `ifdef VX_CFG_TCU_WGMMA_ENABLE - VX_mem_bus_connect dma_arb_in_lmem_dma_tcu_idx_connect ( - .bus_in_if (tcu_lmem_if), - .bus_out_if (dma_arb_in_if[LMEM_DMA_TCU_IDX]) - ); - `endif - - // Round-robin, so a DXA write stream cannot starve the TCU's operand reads. - VX_mem_bus_arb #( - .NUM_INPUTS (LMEM_DMA_INPUTS), - .NUM_OUTPUTS (1), - .DATA_SIZE (LMEM_DMA_DATA_SIZE), - .TAG_WIDTH (LMEM_DMA_IN_TAG_W), - .ATTR_WIDTH (LMEM_DMA_ATTR_W), - .ADDR_WIDTH (LMEM_DMA_ADDR_WIDTH), - .ARBITER ("R") - ) lmem_dma_arb ( - .clk (clk), - .reset (reset), - .bus_in_if (dma_arb_in_if), - .bus_out_if (dma_arb_out_if) - ); + VX_mem_bus_if #( + .DATA_SIZE (LMEM_DMA_DATA_SIZE), + .TAG_WIDTH (LMEM_DMA_RD_TAG_W), + .ATTR_WIDTH (LMEM_DMA_ATTR_W), + .ADDR_WIDTH (LMEM_DMA_ADDR_WIDTH) + ) lmem_dma_rd_if(); - VX_mem_bus_connect lmem_dma_connect ( - .bus_in_if (dma_arb_out_if[0]), - .bus_out_if (lmem_dma_if) - ); +`ifdef VX_CFG_EXT_DXA_ENABLE + // DXA issues LMEM-relative word addresses directly (issuer_lmem_base + intra, + // with multicast replay adding r×smem_stride per beat), so no per-slot + // address translation is needed here. + VX_mem_bus_connect lmem_dma_wr_connect ( + .bus_in_if (dxa_lmem_bus_if), + .bus_out_if (lmem_dma_wr_if) + ); - `ifdef VX_CFG_EXT_DXA_ENABLE - wire [`VX_CFG_LMEM_NUM_BANKS-1:0] dxa_bank_wr_fire; - for (genvar i = 0; i < `VX_CFG_LMEM_NUM_BANKS; ++i) begin : g_dxa_bank_wr_fire - assign dxa_bank_wr_fire[i] = lmem_dma_if.req_valid - && lmem_dma_if.req_ready - && lmem_dma_if.req_data.rw - && (|lmem_dma_if.req_data.byteen[i*LSU_MEM_WORD_SIZE +: LSU_MEM_WORD_SIZE]); - end + wire [`VX_CFG_LMEM_NUM_BANKS-1:0] dxa_bank_wr_fire; + for (genvar i = 0; i < `VX_CFG_LMEM_NUM_BANKS; ++i) begin : g_dxa_bank_wr_fire + assign dxa_bank_wr_fire[i] = lmem_dma_wr_if.req_valid + && lmem_dma_wr_if.req_ready + && (|lmem_dma_wr_if.req_data.byteen[i*LSU_MEM_WORD_SIZE +: LSU_MEM_WORD_SIZE]); + end - VX_dxa_completion #( - .INSTANCE_ID (`SFORMATF(("%s-lmem-dma-compl_det", INSTANCE_ID))), - .NUM_BANKS (`VX_CFG_LMEM_NUM_BANKS), - .ATTR_WIDTH (DXA_LMEM_ATTR_W) - ) dxa_completion_detect ( - .clk (clk), - .reset (reset), - .bank_wr_fire (dxa_bank_wr_fire), - .bank_wr_attr (DXA_LMEM_ATTR_W'(lmem_dma_if.req_data.attr)), - .txbar_bus_if (dxa_txbar_bus_if) - ); + VX_dxa_completion #( + .INSTANCE_ID (`SFORMATF(("%s-lmem-dma-compl_det", INSTANCE_ID))), + .NUM_BANKS (`VX_CFG_LMEM_NUM_BANKS), + .ATTR_WIDTH (DXA_LMEM_ATTR_W) + ) dxa_completion_detect ( + .clk (clk), + .reset (reset), + .bank_wr_fire (dxa_bank_wr_fire), + .bank_wr_attr (DXA_LMEM_ATTR_W'(lmem_dma_wr_if.req_data.attr)), + .txbar_bus_if (dxa_txbar_bus_if) + ); - `ifdef DBG_TRACE_DXA - always @(posedge clk) begin - if (dxa_txbar_bus_if.valid && !reset) begin - `TRACE(2, ("%t: %s-lmem-dma: dxa_txbar valid=1, bar_addr=0x%0h, ready=%b\n", - $time, INSTANCE_ID, dxa_txbar_bus_if.data.addr, dxa_txbar_bus_if.ready)) - end + `ifdef DBG_TRACE_DXA + always @(posedge clk) begin + if (dxa_txbar_bus_if.valid && !reset) begin + `TRACE(2, ("%t: %s-lmem-dma: dxa_txbar valid=1, bar_addr=0x%0h, ready=%b\n", + $time, INSTANCE_ID, dxa_txbar_bus_if.data.addr, dxa_txbar_bus_if.ready)) end - `endif - + end `endif +`else + assign lmem_dma_wr_if.req_valid = 1'b0; + assign lmem_dma_wr_if.req_data = '0; + assign lmem_dma_wr_if.rsp_ready = 1'b0; + `UNUSED_VAR (lmem_dma_wr_if.req_ready) + `UNUSED_VAR (lmem_dma_wr_if.rsp_valid) + `UNUSED_VAR (lmem_dma_wr_if.rsp_data) +`endif - end else begin : g_no_lmem_dma - - assign lmem_dma_if.req_valid = 1'b0; - assign lmem_dma_if.req_data = '0; - `UNUSED_VAR (lmem_dma_if.req_ready) - - `UNUSED_VAR (lmem_dma_if.rsp_valid) - `UNUSED_VAR (lmem_dma_if.rsp_data) - assign lmem_dma_if.rsp_ready = 1'b0; - - end +`ifdef VX_CFG_TCU_WGMMA_ENABLE + VX_mem_bus_connect lmem_dma_rd_connect ( + .bus_in_if (tcu_lmem_if), + .bus_out_if (lmem_dma_rd_if) + ); +`else + assign lmem_dma_rd_if.req_valid = 1'b0; + assign lmem_dma_rd_if.req_data = '0; + assign lmem_dma_rd_if.rsp_ready = 1'b0; + `UNUSED_VAR (lmem_dma_rd_if.req_ready) + `UNUSED_VAR (lmem_dma_rd_if.rsp_valid) + `UNUSED_VAR (lmem_dma_rd_if.rsp_data) +`endif VX_lmem_unit #( .INSTANCE_ID (`SFORMATF(("%s-lmem", INSTANCE_ID))), @@ -189,8 +156,9 @@ module VX_mem_unit import VX_gpu_pkg::*; #( .LANE_SIZE (LSU_WORD_SIZE), .ADDR_WIDTH (LMEM_ADDR_WIDTH), .TAG_WIDTH (LSU_TAG_WIDTH), - .DMA_ENABLE (LMEM_DMA_EN), - .DMA_TAG_WIDTH (LMEM_DMA_TAG_WIDTH), + .DMA_WR_ENABLE (`VX_CFG_EXT_DXA_ENABLED), + .DMA_RD_ENABLE (`VX_CFG_TCU_WGMMA_ENABLED), + .DMA_TAG_WIDTH (LMEM_DMA_RD_TAG_W), .AMO_ENABLE (`VX_CFG_EXT_A_ENABLED) ) lmem_unit ( .clk (clk), @@ -199,7 +167,8 @@ module VX_mem_unit import VX_gpu_pkg::*; #( .lmem_perf (lmem_perf), `endif .lsu_mem_if (lmem_if), - .dma_bus_if (lmem_dma_if) + .dma_wr_if (lmem_dma_wr_if), + .dma_rd_if (lmem_dma_rd_if) ); `else diff --git a/hw/rtl/mem/VX_lmem_unit.sv b/hw/rtl/mem/VX_lmem_unit.sv index a990750b95..8545db551e 100644 --- a/hw/rtl/mem/VX_lmem_unit.sv +++ b/hw/rtl/mem/VX_lmem_unit.sv @@ -27,11 +27,17 @@ // the first engine may be taking one. A write therefore never meets a read of // the other port in a bank, and keeps its order against every read. // -// The DMA port (DXA writes, TCU reads) takes whole bank rows. A DMA request seen -// in one cycle gets the banks the next: no pass is issued in a cycle a DMA -// request is seen, and it is accepted in the cycle that follows. An atomic owns -// its bank for three cycles (read, capture, write back), so no pass or DMA access -// is issued in the two cycles after an atomic pass. +// Agents other than the LSU (the DXA writing, the TCU reading) take whole bank +// rows through two DMA ports, one for row writes and one for row reads. A DMA +// request seen in one cycle gets the banks the next: no pass is issued in a +// cycle a DMA request is seen, and it is accepted in the cycle that follows. +// With both ports and several LSU blocks, row reads use the banks' second port, +// so a row write and a row read go through in the same cycle; a read of the +// row written in that cycle returns undefined data, as a race the kernel's +// barrier rules out. With one LSU block the banks are single-ported, and the +// two alternate. +// An atomic owns its bank for three cycles (read, capture, write back), so no +// pass or DMA access is issued in the two cycles after an atomic pass. module VX_lmem_unit import VX_gpu_pkg::*; #( parameter `STRING INSTANCE_ID = "", @@ -52,8 +58,10 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( // Request tag size parameter TAG_WIDTH = 16, - // Enable DMA port - parameter DMA_ENABLE = 0, + // Enable the DMA row-write and row-read ports + parameter DMA_WR_ENABLE = 0, + parameter DMA_RD_ENABLE = 0, + // Row-read tag size parameter DMA_TAG_WIDTH = 1, // Synthesize atomic-op + LR/SC logic in the banks @@ -69,8 +77,9 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( // LSU blocks' warp requests VX_lsu_mem_if.slave lsu_mem_if [NUM_BLOCKS], - // DMA read/write port - VX_mem_bus_if.slave dma_bus_if + // DMA row writes and row reads + VX_mem_bus_if.slave dma_wr_if, + VX_mem_bus_if.slave dma_rd_if ); `UNUSED_SPARAM (INSTANCE_ID) @@ -81,6 +90,10 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( localparam BLOCK_BITS = `CLOG2(NUM_BLOCKS); localparam BLOCK_WIDTH = `UP(BLOCK_BITS); localparam DUAL = (NUM_BLOCKS > 1); + // With both DMA ports, row reads take the banks' second port when there is + // one, and otherwise alternate with row writes on the first. + localparam DMA_RD_PORT_B = DMA_WR_ENABLE && DMA_RD_ENABLE && DUAL; + localparam DMA_SHARED = DMA_WR_ENABLE && DMA_RD_ENABLE && !DUAL; // A pass's response reaches its block's response register four cycles // after the pass at the earliest, and its slot is free for a pass the cycle // after the block takes it: eight slots keep one pass per cycle going. @@ -519,30 +532,116 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( end end - wire dma_valid = DMA_ENABLE && dma_bus_if.req_valid; + // A row read for port B is taken into a register as it arrives and fires + // from it in the next cycle's slot, so port B's read enable and address + // come from registers only. Elsewhere a row read fires from the port. + wire dma_rd_req_valid; + wire [BANK_ADDR_WIDTH-1:0] dma_rd_addr; + wire [DMA_TAG_WIDTH-1:0] dma_rd_tag; + + wire dma_wr_valid = DMA_WR_ENABLE && dma_wr_if.req_valid; + wire dma_rd_valid = DMA_RD_ENABLE && (dma_rd_if.req_valid || (DMA_RD_PORT_B && dma_rd_req_valid)); + // A DMA request of either port keeps passes off the banks, so the next + // cycle the banks are free for both ports. reg dma_slot_r; always @(posedge clk) begin if (reset) begin dma_slot_r <= 1'b0; end else begin - dma_slot_r <= dma_valid && ~amo_stall; + dma_slot_r <= (dma_wr_valid || dma_rd_valid) && ~amo_stall; end end - assign pass_en = ~dma_valid && ~amo_stall; + assign pass_en = ~dma_wr_valid && ~dma_rd_valid && ~amo_stall; - // DMA port handshake - // rw=0 reads : accepted when the response pipe-buffer has space. - // rw=1 writes : no response issued. + // A row write issues no response; a row read is accepted when the + // response pipe-buffer has space. wire dma_rsp_buf_ready; - wire dma_fire = dma_slot_r && dma_valid && (dma_bus_if.req_data.rw || dma_rsp_buf_ready); - wire dma_rd_fire = dma_fire && ~dma_bus_if.req_data.rw; - wire [NUM_BANKS-1:0][WORD_WIDTH-1:0] per_bank_rdata_a; + wire dma_wr_can = dma_slot_r && dma_wr_valid; + wire dma_rd_can = dma_slot_r && dma_rd_req_valid && dma_rsp_buf_ready; + wire dma_wr_grant; + wire dma_rd_grant; + wire dma_wr_fire = dma_wr_can && dma_wr_grant; + wire dma_rd_fire = dma_rd_can && dma_rd_grant; + if (DMA_SHARED) begin : g_dma_rr + // one bank port: round-robin between row writes and row reads, the + // side served last yielding to the other + reg rd_first_r; + always @(posedge clk) begin + if (reset) begin + rd_first_r <= 1'b0; + end else if (dma_wr_fire || dma_rd_fire) begin + rd_first_r <= dma_wr_fire; + end + end + assign dma_wr_grant = ~(dma_rd_can && rd_first_r); + assign dma_rd_grant = ~(dma_wr_can && ~rd_first_r); + end else begin : g_dma_no_rr + assign dma_wr_grant = 1'b1; + assign dma_rd_grant = 1'b1; + end + // A row read on port A when the banks have no second port for it. + wire dma_rd_a = !DMA_RD_PORT_B && dma_rd_fire; + wire dma_rd_b = DMA_RD_PORT_B && dma_rd_fire; + wire [BANK_ADDR_WIDTH-1:0] dma_wr_addr = BANK_ADDR_WIDTH'(dma_wr_if.req_data.addr); - if (DMA_ENABLE) begin : g_dma_enable - `UNUSED_VAR (dma_bus_if.req_data.attr) + wire [NUM_BANKS-1:0][WORD_WIDTH-1:0] per_bank_rdata_a; + wire [NUM_BANKS-1:0][WORD_WIDTH-1:0] per_bank_rdata_b; + wire [NUM_BANKS-1:0][WORD_WIDTH-1:0] per_bank_rdata_dma = DMA_RD_PORT_B ? per_bank_rdata_b : per_bank_rdata_a; + + if (DMA_WR_ENABLE) begin : g_dma_wr + `UNUSED_VAR (dma_wr_if.req_data.attr) + `UNUSED_VAR (dma_wr_if.req_data.tag) + `UNUSED_VAR (dma_wr_if.req_data.rw) + `UNUSED_VAR (dma_wr_if.rsp_ready) + `RUNTIME_ASSERT(~dma_wr_if.req_valid || dma_wr_if.req_data.rw, ("%t: *** %s DMA row-write port given a read", $time, INSTANCE_ID)) + assign dma_wr_if.req_ready = dma_slot_r && dma_wr_grant; + assign dma_wr_if.rsp_valid = 1'b0; + assign dma_wr_if.rsp_data = '0; + end else begin : g_no_dma_wr + assign dma_wr_if.req_ready = 1'b0; + assign dma_wr_if.rsp_valid = 1'b0; + assign dma_wr_if.rsp_data = '0; + `UNUSED_VAR (dma_wr_if.req_valid) + `UNUSED_VAR (dma_wr_if.req_data) + `UNUSED_VAR (dma_wr_if.rsp_ready) + end - assign dma_bus_if.req_ready = dma_slot_r && (dma_bus_if.req_data.rw || dma_rsp_buf_ready); + if (DMA_RD_ENABLE) begin : g_dma_rd + `UNUSED_VAR (dma_rd_if.req_data.attr) + `UNUSED_VAR (dma_rd_if.req_data.data) + `UNUSED_VAR (dma_rd_if.req_data.byteen) + `UNUSED_VAR (dma_rd_if.req_data.rw) + `RUNTIME_ASSERT(~dma_rd_if.req_valid || ~dma_rd_if.req_data.rw, ("%t: *** %s DMA row-read port given a write", $time, INSTANCE_ID)) + + if (DMA_RD_PORT_B) begin : g_rd_reg + // Taken whenever the register is free or its read fires, which is + // the cycle before the read could fire straight from the port. + reg rd_valid_r; + reg [BANK_ADDR_WIDTH-1:0] rd_addr_r; + reg [DMA_TAG_WIDTH-1:0] rd_tag_r; + wire rd_take = ~rd_valid_r || dma_rd_fire; + always @(posedge clk) begin + if (reset) begin + rd_valid_r <= 1'b0; + end else if (rd_take) begin + rd_valid_r <= dma_rd_if.req_valid; + end + if (rd_take) begin + rd_addr_r <= BANK_ADDR_WIDTH'(dma_rd_if.req_data.addr); + rd_tag_r <= dma_rd_if.req_data.tag; + end + end + assign dma_rd_req_valid = rd_valid_r; + assign dma_rd_addr = rd_addr_r; + assign dma_rd_tag = rd_tag_r; + assign dma_rd_if.req_ready = rd_take; + end else begin : g_rd_port + assign dma_rd_req_valid = dma_rd_if.req_valid; + assign dma_rd_addr = BANK_ADDR_WIDTH'(dma_rd_if.req_data.addr); + assign dma_rd_tag = dma_rd_if.req_data.tag; + assign dma_rd_if.req_ready = dma_slot_r && dma_rsp_buf_ready && dma_rd_grant; + end // the tag follows the SRAM read to its output register VX_pipe_buffer #( @@ -552,10 +651,10 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( .reset (reset), .valid_in (dma_rd_fire), .ready_in (dma_rsp_buf_ready), - .data_in (dma_bus_if.req_data.tag), - .valid_out (dma_bus_if.rsp_valid), - .data_out (dma_bus_if.rsp_data.tag), - .ready_out (dma_bus_if.rsp_ready) + .data_in (dma_rd_tag), + .valid_out (dma_rd_if.rsp_valid), + .data_out (dma_rd_if.rsp_data.tag), + .ready_out (dma_rd_if.rsp_ready) ); // The response buffer holds only the tag; the data is the live SRAM @@ -563,53 +662,60 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( // back-pressured, serve a copy of the row latched on its first cycle. reg [NUM_BANKS-1:0][WORD_WIDTH-1:0] dma_rsp_hold_data_r; reg dma_rsp_hold_valid_r; - wire dma_rsp_consumed = dma_bus_if.rsp_valid && dma_bus_if.rsp_ready; + wire dma_rsp_consumed = dma_rd_if.rsp_valid && dma_rd_if.rsp_ready; always @(posedge clk) begin if (reset) begin dma_rsp_hold_valid_r <= 1'b0; end else if (dma_rsp_consumed) begin dma_rsp_hold_valid_r <= 1'b0; - end else if (dma_bus_if.rsp_valid && ~dma_rsp_hold_valid_r) begin - dma_rsp_hold_data_r <= per_bank_rdata_a; + end else if (dma_rd_if.rsp_valid && ~dma_rsp_hold_valid_r) begin + dma_rsp_hold_data_r <= per_bank_rdata_dma; dma_rsp_hold_valid_r <= 1'b1; end end for (genvar i = 0; i < NUM_BANKS; ++i) begin : g_dma_rsp_data - assign dma_bus_if.rsp_data.data[i*WORD_WIDTH +: WORD_WIDTH] = - dma_rsp_hold_valid_r ? dma_rsp_hold_data_r[i] : per_bank_rdata_a[i]; + assign dma_rd_if.rsp_data.data[i*WORD_WIDTH +: WORD_WIDTH] = + dma_rsp_hold_valid_r ? dma_rsp_hold_data_r[i] : per_bank_rdata_dma[i]; end - end else begin : g_no_dma - assign dma_rsp_buf_ready = 1'b0; - assign dma_bus_if.req_ready = 1'b0; - assign dma_bus_if.rsp_valid = 1'b0; - assign dma_bus_if.rsp_data = '0; - `UNUSED_VAR (dma_bus_if.req_valid) - `UNUSED_VAR (dma_bus_if.req_data) - `UNUSED_VAR (dma_bus_if.rsp_ready) - `UNUSED_VAR (per_bank_rdata_a) + end else begin : g_no_dma_rd + assign dma_rsp_buf_ready = 1'b0; + assign dma_rd_req_valid = 1'b0; + assign dma_rd_addr = '0; + assign dma_rd_tag = '0; + assign dma_rd_if.req_ready = 1'b0; + `UNUSED_VAR (dma_rd_tag) + assign dma_rd_if.rsp_valid = 1'b0; + assign dma_rd_if.rsp_data = '0; + `UNUSED_VAR (dma_rd_if.req_valid) + `UNUSED_VAR (dma_rd_if.req_data) + `UNUSED_VAR (dma_rd_if.rsp_ready) + `UNUSED_VAR (per_bank_rdata_dma) end - // banks + // banks: port A takes a row write (or a row read with no second port for + // it), port B a row read beside the read engine, which no pass uses in a + // DMA cycle for (genvar i = 0; i < NUM_BANKS; ++i) begin : g_data_store + wire dma_a = dma_wr_fire || dma_rd_a; VX_lmem_bank #( .SIZE (WORDS_PER_BANK), .WORD_SIZE (WORD_SIZE), .DUAL (DUAL), - .DMA_ENABLE (DMA_ENABLE), + .DMA_ENABLE (DMA_WR_ENABLE || DMA_RD_ENABLE), .AMO_ENABLE (AMO_ENABLE), .PAYLOAD_WIDTH (PAYLOAD_WIDTH), .ATTR_WIDTH (ATTR_WIDTH) ) bank ( .clk (clk), .reset (reset), - .dma_fire (dma_fire), - .dma_rd_fire (dma_rd_fire), - .dma_rw (dma_bus_if.req_data.rw), - .dma_addr (BANK_ADDR_WIDTH'(dma_bus_if.req_data.addr)), - .dma_wdata (dma_bus_if.req_data.data[i*WORD_WIDTH +: WORD_WIDTH]), - .dma_byteen (dma_bus_if.req_data.byteen[i*WORD_SIZE +: WORD_SIZE]), + .dma_fire (dma_a), + .dma_rd_fire (dma_rd_a), + .dma_rw (dma_wr_fire), + .dma_addr ((DMA_RD_PORT_B || dma_wr_fire) ? dma_wr_addr : dma_rd_addr), + .dma_wdata (dma_wr_if.req_data.data[i*WORD_WIDTH +: WORD_WIDTH]), + .dma_byteen (dma_wr_if.req_data.byteen[i*WORD_SIZE +: WORD_SIZE]), .a_valid (a_bank_valid[i]), .a_rw (a_bank_rw), .a_amo (a_bank_amo), @@ -618,10 +724,11 @@ module VX_lmem_unit import VX_gpu_pkg::*; #( .a_payload (a_bank_payload[i]), .sram_rdata_a (per_bank_rdata_a[i]), .a_rdata (a_bank_rdata[i]), - .b_valid (b_bank_valid[i]), - .b_addr (b_bank_addr[i]), - .b_rdata (b_bank_rdata[i]) + .b_valid (dma_rd_b || b_bank_valid[i]), + .b_addr (dma_rd_b ? dma_rd_addr : b_bank_addr[i]), + .b_rdata (per_bank_rdata_b[i]) ); + assign b_bank_rdata[i] = per_bank_rdata_b[i]; end `ifdef PERF_ENABLE diff --git a/hw/unittest/lmem_unit/VX_lmem_unit_top.sv b/hw/unittest/lmem_unit/VX_lmem_unit_top.sv index 06b61524e3..93d25c2ddf 100644 --- a/hw/unittest/lmem_unit/VX_lmem_unit_top.sv +++ b/hw/unittest/lmem_unit/VX_lmem_unit_top.sv @@ -14,9 +14,9 @@ `include "VX_define.vh" // Synthesis wrapper of the warp-wide local memory at the configured core -// shape: one warp request port per LSU block, and the row-wide DMA port. The -// requests arrive through a register each, as from the LSU blocks' local-path -// buffers and the DMA arbiter in the core; out-of-context synthesis leaves +// shape: one warp request port per LSU block, and the row-wide DMA write and +// read ports. The requests arrive through a register each, as from the LSU +// blocks' local-path buffers and the DMA agents; out-of-context synthesis leaves // paths from the ports untimed, so this is what puts the unit's request // decoding on the timing report. module VX_lmem_unit_top import VX_gpu_pkg::*; #( @@ -33,7 +33,7 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( parameter LANE_WIDTH = LANE_SIZE * 8, parameter DMA_ADDR_WIDTH = ADDR_WIDTH - `CLOG2(NUM_BANKS), parameter DMA_DATA_SIZE = NUM_BANKS * WORD_SIZE, - parameter DMA_TAG_WIDTH = LMEM_DMA_TAG_WIDTH + parameter DMA_TAG_WIDTH = LMEM_DMA_RD_TAG_W ) ( input wire clk, input wire reset, @@ -56,7 +56,17 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( output wire [NUM_BLOCKS-1:0][TAG_WIDTH-1:0] rsp_tag, input wire [NUM_BLOCKS-1:0] rsp_ready, - // DMA requests + // DMA row writes + input wire dma_wr_valid, + input wire dma_wr_rw, + input wire [DMA_ADDR_WIDTH-1:0] dma_wr_addr, + input wire [DMA_DATA_SIZE*8-1:0] dma_wr_data, + input wire [DMA_DATA_SIZE-1:0] dma_wr_byteen, + input wire [MEM_ATTR_WIDTH-1:0] dma_wr_attr, + input wire [DMA_TAG_WIDTH-1:0] dma_wr_tag, + output wire dma_wr_ready, + + // DMA row reads input wire dma_req_valid, input wire dma_req_rw, input wire [DMA_ADDR_WIDTH-1:0] dma_req_addr, @@ -65,7 +75,7 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( input wire [DMA_TAG_WIDTH-1:0] dma_req_tag, output wire dma_req_ready, - // DMA responses + // DMA row-read responses output wire dma_rsp_valid, output wire [DMA_DATA_SIZE*8-1:0] dma_rsp_data, output wire [DMA_TAG_WIDTH-1:0] dma_rsp_tag, @@ -73,6 +83,11 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( ); localparam REQ_DATAW = NUM_LANES + 1 + NUM_LANES * (LSU_ADDR_WIDTH + LANE_WIDTH + LANE_SIZE + MEM_ATTR_WIDTH) + TAG_WIDTH; localparam DMA_REQ_DATAW = 1 + DMA_ADDR_WIDTH + DMA_DATA_SIZE * 8 + DMA_DATA_SIZE + MEM_ATTR_WIDTH + DMA_TAG_WIDTH; + // a row read's data and byte enables are unused: only the fields the unit + // reads go through the register, the rest come from the ports unregistered + // so that synthesis can neither count them as registers nor fold them as + // constants + localparam DMA_RD_REQ_DATAW = 1 + DMA_ADDR_WIDTH + MEM_ATTR_WIDTH + DMA_TAG_WIDTH; VX_lsu_mem_if #( .NUM_LANES (NUM_LANES), @@ -85,7 +100,13 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( .DATA_SIZE (NUM_BANKS * WORD_SIZE), .TAG_WIDTH (DMA_TAG_WIDTH), .ADDR_WIDTH (DMA_ADDR_WIDTH) - ) dma_bus_if(); + ) dma_wr_if(); + + VX_mem_bus_if #( + .DATA_SIZE (NUM_BANKS * WORD_SIZE), + .TAG_WIDTH (DMA_TAG_WIDTH), + .ADDR_WIDTH (DMA_ADDR_WIDTH) + ) dma_rd_if(); for (genvar k = 0; k < NUM_BLOCKS; ++k) begin : g_blocks wire [NUM_LANES-1:0][LSU_ADDR_WIDTH-1:0] lsu_addr; @@ -117,21 +138,43 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( VX_elastic_buffer #( .DATAW (DMA_REQ_DATAW), .SIZE (1) - ) dma_req_buf ( + ) dma_wr_buf ( + .clk (clk), + .reset (reset), + .valid_in (dma_wr_valid), + .ready_in (dma_wr_ready), + .data_in ({dma_wr_rw, dma_wr_addr, dma_wr_data, dma_wr_byteen, dma_wr_attr, dma_wr_tag}), + .data_out (dma_wr_if.req_data), + .valid_out (dma_wr_if.req_valid), + .ready_out (dma_wr_if.req_ready) + ); + + `UNUSED_VAR (dma_wr_if.rsp_valid) + `UNUSED_VAR (dma_wr_if.rsp_data) + // row writes have no response; the unit ignores this ready, which is + // driven from a port and not a constant so that no logic folds behind it + assign dma_wr_if.rsp_ready = dma_rsp_ready; + + VX_elastic_buffer #( + .DATAW (DMA_RD_REQ_DATAW), + .SIZE (1) + ) dma_rd_buf ( .clk (clk), .reset (reset), .valid_in (dma_req_valid), .ready_in (dma_req_ready), - .data_in ({dma_req_rw, dma_req_addr, dma_req_data, dma_req_byteen, MEM_ATTR_WIDTH'(0), dma_req_tag}), - .data_out (dma_bus_if.req_data), - .valid_out (dma_bus_if.req_valid), - .ready_out (dma_bus_if.req_ready) + .data_in ({dma_req_rw, dma_req_addr, MEM_ATTR_WIDTH'(0), dma_req_tag}), + .data_out ({dma_rd_if.req_data.rw, dma_rd_if.req_data.addr, dma_rd_if.req_data.attr, dma_rd_if.req_data.tag}), + .valid_out (dma_rd_if.req_valid), + .ready_out (dma_rd_if.req_ready) ); + assign dma_rd_if.req_data.data = dma_req_data; + assign dma_rd_if.req_data.byteen = dma_req_byteen; - assign dma_rsp_valid = dma_bus_if.rsp_valid; - assign dma_rsp_data = dma_bus_if.rsp_data.data; - assign dma_rsp_tag = dma_bus_if.rsp_data.tag; - assign dma_bus_if.rsp_ready = dma_rsp_ready; + assign dma_rsp_valid = dma_rd_if.rsp_valid; + assign dma_rsp_data = dma_rd_if.rsp_data.data; + assign dma_rsp_tag = dma_rd_if.rsp_data.tag; + assign dma_rd_if.rsp_ready = dma_rsp_ready; VX_lmem_unit #( .INSTANCE_ID (INSTANCE_ID), @@ -143,7 +186,8 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( .LANE_SIZE (LANE_SIZE), .ADDR_WIDTH (ADDR_WIDTH), .TAG_WIDTH (TAG_WIDTH), - .DMA_ENABLE (1), + .DMA_WR_ENABLE (1), + .DMA_RD_ENABLE (1), .DMA_TAG_WIDTH (DMA_TAG_WIDTH), .AMO_ENABLE (`VX_CFG_EXT_A_ENABLED) ) lmem_unit ( @@ -153,7 +197,8 @@ module VX_lmem_unit_top import VX_gpu_pkg::*; #( `UNUSED_PIN (lmem_perf), `endif .lsu_mem_if (lsu_mem_if), - .dma_bus_if (dma_bus_if) + .dma_wr_if (dma_wr_if), + .dma_rd_if (dma_rd_if) ); endmodule diff --git a/sim/simx/mem/local_mem.cpp b/sim/simx/mem/local_mem.cpp index 36c9bb3135..8d3fee438b 100644 --- a/sim/simx/mem/local_mem.cpp +++ b/sim/simx/mem/local_mem.cpp @@ -109,8 +109,8 @@ class LocalMem::Impl { Selection a_sel_; Selection b_sel_; bool write_waiting_r_; - bool dma_slot_; - uint32_t dma_last_grant_; + bool dma_slot_; // a DMA request was seen the cycle before + bool dma_rd_first_; // the shared port's round-robin choice mutable PerfStats perf_stats_; uint64_t to_local_addr(uint64_t addr) const { @@ -275,60 +275,106 @@ class LocalMem::Impl { return false; } - // Serve one DMA client's row access. Clients are served round-robin, - // starting after the last one served. - void dma_fire() { - for (uint32_t i = 0; i < config_.dma_clients; ++i) { - uint32_t c = (dma_last_grant_ + 1 + i) % config_.dma_clients; - bool pending = false; - bool rsp_ready = true; - for (uint32_t p = 0; p < DMA_PORTS; ++p) { - auto& in = simobject_->DmaInputs.at(c * DMA_PORTS + p); - if (in.empty()) { - continue; - } - pending = true; - if (!in.peek().is_write() && simobject_->DmaOutputs.at(c * DMA_PORTS + p).full()) { - rsp_ready = false; - } + bool dma_client_pending(uint32_t c) const { + for (uint32_t p = 0; p < DMA_PORTS; ++p) { + if (!simobject_->DmaInputs.at(c * DMA_PORTS + p).empty()) { + return true; } - if (!pending) { + } + return false; + } + + // A client's row: a write, or a read with room for its response. A client + // only writes or only reads, so its pending ports agree on the direction. + bool dma_client_ready(uint32_t c, bool *is_write) const { + bool ready = true; + bool seen = false; + for (uint32_t p = 0; p < DMA_PORTS; ++p) { + auto &in = simobject_->DmaInputs.at(c * DMA_PORTS + p); + if (in.empty()) { continue; } - if (!rsp_ready) { - return; + bool w = in.peek().is_write(); + VX_ASSERT(!seen || w == *is_write, "DMA client " << c << " mixes row writes and row reads"); + seen = true; + *is_write = w; + if (!*is_write && simobject_->DmaOutputs.at(c * DMA_PORTS + p).full()) { + ready = false; } - for (uint32_t p = 0; p < DMA_PORTS; ++p) { - auto& in = simobject_->DmaInputs.at(c * DMA_PORTS + p); - if (in.empty()) { - continue; - } - auto& req = in.peek(); - uint64_t line_addr = to_local_addr(req.addr) & ~uint64_t(VX_CFG_MEM_BLOCK_SIZE - 1); - if (req.is_write()) { - for (uint32_t b = 0; req.data && b < VX_CFG_MEM_BLOCK_SIZE; ++b) { - if (req.byteen & (1ull << b)) { - uint8_t value = (*req.data)[b]; - ram_.write(&value, line_addr + b, 1); - } + } + return ready; + } + + // Serve one DMA client's row access. + void dma_serve(uint32_t c) { + for (uint32_t p = 0; p < DMA_PORTS; ++p) { + auto &in = simobject_->DmaInputs.at(c * DMA_PORTS + p); + if (in.empty()) { + continue; + } + auto &req = in.peek(); + uint64_t line_addr = to_local_addr(req.addr) & ~uint64_t(VX_CFG_MEM_BLOCK_SIZE - 1); + if (req.is_write()) { + for (uint32_t b = 0; req.data && b < VX_CFG_MEM_BLOCK_SIZE; ++b) { + if (req.byteen & (1ull << b)) { + uint8_t value = (*req.data)[b]; + ram_.write(&value, line_addr + b, 1); } + } #if VX_CFG_EXT_A_ENABLED - amo_unit_.invalidate(to_local_addr(req.addr), req.hart_id); + amo_unit_.invalidate(to_local_addr(req.addr), req.hart_id); #endif - } else { - MemRsp rsp{req.tag, req.hart_id, req.uuid}; - auto rsp_data = make_mem_block(); - ram_.read(rsp_data->data(), line_addr, VX_CFG_MEM_BLOCK_SIZE); - rsp.data = rsp_data; - // The request arrived over a registered channel; the read data - // returns the cycle after it was issued. - simobject_->DmaOutputs.at(c * DMA_PORTS + p).send(rsp, 0); + } else { + MemRsp rsp{req.tag, req.hart_id, req.uuid}; + auto rsp_data = make_mem_block(); + ram_.read(rsp_data->data(), line_addr, VX_CFG_MEM_BLOCK_SIZE); + rsp.data = rsp_data; + // The request arrived over a registered channel; the read data + // returns the cycle after it was issued. + simobject_->DmaOutputs.at(c * DMA_PORTS + p).send(rsp, 0); + } + DT(4, simobject_->name() << "-dma" << c << " req : " << req); + in.pop(); + } + } + + // Serve the DMA clients, the cycle after a DMA request was seen. Each client only + // writes (DXA) or only reads (TCU). With several LSU blocks a row read has + // the banks' second port and goes through beside a row write; with one, the + // banks are single-ported and the two alternate. Reads go first: a read of + // the row written in the same cycle sees the old data. + void dma_fire() { + uint32_t n = config_.dma_clients; + uint32_t can = 0; // bit c: client c is served this cycle + uint32_t is_write = 0; // bit c: client c writes rows + for (uint32_t c = 0; c < n; ++c) { + bool w = false; + if (this->dma_client_pending(c) && this->dma_client_ready(c, &w)) { + can |= (1u << c); + } + is_write |= (uint32_t(w) << c); + } + bool shared = (config_.num_blocks == 1); + if (shared && can != 0) { + // the side served last yields to the other + if ((can & (can - 1)) != 0) { + can &= dma_rd_first_ ? ~is_write : is_write; + } + for (uint32_t c = 0; c < n; ++c) { + if (can & (1u << c)) { + dma_rd_first_ = (is_write >> c) & 1; } - DT(4, simobject_->name() << "-dma" << c << " req : " << req); - in.pop(); } - dma_last_grant_ = c; - return; + } + for (uint32_t c = 0; c < n; ++c) { + if ((can & ~is_write) & (1u << c)) { + this->dma_serve(c); + } + } + for (uint32_t c = 0; c < n; ++c) { + if ((can & is_write) & (1u << c)) { + this->dma_serve(c); + } } } @@ -453,23 +499,23 @@ class LocalMem::Impl { } public: - Impl(LocalMem* simobject, const Config& config) - : simobject_(simobject) - , config_(config) - , ram_(1ull << log2ceil(config.capacity)) - , addr_bits_(log2ceil(config.capacity)) - , lg2_word_(log2ceil(config.word_size)) + Impl(LocalMem *simobject, const Config &config) + : simobject_(simobject) + , config_(config) + , ram_(1ull << log2ceil(config.capacity)) + , addr_bits_(log2ceil(config.capacity)) + , lg2_word_(log2ceil(config.word_size)) #if VX_CFG_EXT_A_ENABLED - , amo_unit_(VX_CFG_AMO_RS_SIZE < 2 ? 2u : (uint32_t)VX_CFG_AMO_RS_SIZE) + , amo_unit_(VX_CFG_AMO_RS_SIZE < 2 ? 2u : (uint32_t)VX_CFG_AMO_RS_SIZE) #endif - , stall_cycles_(0) - , engines_((config.num_blocks > 1) ? 2 : 1) - , rsp_regs_(config.num_blocks) - , arb_last_(engines_.size(), 0) - , write_waiting_r_(false) - , dma_slot_(false) - , dma_last_grant_(0) - { + , stall_cycles_(0) + , engines_((config.num_blocks > 1) ? 2 : 1) + , rsp_regs_(config.num_blocks) + , arb_last_(engines_.size(), 0) + , write_waiting_r_(false) + , dma_slot_(false) + , dma_rd_first_(false) { + VX_ASSERT(config.dma_clients <= 32, "a DMA client mask holds 32 clients, not " << config.dma_clients); for (auto& e : engines_) { e.pending = BitVector<>(config.num_lanes); } @@ -497,7 +543,7 @@ class LocalMem::Impl { b_sel_ = Selection(); write_waiting_r_ = false; dma_slot_ = false; - dma_last_grant_ = config_.dma_clients ? (config_.dma_clients - 1) : 0; + dma_rd_first_ = false; } void tick() { diff --git a/sim/simx/mem/local_mem.h b/sim/simx/mem/local_mem.h index 465ec6ea01..458c6bf21e 100644 --- a/sim/simx/mem/local_mem.h +++ b/sim/simx/mem/local_mem.h @@ -38,7 +38,7 @@ class LocalMem : public SimObject { uint32_t num_blocks; // LSU blocks, one warp request port each uint32_t num_lanes; // lanes of a warp request uint32_t B; // log2 number of banks - uint32_t dma_clients; // row-wide DMA masters, served round-robin + uint32_t dma_clients; // row-wide DMA agents, each only writing or only reading }; struct PerfStats {