Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description='Setup Project')
    parser.add_argument('--cc',
                        type=int,
                        help='Compute Capability',
                        default=70)
    args = parser.parse_args()

    async_flag = "CC{}".format(str(args.cc))
    sync_flag = "CC{}".format(str(args.cc))
    if args.cc >= 70:
        async_flag += "_ASYNC"
        sync_flag += "_SYNC"

    if os.name == 'nt':  # If on Windows
        Command("cmake -B build -D{}=ON -DSYNC_BUILD=OFF".format(
            async_flag)).run()
        Command("msbuild build/GPUMemoryManagers.sln /p:Configuration=Release"
                ).run()
        Command("cmake -B sync_build -D{}=ON -DSYNC_BUILD=ON".format(
            sync_flag)).run()
        Command(
            "msbuild sync_build/GPUMemoryManagers.sln /p:Configuration=Release"
        ).run()
    else:  # If on Linux
        Command(
            "mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -D{}=ON -DSYNC_BUILD=OFF"
            .format(async_flag)).run()
        Command("cd build && make").run()
        Command(
            "mkdir sync_build && cd sync_build && cmake .. -DCMAKE_BUILD_TYPE=Release -D{}=ON -DSYNC_BUILD=ON"
            .format(sync_flag)).run()
        Command("cd sync_build && make").run()
    print("Setup done!")
Exemple #2
0
def main():
    current_dir = os.getcwd()

    # Build general testcase
    Command("python clean.py".format()).run()

    # Build allocation testcases
    os.chdir(os.path.join(current_dir, "tests/alloc_tests"))
    Command("python clean.py".format()).run()

    # Build fragmentation testcases
    os.chdir(os.path.join(current_dir, "tests/frag_tests"))
    Command("python clean.py".format()).run()

    # Build graph testcases
    os.chdir(os.path.join(current_dir, "tests/graph_tests"))
    Command("python clean.py".format()).run()

    # Build synthetic testcases
    os.chdir(os.path.join(current_dir, "tests/synth_tests"))
    Command("python clean.py".format()).run()

    print("Setup done!")
Exemple #3
0
def main():
	start = time.time()
	parser = argparse.ArgumentParser(description='Setup Project')
	parser.add_argument('--cc', type=int, help='Compute Capability (e.g. 61, 70, 75', default=70)
	args = parser.parse_args()

	current_dir = os.getcwd()

	# Build general testcase
	Command("python clean.py".format()).run()
	Command("python setup.py --cc {}".format(str(args.cc))).run(timeout=3600)

	# Build allocation testcases
	os.chdir(os.path.join(current_dir, "tests/alloc_tests"))
	Command("python clean.py".format()).run()
	Command("python setup.py --cc {}".format(str(args.cc))).run(timeout=3600)

	# Build fragmentation testcases
	os.chdir(os.path.join(current_dir, "tests/frag_tests"))
	Command("python clean.py".format()).run()
	Command("python setup.py --cc {}".format(str(args.cc))).run(timeout=3600)

	# Build graph testcases
	os.chdir(os.path.join(current_dir, "tests/graph_tests"))
	Command("python clean.py".format()).run()
	Command("python setup.py --cc {}".format(str(args.cc))).run(timeout=3600)

	# Build synthetic testcases
	os.chdir(os.path.join(current_dir, "tests/synth_tests"))
	Command("python clean.py".format()).run()
	Command("python setup.py --cc {}".format(str(args.cc))).run(timeout=3600)

	end = time.time()
	timing = end - start
	print("Script finished in {0:.0f} min {1:.0f} sec".format(timing / 60, timing % 60))
	print("Setup done!")
def main():
    # Run all files from a directory
    print(
        "##############################################################################"
    )
    print("Callable as: python test_fragmentation.py")
    print(
        "##############################################################################"
    )

    # Specify which test configuration to use
    testcases = {}
    num_allocations = 10000
    smallest_allocation_size = 4
    largest_allocation_size = 1024
    alloc_size = 8
    num_iterations = 1
    free_memory = 1
    generate_results = True
    generate_plots = True
    clean_temporary_files = True
    test_warp_based = False
    filetype = "pdf"
    time_out_val = 100
    if os.name == 'nt':  # If on Windows
        build_path = os.path.join("build", "Release")
        sync_build_path = os.path.join("sync_build", "Release")
    else:
        build_path = "build/"
        sync_build_path = "sync_build/"

    parser = argparse.ArgumentParser(
        description='Test fragmentation for various frameworks')
    parser.add_argument(
        '-t',
        type=str,
        help=
        'Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc'
    )
    parser.add_argument('-num',
                        type=int,
                        help='How many allocations to perform')
    parser.add_argument('-range',
                        type=str,
                        help='Sepcify Allocation Range, e.g. 4-1024')
    parser.add_argument('-iter', type=int, help='How many iterations?')
    parser.add_argument('-runtest',
                        action='store_true',
                        default=False,
                        help='Run testcases')
    parser.add_argument('-genres',
                        action='store_true',
                        default=False,
                        help='Generate results')
    parser.add_argument('-genplot',
                        action='store_true',
                        default=False,
                        help='Generate results file and plot')
    parser.add_argument(
        '-timeout',
        type=int,
        help=
        'Timeout Value in Seconds, process will be killed after as many seconds'
    )
    parser.add_argument('-plotscale', type=str, help='log/linear')
    parser.add_argument('-filetype', type=str, help='png or pdf')
    parser.add_argument('-allocsize',
                        type=int,
                        help='How large is the manageable memory in GiB?',
                        default=8)
    parser.add_argument('-device',
                        type=int,
                        help='Which device to use',
                        default=0)
    parser.add_argument(
        '-mailpass',
        type=str,
        help='Supply the mail password if you want to be notified',
        default=None)

    args = parser.parse_args()

    executable_extension = ""
    if os.name == 'nt':  # If on Windows
        executable_extension = ".exe"
    # Parse approaches
    if (args.t):
        if any("c" in s for s in args.t):
            testcases["CUDA"] = os.path.join(
                build_path,
                str("c_frag_test") + executable_extension)
        if any("x" in s for s in args.t):
            testcases["XMalloc"] = os.path.join(
                sync_build_path,
                str("x_frag_test") + executable_extension)
        if any("h" in s for s in args.t):
            testcases["Halloc"] = os.path.join(
                sync_build_path,
                str("h_frag_test") + executable_extension)
        if any("s" in s for s in args.t):
            testcases["ScatterAlloc"] = os.path.join(
                sync_build_path,
                str("s_frag_test") + executable_extension)
        if any("o" in s for s in args.t):
            # testcases["Ouroboros-P-S"] = os.path.join(build_path, str("o_frag_test_p") + executable_extension)
            testcases["Ouroboros-P-VA"] = os.path.join(
                build_path,
                str("o_frag_test_vap") + executable_extension)
            # testcases["Ouroboros-P-VL"] = os.path.join(build_path, str("o_frag_test_vlp") + executable_extension)
            # testcases["Ouroboros-C-S"] = os.path.join(build_path, str("o_frag_test_c") + executable_extension)
            # testcases["Ouroboros-C-VA"] = os.path.join(build_path, str("o_frag_test_vac") + executable_extension)
            # testcases["Ouroboros-C-VL"] = os.path.join(build_path, str("o_frag_test_vlc") + executable_extension)
        if any("f" in s for s in args.t):
            testcases["FDGMalloc"] = os.path.join(
                sync_build_path,
                str("f_frag_test") + executable_extension)
        if any("r" in s for s in args.t):
            # testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_frag_test_a") + executable_extension)
            testcases["RegEff-AW"] = os.path.join(
                sync_build_path,
                str("r_frag_test_aw") + executable_extension)
            # testcases["RegEff-C"] = os.path.join(sync_build_path, str("r_frag_test_c") + executable_extension)
            # testcases["RegEff-CF"] = os.path.join(sync_build_path, str("r_frag_test_cf") + executable_extension)
            # testcases["RegEff-CM"] = os.path.join(sync_build_path, str("r_frag_test_cm") + executable_extension)
            # testcases["RegEff-CFM"] = os.path.join(sync_build_path, str("r_frag_test_cfm") + executable_extension)

    # Parse num allocation
    if (args.num):
        num_allocations = args.num

    # Parse range
    if (args.range):
        selected_range = args.range.split('-')
        smallest_allocation_size = int(selected_range[0])
        largest_allocation_size = int(selected_range[1])

    # Parse num iterations
    if (args.iter):
        num_iterations = args.iter

    # Run Testcases
    run_testcases = args.runtest

    # Generate results
    generate_results = args.genres

    # Generate plots
    generate_plots = args.genplot

    # Plot Axis scaling
    plotscale = args.plotscale

    # Timeout (in seconds)
    if (args.timeout):
        time_out_val = args.timeout

    if (args.filetype):
        filetype = args.filetype

    if (args.allocsize):
        alloc_size = args.allocsize

    mailalert = EmailAlert(args.mailpass)

    ####################################################################################################
    ####################################################################################################
    # Run testcases
    ####################################################################################################
    ####################################################################################################
    if run_testcases:
        for name, executable in testcases.items():
            csv_path = "results/frag_" + name + "_" + str(
                num_allocations) + "_" + str(
                    smallest_allocation_size) + "-" + str(
                        largest_allocation_size) + ".csv"
            if (os.path.isfile(csv_path)):
                print(
                    "This file already exists, do you really want to OVERWRITE?"
                )
                inputfromconsole = input()
                if not (inputfromconsole == "yes" or inputfromconsole == "y"):
                    continue
            with open(csv_path, "w", newline='') as csv_file:
                csv_file.write("AllocationSize (in Byte)")
                for i in range(num_iterations):
                    csv_file.write(",range, static range")
            allocation_size = smallest_allocation_size
            while allocation_size <= largest_allocation_size:
                with open(csv_path, "a", newline='') as csv_file:
                    csv_file.write("\n" + str(allocation_size))
                run_config = str(num_allocations) + " " + str(
                    allocation_size) + " " + str(
                        num_iterations) + " 0 " + csv_path + " " + str(
                            alloc_size) + " " + str(args.device)
                executecommand = "{0} {1}".format(executable, run_config)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print("Running " + name + " with command -> " + executecommand)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print(executecommand)
                _, process_killed = Command(executecommand).run(
                    timeout=time_out_val)
                if process_killed:
                    print("We killed the process!")
                    with open(csv_path, "a", newline='') as csv_file:
                        csv_file.write(
                            ",0,0,-------------------> Ran longer than " +
                            str(time_out_val))
                else:
                    print("Success!")
                allocation_size += 4
            if args.mailpass:
                message = "Testcase {0} ran through! Testset: ({1})".format(
                    str(name), " | ".join(testcases.keys()))
                mailalert.sendAlert(message)

    ####################################################################################################
    ####################################################################################################
    # Generate new Results
    ####################################################################################################
    ####################################################################################################
    if generate_results:
        if not os.path.exists("results/aggregate"):
            os.mkdir("results/aggregate")
        generateResultsFromFileFragmentation("results", num_allocations,
                                             smallest_allocation_size,
                                             largest_allocation_size, "Bytes",
                                             1, num_iterations)

    ####################################################################################################
    ####################################################################################################
    # Generate new plots
    ####################################################################################################
    ####################################################################################################
    # if generate_plots:
    # 	result_frag = list()
    # 	# Get Timestring
    # 	now = datetime.now()
    # 	time_string = now.strftime("%b-%d-%Y_%H-%M-%S")

    # 	if plotscale == "log":
    # 		time_string += "_log"
    # 	else:
    # 		time_string += "_lin"

    # 	for file in os.listdir("results/aggregate"):
    # 		filename = str("results/aggregate/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		if filename.split("_")[2] != "frag" or str(num_allocations) != filename.split('_')[3] or str(smallest_allocation_size) + "-" + str(largest_allocation_size) != filename.split('_')[4].split(".")[0]:
    # 			continue
    # 		# We want the one matching our input
    # 		with open(filename) as f:
    # 			result_frag = list(csv.reader(f))

    # 	####################################################################################################
    # 	# Lineplot
    # 	####################################################################################################
    # 	plotLineRange(result_frag,
    # 		testcases,
    # 		plotscale,
    # 		False,
    # 		'Bytes',
    # 		'Byte - Range',
    # 		"Fragmentation: Byte-Range for " + str(num_allocations) + " allocations",
    # 		str("results/plots/") + time_string + "_frag." + filetype)

    # 	####################################################################################################
    # 	# Lineplot with range
    # 	####################################################################################################
    # 	plotLineRange(result_frag,
    # 		testcases,
    # 		plotscale,
    # 		True,
    # 		'Bytes',
    # 		'Byte - Range',
    # 		"Fragmentation: Byte-Range for " + str(num_allocations) + " allocations",
    # 		str("results/plots/") + time_string + "_frag_range." + filetype)
    if args.mailpass:
        message = "Test Allocation finished!"
        mailalert.sendAlert(message)
    print("Done")
Exemple #5
0
def main():
	start = time.time()
	parser = argparse.ArgumentParser(description='Run all testcases')
	parser.add_argument('-mem_size', type=int, help='Size of the manageable memory in GB', default=8)
	parser.add_argument('-device', type=int, help='Which device to use', default=0)
	parser.add_argument('-runtest', action='store_true', default=False, help='Run testcases')
	parser.add_argument('-genres', action='store_true', default=False, help='Generate results')
	args = parser.parse_args()

	current_dir = os.getcwd()

	print("The selected amount of manageable memory is: {0} Gb".format(str(args.mem_size)))

	runteststr = ""
	if args.runtest:
		runteststr = "-runtest"
	genresstr = ""
	if args.genres:
		genresstr = "-genres"

	# Which tests to run
	tests = {
		"alloc_tests" : [
			["python test_allocation.py -t o+s+h+c+r+x -num 10000 -range 4-32 -iter 50 {0} {1} -timeout 60 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), "performance"],
			["python test_mixed_allocation.py -t o+s+h+c+r+x -num 10000 -range 4-32 -iter 50 {0} {1} -timeout 30 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), "mixed_performance"],
			["python test_scaling.py -t o+s+h+c+r+x -byterange 16-32 -threadrange 0-10 -iter 50 {0} {1} -timeout 60 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), "scaling"]
		],
		"frag_tests"  : [
			["python test_fragmentation.py -t o+s+h+c+r+x -num 10000 -range 4-32 -iter 50 {0} {1} -timeout 60 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_oom.py -t o+s+h+c+r+x -num 10000 -range 512-512 {0} {1} -timeout 60 -allocsize 2".format(runteststr, genresstr), ""]
		],
		"graph_tests" : [
			["python test_graph_init.py -t o+s+h+c+r+x -configfile config_init.json {0} {1} -timeout 15 -allocsize {2} -device {3} -graphstats".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_graph_init.py -t o+s+h+c+r+x -configfile config_init.json {0} {1} -timeout 10 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_graph_update.py -t o+s+h+c+r+x -configfile config_update.json {0} {1} -timeout 10 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_graph_update.py -t o+s+h+c+r+x -configfile config_update_range.json {0} {1} -timeout 10 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""]
		],
		"synth_tests" : [
			["python test_registers.py -t o+s+h+c+r+x {0} {1} -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_synth_init.py -t o+s+h+c+r+x {0} {1} -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_synth_workload.py -t b+o+s+h+c+r+x -threadrange 0-10 -range 16-32 -iter 50 {0} {1} -timeout 10 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""],
			["python test_synth_workload.py -t b+o+s+h+c+r+x -threadrange 0-10 -range 16-32 -iter 5 {0} {1} -testwrite -timeout 10 -allocsize {2} -device {3}".format(runteststr, genresstr, str(args.mem_size), str(args.device)), ""]
		]
	}

	for path, commands in tests.items():
		for command in commands:
			print("Will execute command in folder {0} (subfolder {2}): {1}".format(path, command[0], command[1]))

	# Run tests
	for path, commands in tests.items():
		for command in commands:
			command_start = time.time()
			full_path = os.path.join(current_dir, "tests", path)
			os.chdir(full_path)
			if not os.path.exists(os.path.join(full_path, "results")):
				os.mkdir(os.path.join(full_path, "results"))
			if command[1] != "":
				if not os.path.exists(os.path.join(full_path, "results", command[1])):
					os.mkdir(os.path.join(full_path, "results", command[1]))
			Command(command[0]).run(timeout=3600)
			if args.genres:
				aggregate_path = os.path.join(full_path, "results", command[1], "aggregate")
				for file in os.listdir(aggregate_path):
					shutil.move(os.path.join(aggregate_path, file), os.path.join(current_dir, "results", file))
			command_end = time.time()
			command_timing = command_end - command_start
			print("Command finished in {0:.0f} min {1:.0f} sec".format(round(command_timing / 60), round(command_timing % 60)))

	end = time.time()
	timing = end - start
	print("Script finished in {0:.0f} min {1:.0f} sec".format(round(timing / 60), round(timing % 60)))
Exemple #6
0
def main():
	# Run all files from a directory
	print("##############################################################################")
	print("Callable as: python test_synth_workload.py")
	print("##############################################################################")
	
	# Specify which test configuration to use
	testcases = {}
	num_allocations = 10000
	smallest_allocation_size = 4
	largest_allocation_size = 1024
	alloc_size = 8
	num_iterations = 1
	free_memory = 1
	generate_results = True
	generate_plots = True
	clean_temporary_files = True
	test_warp_based = False
	filetype = "pdf"
	time_out_val = 100
	if os.name == 'nt': # If on Windows
		build_path = os.path.join("build", "Release")
		sync_build_path = os.path.join("sync_build", "Release")
	else:
		build_path = "build/"
		sync_build_path = "sync_build/"

	parser = argparse.ArgumentParser(description='Test workload for various frameworks')
	parser.add_argument('-t', type=str, help='Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x+b ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc')
	parser.add_argument('-threadrange', type=str, help='Specify number of threads, given as powers of two, e.g. 0-5 -> results in 1-32')
	parser.add_argument('-range', type=str, help='Sepcify Allocation Range, e.g. 4-1024')
	parser.add_argument('-iter', type=int, help='How many iterations?')
	parser.add_argument('-runtest', action='store_true', default=False, help='Run testcases')
	parser.add_argument('-genres', action='store_true', default=False, help='Generate results')
	parser.add_argument('-genplot', action='store_true', default=False, help='Generate results file and plot')
	parser.add_argument('-testwrite', action='store_true', default=False, help='If set tests write performance, not allocation performance')
	parser.add_argument('-timeout', type=int, help='Timeout Value in Seconds, process will be killed after as many seconds')
	parser.add_argument('-plotscale', type=str, help='log/linear')
	parser.add_argument('-filetype', type=str, help='png or pdf')
	parser.add_argument('-allocsize', type=int, help='How large is the manageable memory in GiB?')
	parser.add_argument('-device', type=int, help='Which device to use', default=0)

	args = parser.parse_args()

	executable_extension = ""
	if os.name == 'nt': # If on Windows
		executable_extension = ".exe"
	# Parse approaches
	if(args.t):
		if any("c" in s for s in args.t):
			testcases["CUDA"] = os.path.join(build_path, str("c_synth_test") + executable_extension)
		if any("x" in s for s in args.t):
			testcases["XMalloc"] = os.path.join(sync_build_path, str("x_synth_test") + executable_extension)
		if any("h" in s for s in args.t):
			testcases["Halloc"] = os.path.join(sync_build_path, str("h_synth_test") + executable_extension)
		if any("s" in s for s in args.t):
			testcases["ScatterAlloc"] = os.path.join(sync_build_path, str("s_synth_test") + executable_extension)
		if any("o" in s for s in args.t):
			testcases["Ouroboros-P-S"] = os.path.join(build_path, str("o_synth_test_p") + executable_extension)
			testcases["Ouroboros-P-VA"] = os.path.join(build_path, str("o_synth_test_vap") + executable_extension)
			testcases["Ouroboros-P-VL"] = os.path.join(build_path, str("o_synth_test_vlp") + executable_extension)
			testcases["Ouroboros-C-S"] = os.path.join(build_path, str("o_synth_test_c") + executable_extension)
			testcases["Ouroboros-C-VA"] = os.path.join(build_path, str("o_synth_test_vac") + executable_extension)
			testcases["Ouroboros-C-VL"] = os.path.join(build_path, str("o_synth_test_vlc") + executable_extension)
		if any("f" in s for s in args.t):
			testcases["FDGMalloc"] = os.path.join(sync_build_path, str("f_synth_test") + executable_extension)
		if any("r" in s for s in args.t):
			# testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_synth_test_a") + executable_extension)
			testcases["RegEff-AW"] = os.path.join(sync_build_path, str("r_synth_test_aw") + executable_extension)
			testcases["RegEff-C"] = os.path.join(sync_build_path, str("r_synth_test_c") + executable_extension)
			testcases["RegEff-CF"] = os.path.join(sync_build_path, str("r_synth_test_cf") + executable_extension)
			testcases["RegEff-CM"] = os.path.join(sync_build_path, str("r_synth_test_cm") + executable_extension)
			testcases["RegEff-CFM"] = os.path.join(sync_build_path, str("r_synth_test_cfm") + executable_extension)
		if any("b" in s for s in args.t):
			testcases["Baseline"] = os.path.join(sync_build_path, str("b_synth_test") + executable_extension)

	# Parse range
	if(args.threadrange):
		selected_range = args.threadrange.split('-')
		smallest_num_threads = 2 ** int(selected_range[0])
		largest_num_threads = 2 ** int(selected_range[1])

	# Parse range
	if(args.range):
		selected_range = args.range.split('-')
		smallest_allocation_size = int(selected_range[0])
		largest_allocation_size = int(selected_range[1])
	
	# Parse num iterations
	if(args.iter):
		num_iterations = args.iter

	# Run Testcases
	run_testcases = args.runtest
	
	# Generate results
	generate_results = args.genres

	# Generate plots
	generate_plots = args.genplot

	# Plot Axis scaling
	plotscale = args.plotscale

	# Timeout (in seconds)
	if(args.timeout):
		time_out_val = args.timeout

	if(args.filetype):
		filetype = args.filetype

	if(args.allocsize):
		alloc_size = args.allocsize 

	####################################################################################################
	####################################################################################################
	# Run testcases
	####################################################################################################
	####################################################################################################
	if run_testcases:
		testwritestr = "0"
		namestr = ""
		if args.testwrite:
			testwritestr = "1"
			namestr = "write_"
		for name, executable in testcases.items():
			csv_path = "results/synth_" + namestr + name + "_" + str(smallest_num_threads)+ "-" + str(largest_num_threads) + "_" + str(smallest_allocation_size) + "-" + str(largest_allocation_size) + ".csv"
			if(os.path.isfile(csv_path)):
				print("This file <" + csv_path + "> already exists, do you really want to OVERWRITE?")
				inputfromconsole = input()
				if not (inputfromconsole == "yes" or inputfromconsole == "y"):
					continue
			with open(csv_path, "w", newline='') as csv_file:
				csv_file.write("NumThreads, mean, std-dev, min, max, median\n")
			num_threads = smallest_num_threads
			while num_threads <= largest_num_threads:
				with open(csv_path, "a", newline='') as csv_file:
					csv_file.write(str(num_threads) + ", ")
				run_config = str(num_threads) + " " + str(smallest_allocation_size) + " " + str(largest_allocation_size) + " " + str(num_iterations) + " 0 " + csv_path + " " + str(alloc_size) + " " + testwritestr + " " + str(args.device)
				executecommand = "{0} {1}".format(executable, run_config)
				print("#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#")
				print("Running " + name + " with command -> " + executecommand)
				print("#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#")
				print(executecommand)
				_, process_killed = Command(executecommand).run(timeout=time_out_val)
				if process_killed :
					print("We killed the process!")
					with open(csv_path, "a", newline='') as csv_file:
						csv_file.write("0,0,-------------------> Ran longer than " + str(time_out_val) + "\n")
				else:
					print("Success!")
					with open(csv_path, "a", newline='') as csv_file:
						csv_file.write("\n")
				num_threads *= 2

	# ####################################################################################################
	# ####################################################################################################
	# # Generate new Results
	# ####################################################################################################
	# ####################################################################################################
	if generate_results:
		if not os.path.exists("results/aggregate"):
			os.mkdir("results/aggregate")
		if args.testwrite:
			generateResultsFromSynthetic(testcases, "results", smallest_num_threads, largest_num_threads, smallest_allocation_size, largest_allocation_size, "Num Threads", "synth_write", 2)
		else:
			generateResultsFromSynthetic(testcases, "results", smallest_num_threads, largest_num_threads, smallest_allocation_size, largest_allocation_size, "Num Threads", "synth", 1)

	print("Done")
Exemple #7
0
def main():
    # Run all files from a directory
    print(
        "##############################################################################"
    )
    print("Callable as: python test_graphs.py -h")
    print(
        "##############################################################################"
    )

    config_file = "config_init.json"
    testcases = {}
    if os.name == 'nt':  # If on Windows
        build_path = os.path.join("build", "Release")
        sync_build_path = os.path.join("sync_build", "Release")
    else:
        build_path = "build/"
        sync_build_path = "sync_build/"
    filetype = "pdf"
    time_out_val = 100
    generate_results = True

    parser = argparse.ArgumentParser(
        description='Test graph initialization for various frameworks')
    parser.add_argument(
        '-t',
        type=str,
        help=
        'Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc'
    )
    parser.add_argument('-configfile',
                        type=str,
                        help='Specify the config file: config.json')
    parser.add_argument('-graphstats',
                        action='store_true',
                        default=False,
                        help='Just write graph stats and do not run testcases')
    parser.add_argument('-runtest',
                        action='store_true',
                        default=False,
                        help='Run testcases')
    parser.add_argument('-genres',
                        action='store_true',
                        default=False,
                        help='Generate results')
    parser.add_argument('-genplot',
                        action='store_true',
                        default=False,
                        help='Generate results file and plot')
    parser.add_argument(
        '-timeout',
        type=int,
        help=
        'Timeout Value in Seconds, process will be killed after as many seconds'
    )
    parser.add_argument('-plotscale', type=str, help='log/linear')
    parser.add_argument('-filetype', type=str, help='png or pdf')
    parser.add_argument('-allocsize',
                        type=int,
                        help='How large is the manageable memory in GiB?',
                        default=8)
    parser.add_argument('-device',
                        type=int,
                        help='Which device to use',
                        default=0)
    parser.add_argument(
        '-mailpass',
        type=str,
        help='Supply the mail password if you want to be notified',
        default=None)

    args = parser.parse_args()

    executable_extension = ""
    if os.name == 'nt':  # If on Windows
        executable_extension = ".exe"
    # Parse approaches
    if (args.t):
        if any("c" in s for s in args.t):
            testcases["CUDA"] = os.path.join(
                build_path,
                str("c_graph_test") + executable_extension)
        if any("x" in s for s in args.t):
            testcases["XMalloc"] = os.path.join(
                sync_build_path,
                str("x_graph_test") + executable_extension)
        if any("h" in s for s in args.t):
            testcases["Halloc"] = os.path.join(
                sync_build_path,
                str("h_graph_test") + executable_extension)
        if any("s" in s for s in args.t):
            testcases["ScatterAlloc"] = os.path.join(
                sync_build_path,
                str("s_graph_test") + executable_extension)
        if any("o" in s for s in args.t):
            # testcases["Ouroboros-P-S"] = os.path.join(build_path, str("o_graph_test_p") + executable_extension)
            testcases["Ouroboros-P-VA"] = os.path.join(
                build_path,
                str("o_graph_test_vap") + executable_extension)
            testcases["Ouroboros-P-VL"] = os.path.join(
                build_path,
                str("o_graph_test_vlp") + executable_extension)
            testcases["Ouroboros-C-S"] = os.path.join(
                build_path,
                str("o_graph_test_c") + executable_extension)
            testcases["Ouroboros-C-VA"] = os.path.join(
                build_path,
                str("o_graph_test_vac") + executable_extension)
            testcases["Ouroboros-C-VL"] = os.path.join(
                build_path,
                str("o_graph_test_vlc") + executable_extension)
        if any("f" in s for s in args.t):
            testcases["FDGMalloc"] = os.path.join(
                sync_build_path,
                str("f_graph_test") + executable_extension)
        if any("r" in s for s in args.t):
            # testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_graph_test_a") + executable_extension)
            # testcases["RegEff-AW"] = os.path.join(sync_build_path, str("r_graph_test_aw") + executable_extension)
            testcases["RegEff-C"] = os.path.join(
                sync_build_path,
                str("r_graph_test_c") + executable_extension)
            testcases["RegEff-CF"] = os.path.join(
                sync_build_path,
                str("r_graph_test_cf") + executable_extension)
            testcases["RegEff-CM"] = os.path.join(
                sync_build_path,
                str("r_graph_test_cm") + executable_extension)
            testcases["RegEff-CFM"] = os.path.join(
                sync_build_path,
                str("r_graph_test_cfm") + executable_extension)

    # Run Testcases
    run_testcases = args.runtest

    # Generate results
    generate_results = args.genres

    # Generate plots
    generate_plots = args.genplot

    # Plot Axis scaling
    plotscale = args.plotscale

    # Config File
    if (args.configfile):
        config_file = args.configfile

    # Timeout (in seconds)
    if (args.timeout):
        time_out_val = args.timeout

    if (args.filetype):
        filetype = args.filetype

    # Sort graphs for consistent ordering
    graphs.sort()

    mailalert = EmailAlert(args.mailpass)

    if not os.path.exists("results/aggregate"):
        os.mkdir("results/aggregate")

    if (args.graphstats):
        csv_path = "results/aggregate/graph_stats.csv"
        if (os.path.isfile(csv_path)):
            print("This file <" + csv_path +
                  "> already exists, do you really want to OVERWRITE?")
            inputfromconsole = input()
            if not (inputfromconsole == "yes" or inputfromconsole == "y"):
                exit()
        with open(csv_path, "w", newline='') as csv_file:
            csv_file.write(
                "Graph Stats, num vertices, num edges, mean adj length, std-dev, min adj length, max adj length\n"
            )
        for graph in graphs:
            with open(csv_path, "a", newline='') as csv_file:
                csv_file.write(graph + ",")
            run_config = config_file + " " + path + graph + " " + str(
                1) + " " + csv_path
            executecommand = "{0} {1}".format(
                os.path.join(build_path,
                             str("c_graph_test") + executable_extension),
                run_config)
            print(
                "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
            )
            print("Running command -> " + executecommand)
            print(
                "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
            )
            print(executecommand)
            _, process_killed = Command(executecommand).run()
            if process_killed:
                print("We killed the process!")
                with open(csv_path, "a", newline='') as csv_file:
                    csv_file.write(
                        "0,0,-------------------> Ran longer than " +
                        str(time_out_val) + "\n")
            else:
                print("Success!")
                with open(csv_path, "a", newline='') as csv_file:
                    csv_file.write("\n")
        exit()

    ####################################################################################################
    ####################################################################################################
    # Run testcases
    ####################################################################################################
    ####################################################################################################
    if run_testcases:
        for name, executable in testcases.items():
            csv_path = "results/graph_init_" + name + ".csv"
            if (os.path.isfile(csv_path)):
                print("This file <" + csv_path +
                      "> already exists, do you really want to OVERWRITE?")
                inputfromconsole = input()
                if not (inputfromconsole == "yes" or inputfromconsole == "y"):
                    continue
            with open(csv_path, "w", newline='') as csv_file:
                csv_file.write(
                    "Graph Init Testcase - " + name +
                    ", mean(ms), std-dev(ms), min(ms), max(ms), median(ms), num iterations\n"
                )
            for graph in graphs:
                with open(csv_path, "a", newline='') as csv_file:
                    csv_file.write(graph + ",")
                run_config = config_file + " " + path + graph + " " + str(
                    0) + " " + csv_path + " insert.csv delete.csv" + " " + str(
                        args.allocsize) + " " + str(args.device)
                executecommand = "{0} {1}".format(executable, run_config)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print("Running " + name + " with command -> " + executecommand)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print(executecommand)
                _, process_killed = Command(executecommand).run(
                    timeout=time_out_val)
                if process_killed:
                    print("We killed the process!")
                    with open(csv_path, "a", newline='') as csv_file:
                        csv_file.write(
                            ",0,0,-------------------> Ran longer than " +
                            str(time_out_val) + "\n")
                else:
                    print("Success!")
                    with open(csv_path, "a", newline='') as csv_file:
                        csv_file.write("\n")
            if args.mailpass:
                message = "Testcase {0} ran through! Testset: ({1})".format(
                    str(name), " | ".join(testcases.keys()))
                mailalert.sendAlert(message)

    # ####################################################################################################
    # ####################################################################################################
    # # Generate new Results
    # ####################################################################################################
    # ####################################################################################################
    if generate_results:
        generateResultsFromGraph(testcases, "results", "Graphs", "init", 2)

    if args.mailpass:
        message = "Test Graph Init finished!"
        mailalert.sendAlert(message)
def main():
    print(
        "##############################################################################"
    )
    print("Callable as: python test_allocation.py -h")
    print(
        "##############################################################################"
    )

    # Specify which test configuration to use
    testcases = {}
    num_allocations = 10000
    smallest_allocation_size = 4
    largest_allocation_size = 1024
    num_iterations = 25
    free_memory = 1
    filetype = "pdf"
    time_out_val = 10
    if os.name == 'nt':  # If on Windows
        build_path = os.path.join("build", "Release")
        sync_build_path = os.path.join("sync_build", "Release")
    else:
        build_path = "build/"
        sync_build_path = "sync_build/"

    parser = argparse.ArgumentParser(
        description='Test allocation performance for various frameworks')
    parser.add_argument(
        '-t',
        type=str,
        help=
        'Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc'
    )
    parser.add_argument('-num',
                        type=int,
                        help='How many allocations to perform')
    parser.add_argument('-range',
                        type=str,
                        help='Specify Allocation Range, e.g. 4-1024')
    parser.add_argument('-iter', type=int, help='How many iterations?')
    parser.add_argument('-runtest',
                        action='store_true',
                        default=False,
                        help='Run testcases')
    parser.add_argument('-genres',
                        action='store_true',
                        default=False,
                        help='Generate results')
    parser.add_argument('-genplot',
                        action='store_true',
                        default=False,
                        help='Generate results file and plot')
    parser.add_argument('-cleantemp',
                        action='store_true',
                        default=False,
                        help='Clean up temporary files')
    parser.add_argument('-warp',
                        action='store_true',
                        default=False,
                        help='Start testcases warp-based')
    parser.add_argument('-devmeasure',
                        action='store_true',
                        default=False,
                        help='Measure performance on device in cycles')
    parser.add_argument('-plotscale', type=str, help='log/linear')
    parser.add_argument(
        '-timeout',
        type=int,
        help=
        'Timeout Value in Seconds, process will be killed after as many seconds'
    )
    parser.add_argument('-filetype', type=str, help='png or pdf')
    parser.add_argument('-allocsize',
                        type=int,
                        help='How large is the manageable memory in GiB?',
                        default=8)
    parser.add_argument('-device',
                        type=int,
                        help='Which device to use',
                        default=0)
    parser.add_argument(
        '-mailpass',
        type=str,
        help='Supply the mail password if you want to be notified',
        default=None)

    args = parser.parse_args()

    executable_extension = ""
    if os.name == 'nt':  # If on Windows
        executable_extension = ".exe"
    # Parse approaches
    if (args.t):
        if any("c" in s for s in args.t):
            testcases["CUDA"] = os.path.join(
                build_path,
                str("c_alloc_test") + executable_extension)
        if any("x" in s for s in args.t):
            testcases["XMalloc"] = os.path.join(
                sync_build_path,
                str("x_alloc_test") + executable_extension)
        if any("h" in s for s in args.t):
            testcases["Halloc"] = os.path.join(
                sync_build_path,
                str("h_alloc_test") + executable_extension)
        if any("s" in s for s in args.t):
            testcases["ScatterAlloc"] = os.path.join(
                sync_build_path,
                str("s_alloc_test") + executable_extension)
        if any("o" in s for s in args.t):
            # testcases["Ouroboros-P-S"] = os.path.join(build_path, str("o_alloc_test_p") + executable_extension)
            # testcases["Ouroboros-P-VA"] = os.path.join(build_path, str("o_alloc_test_vap") + executable_extension)
            # testcases["Ouroboros-P-VL"] = os.path.join(build_path, str("o_alloc_test_vlp") + executable_extension)
            testcases["Ouroboros-C-S"] = os.path.join(
                build_path,
                str("o_alloc_test_c") + executable_extension)
            # testcases["Ouroboros-C-VA"] = os.path.join(build_path, str("o_alloc_test_vac") + executable_extension)
            testcases["Ouroboros-C-VL"] = os.path.join(
                build_path,
                str("o_alloc_test_vlc") + executable_extension)
        if any("f" in s for s in args.t):
            testcases["FDGMalloc"] = os.path.join(
                sync_build_path,
                str("f_alloc_test") + executable_extension)
        if any("r" in s for s in args.t):
            # testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_alloc_test_a") + executable_extension)
            # testcases["RegEff-AW"] = os.path.join(sync_build_path, str("r_alloc_test_aw") + executable_extension)
            testcases["RegEff-C"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_c") + executable_extension)
            testcases["RegEff-CF"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cf") + executable_extension)
            testcases["RegEff-CM"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cm") + executable_extension)
            testcases["RegEff-CFM"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cfm") + executable_extension)

    # Parse num allocation
    if (args.num):
        num_allocations = args.num

    # Parse range
    if (args.range):
        selected_range = args.range.split('-')
        smallest_allocation_size = int(selected_range[0])
        largest_allocation_size = int(selected_range[1])

    # Parse num iterations
    if (args.iter):
        num_iterations = args.iter

    # Generate results
    warpstring = str("")
    if args.warp:
        test_warp_based = 1
        warpstring = "warp_"
    else:
        test_warp_based = 0

    # Run Testcases
    run_testcases = args.runtest

    # Generate results
    generate_results = args.genres

    # Generate plots
    generate_plots = args.genplot

    # Plot Axis scaling
    plotscale = args.plotscale

    # Clean temporary files
    clean_temporary_files = args.cleantemp

    # Measure on device
    if args.devmeasure:
        measure_on_device = 1
    else:
        measure_on_device = 0

    # Currently we cannot measure on the device when running warp-based
    if measure_on_device and test_warp_based:
        print("Cannot measure on device and warp-based at the same time!")
        exit(-1)

    # Timeout (in seconds)
    if (args.timeout):
        time_out_val = args.timeout

    if (args.filetype):
        filetype = args.filetype

    mailalert = EmailAlert(args.mailpass)

    ####################################################################################################
    ####################################################################################################
    # Run testcases
    ####################################################################################################
    ####################################################################################################
    if run_testcases:
        # Run Testcase
        for name, path in testcases.items():
            csv_path_alloc = "results/performance/" + warpstring + "perf_alloc_" + name + "_" + str(
                num_allocations) + "_" + str(
                    smallest_allocation_size) + "-" + str(
                        largest_allocation_size) + ".csv"
            csv_path_free = "results/performance/" + warpstring + "perf_free_" + name + "_" + str(
                num_allocations) + "_" + str(
                    smallest_allocation_size) + "-" + str(
                        largest_allocation_size) + ".csv"
            if (os.path.isfile(csv_path_alloc)):
                print("This file <" + csv_path_alloc +
                      "> already exists, do you really want to OVERWRITE?")
                inputfromconsole = input()
                if not (inputfromconsole == "yes" or inputfromconsole == "y"):
                    continue
            with open(csv_path_alloc, "w", newline='') as csv_file:
                csv_file.write(
                    "AllocationSize (in Byte), mean, std-dev, min, max, median"
                )
            with open(csv_path_free, "w", newline='') as csv_file:
                csv_file.write(
                    "AllocationSize (in Byte), mean, std-dev, min, max, median"
                )
            allocation_size = smallest_allocation_size
            while allocation_size <= largest_allocation_size:
                with open(csv_path_alloc, "a", newline='') as csv_file:
                    csv_file.write("\n" + str(allocation_size) + ",")
                with open(csv_path_free, "a", newline='') as csv_file:
                    csv_file.write("\n" + str(allocation_size) + ",")
                run_config = str(num_allocations) + " " + str(
                    allocation_size) + " " + str(num_iterations) + " " + str(
                        measure_on_device
                    ) + " " + str(test_warp_based) + " 1 " + str(
                        free_memory
                    ) + " " + csv_path_alloc + " " + csv_path_free + " " + str(
                        args.allocsize) + " " + str(args.device)
                executecommand = "{0} {1}".format(path, run_config)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print("Running " + name + " with command -> " + executecommand)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                _, process_killed = Command(executecommand).run(
                    timeout=time_out_val)
                if process_killed:
                    print("We killed the process!")
                    with open(csv_path_alloc, "a", newline='') as csv_file:
                        csv_file.write(
                            "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                            + str(time_out_val))
                    with open(csv_path_free, "a", newline='') as csv_file:
                        csv_file.write(
                            "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                            + str(time_out_val))
                else:
                    print("Success!")
                allocation_size += 4
            if args.mailpass:
                message = "Testcase {0} ran through! Testset: ({1})".format(
                    str(name), " | ".join(testcases.keys()))
                mailalert.sendAlert(message)

    ####################################################################################################
    ####################################################################################################
    # Generate new Results
    ####################################################################################################
    ####################################################################################################
    if generate_results:
        if not os.path.exists("results/performance/aggregate"):
            os.mkdir("results/performance/aggregate")
        generateResultsFromFileAllocation(testcases, "results/performance",
                                          num_allocations,
                                          smallest_allocation_size,
                                          largest_allocation_size, "Bytes",
                                          "perf", 2 if not args.warp else 3)

    # ####################################################################################################
    # ####################################################################################################
    # # Generate new plots
    # ####################################################################################################
    # ####################################################################################################
    # if generate_plots:
    # 	result_alloc = list(list())
    # 	result_free = list(list())
    # 	# Get Timestring
    # 	now = datetime.now()
    # 	time_string = now.strftime("%b-%d-%Y_%H-%M-%S")

    # 	if plotscale == "log":
    # 		time_string += "_log"
    # 	else:
    # 		time_string += "_lin"

    # 	for file in os.listdir("results/performance/aggregate"):
    # 		filename = str("results/performance/aggregate/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		if filename.split("_")[2] != "perf" or str(num_allocations) != filename.split('_')[4] or str(smallest_allocation_size) + "-" + str(largest_allocation_size) != filename.split('_')[5].split(".")[0]:
    # 			continue
    # 		# We want the one matching our input
    # 		with open(filename) as f:
    # 			reader = csv.reader(f)
    # 			if "free" in filename:
    # 				result_free = list(reader)
    # 			else:
    # 				result_alloc = list(reader)

    # 	####################################################################################################
    # 	# Alloc - Mean - Std-dev
    # 	####################################################################################################
    # 	plotMean(result_alloc,
    # 		testcases,
    # 		plotscale,
    # 		False,
    # 		'Bytes',
    # 		'ms',
    # 		"Allocation performance for " + str(num_allocations) + " allocations (mean)",
    # 		str("results/plots/performance/") + time_string + "_alloc." + filetype,
    # 		"stddev")
    # 	print("---------------------------------------")
    # 	plotMean(result_alloc,
    # 		testcases,
    # 		plotscale,
    # 		True,
    # 		'Bytes',
    # 		'ms',
    # 		"Allocation performance for " + str(num_allocations) + " allocations (mean + std-dev)",
    # 		str("results/plots/performance/") + time_string + "_alloc_stddev." + filetype,
    # 		"stddev")
    # 	print("---------------------------------------")
    # 	####################################################################################################
    # 	# Free - Mean - Std-dev
    # 	####################################################################################################
    # 	plotMean(result_free,
    # 		testcases,
    # 		plotscale,
    # 		False,
    # 		'Bytes',
    # 		'ms',
    # 		"Free performance for " + str(num_allocations) + " allocations (mean)",
    # 		str("results/plots/performance/") + time_string + "_free." + filetype,
    # 		"stddev")
    # 	print("---------------------------------------")
    # 	plotMean(result_free,
    # 		testcases,
    # 		plotscale,
    # 		True,
    # 		'Bytes',
    # 		'ms',
    # 		"Free performance for " + str(num_allocations) + " allocations (mean + std-dev)",
    # 		str("results/plots/performance/") + time_string + "_free_stddev." + filetype,
    # 		"stddev")
    # 	print("---------------------------------------")
    # 	####################################################################################################
    # 	# Alloc - Mean - Min/Max
    # 	####################################################################################################
    # 	plotMean(result_alloc,
    # 		testcases,
    # 		plotscale,
    # 		True,
    # 		'Bytes',
    # 		'ms',
    # 		"Allocation performance for " + str(num_allocations) + " allocations (mean + min/max)",
    # 		str("results/plots/performance/") + time_string + "_alloc_min_max." + filetype,
    # 		"minmax")
    # 	print("---------------------------------------")
    # 	####################################################################################################
    # 	# Free - Mean - Min/Max
    # 	####################################################################################################
    # 	plotMean(result_free,
    # 		testcases,
    # 		plotscale,
    # 		True,
    # 		'Bytes',
    # 		'ms',
    # 		"Free performance for " + str(num_allocations) + " allocations (mean + min/max)",
    # 		str("results/plots/performance/") + time_string + "_free_min_max." + filetype,
    # 		"minmax")
    # 	print("---------------------------------------")
    # 	####################################################################################################
    # 	# Alloc - Median
    # 	####################################################################################################
    # 	plotMean(result_alloc,
    # 		testcases,
    # 		plotscale,
    # 		False,
    # 		'Bytes',
    # 		'ms',
    # 		"Allocation performance for " + str(num_allocations) + " allocations (median)",
    # 		str("results/plots/performance/") + time_string + "_alloc_median." + filetype,
    # 		"median")
    # 	print("---------------------------------------")
    # 	####################################################################################################
    # 	# Free - Median
    # 	####################################################################################################
    # 	plotMean(result_free,
    # 		testcases,
    # 		plotscale,
    # 		False,
    # 		'Bytes',
    # 		'ms',
    # 		"Free performance for " + str(num_allocations) + " allocations (median)",
    # 		str("results/plots/performance/") + time_string + "_free_median." + filetype,
    # 		"median")
    # 	print("---------------------------------------")

    # ####################################################################################################
    # ####################################################################################################
    # # Clean temporary files
    # ####################################################################################################
    # ####################################################################################################
    # if clean_temporary_files:
    # 	print("Do you REALLY want to delete all temporary files?:")
    # 	inputfromconsole = input()
    # 	if not (inputfromconsole == "yes" or inputfromconsole == "y"):
    # 		exit(-1)
    # 	for file in os.listdir("results/tmp"):
    # 		filename = str("results/tmp/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)
    # 	for file in os.listdir("results/tmp/aggregate"):
    # 		filename = str("results/tmp/aggregate/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)
    # 	for file in os.listdir("results/plots"):
    # 		filename = str("results/plots/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)
    if args.mailpass:
        message = "Test Allocation finished!"
        mailalert.sendAlert(message)
    print("Done")
def main():
	# Run all files from a directory
	print("##############################################################################")
	print("Callable as: python test_registers.py")
	print("##############################################################################")
	
	# Specify which test configuration to use
	testcases = {}
	alloc_size = 8
	generate_results = True
	generate_plots = True
	filetype = "pdf"
	time_out_val = 100
	if os.name == 'nt': # If on Windows
		build_path = os.path.join("build", "Release")
		sync_build_path = os.path.join("sync_build", "Release")
	else:
		build_path = "build/"
		sync_build_path = "sync_build/"

	parser = argparse.ArgumentParser(description='Test register requirements for various frameworks')
	parser.add_argument('-t', type=str, help='Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x+b ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc')
	parser.add_argument('-runtest', action='store_true', default=False, help='Run testcases')
	parser.add_argument('-genres', action='store_true', default=False, help='Generate results')
	parser.add_argument('-genplot', action='store_true', default=False, help='Generate results file and plot')
	parser.add_argument('-timeout', type=int, help='Timeout Value in Seconds, process will be killed after as many seconds')
	parser.add_argument('-plotscale', type=str, help='log/linear')
	parser.add_argument('-filetype', type=str, help='png or pdf')
	parser.add_argument('-allocsize', type=int, help='How large is the manageable memory in GiB?')
	parser.add_argument('-device', type=int, help='Which device to use', default=0)

	args = parser.parse_args()

	executable_extension = ""
	if os.name == 'nt': # If on Windows
		executable_extension = ".exe"
	# Parse approaches
	if(args.t):
		if any("c" in s for s in args.t):
			testcases["CUDA"] = os.path.join(build_path, str("c_reg_test") + executable_extension)
		if any("x" in s for s in args.t):
			testcases["XMalloc"] = os.path.join(sync_build_path, str("x_reg_test") + executable_extension)
		if any("h" in s for s in args.t):
			testcases["Halloc"] = os.path.join(sync_build_path, str("h_reg_test") + executable_extension)
		if any("s" in s for s in args.t):
			testcases["ScatterAlloc"] = os.path.join(sync_build_path, str("s_reg_test") + executable_extension)
		if any("o" in s for s in args.t):
			testcases["Ouroboros-P-S"] = os.path.join(build_path, str("o_reg_test_p") + executable_extension)
			testcases["Ouroboros-P-VA"] = os.path.join(build_path, str("o_reg_test_vap") + executable_extension)
			testcases["Ouroboros-P-VL"] = os.path.join(build_path, str("o_reg_test_vlp") + executable_extension)
			testcases["Ouroboros-C-S"] = os.path.join(build_path, str("o_reg_test_c") + executable_extension)
			testcases["Ouroboros-C-VA"] = os.path.join(build_path, str("o_reg_test_vac") + executable_extension)
			testcases["Ouroboros-C-VL"] = os.path.join(build_path, str("o_reg_test_vlc") + executable_extension)
		if any("f" in s for s in args.t):
			testcases["FDGMalloc"] = os.path.join(sync_build_path, str("f_reg_test") + executable_extension)
		if any("r" in s for s in args.t):
			# testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_reg_test_a") + executable_extension)
			testcases["RegEff-AW"] = os.path.join(sync_build_path, str("r_reg_test_aw") + executable_extension)
			testcases["RegEff-C"] = os.path.join(sync_build_path, str("r_reg_test_c") + executable_extension)
			testcases["RegEff-CF"] = os.path.join(sync_build_path, str("r_reg_test_cf") + executable_extension)
			testcases["RegEff-CM"] = os.path.join(sync_build_path, str("r_reg_test_cm") + executable_extension)
			testcases["RegEff-CFM"] = os.path.join(sync_build_path, str("r_reg_test_cfm") + executable_extension)
	
	# Run Testcases
	run_testcases = args.runtest
	
	# Generate results
	generate_results = args.genres

	# Generate plots
	generate_plots = args.genplot

	# Plot Axis scaling
	plotscale = args.plotscale

	# Timeout (in seconds)
	if(args.timeout):
		time_out_val = args.timeout

	if(args.filetype):
		filetype = args.filetype

	if(args.allocsize):
		alloc_size = args.allocsize 

	####################################################################################################
	####################################################################################################
	# Run testcases
	####################################################################################################
	####################################################################################################
	if run_testcases:
		for name, executable in testcases.items():
			csv_path = "results/reg_" + name + ".csv"
			if(os.path.isfile(csv_path)):
				print("This file already exists, do you really want to OVERWRITE?")
				inputfromconsole = input()
				if not (inputfromconsole == "yes" or inputfromconsole == "y"):
					continue
			with open(csv_path, "w", newline='') as csv_file:
				csv_file.write("Malloc-Kernel Registers, Free-Kernel Registers\n")
			run_config = csv_path + " " + str(args.device)
			executecommand = "{0} {1}".format(executable, run_config)
			print("#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#")
			print("Running " + name + " with command -> " + executecommand)
			print("#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#")
			print(executecommand)
			_, process_killed = Command(executecommand).run(timeout=time_out_val)
			if process_killed :
				print("We killed the process!")
				with open(csv_path, "a", newline='') as csv_file:
					csv_file.write("0-------------------> Ran longer than " + str(time_out_val))
			else:
				print("Success!")

	####################################################################################################
	####################################################################################################
	# Generate new Results
	####################################################################################################
	####################################################################################################
	if generate_results:
		if not os.path.exists("results/aggregate"):
			os.mkdir("results/aggregate")
		generateResultsFromFileRegisters("results", "Bytes", 1)

	# ####################################################################################################
	# ####################################################################################################
	# # Generate new plots
	# ####################################################################################################
	# ####################################################################################################
	# if generate_plots:
	# 	result_reg = list()
	# 	# Get Timestring
	# 	now = datetime.now()
	# 	time_string = now.strftime("%b-%d-%Y_%H-%M-%S")

	# 	if plotscale == "log":
	# 		time_string += "_log"
	# 	else:
	# 		time_string += "_lin"

	# 	for file in os.listdir("results/aggregate"):
	# 		filename = str("results/aggregate/") + os.fsdecode(file)
	# 		if(os.path.isdir(filename)):
	# 			continue
	# 		if filename.split("_")[2].split(".")[0] != "reg":
	# 			continue
	# 		# We want the one matching our input
	# 		with open(filename) as f:
	# 			reader = csv.reader(f)
	# 			result_reg = list(reader)

	# 	####################################################################################################
	# 	# Barplot per approach
	# 	####################################################################################################
	# 	plotRegisters(result_reg, 
	# 		testcases,
	# 		plotscale,
	# 		'Approaches', 
	# 		'#Registers', 
	# 		"Register-Requirements for malloc/free operations", 
	# 		str("results/plots/") + time_string + "_reg_approach." + filetype, 'per_approach')

	# 	####################################################################################################
	# 	# Barplot test
	# 	####################################################################################################
	# 	plotRegisters(result_reg, 
	# 		testcases,
	# 		plotscale,
	# 		'Testcases', 
	# 		'#Registers', 
	# 		"Register-Requirements for malloc/free operations", 
	# 		str("results/plots/") + time_string + "_reg_test." + filetype, 'per_test')


	print("Done")
def main():
    print(
        "##############################################################################"
    )
    print("Callable as: python test_mixed_allocation.py -h")
    print(
        "##############################################################################"
    )

    # Specify which test configuration to use
    testcases = {}
    num_allocations = 10000
    smallest_allocation_size = 4
    largest_allocation_size = 1024
    num_iterations = 25
    free_memory = 1
    filetype = "pdf"
    time_out_val = 10
    if os.name == 'nt':  # If on Windows
        build_path = os.path.join("build", "Release")
        sync_build_path = os.path.join("sync_build", "Release")
    else:
        build_path = "build/"
        sync_build_path = "sync_build/"

    parser = argparse.ArgumentParser(
        description='Test allocation performance for various frameworks')
    parser.add_argument(
        '-t',
        type=str,
        help=
        'Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc'
    )
    parser.add_argument('-num',
                        type=int,
                        help='How many allocations to perform')
    parser.add_argument(
        '-range',
        type=str,
        help=
        'Specify Allocation Range from which these allocations come from, e.g. 4-1024'
    )
    parser.add_argument('-iter', type=int, help='How many iterations?')
    parser.add_argument('-runtest',
                        action='store_true',
                        default=False,
                        help='Run testcases')
    parser.add_argument('-genres',
                        action='store_true',
                        default=False,
                        help='Generate results')
    parser.add_argument('-genplot',
                        action='store_true',
                        default=False,
                        help='Generate results file and plot')
    parser.add_argument('-cleantemp',
                        action='store_true',
                        default=False,
                        help='Clean up temporary files')
    parser.add_argument('-warp',
                        action='store_true',
                        default=False,
                        help='Start testcases warp-based')
    parser.add_argument('-devmeasure',
                        action='store_true',
                        default=False,
                        help='Measure performance on device in cycles')
    parser.add_argument('-plotscale', type=str, help='log/linear')
    parser.add_argument(
        '-timeout',
        type=int,
        help=
        'Timeout Value in Seconds, process will be killed after as many seconds'
    )
    parser.add_argument('-filetype', type=str, help='png or pdf')
    parser.add_argument('-allocsize',
                        type=int,
                        help='How large is the manageable memory in GiB?',
                        default=8)
    parser.add_argument('-device',
                        type=int,
                        help='Which device to use',
                        default=0)

    args = parser.parse_args()

    executable_extension = ""
    if os.name == 'nt':  # If on Windows
        executable_extension = ".exe"
    # Parse approaches
    if (args.t):
        if any("c" in s for s in args.t):
            testcases["CUDA"] = os.path.join(
                build_path,
                str("c_mixed_alloc_test") + executable_extension)
        if any("x" in s for s in args.t):
            testcases["XMalloc"] = os.path.join(
                sync_build_path,
                str("x_mixed_alloc_test") + executable_extension)
        if any("h" in s for s in args.t):
            testcases["Halloc"] = os.path.join(
                sync_build_path,
                str("h_mixed_alloc_test") + executable_extension)
        if any("s" in s for s in args.t):
            testcases["ScatterAlloc"] = os.path.join(
                sync_build_path,
                str("s_mixed_alloc_test") + executable_extension)
        if any("o" in s for s in args.t):
            testcases["Ouroboros-P-S"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_p") + executable_extension)
            testcases["Ouroboros-P-VA"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_vap") + executable_extension)
            testcases["Ouroboros-P-VL"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_vlp") + executable_extension)
            testcases["Ouroboros-C-S"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_c") + executable_extension)
            testcases["Ouroboros-C-VA"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_vac") + executable_extension)
            testcases["Ouroboros-C-VL"] = os.path.join(
                build_path,
                str("o_mixed_alloc_test_vlc") + executable_extension)
        if any("f" in s for s in args.t):
            testcases["FDGMalloc"] = os.path.join(
                sync_build_path,
                str("f_mixed_alloc_test") + executable_extension)
        if any("r" in s for s in args.t):
            # testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_mixed_alloc_test_a") + executable_extension)
            testcases["RegEff-AW"] = os.path.join(
                sync_build_path,
                str("r_mixed_alloc_test_aw") + executable_extension)
            testcases["RegEff-C"] = os.path.join(
                sync_build_path,
                str("r_mixed_alloc_test_c") + executable_extension)
            testcases["RegEff-CF"] = os.path.join(
                sync_build_path,
                str("r_mixed_alloc_test_cf") + executable_extension)
            testcases["RegEff-CM"] = os.path.join(
                sync_build_path,
                str("r_mixed_alloc_test_cm") + executable_extension)
            testcases["RegEff-CFM"] = os.path.join(
                sync_build_path,
                str("r_mixed_alloc_test_cfm") + executable_extension)

    # Parse num allocation
    if (args.num):
        num_allocations = args.num

    # Parse range
    if (args.range):
        selected_range = args.range.split('-')
        smallest_allocation_size = int(selected_range[0])
        largest_allocation_size = int(selected_range[1])

    # Parse num iterations
    if (args.iter):
        num_iterations = args.iter

    # Generate results
    if args.warp:
        test_warp_based = 1
    else:
        test_warp_based = 0

    # Run Testcases
    run_testcases = args.runtest

    # Generate results
    generate_results = args.genres

    # Generate plots
    generate_plots = args.genplot

    # Plot Axis scaling
    plotscale = args.plotscale

    # Clean temporary files
    clean_temporary_files = args.cleantemp

    # Measure on device
    if args.devmeasure:
        measure_on_device = 1
    else:
        measure_on_device = 0

    # Currently we cannot measure on the device when running warp-based
    if measure_on_device and test_warp_based:
        print("Cannot measure on device and warp-based at the same time!")
        exit(-1)

    # Timeout (in seconds)
    if (args.timeout):
        time_out_val = args.timeout

    if (args.filetype):
        filetype = args.filetype

    ####################################################################################################
    ####################################################################################################
    # Run testcases
    ####################################################################################################
    ####################################################################################################
    if run_testcases:
        # Run Testcase
        for name, path in testcases.items():
            csv_path_alloc = "results/mixed_performance/perf_mixed_alloc_" + name + "_" + str(
                num_allocations) + "_" + str(
                    smallest_allocation_size) + "-" + str(
                        largest_allocation_size) + ".csv"
            csv_path_free = "results/mixed_performance/perf_mixed_free_" + name + "_" + str(
                num_allocations) + "_" + str(
                    smallest_allocation_size) + "-" + str(
                        largest_allocation_size) + ".csv"
            if (os.path.isfile(csv_path_alloc)):
                print(
                    "This file already exists, do you really want to OVERWRITE?"
                )
                inputfromconsole = input()
                if not (inputfromconsole == "yes" or inputfromconsole == "y"):
                    continue
            with open(csv_path_alloc, "w", newline='') as csv_file:
                csv_file.write(
                    "AllocationRange (in Byte), mean, std-dev, min, max, median"
                )
            with open(csv_path_free, "w", newline='') as csv_file:
                csv_file.write(
                    "AllocationRange (in Byte), mean, std-dev, min, max, median"
                )
            allocation_size = smallest_allocation_size
            while allocation_size <= largest_allocation_size:
                with open(csv_path_alloc, "a", newline='') as csv_file:
                    csv_file.write("\n" + str(smallest_allocation_size) + "-" +
                                   str(allocation_size) + ",")
                with open(csv_path_free, "a", newline='') as csv_file:
                    csv_file.write("\n" + str(smallest_allocation_size) + "-" +
                                   str(allocation_size) + ",")
                run_config = str(num_allocations) + " " + str(
                    smallest_allocation_size
                ) + " " + str(allocation_size) + " " + str(
                    num_iterations) + " " + str(measure_on_device) + " " + str(
                        test_warp_based
                    ) + " 1 " + str(
                        free_memory
                    ) + " " + csv_path_alloc + " " + csv_path_free + " " + str(
                        args.allocsize) + " " + str(args.device)
                executecommand = "{0} {1}".format(path, run_config)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                print("Running " + name + " with command -> " + executecommand)
                print(
                    "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                )
                _, process_killed = Command(executecommand).run(
                    timeout=time_out_val)
                if process_killed:
                    print("We killed the process!")
                    with open(csv_path_alloc, "a", newline='') as csv_file:
                        csv_file.write(
                            "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                            + str(time_out_val * 1000))
                    with open(csv_path_free, "a", newline='') as csv_file:
                        csv_file.write(
                            "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                            + str(time_out_val * 1000))
                else:
                    print("Success!")
                allocation_size *= 2

    ####################################################################################################
    ####################################################################################################
    # Generate new Results
    ####################################################################################################
    ####################################################################################################
    if generate_results:
        if not os.path.exists("results/mixed_performance/aggregate"):
            os.mkdir("results/mixed_performance/aggregate")
        generateResultsFromFileAllocation(testcases,
                                          "results/mixed_performance",
                                          num_allocations,
                                          smallest_allocation_size,
                                          largest_allocation_size,
                                          "Byte-Range", "perf_mixed", 4)
def main():
    # Run all files from a directory
    print(
        "##############################################################################"
    )
    print("Callable as: python test_scaling.py -h")
    print(
        "##############################################################################"
    )

    # Specify which test configuration to use
    testcases = {}
    smallest_allocation_size = 4
    largest_allocation_size = 1024
    smallest_num_threads = 2**0
    largest_num_threads = 2**10
    num_iterations = 25
    filetype = "pdf"
    time_out_val = 10
    free_memory = 1
    if os.name == 'nt':  # If on Windows
        build_path = os.path.join("build", "Release")
        sync_build_path = os.path.join("sync_build", "Release")
    else:
        build_path = "build/"
        sync_build_path = "sync_build/"

    parser = argparse.ArgumentParser(
        description='Test allocation performance for various frameworks')
    parser.add_argument(
        '-t',
        type=str,
        help=
        'Specify which frameworks to test, separated by +, e.g. o+s+h+c+f+r+x ---> c : cuda | s : scatteralloc | h : halloc | o : ouroboros | f : fdgmalloc | r : register-efficient | x : xmalloc'
    )
    parser.add_argument('-byterange',
                        type=str,
                        help='Specify Allocation Range, e.g. 16-8192')
    parser.add_argument(
        '-threadrange',
        type=str,
        help=
        'Specify number of threads, given as powers of two, e.g. 0-5 -> results in 1-32'
    )
    parser.add_argument('-iter', type=int, help='How many iterations?')
    parser.add_argument('-runtest',
                        action='store_true',
                        default=False,
                        help='Run testcases')
    parser.add_argument('-genres',
                        action='store_true',
                        default=False,
                        help='Generate results')
    parser.add_argument('-genplot',
                        action='store_true',
                        default=False,
                        help='Generate results file and plot')
    parser.add_argument('-cleantemp',
                        action='store_true',
                        default=False,
                        help='Clean up temporary files')
    parser.add_argument('-warp',
                        action='store_true',
                        default=False,
                        help='Start testcases warp-based')
    parser.add_argument('-devmeasure',
                        action='store_true',
                        default=False,
                        help='Measure performance on device in cycles')
    parser.add_argument('-plotscale', type=str, help='log/linear')
    parser.add_argument(
        '-timeout',
        type=int,
        help=
        'Timeout Value in Seconds, process will be killed after as many seconds'
    )
    parser.add_argument('-filetype', type=str, help='png or pdf')
    parser.add_argument('-allocsize',
                        type=int,
                        help='How large is the manageable memory in GiB?',
                        default=8)
    parser.add_argument('-device',
                        type=int,
                        help='Which device to use',
                        default=0)

    args = parser.parse_args()

    executable_extension = ""
    if os.name == 'nt':  # If on Windows
        executable_extension = ".exe"
    # Parse approaches
    if (args.t):
        if any("c" in s for s in args.t):
            testcases["CUDA"] = os.path.join(
                build_path,
                str("c_alloc_test") + executable_extension)
        if any("x" in s for s in args.t):
            testcases["XMalloc"] = os.path.join(
                sync_build_path,
                str("x_alloc_test") + executable_extension)
        if any("h" in s for s in args.t):
            testcases["Halloc"] = os.path.join(
                sync_build_path,
                str("h_alloc_test") + executable_extension)
        if any("s" in s for s in args.t):
            testcases["ScatterAlloc"] = os.path.join(
                sync_build_path,
                str("s_alloc_test") + executable_extension)
        if any("o" in s for s in args.t):
            testcases["Ouroboros-P-S"] = os.path.join(
                build_path,
                str("o_alloc_test_p") + executable_extension)
            testcases["Ouroboros-P-VA"] = os.path.join(
                build_path,
                str("o_alloc_test_vap") + executable_extension)
            testcases["Ouroboros-P-VL"] = os.path.join(
                build_path,
                str("o_alloc_test_vlp") + executable_extension)
            testcases["Ouroboros-C-S"] = os.path.join(
                build_path,
                str("o_alloc_test_c") + executable_extension)
            testcases["Ouroboros-C-VA"] = os.path.join(
                build_path,
                str("o_alloc_test_vac") + executable_extension)
            testcases["Ouroboros-C-VL"] = os.path.join(
                build_path,
                str("o_alloc_test_vlc") + executable_extension)
        if any("f" in s for s in args.t):
            testcases["FDGMalloc"] = os.path.join(
                sync_build_path,
                str("f_alloc_test") + executable_extension)
        if any("r" in s for s in args.t):
            # testcases["RegEff-A"] = os.path.join(sync_build_path, str("r_alloc_test_a") + executable_extension)
            testcases["RegEff-AW"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_aw") + executable_extension)
            testcases["RegEff-C"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_c") + executable_extension)
            testcases["RegEff-CF"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cf") + executable_extension)
            testcases["RegEff-CM"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cm") + executable_extension)
            testcases["RegEff-CFM"] = os.path.join(
                sync_build_path,
                str("r_alloc_test_cfm") + executable_extension)

    # Parse allocation size
    if (args.byterange):
        selected_range = args.byterange.split('-')
        smallest_allocation_size = int(selected_range[0])
        largest_allocation_size = int(selected_range[1])

    # Parse range
    if (args.threadrange):
        selected_range = args.threadrange.split('-')
        smallest_num_threads = 2**int(selected_range[0])
        largest_num_threads = 2**int(selected_range[1])

    # Parse num iterations
    if (args.iter):
        num_iterations = args.iter

    # Generate results
    if args.warp:
        test_warp_based = 1
    else:
        test_warp_based = 0

    # Run Testcases
    run_testcases = args.runtest

    # Generate results
    generate_results = args.genres

    # Generate plots
    generate_plots = args.genplot

    # Plot Axis scaling
    plotscale = args.plotscale

    # Clean temporary files
    clean_temporary_files = args.cleantemp

    # Measure on device
    if args.devmeasure:
        measure_on_device = 1
    else:
        measure_on_device = 0

    if measure_on_device and test_warp_based:
        print("Cannot measure on device and warp-based at the same time!")
        exit(-1)

    # Timeout (in seconds)
    if (args.timeout):
        time_out_val = args.timeout

    if (args.filetype):
        filetype = args.filetype

    ####################################################################################################
    ####################################################################################################
    # Run testcases
    ####################################################################################################
    ####################################################################################################
    if run_testcases:
        allocation_size = smallest_allocation_size
        while allocation_size <= largest_allocation_size:
            for name, path in testcases.items():
                csv_path_alloc = "results/scaling/scale_alloc_" + name + "_" + str(
                    allocation_size) + "_" + str(
                        smallest_num_threads) + "-" + str(
                            largest_num_threads) + ".csv"
                csv_path_free = "results/scaling/scale_free_" + name + "_" + str(
                    allocation_size) + "_" + str(
                        smallest_num_threads) + "-" + str(
                            largest_num_threads) + ".csv"
                if (os.path.isfile(csv_path_alloc)):
                    print(
                        "This file already exists, do you really want to OVERWRITE?"
                    )
                    inputfromconsole = input()
                    if not (inputfromconsole == "yes"
                            or inputfromconsole == "y"):
                        continue
                with open(csv_path_alloc, "w", newline='') as csv_file:
                    csv_file.write(
                        "NumThreads, mean, std-dev, min, max, median")
                with open(csv_path_free, "w", newline='') as csv_file:
                    csv_file.write(
                        "NumThreads, mean, std-dev, min, max, median")
                num_threads = smallest_num_threads
                while num_threads <= largest_num_threads:
                    with open(csv_path_alloc, "a", newline='') as csv_file:
                        csv_file.write("\n" + str(num_threads) + ",")
                    with open(csv_path_free, "a", newline='') as csv_file:
                        csv_file.write("\n" + str(num_threads) + ",")
                    run_config = str(num_threads) + " " + str(
                        allocation_size
                    ) + " " + str(num_iterations) + " " + str(
                        measure_on_device
                    ) + " " + str(test_warp_based) + " 1 " + str(
                        free_memory
                    ) + " " + csv_path_alloc + " " + csv_path_free + " " + str(
                        args.allocsize) + " " + str(args.device)
                    executecommand = "{0} {1}".format(path, run_config)
                    print(
                        "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                    )
                    print("Running " + name + " with command -> " +
                          executecommand)
                    print(
                        "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"
                    )
                    _, process_killed = Command(executecommand).run(
                        timeout=time_out_val)
                    if process_killed:
                        print("We killed the process!")
                        with open(csv_path_alloc, "a", newline='') as csv_file:
                            csv_file.write(
                                "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                                + str(time_out_val * 1000))
                        with open(csv_path_free, "a", newline='') as csv_file:
                            csv_file.write(
                                "0.00,0.00,0.00,0.00,0.00,-------------------> Ran longer than "
                                + str(time_out_val * 1000))
                    num_threads *= 2
            allocation_size *= 2

    ####################################################################################################
    ####################################################################################################
    # Generate new Results
    ####################################################################################################
    ####################################################################################################
    if generate_results:
        if not os.path.exists("results/scaling/aggregate"):
            os.mkdir("results/scaling/aggregate")
        allocation_size = smallest_allocation_size
        while allocation_size <= largest_allocation_size:
            generateResultsFromFileAllocation(testcases, "results/scaling",
                                              allocation_size,
                                              smallest_num_threads,
                                              largest_num_threads, "Threads",
                                              "scale", 2)
            allocation_size *= 2

    # ####################################################################################################
    # ####################################################################################################
    # # Generate plots
    # ####################################################################################################
    # ####################################################################################################
    # if generate_plots:
    # 	# Get Timestring
    # 	now = datetime.now()
    # 	time_string = now.strftime("%b-%d-%Y_%H-%M-%S")
    # 	if plotscale == "log":
    # 		time_string += "_log"
    # 	else:
    # 		time_string += "_lin"
    # 	# Generate plots for each byte size
    # 	byte_range = []
    # 	start_val = smallest_allocation_size
    # 	while start_val <= largest_allocation_size:
    # 		byte_range.append(start_val)
    # 		start_val *= 2

    # 	for num_bytes in byte_range:
    # 		# Generate plots for this byte size
    # 		print("Generate plots for size: " + str(num_bytes) + " Bytes")
    # 		result_alloc = list(list())
    # 		result_free = list(list())

    # 		for file in os.listdir("results/scaling/aggregate"):
    # 			filename = str("results/scaling/aggregate/") + os.fsdecode(file)
    # 			if(os.path.isdir(filename)):
    # 				continue
    # 			if filename.split("_")[2] != "scale" or str(num_bytes) != filename.split('_')[4] or str(smallest_num_threads) + "-" + str(largest_num_threads) != filename.split('_')[5].split(".")[0]:
    # 				continue
    # 			# We want the one matching our input
    # 			with open(filename) as f:
    # 				reader = csv.reader(f)
    # 				if "free" in filename:
    # 					result_free = list(reader)
    # 				else:
    # 					result_alloc = list(reader)

    # 		####################################################################################################
    # 		# Alloc - Mean - Std-dev
    # 		####################################################################################################
    # 		print("Generate mean/stddev alloc plot for " + str(num_bytes))
    # 		plotMean(result_alloc,
    # 			testcases,
    # 			plotscale,
    # 			False,
    # 			'Threads',
    # 			'ms',
    # 			"Allocation Scaling for " + str(num_bytes) + " Bytes (mean)",
    # 			str("results/plots/scaling/") + time_string + "_alloc_scale_" + str(num_bytes) + "_mean." + filetype,
    # 			"stddev")
    # 		plotMean(result_alloc,
    # 			testcases,
    # 			plotscale,
    # 			True,
    # 			'Threads',
    # 			'ms',
    # 			"Allocation Scaling for " + str(num_bytes) + " Bytes (mean + std-dev)",
    # 			str("results/plots/scaling/") + time_string + "_alloc_scale_" + str(num_bytes) + "_mean_stddev." + filetype,
    # 			"stddev")

    # 		####################################################################################################
    # 		# Free - Mean - Std-dev
    # 		####################################################################################################
    # 		print("Generate mean/stddev free plot for " + str(num_bytes))
    # 		plotMean(result_free,
    # 			testcases,
    # 			plotscale,
    # 			False,
    # 			'Threads',
    # 			'ms',
    # 			"Free scaling for " + str(num_bytes) + " Bytes (mean)",
    # 			str("results/plots/scaling/") + time_string + "_free_scale_" + str(num_bytes) + "_mean." + filetype,
    # 			"stddev")
    # 		plotMean(result_free,
    # 			testcases,
    # 			plotscale,
    # 			True,
    # 			'Threads',
    # 			'ms',
    # 			"Free scaling for " + str(num_bytes) + " Bytes (mean + std-dev)",
    # 			str("results/plots/scaling/") + time_string + "_free_scale_" + str(num_bytes) + "_mean_stddev." + filetype,
    # 			"stddev")

    # 		####################################################################################################
    # 		# Alloc - Mean - Min/Max
    # 		####################################################################################################
    # 		print("Generate mean/min/max alloc plot for " + str(num_bytes))
    # 		plotMean(result_alloc,
    # 			testcases,
    # 			plotscale,
    # 			True,
    # 			'Threads',
    # 			'ms',
    # 			"Allocation scaling for " + str(num_bytes) + " Bytes (mean + min/max)",
    # 			str("results/plots/scaling/") + time_string + "_alloc_scale_" + str(num_bytes) + "_min_max." + filetype,
    # 			"minmax")

    # 		####################################################################################################
    # 		# Free - Mean - Min/Max
    # 		####################################################################################################
    # 		print("Generate mean/min/max free plot for " + str(num_bytes))
    # 		plotMean(result_free,
    # 			testcases,
    # 			plotscale,
    # 			True,
    # 			'Threads',
    # 			'ms',
    # 			"Free scaling for " + str(num_bytes) + " Bytes (mean + min/max)",
    # 			str("results/plots/scaling/") + time_string + "_free_scale_" + str(num_bytes) + "_min_max." + filetype,
    # 			"minmax")

    # 		####################################################################################################
    # 		# Alloc - Median
    # 		####################################################################################################
    # 		print("Generate median alloc plot for " + str(num_bytes))
    # 		plotMean(result_alloc,
    # 			testcases,
    # 			plotscale,
    # 			False,
    # 			'Threads',
    # 			'ms',
    # 			"Allocation scaling for " + str(num_bytes) + " Bytes (median)",
    # 			str("results/plots/scaling/") + time_string + "_alloc_scale_" + str(num_bytes) + "_median." + filetype,
    # 			"median")

    # 		####################################################################################################
    # 		# Free - Median
    # 		####################################################################################################
    # 		print("Generate median free plot for " + str(num_bytes))
    # 		plotMean(result_free,
    # 			testcases,
    # 			plotscale,
    # 			False,
    # 			'Threads',
    # 			'ms',
    # 			"Free scaling for " + str(num_bytes) + " Bytes (median)",
    # 			str("results/plots/scaling/") + time_string + "_free_scale_" + str(num_bytes) + "_median." + filetype,
    # 			"median")

    # ####################################################################################################
    # ####################################################################################################
    # # Clean temporary files
    # ####################################################################################################
    # ####################################################################################################
    # if clean_temporary_files:
    # 	print("Do you REALLY want to delete all temporary files?:")
    # 	inputfromconsole = input()
    # 	if not (inputfromconsole == "yes" or inputfromconsole == "y"):
    # 		exit(-1)
    # 	for file in os.listdir("results/tmp"):
    # 		filename = str("results/tmp/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)
    # 	for file in os.listdir("results/tmp/aggregate"):
    # 		filename = str("results/tmp/aggregate/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)
    # 	for file in os.listdir("results/plots"):
    # 		filename = str("results/plots/") + os.fsdecode(file)
    # 		if(os.path.isdir(filename)):
    # 			continue
    # 		os.remove(filename)

    print("Done")