From d222e006e31431f4c82608a54bfc350c52ff5692 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 14 Mar 2024 16:07:48 +0000 Subject: [PATCH] kernels(omp): refine plot and scripts --- tasks/kernels_omp/README.md | 8 ++--- tasks/kernels_omp/plot.py | 64 ++++++++++++++++++++----------------- tasks/kernels_omp/run.py | 30 +++++++---------- tasks/kernels_omp/wasm.py | 17 ++-------- tasks/util/env.py | 7 +--- tasks/util/kernels.py | 17 +++++++++- 6 files changed, 70 insertions(+), 73 deletions(-) diff --git a/tasks/kernels_omp/README.md b/tasks/kernels_omp/README.md index f3b5947..3d0f3ef 100644 --- a/tasks/kernels_omp/README.md +++ b/tasks/kernels_omp/README.md @@ -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: @@ -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 diff --git a/tasks/kernels_omp/plot.py b/tasks/kernels_omp/plot.py index fdc2b89..ed7cc9e 100644 --- a/tasks/kernels_omp/plot.py +++ b/tasks/kernels_omp/plot.py @@ -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] @@ -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 = [] @@ -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, @@ -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)) diff --git a/tasks/kernels_omp/run.py b/tasks/kernels_omp/run.py index 3973095..e883504 100644 --- a/tasks/kernels_omp/run.py +++ b/tasks/kernels_omp/run.py @@ -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 """ @@ -28,21 +28,15 @@ 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)) @@ -50,7 +44,7 @@ def _write_csv_line(csv_name, 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), @@ -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 """ diff --git a/tasks/kernels_omp/wasm.py b/tasks/kernels_omp/wasm.py index a45eb04..2c9292c 100644 --- a/tasks/kernels_omp/wasm.py +++ b/tasks/kernels_omp/wasm.py @@ -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 @@ -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( { diff --git a/tasks/util/env.py b/tasks/util/env.py index 3d08200..d44584c 100644 --- a/tasks/util/env.py +++ b/tasks/util/env.py @@ -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" @@ -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") diff --git a/tasks/util/kernels.py b/tasks/util/kernels.py index 708c11a..60e2f7b 100644 --- a/tasks/util/kernels.py +++ b/tasks/util/kernels.py @@ -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") @@ -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")