From 069889108660262a0ad9b79027318d318259dd98 Mon Sep 17 00:00:00 2001 From: Vinay Date: Tue, 20 Oct 2015 11:46:46 -0500 Subject: [PATCH] Source code fix for memory module and testbench --- src/verilog/rtl/memory/memory.vp | 209 ----- src/verilog/tb/gpu_tb.v | 1460 ++++++++++++++++-------------- 2 files changed, 777 insertions(+), 892 deletions(-) delete mode 100644 src/verilog/rtl/memory/memory.vp diff --git a/src/verilog/rtl/memory/memory.vp b/src/verilog/rtl/memory/memory.vp deleted file mode 100644 index a6eca67..0000000 --- a/src/verilog/rtl/memory/memory.vp +++ /dev/null @@ -1,209 +0,0 @@ -extern "C" void Init_cache(int a, int c, int b); -extern "C" int RunTraceWrapper(int write, int read, int address, int data); - -module memory( - gm_or_lds, - rd_en, - wr_en, - addresses, - wr_data, - input_tag, - wr_mask, - rd_data, - output_tag, - ack, - tracemon_addr, - tracemon_store_data, - tracemon_store_en, - clk, - rst - ); - -parameter NUMOFCU = 1; -parameter DELAY = 100; - -input clk; -input rst; - -input [(NUMOFCU - 1):0] gm_or_lds; -input [(NUMOFCU*4 - 1):0] rd_en, wr_en; -input [(NUMOFCU*7 - 1):0] input_tag; -input [(NUMOFCU*64 - 1):0] wr_mask; -input [(NUMOFCU*2048 - 1):0] addresses; -input [(NUMOFCU*8192 - 1):0] wr_data; - -output [(NUMOFCU - 1):0] ack; -output [(NUMOFCU*4 - 1):0] tracemon_store_en; -output [(NUMOFCU*7 - 1):0] output_tag; -output [(NUMOFCU*2048 - 1):0] tracemon_addr; -output [(NUMOFCU*8192 - 1):0] rd_data, tracemon_store_data; - -reg [(NUMOFCU - 1):0] ack; -reg [(NUMOFCU*4 - 1):0] tracemon_store_en, tracemon_store_en_buff; -reg [(NUMOFCU*7 - 1):0] output_tag; -reg [(NUMOFCU*2048 - 1):0] tracemon_addr, tracemon_addr_buff; -reg [(NUMOFCU*8192 - 1):0] rd_data, tracemon_store_data, tracemon_store_data_buff; - -/////////////////////////////// -//Your code goes here - beware: script does not recognize changes -// into files. It ovewrites everithing without mercy. Save your work before running the script -/////////////////////////////// - -// input buffering to introduce delay -reg [(NUMOFCU - 1):0] gm_or_lds_dbuff [DELAY]; -reg [(NUMOFCU*4 - 1):0] rd_en_dbuff [DELAY], wr_en_dbuff [DELAY]; -reg [(NUMOFCU*7 - 1):0] input_tag_dbuff [DELAY]; -reg [(NUMOFCU*64 - 1):0] wr_mask_dbuff [DELAY]; -reg [(NUMOFCU*2048 - 1):0] addresses_dbuff [DELAY]; -reg [(NUMOFCU*8192 - 1):0] wr_data_dbuff [DELAY]; - -// memory registers -reg[7:0] data_memory[50000:0]; -reg[7:0] lds_memory[(NUMOFCU*65536 -1):0]; - -reg hit; -int reth; -integer i, j, k, m, d; -integer locrd = 16; // num of loc to read -integer addr_index, data_index; - -initial begin - Init_cache(2, 262144, 128); -end - -always @ (posedge clk) begin - hit = 1'b1; - - if (~rst) begin - tracemon_addr = tracemon_addr_buff; - tracemon_store_en = tracemon_store_en_buff; - tracemon_store_data = tracemon_store_data_buff; - - for(d = DELAY-2; d >=0; d--) begin - gm_or_lds_dbuff[d+1] = gm_or_lds_dbuff[d]; - rd_en_dbuff[d+1] = rd_en_dbuff[d]; - wr_en_dbuff[d+1] = wr_en_dbuff[d]; - input_tag_dbuff[d+1] = input_tag_dbuff[d]; - wr_mask_dbuff[d+1] = wr_mask_dbuff[d]; - addresses_dbuff[d+1] = addresses_dbuff[d]; - wr_data_dbuff[d+1] = wr_data_dbuff[d]; - end - - // if no memory access treat as miss - if(~(|rd_en[3:0]) & ~(|wr_en[3:0])) begin - hit = 1'b0; - end - // if global memory access, check for hit - // treat lds as a cache hit - else if (~gm_or_lds) begin - for(k = 0; k < 64; k++) begin - if(wr_mask[k]) begin - addr_index = k*32 + 31; - - if ((|wr_en[3:0]) | (|rd_en[3:0])) begin - reth = RunTraceWrapper(|wr_en[3:0], |rd_en[3:0], addresses[addr_index-:32], 0); - if (reth == 1'b0) hit = 1'b0; - end - end - end - end - - // if hit placing at the lowest free delay slot - if(hit == 1'd1) begin - for(d = DELAY-1; d > 0; d--) begin - if(~(|rd_en_dbuff[d]) & ~(|wr_en_dbuff[d])) break; - end - - gm_or_lds_dbuff[d] = gm_or_lds; - rd_en_dbuff[d] = rd_en; - wr_en_dbuff[d] = wr_en; - input_tag_dbuff[d] = input_tag; - wr_mask_dbuff[d] = wr_mask; - addresses_dbuff[d] = addresses; - wr_data_dbuff[d] = wr_data; - - // clearing the rd/wr signals in the highest delay slot - if(d != 0) begin - rd_en_dbuff[0] = 'b0; - wr_en_dbuff[0] = 'b0; - end - end - // else setting DELAY cycle delay - else begin - gm_or_lds_dbuff[0] = gm_or_lds; - rd_en_dbuff[0] = rd_en; - wr_en_dbuff[0] = wr_en; - input_tag_dbuff[0] = input_tag; - wr_mask_dbuff[0] = wr_mask; - addresses_dbuff[0] = addresses; - wr_data_dbuff[0] = wr_data; - end - - #1; - - // accessing memory for request to be serviced - for(i = 0; i < NUMOFCU; i++) begin - if (rd_en_dbuff[DELAY-1][(4*i+3)-:4]) begin - - for(k=0; k<64; k=k+1) begin - addr_index = i*2048 + k*32 +31; - - for(j=0; j