punk@32: #!/usr/bin/env perl punk@32: # -*- perl -*- punk@32: punk@32: ############################################################## punk@32: # punk@32: # Benchmark setup for HAsim punk@32: # punk@32: # Usage: setup-bmark punk@32: # punk@32: # Setup benchmark to run in punk@32: # punk@32: ############################################################## punk@32: rlm@34: #use strict; punk@32: use warnings; punk@32: use File::Basename; punk@32: use Getopt::Long; punk@32: punk@32: sub Usage(); punk@32: sub ErrorExit($); punk@32: punk@32: # punk@32: # Turn on warnings punk@32: # punk@32: $^W = 1; punk@32: punk@32: my $binary = undef; punk@32: my $compare = undef; punk@32: my $data = undef; punk@32: my $feeder = ''; punk@32: my $group = undef; punk@32: my $isa = "unknown_ISA"; punk@32: my $linkto = undef; punk@32: my $numContexts = 1; punk@32: punk@32: # punk@32: # Find the root of the benchmarks directory tree. punk@32: # punk@32: my $benchmark_root = `awb-resolver --config=benchmarkdir`; punk@32: chomp($benchmark_root); punk@32: ErrorExit("Can't find benchmark root") if ($benchmark_root eq ''); punk@32: punk@32: # punk@32: # Parse the command line switches punk@32: # punk@32: if (! GetOptions('binary=s' => \$binary, punk@32: 'compare=s' => \$compare, punk@32: 'data=s' => \$data, punk@32: 'feeder=s' => \$feeder, punk@32: 'group=s' => \$group, punk@32: 'isa=s' => \$isa, punk@32: 'linkto=s' => \$linkto, punk@32: 'contexts=i' => \$numContexts, punk@32: )) { punk@32: Usage(); punk@32: } punk@32: punk@32: if ($#ARGV != 2) { punk@32: Usage(); punk@32: } punk@32: punk@32: my $bmark = $ARGV[0]; punk@32: my $srcdir = $ARGV[1]; punk@32: my $dstdir = $ARGV[2]; punk@32: my $basedir = `pwd`; punk@32: chomp($basedir); punk@32: punk@32: print "BMARK: $bmark\n"; punk@32: print "SRC: $srcdir\n"; punk@32: print "DST: $dstdir\n"; punk@32: print "BASE: $basedir\n"; punk@32: rlm@47: $pygarRoot = "$srcdir/.."; rlm@47: rlm@47: punk@32: if (! defined($group)) { punk@32: $group = $bmark; punk@32: } punk@32: punk@32: chdir($dstdir) or ErrorExit("Failed to cd to $dstdir"); punk@32: punk@32: mkdir('hasim_debug') or ErrorExit("Failed to make 'hasim_debug' directory"); punk@32: punk@32: # Set up benchmark for non-null feeders punk@32: my $context = 0; punk@32: while ($context < $numContexts) { punk@32: if ($feeder ne "none") { punk@32: my $src_prog; punk@32: punk@32: mkdir("program.${context}") or ErrorExit("Failed to make program directory"); punk@32: chdir("program.${context}") or ErrorExit("Failed to cd to program directory"); punk@32: rlm@47: #print "***********************\n\n$benchmark_root --- ${benchmark_root}\n\n******************************\n"; rlm@47: punk@32: if (defined($binary)) { punk@32: $src_prog = "${benchmark_root}/hasim/${isa}/${group}/${binary}"; punk@32: } rlm@47: rlm@47: elsif (-f "$pygarRoot/benchProgs/${bmark}.${isa}.vmh"){ rlm@47: print"\n*******************\n rlm:using speciel Pygar program\n**************************\n"; rlm@47: $src_prog = "$pygarRoot/benchProgs/${bmark}.${isa}.vmh";} rlm@47: punk@32: elsif (-f "${benchmark_root}/hasim/${isa}/${group}/${bmark}.${isa}.bin") { punk@32: $src_prog = "${benchmark_root}/hasim/${isa}/${group}/${bmark}.${isa}.bin"; punk@32: } punk@32: elsif (-f "${benchmark_root}/hasim/${isa}/${group}/${bmark}.${isa}.vmh") { punk@32: $src_prog = "${benchmark_root}/hasim/${isa}/${group}/${bmark}.${isa}.vmh"; punk@32: } rlm@47: rlm@47: rlm@47: punk@32: else { punk@32: print STDERR "Can't find binary in ${benchmark_root}/hasim/${isa}/${group}\n"; punk@32: exit(1); punk@32: } punk@32: punk@32: my $dst_prog = basename($src_prog); punk@32: punk@32: unlink($dst_prog); rlm@40: rlm@40: print "\n\nRLM: putting $src_prog in $dst_prog, and also program.vmh\n"; rlm@40: punk@32: symlink($src_prog, $dst_prog) or ErrorExit("Failed to symlink $dst_prog => $src_prog"); rlm@40: symlink($src_prog, "program.vmh") or ErrorExit("Failed to symlink $dst_prog => $src_prog"); rlm@40: punk@32: # Copy input data files punk@32: if (defined($data)) { punk@32: # No trailing slash. Just link to a single object rlm@34: rlm@34: rlm@34: # rlm: oh my gosh here we go with TWO files! rlm@34: print "\nRLM: moving TWO files:\n"; rlm@34: print "OHYEAH:: $data\n\n"; rlm@34: $data =~ m#^.*/([^/]*)\.wav$#; rlm@34: #print "OHYYYYYYEAH::: $1\n\n\n!!!"; rlm@34: $newFile = $1."1.wav"; punk@32: print "data: $data\n"; rlm@34: print "rlm: data2: $newFile\n"; rlm@34: print "\nrlm: move ${srcdir}/${data} to input.wav\n\n"; rlm@34: rlm@34: symlink("${srcdir}/${data}", "../input.wav") or die("Failed to link to $data"); rlm@34: symlink("${srcdir}/../benchmarks/audio_processor_test/$newFile", "../input1.wav") or die("Failed to link to $newFile"); rlm@34: rlm@34: punk@32: } punk@32: # this came from processor bit and not sure what it is expecting punk@32: # Copy input data files punk@32: # if (defined($data)) { punk@32: # if ($data =~ /\.tar\.gz$/) { punk@32: # system("tar xzf ${data}"); punk@32: # } punk@32: # elsif ($data =~ /\.tar$/) { punk@32: # system("tar xf ${data}"); punk@32: # } punk@32: # } punk@32: punk@32: # Link to files or directories punk@32: if (defined($linkto)) { punk@32: foreach my $tgt (split(':', $linkto)) { punk@32: if ($tgt =~ /\/$/) { punk@32: # Trailing slash means link to all the files individually within punk@32: # a directory. punk@32: if (-d $tgt) { punk@32: opendir(DIR, $tgt) || die("Cannot open directory for --linkto $tgt\n"); punk@32: my @tgt_objs = readdir(DIR); punk@32: closedir(DIR); punk@32: foreach my $t (@tgt_objs) { punk@32: if (! (($t eq '.') || ($t eq '..'))) { punk@32: symlink("${tgt}${t}", basename($t)) or die("Failed to link to ${tgt}${t}"); punk@32: } punk@32: } punk@32: } punk@32: } punk@32: else { punk@32: # No trailing slash. Just link to a single object punk@32: symlink($tgt, basename($tgt)) or die("Failed to link to $tgt"); punk@32: } punk@32: } punk@32: } punk@32: punk@32: # Back to main workload directory punk@32: chdir(".."); punk@32: } punk@32: punk@32: $context += 1; punk@32: } punk@32: punk@32: # Store compare rules to config punk@32: open(ENV, '>>config/env.sh') or die("Failed to open config/env.sh"); punk@32: print ENV "ISA=\"${isa}\"\n"; punk@32: if ($numContexts != 0) { punk@32: print ENV "workloadContexts=\"${numContexts}\"\n"; punk@32: } punk@32: if (defined($compare)) { punk@32: print ENV "compare=\"${compare}\"\n"; rlm@40: #print ENV "compare=\"ls\"\n"; punk@32: } punk@32: close(ENV); punk@32: punk@32: # Set up m5 environment punk@32: if ($feeder eq 'm5') { punk@32: system("(cd $srcdir; tar cf - ./m5_configs) | tar xf -"); punk@32: } punk@32: punk@32: system("cp -f ${srcdir}/run.bmark run"); punk@32: chmod(0755, "run"); punk@32: punk@32: exit(0); punk@32: punk@32: punk@32: punk@32: sub Usage() { punk@32: print STDERR "Usage: setup-bmark [--binary ]\n"; punk@32: print STDERR " [--compare ]\n"; punk@32: print STDERR " [--contexts ]\n"; punk@32: print STDERR " [--data ]\n"; punk@32: print STDERR " [--group ]\n"; punk@32: print STDERR " [--isa ]\n"; punk@32: print STDERR " [--linkto :...:]\n"; punk@32: print STDERR " \n"; punk@32: exit(1); punk@32: } punk@32: punk@32: punk@32: sub ErrorExit($) { punk@32: print STDERR @_ . "\n"; punk@32: exit(1); punk@32: }