Skip to content

Commit

Permalink
Add utilities for benchmarking different code versions (#65)
Browse files Browse the repository at this point in the history
* Move benchmark data

* Rework dataset size benchmark

* Move data generation script

* Move profiling code inside benchmark

* Remove old scripts

* Add script for fetching other CLUE versions for comparison

* Update workflow for benchmark and profiling

* Delete workflow for uploading log

* Fix namespace name

* Deactivate automatic profiling for now

* Add small script for cache profiling with perf
  • Loading branch information
sbaldu authored Oct 29, 2024
1 parent 495ca6e commit d3d93a1
Show file tree
Hide file tree
Showing 38 changed files with 2,196,776 additions and 10,210 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/bench_profile_serial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Run benchmark and profiling

# The workflow gets triggered by pushes and pull requests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
# checks out the code in the repository
- uses: actions/checkout@v3
with:
submodules: true

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install matplotlib
- name: Compile and run benchmark
working-directory: ${{ github.workspace }}/benchmark/dataset_size
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -- -j 2
./build/serial.out 10 18
# TODO: this works on local but not on github actions
# - name: Compile and run profiling
# working-directory: ${{ github.workspace }}/benchmark/profiling
# run: |
# cmake -B build/Debug -DCMAKE_BUILD_TYPE=Debug
# cmake --build build/Debug -- -j 2
# cmake -B build/Release -DCMAKE_BUILD_TYPE=Release
# cmake --build build/Release -- -j 2
# ./build/Debug/serial.out ../../data/data_32768.csv
# gprof ./build/Debug/serial.out ../../data/data_32768.csv
# ./build/Release/serial.out ../../data/data_32768.csv
# gprof ./build/Release/serial.out ../../data/data_32768.csv

# - name: Check cache misses with perf
# working-directory: ${{ github.workspace }}/benchmark/profiling
# run: |
# perf stat -B -e cache-misses,cycles,instructions,branches ./build/Debug/serial.out ../../data/data_32768.csv
# perf stat -B -e cache-misses,cycles,instructions,branches ./build/Release/serial.out ../../data/data_32768.csv

44 changes: 0 additions & 44 deletions .github/workflows/profile_serial.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/upload_profile_log.yml

This file was deleted.

6 changes: 3 additions & 3 deletions CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(
tiles_working_div, KernelResetTiles{}, m_tiles, nTiles, nPerDim));

alpaka::memcpy(
queue_,
d_points.coords,
Expand Down Expand Up @@ -198,7 +197,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
/* m_domains.data(), */
dc_,
h_points.n));

alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div,
KernelCalculateNearestHigher{},
Expand All @@ -208,7 +206,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
dm_,
dc_,
h_points.n));

alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div,
KernelFindClusters<Ndim>{},
Expand All @@ -224,6 +221,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
const Idx grid_size_seeds = cms::alpakatools::divide_up_by(reserve, block_size);
auto working_div_seeds =
cms::alpakatools::make_workdiv<Acc1D>(grid_size_seeds, block_size);

alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div_seeds,
KernelAssignClusters<Ndim>{},
Expand All @@ -249,6 +247,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
d_points.nearest_higher,
static_cast<uint32_t>(h_points.n));
#endif

alpaka::memcpy(
queue_,
cms::alpakatools::make_host_view(h_points.m_clusterIndex.data(), h_points.n),
Expand All @@ -265,4 +264,5 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
return {h_points.m_clusterIndex, h_points.m_isSeed};
}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif
126 changes: 126 additions & 0 deletions benchmark/cluerel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/python3

import os
import subprocess
import sys

def parse_args() -> tuple:
path = sys.argv[2]
flags = []
values = []
for arg in sys.argv[2:]:
parsed = arg.split('=')
flags.append(parsed[0])
values.append(parsed[1])

return (flags, values)

if sys.argv[1] == "-h" or sys.argv[1] == "--help" or len(sys.argv) < 3:
print("Usage: $0 <path> <version> <fork>")
sys.exit(0)

flags, values = parse_args()
if '--fork' in flags:
fork = values[flags.index('--fork')]
else:
fork = 'cms-patatrack'
if '--commit' in flags:
is_commit = True
is_branch = False
version = values[flags.index('--commit')]
elif '--branch' in flags:
is_commit = False
is_branch = True
version = values[flags.index('--branch')]

clue_version = f"CLUEstering_{fork}_{version}"

if is_commit:
print(f"Fetching CLUEstering commit {version} from {fork}")
if is_branch:
print(f"Fetching CLUEstering branch {version} from {fork}")

repo_url = f"https://github.com/{fork}/CLUEstering.git"
# Checkout the repo
os.system("mkdir -p " + clue_version)

clone = subprocess.run(["git",
"clone",
repo_url,
f"{clue_version}/Debug",
"--recursive",
"--depth=1"], capture_output=True, text=True)
if clone.returncode != 0:
print(f"Error: {clone.stderr}")
print((f"Failed to clone the repo {repo_url}. Check that the insersted repository,"
"commit or branch are correct"))
sys.exit(1)
os.system("cp -r " +
f"{clue_version}/Debug " +
f"{clue_version}/Release")
print(f"Cloned {clue_version} successfully")
print('')
print("Compiling the Debug version of the library")
os.chdir(f"{clue_version}/Debug")
# Compile the debug version
compile_debug = subprocess.run(["cmake",
"-B",
"build",
"-DCMAKE_BUILD_TYPE=Debug"],
capture_output=True,
text=True)
if compile_debug.returncode != 0:
print(f"Error: {compile_debug.stderr}")
print("Failed to compile the debug version of the project")
sys.exit(1)
compile_debug = subprocess.run(["cmake",
"--build",
"build",
"--",
"-j",
"2"],
capture_output=True,
text=True)
compile_debug = subprocess.run(["cmake",
"-B",
"build"],
capture_output=True,
text=True)
if compile_debug.returncode != 0:
print(f"Error: {compile_debug.stderr}")
print("Failed to compile the debug version of the project")
sys.exit(1)
print("Finished compiling the debug version.")
print('')
print("Compiling the Release version of the library")
os.chdir("../Release")
# Compile the release version
compile_release = subprocess.run(["cmake",
"-B",
"build",
"-DCMAKE_BUILD_TYPE=Release"],
capture_output=True,
text=True)
if compile_release.returncode != 0:
print(f"Error: {compile_release.stderr}")
print("Failed to compile the release version of the project")
sys.exit(1)
compile_release = subprocess.run(["cmake",
"--build",
"build",
"--",
"-j",
"2"],
capture_output=True,
text=True)
compile_release = subprocess.run(["cmake",
"-B",
"build",
"-DCMAKE_BUILD_TYPE=Release"],
capture_output=True,
text=True)
if compile_release.returncode != 0:
print(f"Error: {compile_release.stderr}")
print("Failed to compile the release version of the project")
sys.exit(1)
print("Finished compiling the release version.")
Loading

0 comments on commit d3d93a1

Please sign in to comment.