Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
aaf8075
Started implementing the ncu wrapper
Damfilius Apr 14, 2025
55fdd14
Added necessary command line options for ngAP benchmarking
Damfilius Apr 14, 2025
ab30c07
updated_envvironemnt sets PATH and LD_LIBRARY_PATH env vars
Damfilius Apr 14, 2025
98dcdc5
Added functions for checking if the user supplied metrics / sections …
Damfilius Apr 23, 2025
edb8945
Added a function for validating that the user supplied set is available
Damfilius Apr 23, 2025
163d76e
Checking for proper metrics, sections and sets using validate functions
Damfilius Apr 23, 2025
a1ec863
Added functions for finding the ncu bin
Damfilius Apr 23, 2025
990afd6
[ncu_wrapper] Users can specify tool arguments as strings with flags …
Damfilius May 7, 2025
a6f9741
[matmul_campaign] Campaign and benchmark for matMul cuda sample program
Damfilius May 8, 2025
cae47e9
[ncu] Added default values for ncu_path and config_path parameters
Damfilius May 8, 2025
d106686
[matMul] Benchmark works
Damfilius May 8, 2025
23ce80d
[ncu] Added post-run hook to update the output results with the ncu p…
Damfilius May 9, 2025
a4c4164
[ncu] _get_available_options does not create iter() object anymore
Damfilius May 9, 2025
9e4c5d4
[ncu] commented out update_environment - everything should be set by …
Damfilius May 9, 2025
da5818e
[campaign] added a post run hook for results collection
Damfilius May 9, 2025
924f8f7
Merge branch 'ncu_wrapper' of github.com:Damfilius/benchkit into ncu_…
Damfilius May 9, 2025
4fb2c79
[ncu] The ncu report file is stored in the appropriate directory
Damfilius May 9, 2025
770755c
[ngAP] Added python lists for the variables and started working on th…
Damfilius May 10, 2025
94709cd
Merge branch 'ngAP_bench' of github.com:Damfilius/benchkit into ngAP_…
Damfilius May 10, 2025
e6a5919
[ngap-benchmark] wrote building of the command
Damfilius Jun 1, 2025
1399d90
[non-ncu benchmark] Added 2 benchmarks with and w/o ncu wrapper
Damfilius Jun 1, 2025
42dee8d
[options querying] Fixed methods for getting and parsing ncu metrics,…
Damfilius Jun 1, 2025
3881f0a
[fetching available options] Caching of sets, sections and names for …
Damfilius Jun 1, 2025
c8ecb5e
[private methods] made the validation methods private
Damfilius Jun 1, 2025
0a68565
[debug] fixed small errors
Damfilius Jun 1, 2025
4c15069
[ncu_parsing] storing of average values
Damfilius Jun 1, 2025
ee8a2bb
[ncu post run hook] mean results are saved properly and the ncu repor…
Damfilius Jun 2, 2025
65a8de8
[ncu wrapper] Changed it to reflect the state on the ncu_wrapper bren…
Damfilius Jun 2, 2025
a96f20f
[parsing configs] Created a script that parses the required config files
Damfilius Jun 2, 2025
55d678d
[parse configs] Finished parse configs file - need to test
Damfilius Jul 9, 2025
ec7ca3b
[parse_options] parse_options works now
Damfilius Jul 10, 2025
04a6d83
[campaign] Updated the variables in the campaign
Damfilius Jul 13, 2025
38d5215
[benchmark + campaign] Finished the benchmark and campaign code - nee…
Damfilius Jul 26, 2025
871686c
[variables] Added support for all ngap variables not just the ones in…
Damfilius Jul 28, 2025
75e1c72
[debug] fixed bugs - commands are made successfully
Damfilius Jul 29, 2025
4b5cf93
Pushed ngap -h output for reference
Damfilius Jul 29, 2025
06cdc8c
[process ncu context] Non-float values are caught (also including Non…
Damfilius Jul 30, 2025
59e405f
[cuda JPEG encoder] Added campaign and benchmark for the cuda JPEG en…
Damfilius Jul 30, 2025
a6d26c6
[requirements] Added a requirements.txt file and updated the README i…
Damfilius Jul 30, 2025
9c0472f
[breakdown] --input-len was getting added twice to the command
Damfilius Aug 1, 2025
c56b239
[pythonpath] Added command for adding ncu_report to PYTHONPATH as a c…
Damfilius Aug 1, 2025
76b3578
[sensitivity] Added sensitivity campaign although its almost exactly …
Damfilius Aug 4, 2025
8a648a3
Merge branch 'ngAP_bench' of github.com:Damfilius/benchkit into ngAP_…
Damfilius Aug 4, 2025
5546589
[campaign] Added general campaign for both sensitivity and breakdown …
Damfilius Aug 5, 2025
d792803
[breakdown configs] Removed breakdown configs directory
Damfilius Aug 5, 2025
56f6a26
[configs] Removed sensitivity configs
Damfilius Aug 5, 2025
1587950
[campaign] Fixed the config-app combinations
Damfilius Aug 7, 2025
177efb9
[parse_results] Improved parse results to account for more complex ng…
Damfilius Aug 8, 2025
f566e17
[ngap benchmark] Added timeout, handling of timeout exceptions and ig…
Damfilius Aug 14, 2025
186fbf4
[campaign] Enabling data_dir and ignoring ncu outputs
Damfilius Aug 14, 2025
2091a0a
[ncu] Handling file not found errors when loading ncu report files (i…
Damfilius Aug 14, 2025
1d688dc
[ncu] Added support for csv log files
Damfilius Aug 16, 2025
b5e254d
Merge branch 'ngAP_bench' into ncu_wrapper
Damfilius Aug 16, 2025
31a98bb
[ncu] Handling of exceptions thrown by pandas when reading the csv lo…
Damfilius Aug 16, 2025
c135cad
[parse-options] Output-file parameter was not getting fetched properly
Damfilius Aug 21, 2025
063c837
[ncu] Added some documentation
Damfilius Aug 21, 2025
eb0a72f
[matmul] Added a readme
Damfilius Aug 21, 2025
8ecc7fc
[ngap] Added readme
Damfilius Aug 21, 2025
99d91f1
Merge branch 'ncu_wrapper'
Damfilius Aug 21, 2025
6a22baf
[nvJPEG_encoder] Added a readme for the source of images
Damfilius Aug 21, 2025
17ba580
Merge branch 'main' of https://github.com/open-s4c/benchkit
Damfilius Sep 2, 2025
b6d049a
[README] Removed cuda sample code and added README with setup instruc…
Damfilius Sep 2, 2025
d85c777
[README] Added a README with setup instructions and removed code from…
Damfilius Sep 2, 2025
1fe7248
[README] Removed the ngAP breakdown configs and specified in the READ…
Damfilius Sep 2, 2025
cc8bc50
Merge branch 'main' into main
Damfilius Sep 2, 2025
3ba0d32
Merge branch 'main' of https://github.com/open-s4c/benchkit
Damfilius Sep 5, 2025
7f1f8a2
Merge branch 'main' of github.com:Damfilius/benchkit
Damfilius Sep 5, 2025
139f103
Merge branch 'open-s4c:main' into main
Damfilius Sep 5, 2025
9b3c4f5
[ncu] Renamed the ncu commandwrapper file to ncu2 and updated any imp…
Damfilius Sep 5, 2025
ca26926
Merge branch 'main' of github.com:Damfilius/benchkit
Damfilius Sep 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
492 changes: 492 additions & 0 deletions benchkit/commandwrappers/ncu2.py

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions examples/cuda_samples_JPEGencoder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Campaign and Benchmark for nvJPEG_encoder

All source files taken from https://github.com/NVIDIA/cuda-samples/tree/master/Samples/4_CUDA_Libraries/nvJPEG_encoder

## Setting up the Python Virtual Environment
```
./configure.sh
source venv/bin/activate
```

## Set up the src directory
```
mkdir src && cd src
mkdir encode_output images
```

### Get the src code file and the cmake lists file
```wget https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/nvJPEG_encoder.cpp```
### Get the cmake lists file
```wget https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/CMakeLists.txt```

### You can download the images in the images directory from https://github.com/NVIDIA/cuda-samples/tree/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images
```
cd images
wget https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img1.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img2.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img3.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img4.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img5.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img6.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img7.jpg?raw=true \
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/4_CUDA_Libraries/nvJPEG_encoder/images/img8.jpg?raw=true
```
#### Rename the image files
```
for f in *?raw=true; do mv "$f" "${f%%?raw=true}"; done
cd ..
```

## Get the helper files
```
wget https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_nvJPEG.hxx \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_string.h \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_timer.h \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/exception.h \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_cuda.h \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_functions.h \
https://raw.githubusercontent.com/NVIDIA/cuda-samples/refs/heads/master/Common/helper_image.h
```

### Edit Files
Edit the helper_cuda.h file by replacing line 41: <helper_string.h> with "helper_string.h"
Edit the helper_timer.h file by replacing line 40: <exception.h> with "exception.h"

### Exit the src directory
```cd ..```

## Running the campaigns
### Without the NCU wrapper
```python3 gpu_jpeg_encoder_campaign.py```
### With the NCU wrapper
```python3 gpu_jpeg_encoder_campaign_ncu.py```
4 changes: 4 additions & 0 deletions examples/cuda_samples_JPEGencoder/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

../../scripts/install_venv.sh
251 changes: 251 additions & 0 deletions examples/cuda_samples_JPEGencoder/gpu_jpeg_encoder_campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@

#!/usr/bin/env python3
# Copyright (C) 2024 Vrije Universiteit Brussel. All rights reserved.
# SPDX-License-Identifier: MIT

import pathlib
import shutil
from typing import Any, Dict, List, Iterable

from benchkit.benchmark import Benchmark, CommandAttachment, PostRunHook, PreRunHook
from benchkit.campaign import CampaignIterateVariables, CampaignSuite
from benchkit.commandwrappers.ncu2 import NcuWrap, CommandWrapper
from benchkit.platforms import Platform
from benchkit.utils.types import PathType
from benchkit.sharedlibs import SharedLib
from benchkit.utils.dir import get_curdir, parentdir
from benchkit.platforms import get_current_platform

# Variables
vars = [
{'image': './build/images/img1.jpg',
'outdir': './build/encode_output/',
'quality': 20,
'subsampling': 411,
'huffman': 1},
{'image': './build/images/img3.jpg',
'outdir': './build/encode_output/',
'quality': 80,
'subsampling': 422,
'huffman': 0},
{'image': './build/images/img5.jpg',
'outdir': './build/encode_output/',
'quality': 50,
'subsampling': 444,
'huffman': 1},
{'image': './build/images/img7.jpg',
'outdir': './build/encode_output/',
'quality': 100,
'subsampling': 440,
'huffman': 0},
]

class JPEGEncodeBench(Benchmark):
def __init__(
self,
command_wrappers: Iterable[CommandWrapper] = (),
command_attachments: Iterable[CommandAttachment] = (),
shared_libs: Iterable[SharedLib] = (),
pre_run_hooks: Iterable[PreRunHook] = (),
post_run_hooks: Iterable[PostRunHook] = (),
platform: Platform | None = None,
) -> None:
super().__init__(
command_wrappers=command_wrappers,
command_attachments=command_attachments,
shared_libs=shared_libs,
pre_run_hooks=pre_run_hooks,
post_run_hooks=post_run_hooks,
)

script_path = get_curdir(__file__)
bench_path = script_path / "src"
build_path = script_path / "build"

self._bench_src_path = bench_path
self._build_dir = build_path

if platform is not None:
self.platform = platform

@property
def bench_src_path(self) -> pathlib.Path:
return self._bench_src_path

@staticmethod
def get_build_var_names() -> List[str]:
return []

'''
Because this is matrix multiplication the outer dims of the 2 matrices have to match
As a result mb_width = ma_height
'''
@staticmethod
def get_run_var_names() -> List[str]:
return [
"image",
"outdir",
"quality",
"subsampling",
"huffman"
]

@staticmethod
def get_tilt_var_names():
return []

def build_bench(
self,
**kwargs,
) -> None:

if self._build_dir.is_dir() and len(str(self._build_dir)) > 4:
shutil.rmtree(str(self._build_dir))

self.platform.comm.makedirs(path=self._build_dir, exist_ok=True)

self.platform.comm.shell(
command="cmake ../src",
current_dir=self._build_dir,
output_is_log=True,
)

self.platform.comm.shell(
command="make",
current_dir=self._build_dir,
)

def single_run(
self,
image,
outdir,
quality,
subsampling,
huffman,
**kwargs,
) -> str:
current_dir = self._build_dir
environment = self._preload_env(**kwargs)

run_command = [
"./nvJPEG_encoder",
f"-i {image}",
f"-o {outdir}",
f"-q {quality}",
f"-s {subsampling}",
f"-huf {huffman}"
]

wrapped_run_command, wrapped_environment = self._wrap_command(
run_command=run_command,
environment=environment,
**kwargs,
)

output = self.run_bench_command(
run_command=run_command,
wrapped_run_command=wrapped_run_command,
current_dir=current_dir,
environment=environment,
wrapped_environment=wrapped_environment,
print_output=True,
)

return output

@staticmethod
def _parse_results(
image: str,
outdir: str,
quality: int,
subsampling: int,
huffman: int,
output: str
) -> Dict[str, Any]:
output_lines = output.splitlines()
num_channels = 0
channel_sizes = []
time = 0.0
for line in output_lines:
if line.startswith("Image is "):
num_channels = int(line.split(' ')[2])
elif line.startswith("Channel "):
sizes = line.split(': ')[1].split(' x ')
size_tup = (int(sizes[0]), int(sizes[1]))
channel_sizes.append(size_tup)
elif line.startswith("Total time spent on encoding: "):
time = float(line.split(': ')[1])

names=[
"image",
"outdir",
"quality",
"subsampling",
"huffman",
"num_channels",
"time"
]
values = [image,outdir,quality,subsampling,huffman,num_channels,time]
for i in range(num_channels):
names.append(f"channel {i}")
values.append(channel_sizes[i])

return dict(zip(names,values))


def parse_output_to_results(
self,
command_output: str,
run_variables: Dict[str, Any],
**_kwargs,
) -> Dict[str, Any]:
result_dict = {}


image = str(run_variables["image"])
outdir = str(run_variables["outdir"])
quality = int(run_variables["quality"])
subsampling = int(run_variables["subsampling"])
huffman = int(run_variables["huffman"])
result_dict = self._parse_results(
image,
outdir,
quality,
subsampling,
huffman,
command_output)

return result_dict


def main():
nb_runs = 1
platform = get_current_platform()

bench = JPEGEncodeBench(
platform=platform
)

campaign = CampaignIterateVariables(
name="gpuJPEGencode",
benchmark=bench,
nb_runs=nb_runs,
variables=vars,
constants=None,
debug=False,
gdb=False,
enable_data_dir=True
)

campaign_suite = CampaignSuite(campaigns=[campaign])
campaign_suite.run_suite()

# campaign_suite.generate_graph(
# plot_name="lineplot",
# x="quality",
# y="time"
# )


if __name__ == "__main__":
main()
Loading