Skip to content

Commit 791dcea

Browse files
committed
Create Level 0 Vulkan micro-benchmark foundation
1 parent 3f509d7 commit 791dcea

13 files changed

Lines changed: 543 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-and-format:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Install deps
13+
run: |
14+
sudo apt-get update
15+
sudo apt-get install -y cmake g++ libvulkan-dev clang-format
16+
- name: Build
17+
run: |
18+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
19+
cmake --build build -j"$(nproc)"
20+
- name: Format check
21+
run: |
22+
clang-format --dry-run --Werror src/main.cpp
23+
24+
benchmark-gpu:
25+
if: ${{ false }}
26+
runs-on: [self-hosted, gpu]
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Placeholder
30+
run: echo "Enable on GPU runner when available"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build/
2+
results/*.json
3+
results/*.txt
4+
results/*.qdrep
5+
results/*.nsys-rep
6+
results/*.sqlite

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(vk_bench LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
find_package(Vulkan REQUIRED)
9+
10+
add_executable(vk-bench src/main.cpp)
11+
target_include_directories(vk-bench PRIVATE include)
12+
target_link_libraries(vk-bench PRIVATE Vulkan::Vulkan)
13+
14+
install(TARGETS vk-bench RUNTIME DESTINATION bin)

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM nvidia/vulkan:1.3.280-ubuntu22.04
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
build-essential \
5+
cmake \
6+
pkg-config \
7+
vulkan-tools \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /workspace
11+
COPY CMakeLists.txt /workspace/CMakeLists.txt
12+
COPY src /workspace/src
13+
COPY include /workspace/include
14+
RUN cmake -S /workspace -B /workspace/build -DCMAKE_BUILD_TYPE=Release \
15+
&& cmake --build /workspace/build --config Release -j"$(nproc)" \
16+
&& install -m 0755 /workspace/build/vk-bench /usr/local/bin/vk-bench
17+
18+
COPY docker/entrypoint.sh /entrypoint.sh
19+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# vk-bench (Level 0 Vulkan micro-benchmark)
2+
3+
**Purpose**
4+
5+
A containerized Vulkan micro-benchmark that renders one controlled workload at a time and produces repeatable performance numbers plus Nsight captures.
6+
7+
## What this benchmarks
8+
9+
This Level 0 repo intentionally scopes to **one executable** (`vk-bench`) and **three micro-scenes**:
10+
11+
- `triangle` (sanity / low work)
12+
- `million-tris` (high draw-like transfer load)
13+
- `compute-copy` (bandwidth-focused transfer load)
14+
15+
No assets, textures, or engine features are included.
16+
17+
## How to run
18+
19+
```bash
20+
docker build -t vk-bench .
21+
docker run --rm --gpus all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix vk-bench
22+
docker run --rm --gpus all vk-bench --headless --frames 300 --out results.json
23+
```
24+
25+
### Bench all 3 scenes
26+
27+
```bash
28+
scripts/run_bench.sh results
29+
```
30+
31+
## Example results
32+
33+
```json
34+
{
35+
"scene": "million-tris",
36+
"cpu_frame_time_ms": {"avg": 0.0731, "p50": 0.0613, "p95": 0.1188},
37+
"gpu_frame_time_ms": {"avg": 2.4182, "p50": 2.3395, "p95": 2.7560}
38+
}
39+
```
40+
41+
![Frame time output screenshot](docs/frame-time-output.svg)
42+
43+
## How timing is measured (CPU/GPU)
44+
45+
- **GPU frame time**: Vulkan timestamp queries (`vkCmdWriteTimestamp`) around the workload command region.
46+
- **CPU frame time (submission)**: host timer around `vkQueueSubmit` call.
47+
- Per-frame values are recorded and summarized as `avg`, `p50`, and `p95` in JSON.
48+
49+
## Nsight steps (exact command)
50+
51+
```bash
52+
scripts/nsight_capture.sh results/nsight_capture
53+
```
54+
55+
Or directly:
56+
57+
```bash
58+
nsys profile --trace=vulkan,nvtx,cuda --output results/nsight_capture \
59+
vk-bench --headless --scene million-tris --warmup 20 --frames 120 --out results/nsight_capture.json
60+
```
61+
62+
![Nsight capture screenshot](docs/nsight-capture.svg)
63+
64+
## Container GPU access options
65+
66+
### Option A: Linux host + NVIDIA (recommended)
67+
68+
- Use `--gpus all`.
69+
- Verify loader + ICD in-container:
70+
71+
```bash
72+
docker run --rm --gpus all vk-bench vulkaninfo --summary
73+
```
74+
75+
### Option B: Headless-only explicit ICD config
76+
77+
If automatic ICD discovery is unavailable, set:
78+
79+
```bash
80+
export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json
81+
vk-bench --headless --frames 300 --out results.json
82+
```
83+
84+
## Known limitations
85+
86+
- Current Level 0 workload uses transfer-copy command streams to provide stable timing; it does not yet create a swapchain/windowed render path.
87+
- CI can validate build/formatting but not real GPU benchmark values unless run on a self-hosted GPU runner.

docker/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM nvidia/vulkan:1.3.280-ubuntu22.04
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
build-essential \
5+
cmake \
6+
pkg-config \
7+
vulkan-tools \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /workspace
11+
COPY CMakeLists.txt /workspace/CMakeLists.txt
12+
COPY src /workspace/src
13+
COPY include /workspace/include
14+
RUN cmake -S /workspace -B /workspace/build -DCMAKE_BUILD_TYPE=Release \
15+
&& cmake --build /workspace/build --config Release -j"$(nproc)" \
16+
&& install -m 0755 /workspace/build/vk-bench /usr/local/bin/vk-bench
17+
18+
COPY docker/entrypoint.sh /entrypoint.sh
19+
ENTRYPOINT ["/entrypoint.sh"]

docker/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ "${1:-}" == "" ]]; then
5+
exec /usr/local/bin/vk-bench --headless --frames 300 --out /workspace/results.json
6+
fi
7+
8+
exec /usr/local/bin/vk-bench "$@"

docs/frame-time-output.svg

Lines changed: 9 additions & 0 deletions
Loading

docs/nsight-capture.svg

Lines changed: 14 additions & 0 deletions
Loading

scripts/collect_system_info.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
OUT="${1:-results/system_info.txt}"
5+
mkdir -p "$(dirname "$OUT")"
6+
7+
{
8+
echo "== Date =="
9+
date -Iseconds
10+
echo
11+
echo "== uname =="
12+
uname -a
13+
echo
14+
echo "== nvidia-smi =="
15+
nvidia-smi || true
16+
echo
17+
echo "== vulkaninfo --summary =="
18+
vulkaninfo --summary || true
19+
} > "$OUT"
20+
21+
echo "Wrote $OUT"

0 commit comments

Comments
 (0)