|
| 1 | +from typing import Iterable |
| 2 | +from numbers import Number |
| 3 | + |
| 4 | +import matplotlib.pyplot as plt |
| 5 | + |
| 6 | +from accelforge.mapper.FFM import Mappings |
| 7 | + |
| 8 | + |
| 9 | +def plot_roofline( |
| 10 | + bandwidth: Number, |
| 11 | + computational_throughput: Number, |
| 12 | + min_computational_intensity: Number = 0, |
| 13 | + max_computational_intensity: Number = None, |
| 14 | +): |
| 15 | + """ |
| 16 | + Plot a roofline model. |
| 17 | +
|
| 18 | + Parameters |
| 19 | + ---------- |
| 20 | + bandwidth: |
| 21 | + The memory bandwidth to use when generating the roofline. |
| 22 | + computational_throughput: |
| 23 | + The peak computational throughput to use when generating the roofline. |
| 24 | + min_computational_intensity: |
| 25 | + The minimum computational intensity to include in the x-axis. |
| 26 | + max_computational_intensity: |
| 27 | + The maximum computational intensity to include in the x-axis. |
| 28 | + """ |
| 29 | + fig, ax = plt.subplots() |
| 30 | + |
| 31 | + roofline_transition = _roofline_transition(bandwidth, computational_throughput) |
| 32 | + if max_computational_intensity is None: |
| 33 | + max_computational_intensity = 2*roofline_transition |
| 34 | + |
| 35 | + ax.plot( |
| 36 | + [min_computational_intensity, roofline_transition], |
| 37 | + [min_computational_intensity*bandwidth, computational_throughput], |
| 38 | + ) |
| 39 | + ax.plot( |
| 40 | + [roofline_transition, max_computational_intensity], |
| 41 | + [computational_throughput, computational_throughput], |
| 42 | + ) |
| 43 | + |
| 44 | + return fig, ax |
| 45 | + |
| 46 | + |
| 47 | +def _roofline_transition(bandwidth, computation_throughput): |
| 48 | + return computation_throughput/bandwidth |
0 commit comments