Skip to content

Commit

Permalink
kernels(omp): refine plot and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Mar 14, 2024
1 parent ac6b30b commit d222e00
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 73 deletions.
8 changes: 4 additions & 4 deletions tasks/kernels_omp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ In the `experiment-base` terminal, run:
(faasm-exp-base) inv cluster.provision --vm Standard_D8_v5 --nodes 2 cluster.credentials
```

## Granny
## Faasm

Deploy the cluster:

```bash
(faasm-exp-faabric) faasmctl deploy.k8s --workers=4
(faasm-exp-faabric) faasmctl deploy.k8s --workers=1
```

Upload the WASM file:
Expand All @@ -28,10 +28,10 @@ Upload the WASM file:
and run the experiment with:

```bash
(faasm-exp-faabric) inv kernels-omp.run.granny
(faasm-exp-faabric) inv kernels-omp.run.wasm
```

finally, delete the Granny cluster:
finally, delete the cluster:

```bash
faasmctl delete
Expand Down
64 changes: 34 additions & 30 deletions tasks/kernels_omp/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
from os import makedirs
from os.path import join
from pandas import read_csv
from tasks.util.env import OPENMP_KERNELS, PLOTS_ROOT, PROJ_ROOT


RESULTS_DIR = join(PROJ_ROOT, "results", "kernels-omp")
PLOTS_DIR = join(PLOTS_ROOT, "kernels-omp")
from tasks.util.env import SYSTEM_NAME
from tasks.util.kernels import (
OPENMP_KERNELS,
OPENMP_KERNELS_PLOTS_DIR,
OPENMP_KERNELS_RESULTS_DIR,
)


def _read_results():
result_dict = {}

for csv in glob(join(RESULTS_DIR, "openmp_*.csv")):
for csv in glob(join(OPENMP_KERNELS_RESULTS_DIR, "openmp_*.csv")):
results = read_csv(csv)

workload = csv.split("_")[1]
Expand Down Expand Up @@ -43,15 +44,15 @@ def plot(ctx):
"""
Plot the slowdown of OpenMP's ParRes kernels
"""
out_file_name = "openmp_kernels_slowdown.pdf"
result_dict = _read_results()
makedirs(PLOTS_DIR, exist_ok=True)
fig, ax = subplots(figsize=(6, 2))
makedirs(OPENMP_KERNELS_PLOTS_DIR, exist_ok=True)
fig, ax = subplots(figsize=(6, 3))

num_kernels = len(OPENMP_KERNELS)
width = float(1 / (num_kernels + 1))
nprocs = list(range(1, 9))

ymax = 2
for ind_kernel, kernel in enumerate(OPENMP_KERNELS):
ys = []
xs = []
Expand All @@ -65,17 +66,18 @@ def plot(ctx):
result_dict["granny"][kernel][np]["mean"]
/ result_dict["native"][kernel][np]["mean"]
)
ys.append(
result_dict["granny"][kernel][np]["mean"]
/ result_dict["native"][kernel][np]["mean"]
)
ax.text(
x=ind_np + x_kern_offset - 0.08,
y=y + 0.1,
s="{} s".format(result_dict["granny"][kernel][np]["mean"]),
rotation=90,
fontsize=6,
)
if y > ymax:
ax.text(
x=ind_np + x_kern_offset - 0.05,
y=ymax - 0.3,
s="{}x".format(round(y, 1)),
rotation=90,
fontsize=6,
)

ys.append(ymax)
else:
ys.append(y)

ax.bar(
xs,
Expand All @@ -91,18 +93,20 @@ def plot(ctx):

# Horizontal line at slowdown of 1
xlim_left = -0.5
xlim_right = len(nprocs) + 0.5
fig.hlines(1, xlim_left, xlim_right, linestyle="dashed", colors="red")
xlim_right = len(nprocs) - 0.5
ax.hlines(1, xlim_left, xlim_right, linestyle="dashed", colors="red")

ymax = 5
ax.set_xlim(left=xlim_left, right=xlim_right)
ax.set_ylim(bottom=0, top=ymax)
ax.set_xlabel("Number of OpenMP threads")
ax.set_ylabel("Slowdown \n [Granny / OpenMPI]")
ax.legend(loc="upper right", ncol=4)
ax.set_ylabel("Slowdown \n [{} / OpenMPI]".format(SYSTEM_NAME))
ax.legend(loc="upper right", ncol=4, bbox_to_anchor=(0.95, 1.35))

fig.tight_layout()
fig.savefig(
join(PLOTS_DIR, out_file_name), format="pdf", bbox_inches="tight"
)

print("Plot saved to: {}".format(join(PLOTS_DIR, out_file_name)))
for plot_format in ["png", "pdf"]:
plot_file = join(
OPENMP_KERNELS_PLOTS_DIR,
"openmp_kernels_slowdown.{}".format(plot_format),
)
fig.savefig(plot_file, format=plot_format, bbox_inches="tight")
print("Plot saved to: {}".format(plot_file))
30 changes: 12 additions & 18 deletions tasks/kernels_omp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from os import makedirs
from os.path import join
from subprocess import run
from tasks.util.env import (
OPENMP_KERNELS,
OPENMP_KERNELS_DOCKER_DIR,
OPENMP_KERNELS_FAASM_USER,
RESULTS_DIR,
)
from tasks.util.faasm import (
get_faasm_exec_time_from_json,
post_async_msg_and_get_result_json,
)
from tasks.util.kernels import (
OPENMP_KERNELS,
OPENMP_KERNELS_DOCKER_DIR,
OPENMP_KERNELS_FAASM_USER,
OPENMP_KERNELS_RESULTS_DIR,
)
from time import time

"""
Expand All @@ -28,29 +28,23 @@


def _init_csv_file(csv_name):
result_dir = join(RESULTS_DIR, "kernels-omp")
makedirs(result_dir, exist_ok=True)
makedirs(OPENMP_KERNELS_RESULTS_DIR, exist_ok=True)

result_file = join(result_dir, csv_name)
makedirs(RESULTS_DIR, exist_ok=True)
result_file = join(OPENMP_KERNELS_RESULTS_DIR, csv_name)
with open(result_file, "w") as out_file:
out_file.write("NumThreads,Run,ExecTimeSecs\n")


def _write_csv_line(csv_name, num_threads, run, exec_time):
result_dir = join(RESULTS_DIR, "kernels-omp")
makedirs(result_dir, exist_ok=True)

result_file = join(result_dir, csv_name)
makedirs(RESULTS_DIR, exist_ok=True)
result_file = join(OPENMP_KERNELS_RESULTS_DIR, csv_name)
with open(result_file, "a") as out_file:
out_file.write("{},{},{}\n".format(num_threads, run, exec_time))


def get_kernel_cmdline(kernel, num_threads):
kernels_cmdline = {
# dgemm: iterations, matrix order, tile size
"dgemm": "10 2048 32",
"dgemm": "20 2048 32",
# global: iterations, scramble string length
# string length must be multiple of num_threads
"global": "10000 {}".format(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 2),
Expand Down Expand Up @@ -95,8 +89,8 @@ def has_execution_failed(results_json):
return False


@task
def granny(ctx, kernel=None, num_threads=None, repeats=1):
@task()
def wasm(ctx, kernel=None, num_threads=None, repeats=1):
"""
Run the OpenMP Kernels
"""
Expand Down
17 changes: 3 additions & 14 deletions tasks/kernels_omp/wasm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from invoke import task
from os.path import join
from tasks.util.env import (
DGEMM_DOCKER_WASM,
DGEMM_FAASM_USER,
DGEMM_FAASM_FUNC,
from tasks.util.kernels import (
KERNELS_WASM_DIR,
OPENMP_KERNELS,
OPENMP_KERNELS_FAASM_USER,
)
from tasks.util.kernels import KERNELS_WASM_DIR
from tasks.util.upload import upload_wasm


Expand All @@ -16,15 +13,7 @@ def upload(ctx):
"""
Upload the OpenMP functions to Granny
"""
wasm_file_details = [
{
"wasm_file": DGEMM_DOCKER_WASM,
"wasm_user": DGEMM_FAASM_USER,
"wasm_function": DGEMM_FAASM_FUNC,
"copies": 1,
},
]

wasm_file_details = []
for kernel in OPENMP_KERNELS:
wasm_file_details.append(
{
Expand Down
7 changes: 1 addition & 6 deletions tasks/util/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
HOME_DIR = expanduser("~")
PROJ_ROOT = dirname(dirname(dirname(realpath(__file__))))
FAASM_ROOT = join(HOME_DIR, "faasm")
SYSTEM_NAME = "Granny"

ACR_NAME = "faasm.azurecr.io"
FAABRIC_EXP_IMAGE_NAME = "faabric-experiments"
Expand Down Expand Up @@ -37,12 +38,6 @@
DGEMM_FAASM_USER = "dgemm"
DGEMM_FAASM_FUNC = "main"

# --- OpenMP Kernels ---

OPENMP_KERNELS_DOCKER_DIR = join(EXAMPLES_DOCKER_DIR, "Kernels")
OPENMP_KERNELS = ["global", "p2p", "sparse", "nstream", "reduce", "dgemm"]
OPENMP_KERNELS_FAASM_USER = "kernels-omp"

# --- MPI Migration Microbenchmark

MPI_MIGRATE_WASM_BINARY = join(EXAMPLES_BASE_DIR, "mpi_migrate.wasm")
Expand Down
17 changes: 16 additions & 1 deletion tasks/util/kernels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from os.path import join
from tasks.util.env import EXAMPLES_DOCKER_DIR
from tasks.util.env import EXAMPLES_DOCKER_DIR, PLOTS_ROOT, RESULTS_DIR

# -------------------
# MPI Kernels
# -------------------

KERNELS_DOCKER_DIR = join(EXAMPLES_DOCKER_DIR, "Kernels")
KERNELS_WASM_DIR = join(KERNELS_DOCKER_DIR, "build", "wasm")
Expand All @@ -17,3 +21,14 @@

# Experiment parameters
KERNELS_EXPERIMENT_NPROCS = [2, 4, 6, 8, 10, 12, 14, 16]

# -------------------
# OpenMP Kernels
# -------------------

OPENMP_KERNELS_DOCKER_DIR = join(EXAMPLES_DOCKER_DIR, "Kernels")
OPENMP_KERNELS = ["global", "p2p", "sparse", "nstream", "reduce", "dgemm"]
OPENMP_KERNELS_FAASM_USER = "kernels-omp"

OPENMP_KERNELS_RESULTS_DIR = join(RESULTS_DIR, "kernels-omp")
OPENMP_KERNELS_PLOTS_DIR = join(PLOTS_ROOT, "kernels-omp")

0 comments on commit d222e00

Please sign in to comment.