#!/usr/bin/perl
|
#!/usr/bin/perl
|
|
|
# This is the main simulation environment laucnher script.
|
# This is the main simulation environment laucnher script.
|
# It will create a regression area under a folder with a
|
# It will create a regression area under a folder with a
|
# unique name.
|
# unique name.
|
#
|
#
|
#
|
#
|
#
|
#
|
#
|
#
|
|
|
use strict;
|
use strict;
|
use Cwd;
|
use Cwd;
|
use File::Copy;
|
use File::Copy;
|
use File::Find;
|
use File::Find;
|
use HTTP::Date;
|
use HTTP::Date;
|
use Time::HiRes;
|
use Time::HiRes;
|
use Data::Dumper;
|
use Data::Dumper;
|
#use File::Copy::Recursive;
|
#use File::Copy::Recursive;
|
|
|
#Globals
|
#Globals
|
my $SimulationCommand = undef;
|
my $SimulationCommand = undef;
|
my @SimulationFiles = undef;
|
my @SimulationFiles = undef;
|
my $SimulationBinary = undef;
|
my $SimulationBinary = undef;
|
my $RegressionTargetDirectory = undef;
|
my $RegressionTargetDirectory = undef;
|
my %TestList = undef;
|
my %TestList = undef;
|
|
|
|
|
my
|
my
|
$ScriptPath = getcwd();
|
$ScriptPath = getcwd();
|
print "Running from $ScriptPath\n";
|
print "Running from $ScriptPath\n";
|
#Read the configuration from this file
|
#Read the configuration from this file
|
eval Slurp( "testlist.pl" );
|
eval Slurp( "testlist.pl" );
|
die "-E- Errors in configuration file!\n".$@."\n" if($@);
|
die "-E- Errors in configuration file!\n".$@."\n" if($@);
|
|
|
my $Scale = 131072; # 2^17
|
my $Scale = 131072; # 2^17
|
CreateTargetTree( $RegressionTargetDirectory );
|
CreateTargetTree( $RegressionTargetDirectory );
|
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
sub hashValueAscendingNum {
|
sub hashValueAscendingNum {
|
$TestList{$a}->{'run_index'} <=> $TestList{$b}->{'run_index'};
|
$TestList{$a}->{'run_index'} <=> $TestList{$b}->{'run_index'};
|
}
|
}
|
|
|
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
sub CreateTargetTree
|
sub CreateTargetTree
|
{
|
{
|
my $DestinationPath = shift;
|
my $DestinationPath = shift;
|
my ($date, $time) = split(" ", HTTP::Date::time2iso());
|
my ($date, $time) = split(" ", HTTP::Date::time2iso());
|
$time =~ s/:/_/g;
|
$time =~ s/:/_/g;
|
my $RegDir = "$RegressionTargetDirectory/regression_${date}_${time}";
|
my $RegDir = "$RegressionTargetDirectory/regression_${date}_${time}";
|
mkdir $RegDir or die "Cannot create regression folder '$RegDir' $!\n";
|
mkdir $RegDir or die "Cannot create regression folder '$RegDir' $!\n";
|
|
|
#Create the regression.log
|
#Create the regression.log
|
open LOG, ">$RegDir/regression.log" or die "Cannot create file regression log file '$RegDir/Regression.log' $!\n";
|
open LOG, ">$RegDir/regression.log" or die "Cannot create file regression log file '$RegDir/Regression.log' $!\n";
|
print LOG "Regression Test-bench started at $date ,time $time\n";
|
print LOG "Regression Test-bench started at $date ,time $time\n";
|
#Collect some information about the system
|
#Collect some information about the system
|
my $system = `uname -a`;
|
my $system = `uname -a`;
|
my $memory = `cat /proc/meminfo | grep -i memtotal`;
|
my $memory = `cat /proc/meminfo | grep -i memtotal`;
|
my $cpu = `cat /proc/cpuinfo | grep -i model | grep name`;
|
my $cpu = `cat /proc/cpuinfo | grep -i model | grep name`;
|
print LOG "System: $system\n";
|
print LOG "System: $system\n";
|
print LOG "RAM: $memory\n";
|
print LOG "RAM: $memory\n";
|
print LOG "CPU:\n$cpu\n";
|
print LOG "CPU:\n$cpu\n";
|
|
|
#for my $i (0 .. $#TestList)
|
#for my $i (0 .. $#TestList)
|
#print Dumper(%TestList);
|
#print Dumper(%TestList);
|
for my $TestName (sort hashValueAscendingNum (keys %TestList))
|
for my $TestName (sort hashValueAscendingNum (keys %TestList))
|
{
|
{
|
chdir $ScriptPath;
|
chdir $ScriptPath;
|
my $TestPath = $TestList{$TestName}->{'path'};
|
my $TestPath = $TestList{$TestName}->{'path'};
|
|
|
|
|
|
|
print LOG "-----------------------------------------------------------------------------------\n";
|
print LOG "-----------------------------------------------------------------------------------\n";
|
print LOG "Scene: '$TestName'\n";
|
print LOG "Scene: '$TestName'\n";
|
my $TestDir = "$RegDir/$TestName";
|
my $TestDir = "$RegDir/$TestName";
|
|
|
mkdir $TestDir;
|
mkdir $TestDir;
|
#Copy compulsory files
|
#Copy compulsory files
|
copy("$TestPath/Vertex.mem","$TestDir/") or die "-E- $TestPath/Vertex.mem $!\n";
|
copy("$TestPath/Vertex.mem","$TestDir/") or die "-E- $TestPath/Vertex.mem $!\n";
|
copy("$TestPath/Params.mem","$TestDir/") or die "-E- $TestPath/Params.mem $!\n";
|
copy("$TestPath/Params.mem","$TestDir/") or die "-E- $TestPath/Params.mem $!\n";
|
copy("$TestPath/Creg.mem","$TestDir/") or die "-E- $TestPath/Config.mem $!\n";
|
copy("$TestPath/Creg.mem","$TestDir/") or die "-E- $TestPath/Config.mem $!\n";
|
copy("$TestPath/Reference.ppm","$TestDir/") or die "-E- $TestPath/Reference.ppm $!\n";
|
copy("$TestPath/Reference.ppm","$TestDir/") or die "-E- $TestPath/Reference.ppm $!\n";
|
copy("$TestPath/Textures.mem","$TestDir/") or die "-E- $TestPath/Textures.ppm $!\n";
|
copy("$TestPath/Textures.mem","$TestDir/") or die "-E- $TestPath/Textures.ppm $!\n";
|
copy("$TestPath/Instructions.mem","$TestDir/") or die "-E- $TestPath/Instructions.ppm $!\n";
|
copy("$TestPath/Instructions.mem","$TestDir/") or die "-E- $TestPath/Instructions.ppm $!\n";
|
copy("$TestPath/Instructions.mem","$TestDir/") or die "-E- $TestPath/Instructions.ppm $!\n";
|
copy("$TestPath/Instructions.mem","$TestDir/") or die "-E- $TestPath/Instructions.ppm $!\n";
|
#Print some information about the scene
|
#Print some information about the scene
|
my $Line = `grep -i width $TestDir/Params.mem`;
|
|
my ($Width,$Height) = split(" ", $Line);
|
|
$Width = (hex $Width)/$Scale;
|
my $Width = $TestList{$TestName}->{'width'};
|
$Height = (hex $Height)/$Scale;
|
my $Height = $TestList{$TestName}->{'height'};
|
|
|
print LOG "Scene Resolution: $Width x $Height\n";
|
print LOG "Scene Resolution: $Width x $Height\n";
|
$Line = `grep -i texture $TestDir/Params.mem`;
|
my $Line = `grep -i texture $TestDir/Params.mem`;
|
my ($Width,$Height) = split(" ", $Line);
|
my ($tWidth,$tHeight) = split(" ", $Line);
|
$Width = (hex $Width)/$Scale;
|
$tWidth = (hex $tWidth)/$Scale;
|
$Height = (hex $Height)/$Scale;
|
$tHeight = (hex $tHeight)/$Scale;
|
print LOG "Texture: $Width x $Height\n";
|
print LOG "Texture: $tWidth x $tHeight\n";
|
my $TringleCount = `grep -A 1 -i child $TestDir/Vertex.mem | grep -v -i child`;
|
my $TringleCount = `grep -A 1 -i child $TestDir/Vertex.mem | grep -v -i child`;
|
print LOG "Triangle count: $TringleCount\n";
|
print LOG "Triangle count: $TringleCount\n";
|
|
|
#Copy the Source files just in case..
|
#Copy the Source files just in case..
|
mkdir "$RegDir/rtl";
|
mkdir "$RegDir/rtl";
|
system("cp -vr ../rtl/*.v $RegDir/rtl");
|
system("cp -vr ../rtl/*.v $RegDir/rtl");
|
#copy("../rtl","$RegDir") or die ("Cannot Copy '" . $_ . "' : $!\n");
|
#copy("../rtl","$RegDir") or die ("Cannot Copy '" . $_ . "' : $!\n");
|
|
|
|
|
#Compile the test code
|
#Compile the test code
|
#print Dumper($TestList{$TestName});
|
#print Dumper($TestList{$TestName});
|
my $CoreCount = $TestList{$TestName}->{core_count};
|
my $CoreCount = $TestList{$TestName}->{core_count};
|
my $MemBankCount = $TestList{$TestName}->{mem_bank_count};
|
my $MemBankCount = $TestList{$TestName}->{mem_bank_count};
|
printf
|
printf
|
"
|
"
|
Compiling Code
|
Compiling Code
|
Number of execution cores: $CoreCount
|
Number of execution cores: $CoreCount
|
Number of texture memory banks: $MemBankCount
|
Number of texture memory banks: $MemBankCount
|
";
|
";
|
|
|
chdir "../simulation";
|
chdir "../simulation";
|
if ( system("make compile GPUCORES=$CoreCount GPUMEMBANKS=$MemBankCount") != 0)
|
if ( system("make compile GPUCORES=$CoreCount GPUMEMBANKS=$MemBankCount WIDTH=$Width HEIGHT=$Height") != 0)
|
{
|
{
|
die "-E- Error compiling test code! ($!)\n";
|
die "-E- Error compiling test code! ($!)\n";
|
}
|
}
|
#Now copy the binary over to our simulation directory
|
#Now copy the binary over to our simulation directory
|
|
|
|
|
copy("$SimulationBinary","$TestDir/") or die "-E- $SimulationBinary $!\n";
|
copy("$SimulationBinary","$TestDir/") or die "-E- $SimulationBinary $!\n";
|
|
|
printf
|
printf
|
"
|
"
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
** Theia Regression Started **
|
** Theia Regression Started **
|
|
|
|
|
Regression Target Directory:
|
Regression Target Directory:
|
'$TestDir'
|
'$TestDir'
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
";
|
";
|
|
|
|
|
#Execute the Simulation
|
#Execute the Simulation
|
chdir $TestDir;
|
chdir $TestDir;
|
my ($StartDate,$StartTime) = split(" ", HTTP::Date::time2iso());
|
my ($StartDate,$StartTime) = split(" ", HTTP::Date::time2iso());
|
|
|
print LOG "Number of execution cores: $CoreCount\n";
|
print LOG "Number of execution cores: $CoreCount\n";
|
print LOG "Number of memory banks: $MemBankCount\n";
|
print LOG "Number of memory banks: $MemBankCount\n";
|
print LOG "Simulation started at: $StartDate $StartTime\n";
|
print LOG "Simulation started at: $StartDate $StartTime\n";
|
|
|
#system "$SimulationCommand -tclbatch isim.tcl";
|
#system "$SimulationCommand -tclbatch isim.tcl";
|
if (system ("perl $ScriptPath/configure_params.pl $CoreCount") != 0)
|
if (system ("perl $ScriptPath/configure_params.pl $CoreCount") != 0)
|
{
|
{
|
die "-E- Error configuing scene parameters! ($!)\n";
|
die "-E- Error configuing scene parameters! ($!)\n";
|
}
|
}
|
my $StartTime = [Time::HiRes::gettimeofday()];
|
my $StartTime = [Time::HiRes::gettimeofday()];
|
if (system("vvp -n $SimulationBinary -none") != 0)
|
if (system("vvp -n $SimulationBinary -none") != 0)
|
{
|
{
|
print LOG "-E- Error running simulation! ($!)\n";
|
print LOG "-E- Error running simulation! ($!)\n";
|
}
|
}
|
|
|
my $diff = Time::HiRes::tv_interval($StartTime);
|
my $diff = Time::HiRes::tv_interval($StartTime);
|
my ($EndDate,$EndTime) = split(" ", HTTP::Date::time2iso());
|
my ($EndDate,$EndTime) = split(" ", HTTP::Date::time2iso());
|
print LOG "Simulation Completed at $EndDate $EndTime\n";
|
print LOG "Simulation Completed at $EndDate $EndTime\n";
|
print LOG "Simulation ran for " . $diff/3600 . " hours\n";
|
print LOG "Simulation ran for " . $diff/3600 . " hours\n";
|
|
|
|
|
ParseOutputPPM( $TestDir );
|
ParseOutputPPM( $TestDir );
|
|
|
# system("perl D:/\Proyecto/\RTL/\Scripts/calculate_stats.pl $TestDir/\CU.log $RegDir/\Regression.log $TestDir/\Simulation.log");
|
# system("perl D:/\Proyecto/\RTL/\Scripts/calculate_stats.pl $TestDir/\CU.log $RegDir/\Regression.log $TestDir/\Simulation.log");
|
|
|
}
|
}
|
close LOG;
|
close LOG;
|
|
|
|
|
|
|
}
|
}
|
|
|
#---------------------------------------------------------------- \
|
#---------------------------------------------------------------- \
|
sub Slurp
|
sub Slurp
|
{
|
{
|
my $file = shift;
|
my $file = shift;
|
open F, "< $file" or die "Error opening '$file' for read: $!";
|
open F, "< $file" or die "Error opening '$file' for read: $!";
|
local $/ = undef;
|
local $/ = undef;
|
my $string = <F>;
|
my $string = <F>;
|
close F;
|
close F;
|
return $string;
|
return $string;
|
}
|
}
|
|
#-------------------------------------------------------------------------------
|
|
sub Round
|
|
{
|
|
my $number = shift;
|
|
my $rounded = sprintf("%.3f", $number);
|
|
return $rounded;
|
|
}
|
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
sub ParseOutputPPM()
|
sub ParseOutputPPM()
|
{
|
{
|
my $TestDir = shift;
|
my $TestDir = shift;
|
open FILE, "$TestDir/Output.ppm" or die "Can't open $TestDir/Output.ppm !$\n";
|
open FILE, "$TestDir/Output.ppm" or die "Can't open $TestDir/Output.ppm !$\n";
|
my $i = 1;
|
my $i = 1;
|
my $CurrentRow;
|
my $CurrentRow;
|
my $CurrentCol;
|
my $CurrentCol;
|
while (<FILE>)
|
while (<FILE>)
|
{
|
{
|
|
|
if (m/^#\s*(\d+)\,\s+(\d+)/)
|
if (m/^#\s*(\d+)\,\s+(\d+)/)
|
{
|
{
|
$CurrentRow = $1;
|
$CurrentRow = $1;
|
$CurrentCol = $2;
|
$CurrentCol = $2;
|
}
|
}
|
|
|
# m/\s*(\d)\s+(\d)\s+(\d).*/;
|
# m/\s*(\d)\s+(\d)\s+(\d).*/;
|
if (m/x+/g)
|
if (m/x+/g)
|
{
|
{
|
print LOG "FATAL ERROR: 'Output.ppm' Found 'x' at row = $CurrentRow , col = $CurrentCol = $2, line $i\n" ;
|
print LOG "FATAL ERROR: 'Output.ppm' Found 'x' at row = $CurrentRow , col = $CurrentCol = $2, line $i\n" ;
|
last;
|
last;
|
return;
|
return;
|
}
|
}
|
$i++;
|
$i++;
|
}
|
}
|
close FILE;
|
close FILE;
|
|
|
|
my $TotalTime = 0;
|
|
open F, "$TestDir/Simulation.log" or die "$TestDir/Simulation.log' : $!\n";
|
|
|
|
|
|
local $/=undef;
|
|
my $Temp = <F>;
|
|
close F;
|
|
my($junk,$StartSimTime) = split /Simulation start time \:\s+/,$Temp;
|
|
my($junk,$EndSimTime) = split /Simulation end time \:\s+/,$Temp;
|
|
$StartSimTime =~ s/ns//;
|
|
$EndSimTime =~ s/ns//;
|
|
$TotalTime = ($EndSimTime-$StartSimTime)/1000000000;
|
|
print LOG "Simulated start time: $StartSimTime\n";
|
|
print LOG "Simulated end time: $EndSimTime\n";
|
|
print LOG "Total Time: $TotalTime seconds\n";
|
|
print LOG "Theorical FPS: ". Round( (1 /$TotalTime) )."\n";
|
}
|
}
|
|
|
|
|