def check_output(dir): for opt in polyopt_options: target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") color_printer.print_bold("checkling %s..."%(target_path)) if os.path.exists(target_path): lst = os.listdir(target_path) if not glob.glob(target_path+ "/*.out"): color_printer.print_fail("%s compiled fail!"%(target_path)) else: color_printer.print_fail("%s compiled fail!"%(target_path))
def compare(dir): sources = os.listdir(dir) for s in sources: fname, ext = os.path.splitext(s) if ext == ".out" and (not fname == "a"): bench_file = s bench_name = fname c_bench_file = dir.split("/")[-2] + ".out" break else: return color_printer.print_bold("[WORKING] running %s..." % (bench_name)) total_res = [] for i in range(repeat): print "iteration %d..." % (i + 1) res = [] # run c standard version: #res.append(run_c(polybench_c_path + dir + c_bench_file)) # run x10 standard version: res.append(run_x10(dir + bench_file)) for opt in polyopt_options: color_printer.print_bold( "[WORKING] running subversion compiled using %s..." % (opt)) target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") # run c version firstly #res.append(run_c(polybench_c_path + target_path + "/" + c_bench_file)) # run_x10 target_bench = target_path + "/" + bench_file if not os.path.exists(target_bench): color_printer.print_warning( "cannot check program %s, this program haven't been compiled by x10c++!" % (target_bench)) continue res.append(run_x10(target_bench)) total_res.append(res) res_d = {} for res in total_res: for dir, time in res: if dir in res_d: res_d[dir].append(time) else: res_d[dir] = [time] #print res_d for dir, times in res_d.iteritems(): try: lines = util.file_as_lines(os.path.dirname(dir) + "/time.dat") except IOError: lines = [] lines += [str(s) + "\n" for s in times] util.lines_to_file(os.path.dirname(dir) + "/time.dat", lines)
def compare(dir): sources = os.listdir(dir) for s in sources: fname, ext = os.path.splitext(s) if ext == ".out" and (not fname == "a"): bench_file = s bench_name = fname c_bench_file = dir.split("/")[-2] + ".out" break else: return color_printer.print_bold("[WORKING] running %s..."%(bench_name)) total_res = [] for i in range(repeat): print "iteration %d..."%(i+1) res = [] # run c standard version: #res.append(run_c(polybench_c_path + dir + c_bench_file)) # run x10 standard version: res.append(run_x10(dir + bench_file)) for opt in polyopt_options: color_printer.print_bold("[WORKING] running subversion compiled using %s..."%(opt)) target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") # run c version firstly #res.append(run_c(polybench_c_path + target_path + "/" + c_bench_file)) # run_x10 target_bench = target_path + "/" + bench_file if not os.path.exists(target_bench): color_printer.print_warning("cannot check program %s, this program haven't been compiled by x10c++!"%(target_bench)) continue res.append(run_x10(target_bench)) total_res.append(res) res_d = {} for res in total_res: for dir, time in res: if dir in res_d: res_d[dir].append(time) else: res_d[dir] = [time] #print res_d for dir, times in res_d.iteritems(): try: lines = util.file_as_lines(os.path.dirname(dir) + "/time.dat") except IOError: lines = [] lines += [str(s)+"\n" for s in times]; util.lines_to_file(os.path.dirname(dir) + "/time.dat", lines)
def replace_file(dir): sources = os.listdir(dir) for s in sources: fname, ext = os.path.splitext(s) if ext == ".x10": bench_file = s bench_name = fname break else: return color_printer.print_bold("[WORKING] replacing %s..."%(bench_name)) #replace_rail(dir+bench_file) for opt in polyopt_options: color_printer.print_bold("[WORKING] replacing option %s using PolyOpt..."%(opt)) target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") replace_rail(target_path+"/"+bench_file)
def poly_opt_compile(dir): sources = os.listdir(dir) for s in sources: fname, ext = os.path.splitext(s) if ext == ".x10": bench_file = s bench_name = fname break else: return color_printer.print_bold("[WORKING] compile %s..."%(bench_name)) cmd = x10cpp_opt + [dir+bench_file, "-o", "%s/%s.out"% (dir, bench_name)] execute(cmd, True) for opt in polyopt_options: color_printer.print_bold("[WORKING] compiling option %s using PolyOpt..."%(opt)) target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") if not os.path.exists(target_path): os.makedirs(target_path) #cmd = [polyopt_bin, #"-rose:skipfinalCompileStep", #"-rose:o", #"%s/%s.x10"%(target_path, bench_name), #opt, #dir + "/" + bench_file] #execute(cmd, True) color_printer.print_bold("[WORKING] compiling using x10c++...") cmd = x10cpp_opt + ["%s/%s.x10"%(target_path, bench_name), "-o", "%s/%s.out"% (target_path, bench_name)] out, err = execute(cmd, True) f = open(target_path + "/report.log", "wb") f.write(out + err) f.close()
color_printer.print_bold("[WORKING] replacing %s..."%(bench_name)) #replace_rail(dir+bench_file) for opt in polyopt_options: color_printer.print_bold("[WORKING] replacing option %s using PolyOpt..."%(opt)) target_path = dir + re.match("--polyopt-([a-zA-Z0-9\-_]+)", opt).group(1).replace("-", "_") replace_rail(target_path+"/"+bench_file) def walk_pharse(dir): benchs = os.listdir(dir) for bench_dir in benchs: replace_file(dir + bench_dir + "/") def signal_handler(signal, frame): print "Aborted" sys.exit(0) if __name__ == '__main__': signal.signal(signal.SIGINT, signal_handler) color_printer.print_warning('WARNING! This operation cannot be reverted! Please make sure you have a backup.') color_printer.print_bold('Press any key to continue, or Ctrl-v to escape.') dummy = raw_input() if len(sys.argv) > 1: if sys.argv[1] == "single": replace_rail(sys.argv[2]) exit() else: walk_pharse(sys.argv[1]) else: for dir in benchmark_directories: walk_pharse(dir)