Skip to content

Commit 2c0a1a9

Browse files
author
George Bisbas
committed
advisor: Update advisor with oneAPI 2025
1 parent e1dcb86 commit 2c0a1a9

6 files changed

Lines changed: 116 additions & 173 deletions

File tree

benchmarks/user/advisor/README.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,50 @@ Example runs:
22

33
* `python3 run_advisor.py --name isotropic --path <path-to-devito>/examples/seismic/acoustic/acoustic_example.py`
44
* `python3 run_advisor.py --name tti_so8 --path <path-to-devito>/examples/seismic/tti/tti_example.py --exec-args "-so 8"`
5-
* `python3 run_advisor.py --name iso_ac_so6 --path <path-to-devito>/benchmarks/user/benchmark.py --exec-args "bench -P acoustic -so 6 --tn 200 -d 100 100 100 --autotune off -x 1"`
5+
* `python3 run_advisor.py --name iso_ac_so4 --path <path-to-devito>/benchmarks/user/benchmark.py --exec-args "run -P acoustic -so 4 --tn 200 -d 100 100 100"`
66

7-
After the run has finished you should be able to plot a roofline with the results and export roofline data to JSON using:
7+
After the run has finished you should be able to save a .json and plot the
8+
roofline with the results:
89
* `python3 roofline.py --name Roofline --project <advisor-project-name>`
910

1011
To create a read-only snapshot for use with Intel Advisor GUI, use:
1112
* `advixe-cl --snapshot --project-dir=<advisor-project-name> pack -- /<new-snapshot-name>`
1213

1314
Prerequisites:
14-
* Support guaranteed only for Intel Advisor as installed with Intel Parallel Studio v 2020 Update 2
15-
and Intel oneAPI 2021; earlier years may not work; other 2020/2021 versions, as well as later years,
16-
may or may not work.
15+
* Support is guaranteed only for Intel oneAPI 2025; earlier versions may not work.
16+
You may download Intel oneAPI [here](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html?packages=oneapi-toolkit&oneapi-toolkit-os=linux&oneapi-lin=apt).
17+
18+
* Add Advisor (advixe-cl) and compilers (icx) in the path. It should be along the lines of:
19+
```sh
20+
source /opt/intel/oneapi/advisor/latest/env/vars.sh
21+
source /opt/intel/oneapi/compiler/latest/env/vars.sh
22+
```
23+
depending on where you installed oneAPI
24+
1725
* In Linux systems you may need to enable system-wide profiling by setting:
18-
- `/proc/sys/kernel/yama/ptrace_scope` to `0`
19-
- `/proc/sys/kernel/perf_event_paranoid` to `1`
2026

21-
* `numactl` must be available on the system. If not available, install with:
22-
`sudo apt-get install numactl`
27+
```sh
28+
/proc/sys/kernel/yama/ptrace_scope to 0
29+
/proc/sys/kernel/perf_event_paranoid to 1
30+
```
31+
32+
* `numactl` must be available on the system. If not available, install using:
33+
```sh
34+
sudo apt-get install numactl
35+
```
2336
* Install `pandas` and `matplotlib`. They are not included in the core Devito installation.
37+
```sh
38+
pip install pandas matplotlib
39+
```
2440

2541
Limitations:
2642

2743
* Untested with more complicated examples.
28-
* Untested on Intel KNL (we might need to ask `numactl` to bind to MCDRAM).
29-
* Running the `tripcounts` analysis takes a lot, despite starting in paused
44+
* Running the `tripcounts` analysis is time-consuming, despite starting in paused
3045
mode. This analysis, together with the `survey` analysis, is necessary to
3146
generate a roofline. Both are run by `run_advisor.py`.
32-
* Requires python3, untested in earlier versions of python and conda environments
33-
* Currently requires download of repository and running `pip3 install .`, the scripts
47+
* Requires Python3, untested in conda environments
48+
* Currently requires download of repository and running `pip install .`, the scripts
3449
are currently not included as a package with the user installation of Devito
3550

3651
TODO:

benchmarks/user/advisor/roofline.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
import sys
1919
import os
2020

21-
from benchmarks.user.advisor.advisor_logging import check, err, log
21+
from advisor_logging import check, err, log
2222

2323

2424
try:
2525
import advisor
2626
except ImportError:
2727
check(False, 'Error: Intel Advisor could not be found on the system,'
2828
' make sure to source environment variables properly. Information can be'
29-
' found at https://software.intel.com/content/www/us/en/develop/'
30-
'documentation/advisor-user-guide/top/launch-the-intel-advisor/'
31-
'intel-advisor-cli/setting-and-using-intel-advisor-environment-variables.html')
29+
' found at https://www.intel.com/content/www/us/en/docs/advisor/'
30+
'user-guide/2024-2/set-up-environment-variables.html')
3231
sys.exit(1)
3332

3433

3534
matplotlib.use('Agg')
3635
# Use fancy plot colors
37-
plt.style.use('seaborn-darkgrid')
36+
plt.style.use('ggplot')
3837

3938

4039
@click.command()
@@ -65,21 +64,25 @@
6564
def roofline(name, project, scale, precision, mode, th):
6665
pd.options.display.max_rows = 20
6766

68-
log('Opening project...')
67+
log(f'Opening project {project}...')
6968
project = advisor.open_project(str(project))
7069

7170
if not project:
72-
err('Could not open project %s.' % project)
71+
err(f'Could not open project {project}.')
7372
log('Loading data...')
7473

7574
data = project.load(advisor.SURVEY)
7675
rows = [{col: row[col] for col in row} for row in data.bottomup]
7776
roofs = data.get_roofs()
7877

78+
# Following deprecation solution from here:
79+
# https://github.com/pandas-dev/pandas/issues/57734
80+
pd.set_option('future.no_silent_downcasting', True)
7981
full_df = pd.DataFrame(rows).replace('', np.nan)
8082

8183
# Narrow down the columns to those of interest
8284
try:
85+
analysis_columns = ['loop_name', 'self_ai', 'self_gflops', 'self_time']
8386
df = full_df[analysis_columns].copy()
8487
except KeyError:
8588
err('Could not read data columns from profiling. Not enough data has been '
@@ -169,7 +172,7 @@ def roofline(name, project, scale, precision, mode, th):
169172
label_y = row.self_gflops
170173
ax.text(label_x, label_y,
171174
'Time: %.2fs\n'
172-
'Incidence: %.0f%%' % (row.self_time, row.percent_weight),
175+
'Peak pct: %.0f%%' % (row.self_time, row.percent_weight),
173176
bbox={'boxstyle': 'round', 'facecolor': 'white'}, fontsize=8)
174177
top_loops_data = [{'ai': row.self_ai,
175178
'gflops': row.self_gflops,
@@ -198,19 +201,17 @@ def roofline(name, project, scale, precision, mode, th):
198201
legend = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5),
199202
prop={'size': 7}, title='Rooflines')
200203

201-
# saving the chart in PNG format
202-
plt.savefig('%s.png' % name, bbox_extra_artists=(legend,), bbox_inches='tight')
204+
# saving the chart in PDF format
205+
plt.savefig('%s.pdf' % name, bbox_extra_artists=(legend,), bbox_inches='tight')
203206
figpath = os.path.realpath(__file__).split(os.path.basename(__file__))[0]
204-
log('Figure saved in %s%s.png.' % (figpath, name))
207+
log('\nFigure saved in %s%s.pdf.' % (figpath, name))
205208

206209
# Save the JSON file
207210
with open('%s.json' % name, 'w') as f:
208211
f.write(json.dumps(roofline_data))
209212

210-
log('JSON file saved as %s.json.' % name)
211-
212-
213-
analysis_columns = ['loop_name', 'self_ai', 'self_gflops', 'self_time']
213+
log('\nJSON file saved as %s.json.' % name)
214+
log('Done!')
214215

215216
if __name__ == '__main__':
216217
roofline()

benchmarks/user/advisor/run_advisor.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
import click
12
import datetime
23
import logging
34
import os
5+
import sys
6+
47
from pathlib import Path
58
from subprocess import check_output, PIPE, Popen
6-
import sys
79
from tempfile import gettempdir, mkdtemp
810

9-
import click
10-
11-
12-
from benchmarks.user.advisor.advisor_logging import (check, log, progress,
13-
log_process)
11+
from advisor_logging import (check, log, progress, log_process)
1412

1513

1614
@click.command()
@@ -49,21 +47,21 @@ def run_with_advisor(path, output, name, exec_args):
4947
output = Path(output).joinpath(name)
5048
output.mkdir(parents=True, exist_ok=True)
5149

52-
# Intel Advisor and Intel compilers must be available through either Intel Parallel
53-
# Studio or Intel oneAPI (currently tested versions include IPS 2020 Update 2 and
54-
# oneAPI 2021 beta08)
50+
# Intel Advisor and Intel compilers must be available through either
51+
# Intel oneAPI (tested with Intel oneAPI 2025.1)
5552
try:
5653
ret = check_output(['advixe-cl', '--version']).decode("utf-8")
5754
except FileNotFoundError:
5855
check(False, "Error: Couldn't detect `advixe-cl` to run Intel Advisor.")
5956

6057
try:
61-
ret = check_output(['icc', '--version']).decode("utf-8")
58+
ret = check_output(['icx', '--version']).decode("utf-8")
59+
log("Found icx version: %s" % ret.strip())
6260
except FileNotFoundError:
63-
check(False, "Error: Couldn't detect Intel Compiler (icc).")
61+
check(False, "Error: Couldn't detect Intel Compiler (icx).")
6462

6563
# All good, Intel compiler and advisor are available
66-
os.environ['DEVITO_ARCH'] = 'intel'
64+
os.environ['DEVITO_ARCH'] = 'icx'
6765

6866
# Tell Devito to instrument the generated code for Advisor
6967
os.environ['DEVITO_PROFILING'] = 'advisor'
@@ -73,7 +71,7 @@ def run_with_advisor(path, output, name, exec_args):
7371
if devito_logging is None:
7472
os.environ['DEVITO_LOGGING'] = 'WARNING'
7573

76-
with progress('Setting up multi-threading environment'):
74+
with progress('Setting up multi-threading environment with OpenMP'):
7775
# Roofline analyses are recommended with threading enabled
7876
os.environ['DEVITO_LANGUAGE'] = 'openmp'
7977

@@ -90,14 +88,14 @@ def run_with_advisor(path, output, name, exec_args):
9088

9189
# Prevent NumPy from using threads, which otherwise leads to a deadlock when
9290
# used in combination with Advisor. This issue has been described at:
93-
# `software.intel.com/en-us/forums/intel-advisor-xe/topic/780506`
91+
# `software.intel.com/en-us/forums/intel-advisor-xe/topic/780506`
9492
# Note: we should rather sniff the BLAS library used by NumPy, and set the
9593
# appropriate env var only
9694
os.environ['OPENBLAS_NUM_THREADS'] = '1'
9795
os.environ['MKL_NUM_THREADS'] = '1'
9896
# Note: `Numaexpr`, used by NumPy, also employs threading, so we shall disable
9997
# it too via the corresponding env var. See:
100-
# `stackoverflow.com/questions/17053671/python-how-do-you-stop-numpy-from-multithreading` # noqa
98+
# `stackoverflow.com/questions/17053671/python-how-do-you-stop-numpy-from-multithreading` # noqa
10199
os.environ['NUMEXPR_NUM_THREADS'] = '1'
102100

103101
# To build a roofline with Advisor, we need to run two analyses back to
@@ -130,8 +128,8 @@ def run_with_advisor(path, output, name, exec_args):
130128
]
131129
py_cmd = [sys.executable, str(path)] + exec_args.split()
132130

133-
# Before collecting the `survey` and `tripcounts` a "pure" python run to warmup the
134-
# jit cache is preceded
131+
# Before collecting the `survey` and `tripcounts` a "pure" python run
132+
# to warmup the jit cache is preceded
135133

136134
log('Starting Intel Advisor\'s `roofline` analysis for `%s`' % name)
137135
dt = datetime.datetime.now()
@@ -147,6 +145,9 @@ def run_with_advisor(path, output, name, exec_args):
147145
advixe_handler.setFormatter(advixe_formatter)
148146
advixe_logger.addHandler(advixe_handler)
149147

148+
log("Project folder: %s" % str(output))
149+
log("Logging progress in: `%s`" % str(advixe_handler))
150+
150151
with progress('Performing `cache warm-up` run'):
151152
try:
152153
p_warm_up = Popen(py_cmd, stdout=PIPE, stderr=PIPE)
@@ -175,6 +176,8 @@ def run_with_advisor(path, output, name, exec_args):
175176
log('python3 roofline.py --name %s --project %s --scale %f'
176177
% (name, str(output), n_sockets))
177178

179+
log('\nTo open the roofline using advixe-gui: ')
180+
log('advixe-gui %s' % str(output))
178181

179182
if __name__ == '__main__':
180183
run_with_advisor()

devito/arch/compiler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,20 @@ def __init_finalize__(self, **kwargs):
769769
self.__init_intel_mpi__()
770770
self.__init_intel_mpi_flags__()
771771

772+
if configuration['profiling'] == 'advisor':
773+
# Locate the Intel Advisor installation and
774+
# add the necessary flags to the compiler
775+
from devito.operator.profiling import locate_intel_advisor
776+
path = locate_intel_advisor()
777+
self.add_include_dirs(path.joinpath('include').as_posix())
778+
779+
_default_libs = ['ittnotify']
780+
self.add_libraries(_default_libs)
781+
782+
libdir = path.joinpath('lib64').as_posix()
783+
self.add_library_dirs(libdir)
784+
self.add_ldflags('-Wl,-rpath,%s' % libdir)
785+
772786
def __init_intel_mpi__(self, **kwargs):
773787
# Make sure the MPI compiler uses an Intel compiler underneath,
774788
# whatever the MPI distro is

devito/operator/profiling.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class AdvancedProfilerVerbose2(AdvancedProfilerVerbose):
353353
class AdvisorProfiler(AdvancedProfiler):
354354

355355
"""
356-
Rely on Intel Advisor ``v >= 2020`` for performance profiling.
356+
Rely on Intel Advisor 2025.1 for performance profiling.
357357
Tested versions of Intel Advisor:
358358
- As contained in Intel Parallel Studio 2020 v 2020 Update 2
359359
- As contained in Intel oneAPI 2021 beta08
@@ -367,19 +367,13 @@ class AdvisorProfiler(AdvancedProfiler):
367367
_ext_calls = [_api_resume, _api_pause]
368368

369369
def __init__(self, name):
370-
self.path = locate_intel_advisor()
371-
if self.path is None:
370+
path = locate_intel_advisor()
371+
if path is None:
372372
self.initialized = False
373373
else:
374-
super().__init__(name)
375-
# Make sure future compilations will get the proper header and
376-
# shared object files
377-
compiler = configuration['compiler']
378-
compiler.add_include_dirs(self.path.joinpath('include').as_posix())
379-
compiler.add_libraries(self._default_libs)
380-
libdir = self.path.joinpath('lib64').as_posix()
381-
compiler.add_library_dirs(libdir)
382-
compiler.add_ldflags('-Wl,-rpath,%s' % libdir)
374+
super(AdvisorProfiler, self).__init__(name)
375+
376+
return
383377

384378
def analyze(self, iet):
385379
return

0 commit comments

Comments
 (0)