Skip to content

Commit

Permalink
fix(explorer): exception handling when profiling enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Jul 12, 2024
1 parent 906c5e1 commit e5b41b7
Showing 1 changed file with 90 additions and 84 deletions.
174 changes: 90 additions & 84 deletions discopop_explorer/discopop_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,79 +190,102 @@ def run(arguments: ExplorerArguments) -> None:
profile = cProfile.Profile()
profile.enable()

if arguments.generate_data_cu_inst is not None:
# start generation of Data_CUInst and stop execution afterwards
from .generate_Data_CUInst import wrapper as generate_data_cuinst_wrapper
try:
if arguments.generate_data_cu_inst is not None:
# start generation of Data_CUInst and stop execution afterwards
from .generate_Data_CUInst import wrapper as generate_data_cuinst_wrapper

generate_data_cuinst_wrapper(
arguments.cu_xml_file,
arguments.dep_file,
arguments.loop_counter_file,
arguments.reduction_file,
arguments.generate_data_cu_inst,
)
sys.exit(0)

print("Loading Hotspots...")

hotspots = load_hotspots(
HotspotLoaderArguments(
verbose=True,
get_loops=True,
get_functions=True,
get_YES=True,
get_MAYBE=True,
get_NO=False,
log_level=arguments.log_level,
write_log=arguments.write_log,
)
)

print("Done.")

generate_data_cuinst_wrapper(
start = time.time()

res = __run(
arguments.project_path,
arguments.cu_xml_file,
arguments.dep_file,
arguments.loop_counter_file,
arguments.reduction_file,
arguments.generate_data_cu_inst,
)
sys.exit(0)

print("Loading Hotspots...")

hotspots = load_hotspots(
HotspotLoaderArguments(
verbose=True,
get_loops=True,
get_functions=True,
get_YES=True,
get_MAYBE=True,
get_NO=False,
log_level=arguments.log_level,
write_log=arguments.write_log,
arguments.plugins,
file_mapping=arguments.file_mapping_file,
cu_inst_result_file=arguments.cu_inst_result_file,
llvm_cxxfilt_path=arguments.llvm_cxxfilt_path,
discopop_build_path=arguments.discopop_build_path,
enable_patterns=arguments.enable_patterns,
enable_task_pattern=arguments.enable_task_pattern,
enable_detection_of_scheduling_clauses=arguments.detect_scheduling_clauses,
hotspot_functions=hotspots,
load_existing_doall_and_reduction_patterns=arguments.load_existing_doall_and_reduction_patterns,
)
)

print("Done.")

start = time.time()

res = __run(
arguments.project_path,
arguments.cu_xml_file,
arguments.dep_file,
arguments.loop_counter_file,
arguments.reduction_file,
arguments.plugins,
file_mapping=arguments.file_mapping_file,
cu_inst_result_file=arguments.cu_inst_result_file,
llvm_cxxfilt_path=arguments.llvm_cxxfilt_path,
discopop_build_path=arguments.discopop_build_path,
enable_patterns=arguments.enable_patterns,
enable_task_pattern=arguments.enable_task_pattern,
enable_detection_of_scheduling_clauses=arguments.detect_scheduling_clauses,
hotspot_functions=hotspots,
load_existing_doall_and_reduction_patterns=arguments.load_existing_doall_and_reduction_patterns,
)

end = time.time()

if arguments.enable_pet_dump_file is not None:
with open(arguments.enable_pet_dump_file, "w+") as f:
f.write(res.pet.dump_to_pickled_json())
f.flush()
f.close()

if arguments.enable_detection_result_dump_file is not None:
with open(arguments.enable_detection_result_dump_file, "w+") as f:
f.write(res.dump_to_pickled_json())
f.flush()
f.close()

if arguments.enable_json_file is None:
print(str(res))
else:
# todo re-enable?
# print(str(res))
# since PETGraphX is not JSON Serializable, delete the field prior to executing the serialization
del res.pet
with open(arguments.enable_json_file, "w+") as f:
json.dump(res, f, indent=2, cls=PatternBaseSerializer)

end = time.time()

if arguments.enable_pet_dump_file is not None:
with open(arguments.enable_pet_dump_file, "w+") as f:
f.write(res.pet.dump_to_pickled_json())
f.flush()
f.close()

if arguments.enable_detection_result_dump_file is not None:
with open(arguments.enable_detection_result_dump_file, "w+") as f:
f.write(res.dump_to_pickled_json())
f.flush()
f.close()

if arguments.enable_json_file is None:
print(str(res))
else:
# todo re-enable?
# print(str(res))
# since PETGraphX is not JSON Serializable, delete the field prior to executing the serialization
del res.pet
with open(arguments.enable_json_file, "w+") as f:
json.dump(res, f, indent=2, cls=PatternBaseSerializer)



# initialize the line_mapping.json
initialize_line_mapping(load_file_mapping(arguments.file_mapping_file), arguments.project_path)

print("Time taken for pattern detection: {0}".format(end - start))

# demonstration of Microbenchmark possibilities
if arguments.microbench_file is not None:
microbench_file = get_path(
arguments.project_path, arguments.microbench_file
) # NOTE: the json file is not usually located in the project, this is just for demonstration purposes
if not os.path.isfile(microbench_file):
raise FileNotFoundError(f"Microbenchmark file not found: {microbench_file}")
extrapBench = ExtrapInterpolatedMicrobench(microbench_file)
sympyExpr = extrapBench.getFunctionSympy()
print(sympyExpr)
print(sympyExpr.free_symbols)
except BaseException:
# required to correctly write profiling data if the program terminates
pass

if arguments.enable_profiling_dump_file is not None:
profile.disable()
Expand All @@ -271,20 +294,3 @@ def run(arguments: ExplorerArguments) -> None:
with open(arguments.enable_profiling_dump_file, "w+") as f:
stats = pstats2.Stats(profile, stream=f).sort_stats("time").reverse_order()
stats.print_stats()

# initialize the line_mapping.json
initialize_line_mapping(load_file_mapping(arguments.file_mapping_file), arguments.project_path)

print("Time taken for pattern detection: {0}".format(end - start))

# demonstration of Microbenchmark possibilities
if arguments.microbench_file is not None:
microbench_file = get_path(
arguments.project_path, arguments.microbench_file
) # NOTE: the json file is not usually located in the project, this is just for demonstration purposes
if not os.path.isfile(microbench_file):
raise FileNotFoundError(f"Microbenchmark file not found: {microbench_file}")
extrapBench = ExtrapInterpolatedMicrobench(microbench_file)
sympyExpr = extrapBench.getFunctionSympy()
print(sympyExpr)
print(sympyExpr.free_symbols)

0 comments on commit e5b41b7

Please sign in to comment.