def run_test(kernel, ts, nx, ny, nz, nt, target_dir, **kwargs): import os import subprocess from string import Template from scripts.utils import ensure_dir from scripts.conf import conf job_template=Template( """$set_threads$th; $mpirun_cmd $pinning_cmd $pinning_args $exec_path --n-tests $ntests --disable-source-point --npx $npx --npy $npy --npz $npz --nx $nx --ny $ny --nz $nz --verbose $verbose --target-ts $ts --nt $nt --target-kernel $kernel --cache-size $cs --thread-group-size $tgs --thx $thx --thy $thy --thz $thz --mwd-type $mwdt --num-wavefronts $nwf --t-dim $tb --threads $th_bind --verify $verify | tee $outpath""") # set default arguments defaults = {'dry_run':0, 'is_dp':1, 'tgs':-1, 'cs':4096, 'mwdt':2, 'npx':1, 'npy':1, 'npz':1, 'nwf':-1, 'ntests':2, 'alignment':16, 'verify':0, 'verbose':1, 'th': 1, 'thx': -1, 'thy': -1, 'thz': -1, 'tb':-1} # set the default run commands and arguments of the machine defaults.update(conf.machine_conf) # override the default arguments using the user specified ones defaults.update(kwargs) # create default file name if not set by the user: if 'outfile' not in kwargs.keys(): defaults['outfile'] = '_'.join(["%s_%s"%(k,v) for k,v in defaults.items()]).replace(" ","_").replace("-","_") # set the output path target_dir = os.path.join(os.path.abspath("."),target_dir) ensure_dir(target_dir) outpath = os.path.join(target_dir,defaults['outfile']) # set the executable if(defaults['is_dp']==1): exec_path = os.path.join(os.path.abspath("."),"build_dp/mwd_kernel") else: exec_path = os.path.join(os.path.abspath("."),"build/mwd_kernel") # set the processes number if defaults['mpirun_cmd'] != '': np = defaults['npx']*defaults['npy']*defaults['npz'] defaults['mpirun_cmd'] = defaults['mpirun_cmd'] + " -np %d "%np # Disable manual binding if likwid is used if('likwid' in defaults['pinning_cmd']): defaults['th_bind'] = -1 else: defaults['th_bind'] = defaults['th'] job_cmd = job_template.substitute(nx=nx, ny=ny, nz=nz, nt=nt, kernel=kernel, ts=ts, outpath=outpath, exec_path=exec_path, **defaults) print job_cmd if(defaults['dry_run']==0): sts = subprocess.call(job_cmd, shell=True) return job_cmd
def main(): import os, subprocess, shutil, sys, itertools from os.path import join as joinp from string import Template from scripts.utils import ensure_dir dry_run = 1 if len(sys.argv)<2 else int(sys.argv[1]) print("Compiler version") subprocess.call('icc -v', shell=True) job_template=Template( """echo "$t1\\n$t1\\n$t2\\n$t3" > ${kernel_path}/tile.sizes && make -C ${kernel_path} -f ../../Makefile SRC=$kernel """) # set the output path base_dir = 'pluto_examples/gen_kernels/' ensure_dir(base_dir) # for kernel in ['3d7pt', '3d25pt', '3d7pt_var', '3d25pt_var']: for kernel in ['3d25pt', '3d25pt_var']: for p in list(itertools.product(*param_space[kernel])): kernel_name="lbpar_" + kernel + "%d_%d_%d_%d"%(p[0], p[0], p[1], p[2]) kernel_path = joinp(base_dir, kernel_name) # skip if already generated fname = joinp(kernel_path, 'lbpar_'+kernel) if(os.path.isfile(fname)): print("Skipping, file already exists: %s"%fname) continue job_cmd = job_template.substitute(t1=p[0], t2=p[1], t3=p[2], kernel=kernel, kernel_name=kernel_name, kernel_path=kernel_path) ensure_dir(kernel_path) # copy the source file and append the tile size information c_tile_sizes = """ tile_size = (int*) realloc((void *)tile_size, sizeof(int)*5); tile_size[0] = %d; tile_size[1] = %d; tile_size[2] = %d; tile_size[3] = %d; tile_size[4] = -1; """%(p[0], p[0], p[1], p[2]) new_src_path = joinp(kernel_path, kernel+'.c') orig_src_path = joinp('pluto_examples', kernel+'.c') shutil.copy(joinp('pluto_examples', 'print_utils.h'), joinp(kernel_path, 'print_utils.h')) with open(orig_src_path, 'r') as src_f, open(new_src_path, 'w') as dst_f: src_tmpl = Template(src_f.read()) dst_f.write(src_tmpl.substitute(reset_tile_sizes=c_tile_sizes)) print job_cmd if(dry_run==0): sts = subprocess.call(job_cmd, shell=True)
def test_cycle_gan(semi_supervised=True): opt = get_opts() ensure_dir(models_prefix) ensure_dir(images_prefix) cycle_gan = CycleGAN(device, models_prefix, opt["lr"], opt["b1"], train=False, semi_supervised=semi_supervised) dataset = TestDataSet(data_root=data_root, image_size=(opt['img_height'], opt['img_width'])) dataloader = DataLoader(dataset, batch_size=1, shuffle=False) total_images = len(dataset.names) print("\n\nTotal images : ", len(dataset.test_names)) print("Total Testing Images", total_images) loss_A = 0.0 loss_B = 0.0 name_loss_A = [] name_loss_B = [] for i, data in enumerate(dataloader): print(i, "/", total_images) name = dataset.names[i] x = data real_A = Variable(x.type(Tensor)) cycle_gan.set_input(real_A, real_A) cycle_gan.test() cycle_gan.save_image(images_prefix, name) loss_A += cycle_gan.test_A loss_B += cycle_gan.test_B name_loss_A.append((cycle_gan.test_A, name)) name_loss_B.append((cycle_gan.test_B, name)) info = "Average Loss A:{} B :{}".format(loss_A / (1.0 * total_images), loss_B / (1.0 * total_images)) print(info) logger.info(info) name_loss_A = sorted(name_loss_A) name_loss_B = sorted(name_loss_B) print("top 10 images") print(name_loss_A[:10]) print(name_loss_B[:10])
def run_pochoir_test(dry_run, th, kernel, nx, ny, nz, nt, target_dir, outfile, pinning_cmd, pinning_args): import os import subprocess from string import Template from scripts.utils import ensure_dir job_template = Template( """$pinning_cmd $pinning_args $exec_path $nx $ny $nz $nt | tee $outpath""" ) #"""echo 'OpenMP Threads: $th' | tee $outpath; $pinning_cmd $pinning_args $exec_path $nx $ny $nz $nt | tee $outpath""") # set the output path target_dir = os.path.join(os.path.abspath("."), target_dir) ensure_dir(target_dir) outpath = os.path.join(target_dir, outfile) # set the executable if (kernel == 0): exec_name = '3dfd' elif (kernel == 1): exec_name = '3d7pt' elif (kernel == 4): exec_name = '3d25pt_var' elif (kernel == 5): exec_name = '3d7pt_var' else: raise exec_path = os.path.join(os.path.abspath("."), exec_name) job_cmd = job_template.substitute(th=th, nx=nx, ny=ny, nz=nz, nt=nt, kernel=kernel, outpath=outpath, exec_path=exec_path, pinning_cmd=pinning_cmd, pinning_args=pinning_args) print job_cmd if (dry_run == 0): sts = subprocess.call(job_cmd, shell=True) return job_cmd
def run_pochoir_test(dry_run, th, kernel, nx, ny, nz, nt, target_dir, outfile, pinning_cmd, pinning_args): import os import subprocess from string import Template from scripts.utils import ensure_dir job_template = Template("""$pinning_cmd $pinning_args $exec_path $nx $ny $nz $nt | tee $outpath""") # """echo 'OpenMP Threads: $th' | tee $outpath; $pinning_cmd $pinning_args $exec_path $nx $ny $nz $nt | tee $outpath""") # set the output path target_dir = os.path.join(os.path.abspath("."), target_dir) ensure_dir(target_dir) outpath = os.path.join(target_dir, outfile) # set the executable if kernel == 0: exec_name = "3dfd" elif kernel == 1: exec_name = "3d7pt" elif kernel == 4: exec_name = "3d25pt_var" elif kernel == 5: exec_name = "3d7pt_var" else: raise exec_path = os.path.join(os.path.abspath("."), exec_name) job_cmd = job_template.substitute( th=th, nx=nx, ny=ny, nz=nz, nt=nt, kernel=kernel, outpath=outpath, exec_path=exec_path, pinning_cmd=pinning_cmd, pinning_args=pinning_args, ) print job_cmd if dry_run == 0: sts = subprocess.call(job_cmd, shell=True) return job_cmd
def create_project_tarball(dest_dir, fname): import tarfile, glob import os from shutil import copyfile import inspect nl = ["src/kernels/*", "src/*.c", "src/*.h", "scripts/*.py", "scripts/*/*.py", "make.inc", "Makefile"] nl = [glob.glob(n) for n in nl] nl = [n for nn in nl for n in nn] out_dir = os.path.join(os.path.abspath("."),dest_dir) ensure_dir(out_dir) out_name = os.path.join(out_dir, fname+".tar.gz") print "Writing project files to:" + out_name with tarfile.open(out_name, "w:gz") as tar: for n in nl: print "Adding to the tar file: " + n tar.add(n) # copy the calling script to the destination dir src_file = inspect.stack()[1][1] dst_file = os.path.join(out_dir, os.path.basename(src_file)) copyfile(src_file, dst_file)