Skip to content

Commit

Permalink
misc: Avoid reinitialization of parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Feb 19, 2025
1 parent 53a26bd commit da91de6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions devito/operator/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ class Profiler:
_default_libs = []
_ext_calls = []

_include_dirs = []
_lib_dirs = []

_supports_async_sections = False

_verbosity = 0

_attempted_init = False

def __init__(self, name):
self.name = name

Expand All @@ -50,11 +55,7 @@ def __init__(self, name):
# Python-level timers
self.py_timers = OrderedDict()

# Instance attributes
self._include_dirs = []
self._lib_dirs = []

self.initialized = True
self._attempted_init = True

def add_include_dir(self, dir_path):
self._include_dirs.append(dir_path)
Expand Down Expand Up @@ -375,14 +376,18 @@ class AdvisorProfiler(AdvancedProfiler):
_ext_calls = [_api_resume, _api_pause]

def __init__(self, name):
if self._attempted_init:
return

super().__init__(name)

path = get_advisor_path()
if path:
self.add_include_dir(path.joinpath('include').as_posix())
self.add_lib_dir(path.joinpath('lib64').as_posix())
self._attempted_init = True
else:
self.initialized = False
self._attempted_init = False

def analyze(self, iet):
"""
Expand Down Expand Up @@ -517,13 +522,13 @@ def create_profile(name):
level = configuration['profiling']
profiler = profiler_registry[level](name)

if profiler.initialized:
if profiler._attempted_init:
return profiler
else:
warning(f"Couldn't set up `{level}` profiler; reverting to 'advanced'")
profiler = profiler_registry['advanced'](name)
# We expect the `advanced` profiler to always initialize successfully
assert profiler.initialized
assert profiler._attempted_init
return profiler


Expand Down

0 comments on commit da91de6

Please sign in to comment.