-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapplication_efficiency.py
executable file
·332 lines (297 loc) · 9.78 KB
/
application_efficiency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python3
# Copyright (c) 2024 Intel Corporation
# SPDX-License-Identifier: 0BSD
"""
.. _working_with_app_efficiency:
Working with Application Efficiency
===================================
Understanding relative performance.
One goal of P3 analysis is to understand how well a given application is able
to adapt to and make effective use of the capabilities of different
platforms. Comparisons of *raw* performance (e.g., time to solution) across
platforms can't help us, because raw performance doesn't reflect how fast an
application **should** run.
To address this, the P3 Analysis Library works with normalized *performance
efficiency* data. With normalized data, an application's performance can be
represented as a number in the range :math:`[0, 1]`, where :math:`1` means
an application is achieving the best possible performance.
There are multiple ways we can normalize the data to measure relative
efficiency, and for this tutorial we will consider *application efficiency*,
defined below:
**Application Efficiency**
The performance of an *application*, measured relative to the best known
performance previously demonstrated for solving the same *problem* on the
same *platform*.
Working with application efficiency is simple because it does not rely on
performance models or theoretical hardware limits. Although it can't tell us
whether an application is performing as well as theoretically possible, it
shows how an application compares to the state-of-the-art, which is often good
enough.
Calculating Application Efficiency
----------------------------------
Let's begin with a very simple example, with a single application, using the
data below:
.. list-table::
:widths: 20 20 20 20 20
:header-rows: 1
* - problem
- application
- platform
- fom
- date
* - Test
- MyApp
- A
- 25.0
- 2023
* - Test
- MyApp
- B
- 12.5
- 2023
* - Test
- MyApp
- C
- 25.0
- 2023
* - Test
- MyApp
- D
- NaN
- 2023
* - Test
- MyApp
- E
- 5.0
- 2023
.. tip::
A NaN or 0.0 performance result is interpreted by the P3 Analysis Library
to mean that an application run was in some way invalid. We can use this
to explicitly represent cases where applications did not compile on
specific platforms, did not run to completion, or ran but produced
numerical results that failed some sort of verification.
"""
# %%
# After loading this data into a :py:class:`pandas.DataFrame` (`df`), we can
# use the :py:func:`p3analysis.metrics.application_efficiency` function to calculate a
# table of application efficiencies.
#sphinx_gallery_start_ignore
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import p3analysis
myapp_data = {
"problem": ["Test"] * 5,
"application": ["MyApp"] * 5,
"platform": ["A", "B", "C", "D", "E"],
"fom": [25.0, 12.5, 25.0, np.nan, 5.0],
"date": [2023] * 5,
}
df = pd.DataFrame(myapp_data)
#sphinx_gallery_end_ignore
effs = p3analysis.metrics.application_efficiency(df)
print(effs)
# %%
# These initial results may be a little surprising, because they're all
# either 1.0 or 0.0. What happened? Since our dataset contains only one result
# for MyApp on each platform, each non-zero result is the "best known" result
# for that platform! The only exception is Platform D, which is assigned an
# efficiency of 0.0 to reflect that it either did not compile, or did not run
# successfully.
#
# .. tip::
# Calculating meaningful application efficiency results requires a minimum
# of two results *per platform*.
#
# Digging Deeper: Adding More Data
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Let's see what happens if we add some more data, from a different application
# running on the same platforms:
#
# .. list-table::
# :widths: 20 20 20 20 20
# :header-rows: 1
#
# * - problem
# - application
# - platform
# - fom
# - date
#
# * - Test
# - YourApp
# - A
# - 25.0
# - 2023
# * - Test
# - YourApp
# - B
# - 10.0
# - 2023
# * - Test
# - YourApp
# - C
# - 12.5
# - 2023
# * - Test
# - YourApp
# - D
# - 6.0
# - 2023
# * - Test
# - YourApp
# - E
# - 1.0
# - 2023
# %%
# After updating our DataFrame, we can re-run the same function as before to
# recompute the application efficiencies.
#sphinx_gallery_start_ignore
yourapp_data = {
"problem": ["Test"] * 5,
"application": ["YourApp"] * 5,
"platform": ["A", "B", "C", "D", "E"],
"fom": [25.0, 10.0, 12.5, 6.0, 1.0],
"date": [2023] * 5,
}
df = pd.concat([df, pd.DataFrame(yourapp_data)], ignore_index=True)
#sphinx_gallery_end_ignore
effs = p3analysis.metrics.application_efficiency(df)
print(effs)
# %%
# YourApp is now the fastest (best known) application on every platform,
# and so it assigned an application efficiency of 1.0 everywhere. The
# application efficiency values for MyApp are all between 0.0 and 1.0,
# reflecting how close it gets to the state-of-the-art performance on each
# platform.
#
# .. important::
# Adding new data changed the application efficiencies for MyApp *and*
# YourApp. Application efficiency values can become stale over time,
# and accurate P3 analysis requires us to track "best known" results
# carefully.
#
# Plotting Application Efficiency
# -------------------------------
#
# The P3 Analysis Library does not contain any dedicated functionality for
# plotting application efficiency values. However, it is straightforward to use
# :py:mod:`matplotlib` and/or the plotting functionality of :py:mod:`pandas` to
# produce useful visualizations.
#
# For example, plotting a bar chart of application efficiences for one
# application can help us to summarize that application's performance more
# effectively than a table:
filtered = effs[effs["application"]=="MyApp"]
filtered.plot(kind="bar", x="platform", y="app eff", xlabel="Platform", ylabel="Application Efficiency", legend=False)
plt.savefig("application_efficiency_bars_2023.png")
# %%
# We can now clearly see that MyApp can adapt to and make very effective use of
# Platforms A and B, is within 2x of state-of-the-art performance on Platform
# C, but performs poorly on Platforms D and E. The key takeaway from this
# analysis is that a developer wishing to improve the "performance portability"
# of MyApp should focus on improving support for Platforms D and E.
#
# Working with Historical Data
# ----------------------------
#
# The performance of an application can change over time, as developers add new
# features and optimize for new platforms, or due to changes in the software
# stack (e.g., new compiler or driver versions).
#
# Let's see how this could affect the application efficiency of MyApp, by adding
# some new data points collected at a later point in time:
#
# .. list-table::
# :widths: 20 20 20 20 20
# :header-rows: 1
#
# * - problem
# - application
# - platform
# - fom
# - date
#
# * - Test
# - MyApp
# - A
# - 30.0
# - 2024
# * - Test
# - MyApp
# - B
# - 15.0
# - 2024
# * - Test
# - MyApp
# - C
# - 25.0
# - 2024
# * - Test
# - MyApp
# - D
# - 3.0
# - 2024
# * - Test
# - MyApp
# - E
# - 2.5
# - 2024
# %%
# We can compute application efficiency as before:
#sphinx_gallery_start_ignore
new_myapp_data = {
"problem": ["Test"] * 5,
"application": ["MyApp"] * 5,
"platform": ["A", "B", "C", "D", "E"],
"fom": [30.0, 15.0, 25.0, 3.0, 2.5],
"date": [2024] * 5,
}
df = pd.concat([df, pd.DataFrame(new_myapp_data)], ignore_index=True)
#sphinx_gallery_end_ignore
effs = p3analysis.metrics.application_efficiency(df)
print(effs)
# %%
# These latest results suggest that the developers of MyApp acted upon
# earlier results and improved support for Platforms D and E. But in doing so,
# a small performance regression was introduced in Platforms A and B.
#
# .. note::
# Such trade-offs are very common, especially when developers wish to
# maintain a single source code that targets multiple platforms.
# Different platforms may respond differently to the same code changes,
# owing to architectural differences (e.g., cache size, available
# parallelism) or differences in the software stack (e.g., compilers
# performing different optimizations).
# For some real-life examples, see the papers
# `here <https://doi.org/10.1016/j.jpdc.2012.07.005>`__
# and
# `here <https://doi.org/10.48550/arXiv.2407.11488>`__.
#
# Computing the correct application efficiency values for MyApp and YourApp
# requires that our dataset contains all of our historical performance results.
# Since what we're really interested in understanding is the *latest*
# application efficiency, we should take care to filter our data appropriately
# before producing any plots.
filtered = effs[(effs["application"]=="MyApp") & (effs["date"]==2024)]
filtered.plot(kind="bar", x="platform", y="app eff", xlabel="Platform", ylabel="Application Efficiency", legend=False)
plt.savefig("application_efficiency_bars_2024.png")
# %%
# Further Analysis
# ----------------
#
# Computing application efficiency is often simply the first step of a
# more detailed P3 analysis.
#
# The examples below show how we can use the visualization capabilities
# of the P3 Analysis Library to compare the efficiency of different
# applications running across the same platform set, or to gain insight
# into how an application's efficiency relates to the code it uses on each
# platform.
#
# .. minigallery::
# :add-heading: Examples
#
# ../../examples/cascade/plot_simple_cascade.py
# ../../examples/navchart/plot_simple_navchart.py