condor_build.pl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Getopt::Long;
  5. open(RVV, '<', 'RepoVivadoVersion');
  6. my $VIVADO_VERSION = <RVV>; chomp $VIVADO_VERSION;
  7. close(RVV);
  8. unless ($VIVADO_VERSION) {
  9. printf "Unable to detect the Vivado version in use in this repository.\n";
  10. exit(1);
  11. }
  12. our $OPT_DO_RUN = undef;
  13. our $OPT_PROJECT = undef;
  14. our $OPT_RUN = undef;
  15. our $OPT_STREAM_STDOUT = 0;
  16. our $OPT_ENABLE_LOG = 1;
  17. GetOptions(
  18. 'do-run=s' => \$OPT_DO_RUN,
  19. 'p|project=s' => \$OPT_PROJECT,
  20. 'r|run=s' => \$OPT_RUN,
  21. 's|stream-stdout!' => \$OPT_STREAM_STDOUT,
  22. 'l|enable-log!' => \$OPT_ENABLE_LOG,
  23. );
  24. if (!defined($OPT_PROJECT) || !defined($OPT_RUN)) {
  25. printf "%s -sl -p ProjectName -r impl_1\n", $0;
  26. printf "\t-p|--project The project to build\n";
  27. printf "\t-r|--run The run to launch\n";
  28. printf "\t-s|--stream-stdout Produce realtime stdout/stderr logs\n";
  29. printf "\t--no-enable-log Do not generate the condor job log file\n";
  30. exit(0);
  31. }
  32. if (!defined $OPT_DO_RUN) {
  33. open(CONDOR, '|-', 'condor_submit') or die "Cannot run condor_submit: $!";
  34. printf CONDOR "executable = condor_build.pl\n";
  35. printf CONDOR "arguments = --do-run=\$(Cluster) --project=%s --run=%s %s\n", $OPT_PROJECT, $OPT_RUN, ($OPT_STREAM_STDOUT ? "--stream-stdout" : "");
  36. printf CONDOR "should_transfer_files = yes\n";
  37. printf CONDOR "when_to_transfer_output = on_exit\n";
  38. printf CONDOR "transfer_input_files = .\n";
  39. printf CONDOR "transfer_output_files = run-%s.%s.\$(Cluster)\n", $OPT_PROJECT, $OPT_RUN;
  40. printf CONDOR "output = run-%s.%s.\$(Cluster).stdout\n", $OPT_PROJECT, $OPT_RUN if ($OPT_STREAM_STDOUT);
  41. printf CONDOR "error = run-%s.%s.\$(Cluster).stderr\n", $OPT_PROJECT, $OPT_RUN if ($OPT_STREAM_STDOUT);
  42. printf CONDOR "log = run-%s.%s.\$(Cluster).condor_log\n", $OPT_PROJECT, $OPT_RUN if ($OPT_ENABLE_LOG);
  43. printf CONDOR "Requirements = HasAFS_OSG && regexp(\"^<?(144\\.92\\.18[0-4]\\.|128\\.104\\.2[89]\\.)\", MyAddress)\n";
  44. printf CONDOR "\n";
  45. printf CONDOR "stream_output = true\n" if ($OPT_STREAM_STDOUT);
  46. printf CONDOR "stream_error = true\n" if ($OPT_STREAM_STDOUT);
  47. printf CONDOR "\n";
  48. printf CONDOR "+IsExpressQueueJob = True\n";
  49. printf CONDOR "Rank = IsExpressSlot\n";
  50. printf CONDOR "Notification = Always\n";
  51. printf CONDOR "\n";
  52. printf CONDOR "queue\n";
  53. close(CONDOR);
  54. exit(0);
  55. }
  56. open(GETENV, '-|', 'bash', '-c', sprintf('export HOME="$(pwd)"; . /afs/hep.wisc.edu/cms/sw/Xilinx/Vivado/%s/settings64.sh; set', $VIVADO_VERSION));
  57. while (<GETENV>) {
  58. chomp;
  59. next unless /^([^=]+)=(.*)$/;
  60. $ENV{$1} = $2;
  61. }
  62. close(GETENV);
  63. my $OutDir = sprintf("run-%s.%s.%d", $OPT_PROJECT, $OPT_RUN, $OPT_DO_RUN);
  64. unlink($OutDir); # Condor puts a empty temp file here. Screw that.
  65. mkdir($OutDir);
  66. unless ($OPT_STREAM_STDOUT) {
  67. # If not enabled to condor, direct it to files in the build dir so it's not completely lost.
  68. close(STDOUT);
  69. open(STDOUT, '>', "$OutDir/stdout.log");
  70. close(STDERR);
  71. open(STDERR, '>', "$OutDir/stderr.log");
  72. }
  73. system('./checkout.pl') and die "Error returned from checkout.pl";
  74. open(VIVADO, '>', sprintf("run-%s.%s.%d.tcl", $OPT_PROJECT, $OPT_RUN, $OPT_DO_RUN));
  75. printf VIVADO "set project \"%s\"\n", $OPT_PROJECT;
  76. printf VIVADO "set run \"%s\"\n", $OPT_RUN;
  77. printf VIVADO "set outdir \"%s\"\n", $OutDir;
  78. printf VIVADO "source condor_pre.tcl\n" if (-f 'condor_pre.tcl');
  79. printf VIVADO <<'EOF';
  80. set_param general.maxThreads 1
  81. if {[get_property IS_IMPLEMENTATION [get_runs $run]]} {
  82. launch_runs -jobs 1 -to_step write_bitstream [get_runs $run]
  83. } {
  84. launch_runs -jobs 1 [get_runs $run]
  85. }
  86. wait_on_run [get_runs $run]
  87. foreach {runname} [get_runs] {
  88. set runlog "[get_property DIRECTORY [get_run $runname]]/runme.log"
  89. puts "Checking for log from run ${runname}"
  90. if [file exists $runlog] {
  91. puts "Copying log from run ${runname}"
  92. file copy "$runlog" "${outdir}/${runname}.runlog"
  93. }
  94. }
  95. open_run [get_runs $run]
  96. write_checkpoint -force "${outdir}/${run}.dcp"
  97. report_timing_summary -delay_type min_max -report_unconstrained -max_paths 10 -input_pins -file "${outdir}/timing.txt"
  98. ## This is generated already, just copy the sysdef that has all this crap in it.
  99. #foreach {bd_file} [get_files -filter {FILE_TYPE == "Block Designs"}] {
  100. # puts "Exporting Block Design ${bd_file}"
  101. # open_bd_design $bd_file
  102. # set bd_shortname [file rootname [file tail $bd_file]]
  103. # file mkdir "${outdir}/${bd_shortname}"
  104. # export_hardware -dir "${outdir}/${bd_shortname}" $bd_file
  105. # close_bd_design $bd_shortname
  106. #}
  107. ## Generated already as a build product, just copy it rather than regenerating it.
  108. ## This'll make things faster, and let modifications to the write_bitstream process function without just crashing us later.
  109. #if {[get_property IS_IMPLEMENTATION [get_runs "$run"]]} {
  110. # write_bitstream -bin_file "${outdir}/${project}.bit"
  111. #}
  112. set run_dir "[get_property DIRECTORY [get_run ${run}]]"
  113. foreach {bitfile} [glob -nocomplain "${run_dir}/*.bit"] {
  114. file copy -force "${bitfile}" "${outdir}/[file tail "${bitfile}"]"
  115. }
  116. foreach {binfile} [glob -nocomplain "${run_dir}/*.bin"] {
  117. file copy -force "${binfile}" "${outdir}/[file tail "${binfile}"]"
  118. }
  119. foreach {sysdef} [glob -nocomplain "${run_dir}/*.sysdef"] {
  120. set sd_name [file rootname [file tail "${sysdef}"]]
  121. file mkdir "${outdir}/hdf/${sd_name}"
  122. file copy -force "${sysdef}" "${outdir}/hdf/${sd_name}/${sd_name}.hdf"
  123. }
  124. foreach {ltx} [glob -nocomplain "${run_dir}/*.ltx"] {
  125. file mkdir "${outdir}/debug_probes"
  126. file copy -force "${ltx}" "${outdir}/debug_probes/[file tail "${ltx}"]"
  127. }
  128. EOF
  129. close(VIVADO);
  130. system('vivado', '-mode', 'batch', '-source', sprintf("run-%s.%s.%d.tcl", $OPT_PROJECT, $OPT_RUN, $OPT_DO_RUN), sprintf("workspace/%s/%s.xpr", $OPT_PROJECT, $OPT_PROJECT));
  131. #system('tar', '-cjf', $OutDir.'.tbz2', $OutDir);