From 47f793b3c24f9e15d2429fdecc83f478a2c2f4ea Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Thu, 4 Jan 2024 13:32:37 +0100 Subject: [PATCH] cleanup(optimizer): verbose: show warnings for missing overhead models --- .../Variables/Experiment.py | 11 +++++++++- .../classes/system/System.py | 20 +++++++++++-------- .../discopop_optimizer/optimizer.py | 4 +++- .../suggestions/importers/do_all.py | 2 +- .../suggestions/importers/reduction.py | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/discopop_library/discopop_optimizer/Variables/Experiment.py b/discopop_library/discopop_optimizer/Variables/Experiment.py index eb3a43135..e247a2db1 100644 --- a/discopop_library/discopop_optimizer/Variables/Experiment.py +++ b/discopop_library/discopop_optimizer/Variables/Experiment.py @@ -16,6 +16,7 @@ from discopop_library.MemoryRegions.utils import get_sizes_of_memory_regions from discopop_library.PathManagement.PathManagement import load_file_mapping from discopop_library.discopop_optimizer.CostModels.CostModel import CostModel +from discopop_library.discopop_optimizer.OptimizerArguments import OptimizerArguments from discopop_library.discopop_optimizer.classes.context.ContextObject import ContextObject from discopop_library.discopop_optimizer.classes.enums.Distributions import FreeSymbolDistribution from discopop_library.discopop_optimizer.classes.nodes.FunctionRoot import FunctionRoot @@ -60,6 +61,8 @@ class Experiment(object): file_mapping: Dict[int, Path] # file-mapping + arguments: OptimizerArguments + detection_result: DetectionResult function_models: Dict[FunctionRoot, List[Tuple[CostModel, ContextObject, str]]] @@ -70,10 +73,16 @@ class Experiment(object): suggestion_to_node_ids_dict: Dict[int, List[int]] def __init__( - self, file_mapping: Dict[int, Path], system: System, detection_result: DetectionResult, profiler_dir: str + self, + file_mapping: Dict[int, Path], + system: System, + detection_result: DetectionResult, + profiler_dir: str, + arguments: OptimizerArguments, ): self.__system = system self.detection_result = detection_result + self.arguments = arguments self.__memory_region_sizes = get_sizes_of_memory_regions( set(), diff --git a/discopop_library/discopop_optimizer/classes/system/System.py b/discopop_library/discopop_optimizer/classes/system/System.py index 5183edc5c..c81dfecd0 100644 --- a/discopop_library/discopop_optimizer/classes/system/System.py +++ b/discopop_library/discopop_optimizer/classes/system/System.py @@ -103,23 +103,27 @@ def __build_GPU(self, device_configuration: Dict[str, Any]): ) self.add_device(gpu, device_configuration["device_id"]) - def set_device_doall_overhead_model(self, device: Device, model: Expr): - print("System: Set DOALL overhead model: ", model) + def set_device_doall_overhead_model(self, device: Device, model: Expr, arguments: OptimizerArguments): + if arguments.verbose: + print("System: Set DOALL overhead model: ", model) self.__device_do_all_overhead_models[device] = model - def set_reduction_overhead_model(self, device: Device, model: Expr): - print("System: Set REDUCTION overhead model: ", model) + def set_reduction_overhead_model(self, device: Device, model: Expr, arguments: OptimizerArguments): + if arguments.verbose: + print("System: Set REDUCTION overhead model: ", model) self.__device_reduction_overhead_models[device] = model - def get_device_doall_overhead_model(self, device: Device) -> Expr: + def get_device_doall_overhead_model(self, device: Device, arguments: OptimizerArguments) -> Expr: if device not in self.__device_do_all_overhead_models: - warnings.warn("No DOALL overhead model, assuming 0 for device: " + str(device)) + if arguments.verbose: + warnings.warn("No DOALL overhead model, assuming 0 for device: " + str(device)) return Expr(Integer(0)) return self.__device_do_all_overhead_models[device] - def get_device_reduction_overhead_model(self, device: Device) -> Expr: + def get_device_reduction_overhead_model(self, device: Device, arguments: OptimizerArguments) -> Expr: if device not in self.__device_reduction_overhead_models: - warnings.warn("No REDUCTION overhead model, assuming 0 for device: " + str(device)) + if arguments.verbose: + warnings.warn("No REDUCTION overhead model, assuming 0 for device: " + str(device)) return Expr(Integer(0)) return self.__device_reduction_overhead_models[device] diff --git a/discopop_library/discopop_optimizer/optimizer.py b/discopop_library/discopop_optimizer/optimizer.py index 0829127ef..23469b0df 100644 --- a/discopop_library/discopop_optimizer/optimizer.py +++ b/discopop_library/discopop_optimizer/optimizer.py @@ -122,6 +122,7 @@ def run(arguments: OptimizerArguments): system.set_device_doall_overhead_model( system.get_device(system.get_host_device_id()), ExtrapInterpolatedMicrobench(arguments.doall_microbench_file).getFunctionSympy(), + arguments, ) if arguments.reduction_microbench_file != "None": # construct and set overhead model for reduction suggestions @@ -130,10 +131,11 @@ def run(arguments: OptimizerArguments): ExtrapInterpolatedMicrobench(arguments.reduction_microbench_file).getFunctionSympy( benchType=MicrobenchType.FOR ), + arguments, ) # define Experiment - experiment = Experiment(file_mapping, system, detection_result, profiler_dir) + experiment = Experiment(file_mapping, system, detection_result, profiler_dir, arguments) # build optimization graph if arguments.verbose: diff --git a/discopop_library/discopop_optimizer/suggestions/importers/do_all.py b/discopop_library/discopop_optimizer/suggestions/importers/do_all.py index 5281b6903..8280eca4f 100644 --- a/discopop_library/discopop_optimizer/suggestions/importers/do_all.py +++ b/discopop_library/discopop_optimizer/suggestions/importers/do_all.py @@ -140,7 +140,7 @@ def get_overhead_term(node_data: Loop, environment: Experiment, device_id: int) unit of the overhead term are micro seconds.""" # retrieve DoAll overhead model overhead_model = environment.get_system().get_device_doall_overhead_model( - environment.get_system().get_device(device_id) + environment.get_system().get_device(device_id), environment.arguments ) # substitute workload, iterations and threads thread_count = environment.get_system().get_device(device_id).get_thread_count() diff --git a/discopop_library/discopop_optimizer/suggestions/importers/reduction.py b/discopop_library/discopop_optimizer/suggestions/importers/reduction.py index 1942a84fd..1f6efb61a 100644 --- a/discopop_library/discopop_optimizer/suggestions/importers/reduction.py +++ b/discopop_library/discopop_optimizer/suggestions/importers/reduction.py @@ -133,7 +133,7 @@ def get_overhead_term(node_data: Loop, environment: Experiment, device_id: int) # retrieve Reduction overhead model overhead_model = environment.get_system().get_device_reduction_overhead_model( - environment.get_system().get_device(device_id) + environment.get_system().get_device(device_id), environment.arguments ) # substitute workload, iterations and threads thread_count = environment.get_system().get_device(device_id).get_thread_count()