From e604510d7ec5d5d5447ef0953bd23bf1528101b6 Mon Sep 17 00:00:00 2001 From: Milo Lurati Date: Tue, 18 Jun 2024 10:52:39 +0200 Subject: [PATCH] moved reinitialization of actor observers to execute method, before was in init --- kernel_tuner/runners/ray/remote_actor.py | 11 ++++++++--- kernel_tuner/strategies/common.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel_tuner/runners/ray/remote_actor.py b/kernel_tuner/runners/ray/remote_actor.py index 219fb673..138636de 100644 --- a/kernel_tuner/runners/ray/remote_actor.py +++ b/kernel_tuner/runners/ray/remote_actor.py @@ -27,10 +27,14 @@ def __init__(self, self.simulation_mode = simulation_mode self.runner = None self.id = get_gpu_id(kernel_source.lang) if not simulation_mode else None - self._reinitialize_observers(observers_type_and_arguments) + self.observers_initialized = False + self.observers_type_and_arguments = observers_type_and_arguments def execute(self, tuning_options, strategy=None, searchspace=None, element=None): + if not self.observers_initialized: + self._reinitialize_observers(self.observers_type_and_arguments) + self.observers_initialized = True tuning_options['observers'] = self.observers if self.runner is None: self.init_runner() @@ -65,6 +69,7 @@ def init_runner(self): self.iterations, self.observers, cache_manager=self.cache_manager) def _reinitialize_observers(self, observers_type_and_arguments): + print("DEBUG: reinit observers called", file=sys.stderr) # observers can't be pickled to the actor so we need to re-initialize them register_observer = False self.observers = [] @@ -75,10 +80,10 @@ def _reinitialize_observers(self, observers_type_and_arguments): register_observer = True else: self.observers.append(observer(**arguments)) - # we dont initialize the dev with observers, as this creates a 'invalid resource handle' error down the line - self.dev = DeviceInterface(self.kernel_source, iterations=self.iterations, **self.device_options) if not self.simulation_mode else None # the register observer needs dev to be initialized, that's why its done later if register_observer: + # we dont initialize the dev with observers, as this creates a 'invalid resource handle' error down the line + self.dev = DeviceInterface(self.kernel_source, iterations=self.iterations, **self.device_options) if not self.simulation_mode else None self.observers.append(RegisterObserver(self.dev)) def get_gpu_type(self, lang): diff --git a/kernel_tuner/strategies/common.py b/kernel_tuner/strategies/common.py index 47fefd50..6d010a0a 100644 --- a/kernel_tuner/strategies/common.py +++ b/kernel_tuner/strategies/common.py @@ -53,7 +53,7 @@ def make_strategy_options_doc(strategy_options): def get_options(strategy_options, options): """Get the strategy-specific options or their defaults from user-supplied strategy_options.""" accepted = list(options.keys()) + ["max_fevals", "time_limit", "ensemble", "candidates", "candidate", "population", - "maxiter", "lsd", "popsize", "alsd", "split_searchspace"] + "maxiter", "lsd", "popsize", "alsd", "split_searchspace", "check_and_retrieve"] for key in strategy_options: if key not in accepted: raise ValueError(f"Unrecognized option {key} in strategy_options")