Skip to content

Commit

Permalink
moved reinitialization of actor observers to execute method, before w…
Browse files Browse the repository at this point in the history
…as in init
  • Loading branch information
MiloLurati committed Jun 18, 2024
1 parent 63d9f65 commit e604510
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions kernel_tuner/runners/ray/remote_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = []
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion kernel_tuner/strategies/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e604510

Please sign in to comment.