Inlining + Reorganization + Roofline
This commit is contained in:
committed by
Linus Baumberger
parent
43f11a661b
commit
b86c856e08
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
sudo cpupower frequency-set -u 2000000
|
||||
sudo cpupower frequency-set -d 2000000
|
||||
@@ -0,0 +1,159 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.ticker import FuncFormatter
|
||||
import numpy as np
|
||||
|
||||
ram_beta = 1.91
|
||||
l1d_l2_beta = 64
|
||||
l3_beta = 32
|
||||
|
||||
pi_scalar = 6.0
|
||||
pi_vector = 48.0
|
||||
|
||||
I_vals = np.logspace(-50, 8, 500, base=2)
|
||||
|
||||
plt.figure(figsize=(10, 7))
|
||||
|
||||
plt.gca().set_facecolor('lightgrey')
|
||||
|
||||
plt.plot(I_vals, ram_beta * I_vals, 'k-', label='_nolegend_')
|
||||
plt.plot(I_vals, l1d_l2_beta * I_vals, 'k-', label='_nolegend_')
|
||||
plt.plot(I_vals, l3_beta * I_vals, 'k-', label='_nolegend_')
|
||||
|
||||
ram_bound_x_pos = 0.25
|
||||
ram_bound_y_pos = ram_beta * ram_bound_x_pos + 0.175
|
||||
|
||||
plt.text(
|
||||
ram_bound_x_pos,
|
||||
ram_bound_y_pos,
|
||||
f'Read β mem. ({ram_beta} bytes/cycle)',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
rotation=20.5,
|
||||
)
|
||||
|
||||
l1d_l2_bound_x_pos = 0.25
|
||||
l1d_l2_bound_y_pos = l1d_l2_beta * l1d_l2_bound_x_pos + 3.5
|
||||
|
||||
plt.text(
|
||||
l1d_l2_bound_x_pos,
|
||||
l1d_l2_bound_y_pos,
|
||||
f'Read β L1D/L2 ({l1d_l2_beta} bytes/cycle)',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
rotation=20.5,
|
||||
)
|
||||
|
||||
l3_bound_x_pos = 0.375
|
||||
l3_bound_y_pos = l3_beta * l3_bound_x_pos + 3.5
|
||||
|
||||
plt.text(
|
||||
l3_bound_x_pos,
|
||||
l3_bound_y_pos,
|
||||
f'Read β L3 ({l3_beta} bytes/cycle)',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
rotation=20.5,
|
||||
)
|
||||
|
||||
plt.plot(I_vals, [pi_scalar] * len(I_vals), 'k-', label='_nolegend_')
|
||||
plt.text(
|
||||
85,
|
||||
pi_scalar + 1.5,
|
||||
f'Peak π seq. ({pi_scalar} flops/cycle)',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
)
|
||||
|
||||
plt.plot(I_vals, [pi_vector] * len(I_vals), 'k-', label='_nolegend_')
|
||||
plt.text(
|
||||
85,
|
||||
pi_vector + 12.5,
|
||||
f'Peak π par. ({pi_vector} flops/cycle)',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
)
|
||||
|
||||
|
||||
def fraction_formatter(x, _pos):
|
||||
if x == 0:
|
||||
return '0'
|
||||
log2_x = np.log2(x)
|
||||
if abs(log2_x - round(log2_x)) < 1e-6:
|
||||
exponent = int(round(log2_x))
|
||||
if exponent < 0:
|
||||
denominator = 2**(-exponent)
|
||||
return f'{1/denominator:.2f}'
|
||||
elif exponent == 0:
|
||||
return '1'
|
||||
else:
|
||||
return str(int(x))
|
||||
return f'{x:.2f}'
|
||||
|
||||
|
||||
formatter = FuncFormatter(fraction_formatter)
|
||||
|
||||
plt.xscale('log', base=2)
|
||||
plt.yscale('log', base=2)
|
||||
plt.gca().xaxis.set_major_formatter(formatter)
|
||||
plt.gca().yaxis.set_major_formatter(formatter)
|
||||
|
||||
plt.xlabel('Operational Intensity [flops/byte]', fontsize=10)
|
||||
plt.title("""Roofline Plot for the Social Force Model
|
||||
CPU: AMD Ryzen AI 7 350 w/ Radeon 860M @ 2 GHz
|
||||
Compiler: g++ (Debian 15.2.0-16) 15.2.0
|
||||
Command: ./main 100 10000
|
||||
|
||||
Performance [flops/cycle]""",
|
||||
loc='left',
|
||||
size=10)
|
||||
plt.scatter([53], [0.0936126],
|
||||
c='black',
|
||||
marker='o',
|
||||
edgecolors='black',
|
||||
label='baseline (-O0)')
|
||||
plt.text(
|
||||
53,
|
||||
0.0936126 - 0.03,
|
||||
f'0.09 flops/cycle',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
)
|
||||
plt.scatter([53], [0.627801],
|
||||
c='black',
|
||||
marker='s',
|
||||
edgecolors='black',
|
||||
label='baseline (-O3 -march=native)')
|
||||
plt.text(
|
||||
53,
|
||||
0.627801 - 0.2,
|
||||
f'0.63 flops/cycle',
|
||||
color='black',
|
||||
va='center',
|
||||
ha='center',
|
||||
fontsize=8,
|
||||
)
|
||||
|
||||
plt.legend(loc='lower right',
|
||||
fontsize=11,
|
||||
frameon=True,
|
||||
facecolor='white',
|
||||
edgecolor='black')
|
||||
plt.grid(True, which="both", ls="-", color='white', alpha=0.8, linewidth=1)
|
||||
|
||||
plt.xlim(0.05, 200)
|
||||
plt.ylim(0.0005, 100)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,35 @@
|
||||
import sys
|
||||
import csv
|
||||
import math
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
sys.exit("Use it like: python verify.py reference.csv generated.csv [tol]")
|
||||
# We can use this later in case that we wanna compare something with a tolerance
|
||||
tol = float(sys.argv[3]) if len(sys.argv) > 3 else 0.00001
|
||||
|
||||
with open(sys.argv[1], newline="") as f:
|
||||
ref = list(csv.reader(f))
|
||||
with open(sys.argv[2], newline="") as f:
|
||||
gen = list(csv.reader(f))
|
||||
|
||||
if len(ref) != len(gen):
|
||||
sys.exit(f"row count differs: ref={len(ref)} got={len(gen)}")
|
||||
|
||||
header = ref[0]
|
||||
for i in range(len(ref)):
|
||||
if len(ref[i]) != len(gen[i]):
|
||||
sys.exit(f"line {i+1}: column count differs")
|
||||
for j in range(len(ref[i])):
|
||||
a = ref[i][j].strip()
|
||||
b = gen[i][j].strip()
|
||||
if a == b:
|
||||
continue
|
||||
# in case that we wanna use tolerance
|
||||
if tol > 0:
|
||||
try:
|
||||
if math.isclose(float(a), float(b), abs_tol=tol):
|
||||
continue
|
||||
except ValueError:
|
||||
pass
|
||||
col = header[j] if j < len(header) else f"col{j}"
|
||||
sys.exit(f"mismatch at line {i+1}, col {j} ('{col}'): ref='{a}' got='{b}'")
|
||||
@@ -0,0 +1,107 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.animation import FuncAnimation
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(
|
||||
"Use it like the following: python visualization.py positions.csv (out.mp4)"
|
||||
)
|
||||
|
||||
df = pd.read_csv(sys.argv[1])
|
||||
frames = sorted(df["time"].unique())
|
||||
|
||||
# Replace p.e with direction-of-next-hop: where the ped actually moves to next frame.
|
||||
# Falls back to p.e for the last frame and for teleport jumps.
|
||||
df = df.sort_values(["id", "time"]).reset_index(drop=True)
|
||||
df["dx"] = df.groupby("id")["x"].shift(-1) - df["x"]
|
||||
df["dy"] = df.groupby("id")["y"].shift(-1) - df["y"]
|
||||
mag = np.sqrt(df["dx"] ** 2 + df["dy"] ** 2)
|
||||
TELEPORT_THRESHOLD = (
|
||||
5.0 # any per-step jump larger than this is the teleport, not motion
|
||||
)
|
||||
fallback = (mag > TELEPORT_THRESHOLD) | mag.isna() | (mag < 1e-9)
|
||||
df.loc[fallback, "dx"] = df.loc[fallback, "p.e.x"]
|
||||
df.loc[fallback, "dy"] = df.loc[fallback, "p.e.y"]
|
||||
mag = np.sqrt(df["dx"] ** 2 + df["dy"] ** 2).replace(0, 1.0)
|
||||
df["dx"] = df["dx"] / mag
|
||||
df["dy"] = df["dy"] / mag
|
||||
|
||||
fig, ax = plt.subplots(figsize=(10, 2.2))
|
||||
ax.set_xlim(0, 50)
|
||||
ax.set_ylim(0, 10)
|
||||
ax.set_aspect("equal")
|
||||
ax.set_facecolor("white")
|
||||
ax.set_xticks([])
|
||||
ax.set_yticks([])
|
||||
for s in ("top", "right", "left", "bottom"):
|
||||
ax.spines[s].set_color("gray")
|
||||
|
||||
s_white = ax.scatter([], [], s=30, facecolors="gray", edgecolor="gray", zorder=2)
|
||||
s_black = ax.scatter([], [], s=30, facecolors="black", edgecolor="black", zorder=2)
|
||||
title = ax.set_title("")
|
||||
|
||||
# Keep a reference to quiver objects so we can remove them each frame
|
||||
quivers = []
|
||||
|
||||
|
||||
def update(t):
|
||||
sub = df[df["time"] == t]
|
||||
w = sub[sub["color"] == 0]
|
||||
b = sub[sub["color"] == 1]
|
||||
|
||||
s_white.set_offsets(w[["x", "y"]].values)
|
||||
s_black.set_offsets(b[["x", "y"]].values)
|
||||
|
||||
# Remove old quiver arrows
|
||||
for q in quivers:
|
||||
q.remove()
|
||||
quivers.clear()
|
||||
|
||||
# Draw fresh arrows each frame
|
||||
arrow_scale = 1.5 # Tune this to change arrow length visually
|
||||
if len(w):
|
||||
q_white = ax.quiver(
|
||||
w["x"],
|
||||
w["y"],
|
||||
w["dx"],
|
||||
w["dy"],
|
||||
color="gray",
|
||||
angles="xy",
|
||||
scale_units="xy",
|
||||
scale=1 / arrow_scale,
|
||||
width=0.003,
|
||||
headwidth=4,
|
||||
headlength=5,
|
||||
zorder=3,
|
||||
)
|
||||
quivers.append(q_white)
|
||||
if len(b):
|
||||
q_black = ax.quiver(
|
||||
b["x"],
|
||||
b["y"],
|
||||
b["dx"],
|
||||
b["dy"],
|
||||
color="black",
|
||||
angles="xy",
|
||||
scale_units="xy",
|
||||
scale=1 / arrow_scale,
|
||||
width=0.003,
|
||||
headwidth=4,
|
||||
headlength=5,
|
||||
zorder=3,
|
||||
)
|
||||
quivers.append(q_black)
|
||||
|
||||
title.set_text(f"t = {t}")
|
||||
return s_white, s_black, title
|
||||
|
||||
|
||||
anim = FuncAnimation(fig, update, frames=frames, interval=50, blit=False)
|
||||
|
||||
if len(sys.argv) >= 3:
|
||||
anim.save(sys.argv[2], writer="ffmpeg", fps=25)
|
||||
print(f"Saved {sys.argv[2]}")
|
||||
else:
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user