OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [testbench/] [TestBench_verilog.v] - Diff between revs 186 and 188

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 186 Rev 188
 
 
 
 
/**********************************************************************************
/**********************************************************************************
Theia, Ray Cast Programable graphic Processing Unit.
Theia, Ray Cast Programable graphic Processing Unit.
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
 
 
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
of the License, or (at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
***********************************************************************************/
***********************************************************************************/
 
 
 
 
/*******************************************************************************
/*******************************************************************************
Module Description:
Module Description:
 
 
This is the Main test bench of the GPU. It simulates the behavior of
This is the Main test bench of the GPU. It simulates the behavior of
an external control unit or CPU that sends configuration information into DUT.
an external control unit or CPU that sends configuration information into DUT.
It also implements a second processs that simulates a Wishbone slave that sends
It also implements a second processs that simulates a Wishbone slave that sends
data from an external memory. These blocks are just behavioral CTE and therefore
data from an external memory. These blocks are just behavioral CTE and therefore
are not meant to be synthethized.
are not meant to be synthethized.
 
 
*******************************************************************************/
*******************************************************************************/
 
 
 
 
 
 
`timescale 1ns / 1ps
`timescale 1ns / 1ps
`include "aDefinitions.v"
`include "aDefinitions.v"
`define RESOLUTION_WIDTH        (rSceneParameters[13] >> `SCALE)
`define RESOLUTION_WIDTH        (rSceneParameters[13] >> `SCALE)
`define RESOLUTION_HEIGHT        (rSceneParameters[14] >> `SCALE)
`define RESOLUTION_HEIGHT        (rSceneParameters[14] >> `SCALE)
`define DELTA_ROW          (32'h1 << `SCALE)
`define DELTA_ROW          (32'h1 << `SCALE)
`define DELTA_COL          (32'h1 << `SCALE)
`define DELTA_COL          (32'h1 << `SCALE)
`define TEXTURE_BUFFER_SIZE       (256*256*3)
`define TEXTURE_BUFFER_SIZE       (256*256*3)
`define MAX_WIDTH          200
`define MAX_WIDTH          200
`define MAX_SCREENBUFFER        (`MAX_WIDTH*`MAX_WIDTH*3)
`define MAX_SCREENBUFFER        (`MAX_WIDTH*`MAX_WIDTH*3)
module TestBench_Theia;
module TestBench_Theia;
 
 
 
 
 //------------------------------------------------------------------------
 //------------------------------------------------------------------------
 //**WARNING: Declare all of your varaibles at the begining
 //**WARNING: Declare all of your varaibles at the begining
 //of the file. I hve noticed that sometimes the verilog
 //of the file. I hve noticed that sometimes the verilog
 //simulator allows you to use some regs even if they have not been 
 //simulator allows you to use some regs even if they have not been 
 //previously declared, leadeing to crahses or unexpected behavior
 //previously declared, leadeing to crahses or unexpected behavior
 // Inputs
 // Inputs
 reg Clock;
 reg Clock;
 reg Reset;
 reg Reset;
 wire [`WB_WIDTH-1:0]   DAT_O;
 wire [`WB_WIDTH-1:0]   DAT_O;
 reg          ACK_O;
 reg          ACK_O;
 wire        ACK_I;
 wire        ACK_I;
 wire [`WB_WIDTH-1:0]   ADR_I,ADR_O;
 wire [`WB_WIDTH-1:0]   ADR_I,ADR_O;
 wire         WE_I,STB_I;
 wire         WE_I,STB_I;
 wire         CYC_O,WE_O,TGC_O,STB_O;
 wire         CYC_O,WE_O,TGC_O,STB_O;
 wire [1:0]       TGA_O;
 wire [1:0]       TGA_O;
 wire [1:0]       TGA_I;
 wire [1:0]       TGA_I;
 reg [`WB_WIDTH-1:0]    TMADR_O,TMDAT_O;
 reg [`WB_WIDTH-1:0]    TMADR_O,TMDAT_O;
 reg [`MAX_TMEM_BANKS-1:0]  TMSEL_O;
 reg [`MAX_TMEM_BANKS-1:0]  TMSEL_O;
 reg         TMWE_O;
 reg         TMWE_O;
 reg [31:0]       rControlRegister[2:0];
 reg [31:0]       rControlRegister[2:0];
 integer          file, log;
 integer          file, log;
 reg [31:0]       rSceneParameters[120:0];
 reg [31:0]       rSceneParameters[120:0];
 reg [31:0]       rVertexBuffer[7000:0];
 reg [31:0]       rVertexBuffer[7000:0];
 reg [31:0]       rInstructionBuffer[512:0];
 reg [31:0]       rInstructionBuffer[512:0];
 reg [31:0]       rTextures[`TEXTURE_BUFFER_SIZE:0];  //Lets asume we use 256*256 textures
 reg [31:0]       rTextures[`TEXTURE_BUFFER_SIZE:0];  //Lets asume we use 256*256 textures
 reg [7:0]        rScreen[`MAX_SCREENBUFFER-1:0];
 reg [7:0]        rScreen[`MAX_SCREENBUFFER-1:0];
 
 
 wire         wDone;
 wire         wDone;
 wire [`MAX_CORES-1:0]   RENDREN_O;
 wire [`MAX_CORES-1:0]   RENDREN_O;
 reg [`MAX_CORE_BITS-1:0]   wOMEMBankSelect;
 reg [`MAX_CORE_BITS-1:0]   wOMEMBankSelect;
 reg [`WB_WIDTH-1:0]    wOMEMReadAddr;  //Output adress (relative to current bank)
 reg [`WB_WIDTH-1:0]    wOMEMReadAddr;  //Output adress (relative to current bank)
 wire [`WB_WIDTH-1:0]       wOMEMData;   //Output data bus (Wishbone)
 wire [`WB_WIDTH-1:0]       wOMEMData;   //Output data bus (Wishbone)
 reg        rHostEnable;
 reg        rHostEnable;
 integer       k,out2;
 integer       k,out2;
 wire GRDY_I;
 wire GRDY_I;
 wire GACK_O;
 wire GACK_O;
 wire STDONE_O;
 wire STDONE_O;
 wire wGPUCommitedResults;
 wire wGPUCommitedResults;
 wire wHostDataAvailable;
 wire wHostDataAvailable;
 
 
 
 
wire[`WB_WIDTH-1:0]               wHostReadAddress;
wire[`WB_WIDTH-1:0]               wHostReadAddress;
wire[`WB_WIDTH-1:0]               wMemorySize;
wire[`WB_WIDTH-1:0]               wMemorySize;
wire[1:0]                         wMemSelect;
wire[1:0]                         wMemSelect;
 
 
MUXFULLPARALELL_2SEL_GENERIC # ( `WB_WIDTH ) MUX2
MUXFULLPARALELL_2SEL_GENERIC # ( `WB_WIDTH ) MUX2
 (
 (
.Sel( wMemSelect ),
.Sel( wMemSelect ),
.I1(  rInstructionBuffer[0] ),
.I1(  rInstructionBuffer[0] ),
.I2(  rSceneParameters[0]   ),
.I2(  rSceneParameters[0]   ),
.I3(  rVertexBuffer[0]      ),
.I3(  rVertexBuffer[0]      ),
.I4(0),
.I4(0),
.O1(wMemorySize)
.O1(wMemorySize)
 );
 );
 
 
 
 
 //---------------------------------------------
 //---------------------------------------------
 top Top
 top Top
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.iHostEnable(      rHostEnable ),
.iHostEnable(      rHostEnable ),
.oHostReadAddress( wHostReadAddress),
.oHostReadAddress( wHostReadAddress),
.iMemorySize(      wMemorySize     ),
.iMemorySize(      wMemorySize     ),
.oMemSelect(       wMemSelect      ),
.oMemSelect(       wMemSelect      ),
.iInstruction(     rInstructionBuffer[wHostReadAddress] ),
.iInstruction(     rInstructionBuffer[wHostReadAddress] ),
.iParameter(       rSceneParameters[wHostReadAddress]   ),
.iParameter(       rSceneParameters[wHostReadAddress]   ),
.iVertex(          rVertexBuffer[wHostReadAddress]      ),
.iVertex(          rVertexBuffer[wHostReadAddress]      ),
.iControlRegister( rControlRegister[0]                  ),
.iControlRegister( rControlRegister[0]                  ),
.iPrimitiveCount(  (rVertexBuffer[6]+1) *7              ),
.iPrimitiveCount(  (rVertexBuffer[6]+1) *7              ),
.iTMEMAdr( TMADR_O ),
.iTMEMAdr( TMADR_O ),
.iTMEMData( TMDAT_O ),
.iTMEMData( TMDAT_O ),
.iTMEM_WE( TMWE_O ),
.iTMEM_WE( TMWE_O ),
.iTMEM_Sel( TMSEL_O ),
.iTMEM_Sel( TMSEL_O ),
.iOMEMBankSelect(  wOMEMBankSelect ),
.iOMEMBankSelect(  wOMEMBankSelect ),
.iOMEMReadAddress( wOMEMReadAddr ),
.iOMEMReadAddress( wOMEMReadAddr ),
.oOMEMData( wOMEMData ),
.oOMEMData( wOMEMData ),
 
 
.iWidth(`RESOLUTION_WIDTH),
.iWidth(`RESOLUTION_WIDTH),
.iHeight(`RESOLUTION_HEIGHT),
.iHeight(`RESOLUTION_HEIGHT),
.oDone( wDone )
.oDone( wDone )
 
 
 
 
);
);
 //---------------------------------------------
 //---------------------------------------------
 //generate the clock signal here
 //generate the clock signal here
 always begin
 always begin
  #`CLOCK_CYCLE  Clock =  ! Clock;
  #`CLOCK_CYCLE  Clock =  ! Clock;
 
 
 end
 end
 //---------------------------------------------
 //---------------------------------------------
 
 
 
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
/*
/*
This makes sure the simulation actually writes the results to the PPM image file
This makes sure the simulation actually writes the results to the PPM image file
once all the cores are done executing
once all the cores are done executing
*/
*/
`define PARTITION_SIZE `RESOLUTION_HEIGHT/`MAX_CORES
`define PARTITION_SIZE `RESOLUTION_HEIGHT/`MAX_CORES
integer i,j,kk;
integer i,j,kk;
reg [31:0] R;
reg [31:0] R;
always @ ( * )
always @ ( * )
begin
begin
 
 
 
 
if (wDone == 1'b1)
if (wDone == 1'b1)
begin
begin
 
 
 $display("Partition Size = %d",`PARTITION_SIZE);
 $display("Partition Size = %d",`PARTITION_SIZE);
 for (kk = 0; kk < `MAX_CORES; kk = kk+1)
 for (kk = 0; kk < `MAX_CORES; kk = kk+1)
   begin
   begin
   wOMEMBankSelect = kk;
   wOMEMBankSelect = kk;
    $display("wOMEMBankSelect = %d\n",wOMEMBankSelect);
    $display("wOMEMBankSelect = %d\n",wOMEMBankSelect);
    for (j=0; j < `PARTITION_SIZE; j=j+1)
    for (j=0; j < `PARTITION_SIZE; j=j+1)
    begin
    begin
 
 
     for (i = 0; i < `RESOLUTION_HEIGHT*3; i = i +1)
     for (i = 0; i < `RESOLUTION_HEIGHT*3; i = i +1)
     begin
     begin
     wOMEMReadAddr = i+j*`RESOLUTION_WIDTH*3;
     wOMEMReadAddr = i+j*`RESOLUTION_WIDTH*3;
     #`CLOCK_PERIOD;
     #`CLOCK_PERIOD;
     #1;
     #1;
     R = ((wOMEMData >> (`SCALE-8)) > 255) ? 255 : (wOMEMData >>  (`SCALE-8));
     R = ((wOMEMData >> (`SCALE-8)) > 255) ? 255 : (wOMEMData >>  (`SCALE-8));
     $fwrite(out2,"%d " , R );
     $fwrite(out2,"%d " , R );
 
 
      if ((i %3) == 0)
      if ((i %3) == 0)
        $fwrite(out2,"\n# %d %d\n",i/3,j);
        $fwrite(out2,"\n# %d %d\n",i/3,j);
 
 
     end
     end
    end
    end
   end
   end
 
 
 
 
 
 
   $fclose(out2);
   $fclose(out2);
   $fwrite(log, "Simulation end time : %dns\n",$time);
   $fwrite(log, "Simulation end time : %dns\n",$time);
   $fclose(log);
   $fclose(log);
 
 
 
 
   $stop();
   $stop();
 
 
 
 
end
end
end
end
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
 
reg [15:0] rTimeOut;
reg [15:0] rTimeOut;
 
 
 // `define MAX_INSTRUCTIONS 2
 // `define MAX_INSTRUCTIONS 2
 
 
 initial begin
 initial begin
  // Initialize Inputs
  // Initialize Inputs
 
 
 
 
  Clock      = 0;
  Clock      = 0;
  Reset      = 0;
  Reset      = 0;
  rTimeOut             = 0;
  rTimeOut             = 0;
  rHostEnable    = 0;
  rHostEnable    = 0;
  //Read Config register values
  //Read Config register values
  $write("Loading control register.... ");
  $write("Loading control register.... ");
  $readmemh("Creg.mem",rControlRegister);
  $readmemh("Creg.mem",rControlRegister);
  $display("Done");
  $display("Done");
 
 
 
 
 
 
  //Read configuration Data
  //Read configuration Data
  $write("Loading scene parameters.... ");
  $write("Loading scene parameters.... ");
  $readmemh("Params.mem", rSceneParameters );
  $readmemh("Params.mem", rSceneParameters );
  $display("Done");
  $display("Done");
 
 
 
 
  //Read Scene Data
  //Read Scene Data
  $write("Loading scene geometry.... ");
  $write("Loading scene geometry.... ");
  $readmemh("Vertex.mem",rVertexBuffer);
  $readmemh("Vertex.mem",rVertexBuffer);
  $display("Done");
  $display("Done");
 
 
  $display("Number of primitives(%d): %d",rVertexBuffer[6],(rVertexBuffer[6]+1) *7);
  $display("Number of primitives(%d): %d",rVertexBuffer[6],(rVertexBuffer[6]+1) *7);
 
 
 
 
  //Read Texture Data
  //Read Texture Data
  $write("Loading scene texture.... ");
  $write("Loading scene texture.... ");
  $readmemh("Textures.mem",rTextures);
  $readmemh("Textures.mem",rTextures);
  $display("Done");
  $display("Done");
 
 
 
 
  //Read instruction data
  //Read instruction data
  $write("Loading code allocation table and user shaders.... ");
  $write("Loading code allocation table and user shaders.... ");
  $readmemh("Instructions.mem",rInstructionBuffer);
  $readmemh("Instructions.mem",rInstructionBuffer);
  $display("Done");
  $display("Done");
 
 
  $display("Control Register : %b",rControlRegister[0]);
  $display("Control Register : %b",rControlRegister[0]);
  $display("Resolution       : %d X %d",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
  $display("Resolution       : %d X %d",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
 
 
 
 
  //Open output file
  //Open output file
  out2 = $fopen("Output.ppm");
  out2 = $fopen("Output.ppm");
 
 
  $fwrite(out2,"P3\n");
  $fwrite(out2,"P3\n");
  $fwrite(out2,"#This file was generated by Theia's RTL simulation\n");
  $fwrite(out2,"#This file was generated by Theia's RTL simulation\n");
  $fwrite(out2,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
  $fwrite(out2,"%d %d\n",`RESOLUTION_WIDTH, `RESOLUTION_HEIGHT );
  $fwrite(out2,"255\n");
  $fwrite(out2,"255\n");
 
 
  #10
  #10
  Reset = 1;
  Reset = 1;
 
 
 
 
  // Wait 100 ns for global reset to finish
  // Wait 100 ns for global reset to finish
  TMWE_O = 1;
  TMWE_O = 1;
  #100  Reset = 0;
  #100  Reset = 0;
  TMWE_O = 1;
  TMWE_O = 1;
 
 
  $display("Intilializing TMEM @ %dns",$time);
  $display("Intilializing TMEM @ %dns",$time);
  //starts in 2 to skip Width and Height
  //starts in 2 to skip Width and Height
  for (k = 0;k < `TEXTURE_BUFFER_SIZE; k = k + 1)
  for (k = 0;k < `TEXTURE_BUFFER_SIZE; k = k + 1)
  begin
  begin
 
 
   TMADR_O <= (k >> (`MAX_CORE_BITS));
   TMADR_O <= (k >> (`MAX_CORE_BITS));
   TMSEL_O <= (k & (`MAX_TMEM_BANKS-1));  //X mod 2^n == X & (2^n - 1)
   TMSEL_O <= (k & (`MAX_TMEM_BANKS-1));  //X mod 2^n == X & (2^n - 1)
   TMDAT_O <= rTextures[k];
   TMDAT_O <= rTextures[k];
   #10;
   #10;
   if ((k % (256*3)) == 0)
   if ((k % (256*3)) == 0)
   begin
   begin
    $write("|");
    $write("|");
    $fflush;
    $fflush;
   end
   end
  end
  end
  $display("\nDone Intilializing TMEM @ %dns",$time);
  $display("\nDone Intilializing TMEM @ %dns",$time);
  TMWE_O = 0;
  TMWE_O = 0;
  rHostEnable = 1;
  rHostEnable = 1;
 
 
  log  = $fopen("Simulation.log");
  log  = $fopen("Simulation.log");
  $fwrite(log, "Simulation start time : %dns\n",$time);
  $fwrite(log, "Simulation start time : %dns\n",$time);
  $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
  $fwrite(log, "Width : %d\n",`RESOLUTION_WIDTH);
  $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
  $fwrite(log, "Height : %d\n",`RESOLUTION_HEIGHT);
 
 
  //Start dumping VCD
  //Start dumping VCD
  $display("-I- Starting VCD Dump\n");
  $display("-I- Starting VCD Dump\n");
 // $dumpfile("TestBench_Theia.vcd");
 // $dumpfile("TestBench_Theia.vcd");
 // $dumpvars(0,TestBench_Theia);
 // $dumpvars(0,TestBench_Theia);
 
 
 end
 end
 
 
 
 
endmodule
endmodule
 No newline at end of file
 No newline at end of file
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.