Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns/1ns
- `define SIPP_UVM_TEST
- `include "../rtl/cv_fft_reg_gen/cv_fft_regs_pkg.vh"
- `include "mvds_sipp_llb_params.inc"
- `include "sipp_func.inc"
- `include "sipp_lbc_types.inc"
- `include "sipp_lbc_func.inc"
- `include "sipp_fp_func.inc"
- //`include "cv_fft_dct_rom_values.inc"
- `include "/nfs/iir/disks/mvds_ip_release_disk001/vpu2p6_IP_REL/amc_vip/amc_vip_v0p0_y19ww34_0008/amc_vip/TESTBENCH/amc_ifs.inc"
- `include "/nfs/iir/disks/mvds_ip_release_disk001/vpu2p6_IP_REL/mvds_sipp_legacy_tb/mvds_sipp_legacy_tb_v0p0_y19ww33_0011/mvds_sipp_legacy_tb/TESTBENCH/pixel_ifs.inc"
- module tb_fft();
- integer seed;
- integer initialseed;
- int N, MODE, LINES;
- int nrpoints, nrlines, pixels_sent;
- int cbits = 15, thresh = 35000, input_addr = 0, cN;
- string TYPE, INTYPE, OUTTYPE, REORDER_BYPASS, INFORMAT, OUTFORMAT, DIMENSION;
- integer args1 = $value$plusargs("SEED=%d",seed);
- integer args2 = $value$plusargs("N=%d",N);
- integer args3 = $value$plusargs("MODE=%d",MODE);
- integer args4 = $value$plusargs("TYPE=%s",TYPE);
- integer args5 = $value$plusargs("INTYPE=%s",INTYPE);
- integer args6 = $value$plusargs("OUTTYPE=%s",OUTTYPE);
- integer args7 = $value$plusargs("REORDER_BYPASS=%s",REORDER_BYPASS);
- integer args8 = $value$plusargs("INFORMAT=%s",INFORMAT);
- integer args9 = $value$plusargs("OUTFORMAT=%s",OUTFORMAT);
- integer args10 = $value$plusargs("DIMENSION=%s",DIMENSION);
- integer args11 = $value$plusargs("LINES=%d",LINES);
- //FILE POINTERS
- integer fwr;
- integer logs, fwrinp_py, fwrinp, modelout;
- logic [1:0]transftype;//FFT -- IFFT -- DCT --IDCT
- logic ffttype;//1D -- 2D
- string stringformatter;
- int ignoreme = 0, matcherrors = 0, onebitmatcherrors = 0, readstotal = 0, run_number = 0;
- logic [1:0]inptype;//COMPLEX -- REALPLANE -- CONJUGATE
- logic [1:0]inpformat;//FP16 U16
- logic outtype;
- logic [1:0]outformat;
- logic reorder_bypass;
- logic [31:0] ignoremedata;
- logic [31:0] regdata;
- logic [31:0] regdata2;
- logic [31:0] regdata3;
- logic [31:0] model_data_out;
- import upa_cmx_constants_pkg::*;
- import "DPI-C" function void start_model(input string filename, input int n, input int mode, input int nrb, input int input_type, input int output_type, input int reorder_bypass,input int input_format, input int output_format, input int lines, input int dimension);
- `include "/nfs/iir/disks/mvds_ip_release_disk001/vpu2p6_IP_REL/amc_vip/amc_vip_v0p0_y19ww33_0007/amc_vip/TESTBENCH/amc_base_classes.inc"
- parameter DRAM_BASE_ADR = 32'h8000_0000;
- //defparam AMC_DW = 32;
- localparam NUM_OF_MEMS = 4;
- localparam PRDATA_WIDTH = 32;
- localparam PWDATA_WIDTH = 32;
- localparam PADDR_WIDTH = 32;
- // -----------------------------------------------------------------------------
- // Input and output declarations
- // -----------------------------------------------------------------------------
- // Clock and reset
- logic clk;
- logic rst_n;
- int readerrors;
- initial begin
- clk = 0;
- forever begin
- #50;
- clk = ~clk;
- end
- end
- // --------------------------------------------
- // DFx
- // --------------------------------------------
- logic fscan_clkungate;
- logic [NUM_OF_MEMS-1:0] test_enable;
- //input ctrl_mem_struct [NUM_OF_MEMS-1:0] cfg_mem_ctrl;
- // --------------------------------------------
- // Interrupt
- // --------------------------------------------
- logic fft_irq;
- // --------------------------------------------
- // APB3 INTERFACE
- // --------------------------------------------
- logic [PADDR_WIDTH-1:0] paddr;
- logic penable;
- logic pwrite;
- logic [PWDATA_WIDTH-1:0] pwdata;
- logic psel;
- logic [PRDATA_WIDTH-1:0] prdata;
- logic pslverr;
- logic pready;
- logic [31:0] tc_addr;
- sipp_lbc_cfg cfg;
- logic en;
- logic [SIPP_FRM_WIDTH_W-1:0] img_width;
- logic [SIPP_FRM_HEIGHT_W-1:0] img_height;
- logic bfl_dec, bfl_inc;
- logic [SIPP_NLW-1:0] bfl;
- pix_if my_pi(clk);
- amc_wif parent_wif(clk);//Parent interface
- amc_rif fft_rif(clk);
- amc_wif fft_wif(clk);
- virtual amc_wif vwif;//Virtual interface of the writing object
- virtual amc_rif vrif;//Virtual interface of the reading object
- AMCIWrIf AmcWr;//Writing object
- AMCIRdIf AmcRd;//Reading object
- event e_trans_done;
- event e_trans_done2;
- initial begin
- vwif = parent_wif;
- vrif = fft_rif;
- AmcWr = new (/* AmcWr */, 1, MXI_CMX_BASE_ADR, 'h20000, vwif, e_trans_done);
- AmcRd = new (/* AmcRd */, 2, MXI_CMX_BASE_ADR, 'h20000, vrif, e_trans_done);
- end
- tb_sipp_parent #(.DW(32),.NC(1), .NP(1))
- tb_sipp_parent_i(
- .clk(clk),
- .rst_n(rst_n),
- .cfg(cfg),
- .img_width(img_width),
- .img_height(img_height),
- .en(en),
- .bfl_dec(bfl_dec),
- .bfl_inc(bfl_inc),
- .bfl(bfl),
- .pi(my_pi),
- .wc(parent_wif)
- );
- cv_fft_wrap cv_fft_wrap_i(
- .clk(clk),
- .rst_n(rst_n),
- .fscan_clkungate(fscan_clkungate),
- .test_enable(1'b0),
- .fft_irq(fft_irq),
- .cfg_mem_ctrl(23'd0),
- .paddr(paddr),
- .penable(penable),
- .pwrite(pwrite),
- .pwdata(pwdata),
- .psel(psel),
- .prdata(prdata),
- .pslverr(pslverr),
- .pready(pready),
- .rd_client_o(fft_rif.o),
- .rd_client_i(fft_rif.i),
- .wr_client_o(fft_wif.o),
- .wr_client_i(fft_wif.i)
- );
- always @(posedge fft_wif.o.req)begin
- if(ffttype == 1'b0 ) begin //|| run_number == 1
- $write("RTL OUTPUT:\n");
- while(fft_wif.o.req == 1'b1)begin
- #1;
- if(transftype < 2) begin
- $fwrite(fwr,"%h %h %h %h %h %h %h %h ",fft_wif.o.data[31:16],fft_wif.o.data[15:0],fft_wif.o.data[63:48],fft_wif.o.data[47:32],fft_wif.o.data[95:80],fft_wif.o.data[79:64],fft_wif.o.data[127:112],fft_wif.o.data[111:96]);
- end
- else begin
- $fwrite(fwr,"%h %h %h %h %h %h %h %h ",fft_wif.o.data[15:0],fft_wif.o.data[31:16],fft_wif.o.data[47:32],fft_wif.o.data[63:48],fft_wif.o.data[79:64],fft_wif.o.data[95:80],fft_wif.o.data[111:96],fft_wif.o.data[127:112]);
- end
- $fscanf(modelout,"%h %h",ignoremedata[31:16],ignoremedata[15:0]);//--------------------------------------------1
- if(ignoremedata == fft_wif.o.data[31:0])
- $write("\033[1;32m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[31:16]),stringformatter,trans_fp16(fft_wif.o.data[15:0]));
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[31:16] == 1) || (ignoremedata[15:0] - fft_wif.o.data[15:0] == 1) || (ignoremedata[31:16] - fft_wif.o.data[31:16] == -1)||(ignoremedata[15:0] - fft_wif.o.data[15:0] == -1)) begin
- $write("\033[1;33m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[31:16]),stringformatter,trans_fp16(fft_wif.o.data[15:0]));
- onebitmatcherrors+=1;
- end
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[31:16] == 2) || (ignoremedata[15:0] - fft_wif.o.data[15:0] == 2) || (ignoremedata[31:16] - fft_wif.o.data[31:16] == -2) ||(ignoremedata[15:0] - fft_wif.o.data[15:0] == -2))
- $write("\033[1;35m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[31:16]),stringformatter,trans_fp16(fft_wif.o.data[15:0]));
- else
- $write("\033[1;31m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[31:16]),stringformatter,trans_fp16(fft_wif.o.data[15:0]));
- matcherrors+=1;
- end
- end
- if (((TYPE == "FFT" || TYPE == "IFFT") && (outtype == 2'b01 || inptype == 2'b10) && N == 1) || ((TYPE == "DCT" || TYPE == "IDCT") && N == 1))begin
- $display("");
- break;
- end
- $fscanf(modelout,"%h %h",ignoremedata[31:16],ignoremedata[15:0]);//--------------------------------------------2
- if(ignoremedata == fft_wif.o.data[63:32])
- $write("\033[1;32m\t\t%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[63:48]),stringformatter,trans_fp16(fft_wif.o.data[47:32]));
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[63:48]== 1) || (ignoremedata[15:0] - fft_wif.o.data[47:32]== 1) ||(ignoremedata[31:16] - fft_wif.o.data[63:48]== -1)||(ignoremedata[15:0] - fft_wif.o.data[47:32]== -1)) begin
- $write("\033[1;33m\t\t%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[63:48]),stringformatter,trans_fp16(fft_wif.o.data[47:32]));
- onebitmatcherrors+=1;
- end
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[63:48]== 2) || (ignoremedata[15:0] - fft_wif.o.data[47:32]== 2) ||(ignoremedata[31:16] - fft_wif.o.data[63:48]== -2) ||(ignoremedata[15:0] - fft_wif.o.data[47:32]== -2))
- $write("\033[1;35m\t\t%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[63:48]),stringformatter,trans_fp16(fft_wif.o.data[47:32]));
- else
- $write("\033[1;31m\t\t%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[63:48]),stringformatter,trans_fp16(fft_wif.o.data[47:32]));
- matcherrors+=1;
- end
- end
- if(transftype == 2'b10 || transftype == 2'b11)
- $write("\n");
- else
- $write("\t\t");
- if (((TYPE == "FFT" || TYPE == "IFFT") && ((outtype == 2'b00 && N == 1) || (outtype == 2'b01 && N == 2))) || ((TYPE == "DCT" || TYPE == "IDCT") && N == 2))begin
- $display("");
- break;
- end
- $fscanf(modelout,"%h %h",ignoremedata[31:16],ignoremedata[15:0]);//-------------------------------------------3
- if(ignoremedata == fft_wif.o.data[95:64])
- $write("\033[1;32m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[95:80]),stringformatter,trans_fp16(fft_wif.o.data[79:64]));
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[95:80] == 1) || (ignoremedata[15:0] - fft_wif.o.data[79:64] == 1) || (ignoremedata[31:16] - fft_wif.o.data[95:80] == -1) ||(ignoremedata[15:0] - fft_wif.o.data[79:64] == -1)) begin
- $write("\033[1;33m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[95:80]),stringformatter,trans_fp16(fft_wif.o.data[79:64]));
- onebitmatcherrors+=1;
- end
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[95:80] == 2) || (ignoremedata[15:0] - fft_wif.o.data[79:64] == 2) || (ignoremedata[31:16] - fft_wif.o.data[95:80] == -2) ||(ignoremedata[15:0] - fft_wif.o.data[79:64] == -2))
- $write("\033[1;35m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[95:80]),stringformatter,trans_fp16(fft_wif.o.data[79:64]));
- else
- $write("\033[1;31m%8.5f%s%8.5f\033[0m",trans_fp16(fft_wif.o.data[95:80]),stringformatter,trans_fp16(fft_wif.o.data[79:64]));
- matcherrors+=1;
- end
- end
- $fscanf(modelout,"%h %h",ignoremedata[31:16],ignoremedata[15:0]);//-------------------------------------------4
- if(ignoremedata == fft_wif.o.data[127:96])
- $write("\033[1;32m\t\t%8f%s%8f\033[0m\n",trans_fp16(fft_wif.o.data[127:112]),stringformatter,trans_fp16(fft_wif.o.data[111:96]));
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[127:112]== 1) || (ignoremedata[15:0] - fft_wif.o.data[111:96]== 1) || (ignoremedata[31:16] - fft_wif.o.data[127:112]== -1)||(ignoremedata[15:0] - fft_wif.o.data[111:96]== -1)) begin
- $write("\033[1;33m\t\t%8.5f%s%8.5f\033[0m\n",trans_fp16(fft_wif.o.data[127:112]),stringformatter,trans_fp16(fft_wif.o.data[111:96]));
- onebitmatcherrors+=1;
- end
- else begin
- if((ignoremedata[31:16] - fft_wif.o.data[127:112]== 2) || (ignoremedata[15:0] - fft_wif.o.data[111:96]== 2) || (ignoremedata[31:16] - fft_wif.o.data[127:112]== -2) ||(ignoremedata[15:0] - fft_wif.o.data[111:96]== -2))
- $write("\033[1;35m\t\t%8.5f%s%8.5f\033[0m\n",trans_fp16(fft_wif.o.data[127:112]),stringformatter,trans_fp16(fft_wif.o.data[111:96]));
- else
- $write("\033[1;31m\t\t%8.5f%s%8.5f\033[0m\n",trans_fp16(fft_wif.o.data[127:112]),stringformatter,trans_fp16(fft_wif.o.data[111:96]));
- matcherrors+=1;
- end
- end
- @(posedge clk);
- #1;
- end
- $fwrite(fwr,"\n");
- end
- end
- int i_2D, j_2D, i_2D_2;
- logic [31:0] out_point_2D;
- logic [31:0] matrix_2D[0:4095][0:2047];
- always @(posedge fft_wif.o.req)begin
- if (ffttype == 1'b1) begin // && run_number == 0
- //if(run_number == 0)
- j_2D = 0;
- while(fft_wif.o.req == 1'b1)begin
- if(run_number == 0) begin
- out_point_2D = fft_wif.o.data >> ((i_2D%4)*32);
- matrix_2D[j_2D][i_2D] = out_point_2D;
- end
- else if(run_number == 1) begin
- out_point_2D = fft_wif.o.data >> (((i_2D_2)%4)*32);
- end
- $fwrite(fwr,"%h %h ",out_point_2D[31:16], out_point_2D[15:0]);
- j_2D++;
- @(posedge clk); #1;
- end
- if(run_number == 0)
- i_2D++;
- else if (run_number == 1)
- i_2D_2++;
- end
- end
- int fftreadsdone;
- always @(posedge fft_rif.i.strb)begin
- logic[127:0]olddata;
- olddata = 'bx;
- if(ffttype == 0) begin
- while((fft_rif.i.strb == 1'b1) || (N == 1 && fftreadsdone == 0))begin
- if(olddata !== fft_rif.i.data) begin
- olddata = fft_rif.i.data;
- #1;
- @(posedge clk); #1;
- fftreadsdone++;
- //$display("------->FFTREADSDONE=%0d--------<%d>------\n",fftreadsdone,$time);
- if(fftreadsdone == readstotal || (N == 1 && fftreadsdone == 1))begin
- $fclose(fwrinp);
- fftreadsdone = 0;
- start_model("input.txt",cN,transftype,cbits,inptype,outtype,reorder_bypass,inpformat,outformat, LINES, ffttype);
- modelout = $fopen("model_output.txt","r");
- end
- end
- else begin @(posedge clk); #1; end
- end
- end
- end
- int aux;
- logic [31:0] elem;
- initial begin
- if($isunknown(seed)) seed = 43041;
- initialseed = seed;
- if($isunknown(initialseed)) initialseed = 43041;
- if($isunknown(MODE)) MODE = 0;//17/15
- if($isunknown(N)) N = 4;//16 points
- if($isunknown(TYPE)) transftype = 2'b00;//FFT
- if($isunknown(INTYPE)) inptype = 2'b00;//COMPLEX
- if($isunknown(OUTTYPE)) outtype = 1'b0;//COMPLEX
- if($isunknown(REORDER_BYPASS)) reorder_bypass = 1'b0;
- if($isunknown(INFORMAT)) inpformat = 2'b00;//FP16
- if($isunknown(OUTFORMAT)) outformat = 2'b00;//FP16
- if($isunknown(DIMENSION)) ffttype = 1'b0;//1D
- if($isunknown(LINES)) LINES = 0;//1 line
- fwrinp_py = $fopen("input_for_python.txt","w");
- //---------------------------------------------------------------------------------
- start_fft();
- //<-------should be fine executia pana aici. next step sa trimit punctele din matrix_2Dl
- $fclose(modelout);
- my_pi.d.frame_end = 1'b0;
- repeat(100)@(posedge clk);
- if(ffttype == 1'b1) begin
- AmcWr.reset(1);
- AmcRd.reset(1);
- /* for(i_2D=0;i_2D<(2**N);i_2D++)begin
- for(j_2D=0;j_2D<nrlines;j_2D++)begin
- elem = matrix_2D[i_2D][j_2D];
- $write("[%h]%8.5f%s[%h]%8.5f \t", elem[31:16], trans_fp16(elem[31:16]), stringformatter, elem[15:0], trans_fp16(elem[15:0]));
- end
- $display("");
- end */
- i_2D = 0;
- //start_fft();
- end
- $display("%s INPUTMODE=%0d OUTPUTMODE=%0d INPUTFORMAT=%0d OUTPUTFORMAT=%0d MODE=%0d N=%0d SEED=%0d BYPASS=%0d and it finished with %0d errors and %0d one bit errors\n",TYPE, inptype, outtype, inpformat,outformat, MODE,N,initialseed, reorder_bypass, matcherrors, onebitmatcherrors);
- if(matcherrors != 0 || onebitmatcherrors > 1)begin
- $fwrite(logs,"%s INPUTMODE=%0d OUTPUTMODE=%0d INPUTFORMAT=%0d OUTPUTFORMAT=%0d MODE=%0d N=%0d SEED=%0d BYPASS=%0d and it finished with %0d errors and %0d one bit errors\n",TYPE, inptype, outtype, inpformat,outformat, MODE,N,initialseed, reorder_bypass, matcherrors, onebitmatcherrors);
- $display("\033[1;31m------------------------------------>TEST FAILED<---------------------------------------------\033[0m");
- end
- else
- $display("\033[1;32m------------------------------------>TEST PASSED<---------------------------------------------\033[0m");
- if(reorder_bypass == 1'b1)
- $display("-------------------------->REORDER BYPASS ENABLED<-----------------------");
- else
- $display("-------------------------->REORDER BYPASS DISABLED<-----------------------");
- $fclose(logs);
- $fclose(fwrinp_py);
- $display("");
- $finish(2);
- end
- task automatic start_fft;
- if(run_number == 1) begin //Swap N and LINES in the second run of the 2D FFT, since the matrix is now transposed
- aux = LINES;
- LINES = N;
- N = aux;
- end
- check_N();
- type_config();
- input_type_config();
- output_type_config();
- cN = 2 ** N;
- fftreadsdone = 0;
- AmcWr.run();
- AmcRd.run();
- nrpoints = (inptype == 2'b01 || inptype == 2'b10) ? (2**(N-1)) : (2 ** N); //If real plane or conjugate then we generate only half the points
- nrlines = (ffttype == 1'b1) ? (2 ** LINES) : 1;
- img_width = nrpoints;
- img_height = nrlines;
- cfg.nl = nrlines;
- cfg.ls = N; // "daca ai 64 puncte atunci 64 * 4 bytes" si trebe sa fie aliniat la 16B
- if(run_number == 0) begin
- my_pi.d.frame_start = 1'b1;
- @(posedge clk);
- my_pi.d.frame_start = 1'b0;
- //my_pi.d.line_start = 1'b1;
- send_pix();
- @(posedge clk);
- //my_pi.d.line_start = 1'b0;
- my_pi.d.frame_start = 1'b0;
- end
- regdata = 'd0;
- regdata[3:0] = N;//N
- regdata[9:8] = transftype; //FFT/IFFT/DCT/IDCT
- regdata[13:10] = LINES;//Number of lines
- regdata[15] = reorder_bypass;//Reorder Bypass
- regdata[7] = ffttype;//1D / 2D
- regdata[6] = outtype;//Output type
- regdata[5:4] = inptype;//Input type
- regdata2 ='d0;
- regdata2[1:0] = MODE;//POINT FORMAT
- regdata2[3:2] = outformat;//OUTPUT FORMAT
- regdata2[5:4] = inpformat;//INPUT FORMAT
- regdata3='d0;
- regdata3[14:4]=N;//line stride -- inseamna de fapt n*16B
- input_addr = (run_number == 1) ? ((2**N)*(2**LINES)*4) : 0;
- write_to_reg(cv_fft_regs_pkg::CV_FFT_CTRL0_CR_ADDR,regdata);
- write_to_reg(cv_fft_regs_pkg::CV_FFT_INT_EN_CR_ADDR,'d3);
- write_to_reg(cv_fft_regs_pkg::CV_FFT_INT_CR_ADDR,'d3);
- write_to_reg(cv_fft_regs_pkg::CV_FFT_CTRL1_CR_ADDR,regdata2);
- write_to_reg(cv_fft_regs_pkg::CV_FFT_INPUT_ADDR_CR_ADDR,input_addr);//Input adress
- write_to_reg(cv_fft_regs_pkg::CV_FFT_OUTPUT_ADDR_CR_ADDR,'h70000);//Output adress
- write_to_reg(cv_fft_regs_pkg::CV_FFT_MEMSETUP_CR_ADDR,regdata3);//idk
- send_lines();
- //repeat(100)@(posedge clk);
- write_to_reg(cv_fft_regs_pkg::CV_FFT_START_CR_ADDR,1'b1);
- $display("Started DUT transftype %d! at time %d",transftype,$time);
- @(posedge clk) penable = 1'b0;
- if(ffttype == 1) begin
- wait(cv_fft_wrap_i.i_cv_fft.i_cv_fft_ctrl.mode_2D_int==1'b1);
- wait(cv_fft_wrap_i.i_cv_fft.i_cv_fft_ctrl.mode_2D_int==1'b0);
- end
- else if(ffttype == 0) begin
- wait(cv_fft_wrap_i.i_cv_fft.i_cv_fft_ctrl.mode_1D_int==1'b1);
- wait(cv_fft_wrap_i.i_cv_fft.i_cv_fft_ctrl.mode_1D_int==1'b0);
- end
- repeat(500)@(posedge clk);
- if(run_number == 1) begin
- //my_pi.d.line_end = 1'b1;
- @(posedge clk);
- my_pi.d.frame_end = 1'b1;
- //my_pi.d.line_end = 1'b0;
- @(posedge clk);
- my_pi.d.frame_end = 1'b0;
- end
- $display("");
- run_number++;
- $fclose(fwr);
- if(ffttype == 1) begin
- start_model("input.txt",cN,transftype,cbits,inptype,outtype,reorder_bypass,inpformat,outformat, nrlines, ffttype);
- verify_fft();
- end
- endtask
- initial begin
- if(ffttype == 0)
- repeat(100000)@(posedge clk);
- else if(ffttype == 1)
- repeat(100000)@(posedge clk);
- $display("\033[1;31m----------------------------------------->TIMEBOMB<-----------------------------------------\033[0m");
- $finish(2);
- end
- task automatic verify_fft;
- logic [31:0] dut, model;
- int i;
- fwr = $fopen("dut_output.txt","r");
- modelout = $fopen("model_output.txt","r");
- $display("");
- repeat(nrlines) begin
- repeat(nrpoints) begin
- $fscanf(fwr,"%h %h",dut[31:16], dut[15:0]);
- $fscanf(modelout,"%h %h",model[31:16], model[15:0]);
- if(model == dut)
- $write("\033[1;32m%8.5f%s%8.5f\t\033[0m",trans_fp16(dut[31:16]),stringformatter,trans_fp16(dut[15:0]));
- else begin
- if((model[31:16] - dut[31:16] == 1) || (model[15:0] - dut[15:0] == 1) || (model[31:16] - dut[31:16] == -1)||(model[15:0] - dut[15:0] == -1)) begin
- $write("\033[1;33m%8.5f%s%8.5f\t\033[0m",trans_fp16(dut[31:16]),stringformatter,trans_fp16(dut[15:0]));
- onebitmatcherrors+=1;
- end
- else begin
- if((model[31:16] - dut[31:16] == 2) || (model[15:0] - dut[15:0] == 2) || (model[31:16] - dut[31:16] == -2) ||(model[15:0] - dut[15:0] == -2))
- $write("\033[1;35m%8.5f%s%8.5f\t\033[0m",trans_fp16(dut[31:16]),stringformatter,trans_fp16(dut[15:0]));
- else
- $write("\033[1;31m%8.5f%s%8.5f\t\033[0m",trans_fp16(dut[31:16]),stringformatter,trans_fp16(dut[15:0]));
- matcherrors+=1;
- end
- end
- i++;
- if((i%4) == 0)
- $display("");
- end
- $display("");
- end
- $fclose(modelout);
- $fclose(fwr);
- endtask
- task automatic send_lines;
- fft_wif.i.gnt = 1'b0;
- fwrinp = $fopen("input.txt","w");
- repeat(nrlines) begin
- if(run_number == 1)
- j_2D = 0;
- pixels_sent = 0;
- my_pi.d.line_start = 1'b1;
- @(posedge clk);
- my_pi.d.line_start = 1'b0;
- repeat(nrpoints) begin
- send_pix();
- send_write();
- //$display("I sent the point for i_2D=%0d and j_2D=%0d\n",i_2D,j_2D);
- //repeat(1) @(posedge clk);
- if(run_number == 1)
- j_2D++;
- end
- if(inptype == 2'b00)begin
- if(N==1)
- repeat(2) begin
- send_pix();
- send_write();
- if(run_number == 1)
- j_2D++;
- end
- end
- else if(inptype == 2'b01 || inptype == 2'b10)begin
- if(N==1)
- repeat(4) begin
- send_pix();
- send_write();
- if(run_number == 1)
- j_2D++;
- end
- else if(N==2)
- repeat(2) begin
- send_pix();
- send_write();
- if(run_number == 1)
- j_2D++;
- end
- end
- /* $fwrite(fwrinp,"\n"); */
- $fwrite(fwrinp_py,"\n");
- if(run_number == 1)
- i_2D++;
- end
- fft_wif.i.gnt = 1'b1;
- $fclose(fwrinp);
- endtask
- task automatic write_to_reg;
- input [31:0] addr;
- input [31:0] data;
- penable = 1'b1;
- pwrite = 1'b1;
- pwdata = data;
- psel = 1'b1;
- paddr = addr;
- @(posedge clk);
- penable = 1'b0;
- pwrite = '0;
- psel = 1'b0;
- endtask
- initial begin
- rst_n = 0;
- fscan_clkungate = 1'b0;
- fft_wif.i.gnt = 1'b1;
- i_2D = 0;
- i_2D_2 = 0;
- j_2D = 0;
- ignoreme = 0;
- en = 1;
- img_width = (2 ** 16) - 1;
- img_height = 2048;
- vwif.o.req = 1'b0;
- vrif.o.req = 1'b0;
- paddr = 0;
- penable = 1'b0;
- pwrite = 1'b0;
- pwdata = 1'b1;
- psel = 1'b1;
- cfg = 'd0;
- cfg.kl = 1;
- cfg.format = 4;
- cfg.auto = 1;
- my_pi.d.frame_start = 1'b0;
- my_pi.d.line_start = 1'b0;
- my_pi.d.line_end = 1'b0;
- my_pi.d.frame_end = 1'b0;
- AmcWr.b.verbose =0;//4 for more prints
- AmcRd.b.verbose =0;//4 for more prints
- repeat(2)@(posedge clk);
- rst_n = 1'b1;
- end
- function shortreal trans_fp16;
- input [DW-1:0] A;
- int sign, mantisa_norm, exp;
- shortreal rl;
- shortreal aux,m;
- /* $display("I get %0h",A); */
- sign = A[15];
- A = A & 16'h7fff;
- mantisa_norm = A % 1024;
- exp = (A / 1024);
- m = 1024 + mantisa_norm;
- exp -= 15;
- if(exp - 10 > 0)
- rl = m * (2 **( exp - 10));
- else begin
- aux = 1.0/(2.0 **( 10 - exp));
- rl = m * aux;
- end
- if(A==0)begin
- trans_fp16 = 0;
- end
- else
- if (sign) begin
- trans_fp16 = -1 * rl;
- /* $display(" and I give %f", -1 * rl); */
- end
- else begin
- trans_fp16 = rl;
- /* $display(" and I give %f", rl); */
- end
- endfunction
- task automatic send_write;
- #1;
- while(!vwif.i.gnt) @(posedge clk);
- /* $display("INFO : (%9d.00 ns) Sending write request for addr: %0h data: %0h", $time, vwif.o.addr, parent_wif.o.data[31:0]); */
- /* while(vwif.i.gnt) @(posedge clk);
- $display("INFO : (%9d.00 ns) \033[1;32mDone writing at addr: %0h data: %0h\033[0m", $time, vwif.o.addr, parent_wif.o.data[31:0]); */
- endtask
- task automatic send_read;
- input [31:0] addr;
- if(addr[31:28] == 4'h7 ) begin
- while(!fft_rif.i.gnt) @(posedge clk);
- /* $display("INFO : (%9d.00 ns) Sending read request for addr: %0h", $time, addr); */
- fft_rif.o.burst = 4'b0000;
- fft_rif.o.page = 1'b0;
- fft_rif.o.addr = addr;
- fft_rif.o.req = 1'b1;
- while(!vrif.i.strb) @(posedge clk);
- /* $display("INFO : (%9d.00 ns) \033[1;49mGot data:%0h at addr: %0h\033[0m", $time, fft_rif.i.data[31:0], addr); */
- fft_rif.o.req = 1'b0;
- end
- else
- $display("ERROR : (%9d.00 ns) \033[1;31mRead addr doesn't match base addr\033[0m", $time);
- endtask
- task automatic send_pix;
- logic [31:0] data;
- int conj1, conj2;
- logic e1,e2;
- int negthresh = -1 * thresh;
- if(ignoreme == 1) begin
- if(run_number == 0) begin
- data = $urandom($random(seed));
- end
- else if (run_number == 1) begin
- data = matrix_2D[i_2D][j_2D];
- //$display("Choosing data from i=%d j=%d",i_2D, j_2D);
- end
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->OUTPUT FROM FIRST RUN MIGHT BE BIGGER THAN THRESH, DATA MIGHT GET RANDOMISED THUS FAILED TEST<--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //----------------------------------------------------------------------------------------
- if(run_number == 0) begin
- if(inpformat==2'b00)begin // FP16
- while((trans_fp16(data[15:0]) > thresh) || (trans_fp16(data[15:0]) <negthresh))begin
- if(run_number == 1)
- $display("I randomize [15:0] %f AND I SHOULDN'T!",trans_fp16(data[15:0]));
- data[15:0] = $urandom($random(seed));
- end
- while((trans_fp16(data[31:16]) > thresh) || (trans_fp16(data[31:16]) <negthresh))begin
- if(run_number == 1)
- $display("I randomize [31:16] %f AND I SHOULDN'T!",trans_fp16(data[31:16]));
- data[31:16] = $urandom($random(seed));
- end
- end
- else if(inpformat==2'b10) begin // U16
- data[15:0] = data[15:0]%thresh;
- data[31:16] = data[31:16]%thresh;
- end
- end
- //----------------------------------------------------------------------------------------
- if((transftype == 2 || transftype == 3) && inptype==2'b00)
- data[15:0] = 16'd0;
- $fwrite(fwrinp,"%h %h ", data[31:16],data[15:0]);
- if(inptype==2'b00)begin // INPUT COMPLEX
- if(inpformat == 2'b00)
- $fwrite(fwrinp_py,"%f + %fj, ", trans_fp16(data[31:16]), trans_fp16(data[15:0]));
- else if(inpformat == 2'b10)
- $fwrite(fwrinp_py,"%d + %dj, ", data[31:16], data[15:0]);
- end
- else if(inptype==2'b01)begin // INPUT REALPLANE
- if(inpformat == 2'b00)
- $fwrite(fwrinp_py,"%f, %f, ",trans_fp16(data[31:16]), trans_fp16(data[15:0]));
- else if(inpformat == 2'b10)
- $fwrite(fwrinp_py,"%d, %d, ",data[31:16], data[15:0]);
- end
- else if(inptype==2'b10)begin // INPUT CONJUGATE
- conj1 = (-1)*data[31:16];
- conj2 = (-1)*data[15:0];
- if(inpformat == 2'b00)
- $fwrite(fwrinp_py,"%f + %fj, %f + %fj, ",trans_fp16(data[31:16]), trans_fp16(data[31:16]^(1<<15)), trans_fp16(data[15:0]), trans_fp16(data[15:0]^(1<<15)));
- else if(inpformat == 2'b10)
- $fwrite(fwrinp_py,"%d + %dj, %d + %dj, ",data[31:16], conj1,data[15:0], conj2);
- end
- pixels_sent++;
- end
- else begin
- ignoreme = 1;
- end
- while(my_pi.c.ready == 1'b0) @(posedge clk);
- bfl_dec = 1'b1;
- my_pi.d.data = data;
- my_pi.d.valid = 1'b1;
- if(pixels_sent == nrpoints) begin
- my_pi.d.line_end = 1'b1;
- end
- @(posedge clk);
- my_pi.d.valid = 1'b0;
- my_pi.d.line_end = 1'b0;
- endtask
- task automatic output_type_config;//-------------------------------INPUT TYPE CONFIGURATION-------------------------------------
- if(OUTTYPE=="COMPLEX")begin
- outtype = 1'b0;
- end
- else if(OUTTYPE=="REALPLANE")begin
- outtype = 1'b1;
- end
- if(OUTFORMAT=="FP16")begin
- outformat = 2'b00;
- end
- else if(OUTFORMAT=="U16")begin
- outformat = 2'b10;
- end
- endtask
- task automatic input_type_config;//-------------------------------INPUT TYPE CONFIGURATION--------------------------------------
- readstotal = 2 ** (N-2);
- repeat(2)@(posedge clk);
- if(INTYPE=="COMPLEX")begin
- inptype = 2'b00;
- end
- else if(INTYPE=="REALPLANE")begin
- inptype = 2'b01;
- readstotal /=2;
- end
- else if(INTYPE=="CONJUGATE")begin
- inptype = 2'b10;
- readstotal /=2;
- end
- if(readstotal == 0)
- readstotal = 1;
- if(INFORMAT=="FP16")begin
- inpformat = 2'b00;
- end
- else if(INFORMAT=="U16")begin
- inpformat = 2'b10;
- end
- endtask
- task automatic check_N;//----------------------------------------TYPE AND POINTS CHECK------------------------------------------
- logs = $fopen("log.txt","a");
- if(MODE == 1) begin
- cbits = 24;
- thresh = 1;
- if (N>6 && (TYPE=="DCT")) begin
- $display("\033[1;31mFOR <8/24> MODE AND <DCT or IDCT> THE MAXIMUM N IS 6! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- else if (N>7 && (TYPE=="FFT" || TYPE=="IFFT" || TYPE=="IDCT")) begin
- $display("\033[1;31mFOR <8/24> MODE AND <FFT or IFFT> THE MAXIMUM N IS 7! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- end
- else if(MODE == 2) begin
- cbits = 20;
- thresh = 1;
- if (N>9 && (TYPE=="DCT")) begin
- $display("\033[1;31mFOR <12/20> MODE AND <DCT or IDCT> THE MAXIMUM N IS 9! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- else if (N>10 && (TYPE=="FFT" || TYPE=="IFFT" || TYPE=="IDCT")) begin
- $display("\033[1;31mFOR <12/20> MODE AND <FFT or IFFT> THE MAXIMUM N IS 10! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- end
- else if(MODE == 0)begin
- cbits = 15;
- thresh = 65536/(2 ** (N+1));
- if (N>10 && (TYPE=="DCT" || TYPE=="IDCT")) begin
- $display("\033[1;31mFOR <17/15> MODE AND <DCT or IDCT> THE MAXIMUM N IS 10! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- else if (N>11 && (TYPE=="FFT" || TYPE=="IFFT")) begin
- $display("\033[1;31mFOR <17/15> MODE AND <FFT or IFFT> THE MAXIMUM N IS 11! FINISHING SIMULATION WITHOUT RUNNING TESTBENCH!\033[0m");
- $finish(2);
- end
- end
- endtask
- task automatic type_config;//---------------------------------------TYPE CONFIGURATION-----------------------------------------
- fwr = $fopen("dut_output.txt","w");
- if(TYPE=="DCT") begin
- transftype = 2'b10;
- stringformatter=" \t";
- if(MODE == 0)
- thresh = thresh/2;
- end
- else if(TYPE=="FFT") begin
- transftype = 2'b00;
- stringformatter=",";
- end
- else if(TYPE=="IDCT") begin
- transftype = 2'b11;
- stringformatter="\t";
- end
- else if(TYPE=="IFFT") begin
- transftype = 2'b01;
- stringformatter=",";
- end
- if (REORDER_BYPASS == "ENABLE")begin
- reorder_bypass = 1'b1;
- end
- else if (REORDER_BYPASS == "DISABLE")begin
- reorder_bypass = 1'b0;
- end
- if(DIMENSION == "1D")begin
- ffttype = 1'b0;
- end
- else if(DIMENSION == "2D")begin
- ffttype = 1'b1;
- end
- endtask
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement