Skip to content

Commit

Permalink
misc: Avoid reinitialization of parent class and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Feb 26, 2025
1 parent ecb58fb commit c6e780d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion benchmarks/user/advisor/run_advisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from subprocess import check_output, PIPE, Popen
from tempfile import gettempdir, mkdtemp

from advisor_logging import (check, log, progress, log_process)
from advisor_logging import check, log, progress, log_process


@click.command()
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def skipif(items, whole_module=False):
skipit = "`icx+cpu64` won't work with this test"
break
# Skip if icx or advisor are not available
if i not in ('noadvisor',) or \
if i == 'noadvisor' and \
not isinstance(configuration['compiler'], IntelCompiler) or \
not get_advisor_path():
skipit = "Only `icx+advisor` should be tested here"
Expand Down
31 changes: 15 additions & 16 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,17 +55,7 @@ def __init__(self, name):
# Python-level timers
self.py_timers = OrderedDict()

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

self.initialized = True

def add_include_dir(self, dir_path):
self._include_dirs.append(dir_path)

def add_lib_dir(self, dir_path):
self._lib_dirs.append(dir_path)
self._attempted_init = True

def analyze(self, iet):
"""
Expand Down Expand Up @@ -375,14 +370,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._include_dirs.append(path.joinpath('include').as_posix())
self._lib_dirs.append(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 +516,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 c6e780d

Please sign in to comment.