hqjenny-centrifuge/scripts/run_hls.pl

115 lines
2.6 KiB
Perl
Raw Permalink Normal View History

2019-10-31 18:06:27 +08:00
#!/usr/bin/perl
use warnings;
use strict;
use Cwd;
use File::Copy;
my $file_name = $ARGV[0];
my $func_name = $ARGV[1];
my $prefix = undef;
my $num_args = $#ARGV + 1;
if ($num_args > 2) {
$prefix = $ARGV[2];
}
#############################GENERATE HLS##############################
# Generate directive file based on LLVM emitted output
# If the variable is of pointer type that an ap_bus interface is generated
my $directive_tcl_insn = 'set_directive_interface -mode ap_bus "FUNC" test_var
2019-10-31 18:06:27 +08:00
';
my $prefix_tcl = "";
if ($prefix) {
$prefix_tcl = "config_rtl -prefix ".$prefix."\n";
}
#my $hls_pgm = undef;
my @hls_pgms = ();
my $cpp_flags = '';
2019-10-31 18:06:27 +08:00
if (-f $file_name.".cpp"){
$cpp_flags = '-cflags "-std=c++0x"';
2019-11-25 19:32:04 +08:00
#@hls_pgms = glob('*.cpp');
push(@hls_pgms, $file_name.'.cpp')
2019-10-31 18:06:27 +08:00
} else {
@hls_pgms = glob('*.c');
2019-11-25 19:32:04 +08:00
#push(@hls_pgms, $file_name.'.c')
2019-10-31 18:06:27 +08:00
}
my @hls_files = ();
foreach my $pgm (@hls_pgms) {
if ($pgm ne 'accel_wrapper.c') {
push(@hls_files, 'add_files '.$pgm.' '.$cpp_flags);
}
}
my $hls_files_str = join "\n", @hls_files;
2019-10-31 18:06:27 +08:00
# should change to add all .c files
my $hls_tcl = 'open_project -reset PGM_prj
set_top FUNC
HLS_FILES_STR
2019-10-31 18:06:27 +08:00
open_solution -reset "solution1"
set_part {xcvu9p-flgb2104-2-i}
config_compile -ignore_long_run_time
create_clock -period 10 -name default
PREFIX_TCL
#source "./PGM_prj/solution1/directives.tcl"
2019-10-31 18:06:27 +08:00
#config_interface -clock_enable
config_interface -m_axi_addr64
csynth_design
#export_design -format ip_catalog
exit';
my $dir = getcwd;
open HLS, ">$dir/run_hls.tcl";
# replace the function name and file name
$hls_tcl =~ s/FUNC/$func_name/g;
$hls_tcl =~ s/PGM/$file_name/g;
$hls_tcl =~ s/PREFIX_TCL/$prefix_tcl/g;
$hls_tcl =~ s/HLS_FILES_STR/$hls_files_str/g;
2019-10-31 18:06:27 +08:00
# run vivado hls
print HLS $hls_tcl;
system("vivado_hls -f run_hls.tcl");
my $vivado_dir = "$dir/$file_name"."_prj/solution1/syn/verilog/";
my $verilog_dir = "$dir/../verilog/";
mkdir $verilog_dir unless (-d $verilog_dir);
unlink glob "$verilog_dir/*";
opendir(DIR, $vivado_dir) or die "Can't opendir $vivado_dir: $! \n";
my @files=readdir(DIR);
closedir(DIR);
foreach my $v_file (@files){
# Open and replace one line
chdir($vivado_dir);
my $vivado_dir_escape = $vivado_dir;
$vivado_dir_escape =~ s/\//\\\//g;
my $perl_cmd = "perl -p -i -e 's/\$readmemh\\\(\\\"\\\.\/\$readmemh(\\\"$vivado_dir_escape/g' *";
print $perl_cmd;
system ($perl_cmd);
$perl_cmd = "perl -p -i -e \"s/'bx/1'b0/g\" *";
system ($perl_cmd);
print $perl_cmd;
chdir($dir);
print "$v_file\n";
if (-f "$vivado_dir/$v_file") {
copy("$vivado_dir/$v_file", $verilog_dir) or die "File cannot be copied! $v_file $verilog_dir\n";
}
}
#die $!;