Skip to content

Commit b6b768b

Browse files
authored
Merge pull request #1 from semihguresci/codex/refactor-vulkan-project-to-level-0-scope
Introduce Level 0 vk-bench micro-benchmark: headless mode, GPU timestamps, container & scripts
2 parents 3f509d7 + 6922df6 commit b6b768b

27 files changed

Lines changed: 2844 additions & 0 deletions

.dockerignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
out/
2+
build/
3+
cmake-build-*/
4+
CMakeFiles/
5+
CMakeCache.txt
6+
*.ninja
7+
.ninja_*
8+
compile_commands.json
9+
Testing/
10+
CTestTestfile.cmake
11+
12+
.git/
13+
.gitignore
14+
.vscode/
15+
.idea/
16+
.vs/
17+
18+
.DS_Store
19+
Thumbs.db
20+
21+
*.tar
22+
*.tar.gz
23+
results/

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
*.sh text eol=lf

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 curl ca-certificates
16+
- name: Install slangc
17+
run: |
18+
SLANG_VERSION=2024.17.2
19+
curl -fsSL -o slang.tar.gz https://github.com/shader-slang/slang/releases/download/v${SLANG_VERSION}/slang-${SLANG_VERSION}-linux-x86_64.tar.gz
20+
tar -xzf slang.tar.gz
21+
sudo install -m 0755 slang-${SLANG_VERSION}/bin/slangc /usr/local/bin/slangc
22+
- name: Build
23+
run: |
24+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
25+
cmake --build build -j"$(nproc)"
26+
- name: Format check
27+
run: |
28+
clang-format --dry-run --Werror src/main.cpp
29+
30+
benchmark-gpu:
31+
if: ${{ false }}
32+
runs-on: [self-hosted, gpu]
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Placeholder
36+
run: echo "Enable on GPU runner when available"

.gitignore

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

AGENTS.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# AGENTS.md
2+
3+
## Purpose
4+
5+
Guidance for coding agents working in this repository.
6+
7+
## Project summary
8+
9+
- Project: `vk-bench` Vulkan micro-benchmark.
10+
- Language: C++ (single primary source file: `src/main.cpp`).
11+
- Build: CMake.
12+
- Runtime: Linux Docker workflow with NVIDIA GPU (`--gpus all`) is the default path.
13+
14+
## What to optimize for
15+
16+
- Keep benchmark behavior deterministic and easy to compare run-to-run.
17+
- Prefer small, reviewable changes over broad refactors.
18+
- Preserve JSON output compatibility unless a change is explicitly requested.
19+
20+
## Editing rules
21+
22+
- Avoid changing benchmark semantics (scene workloads, frame loops, timing region boundaries) unless requested.
23+
- Add comments only where logic is non-obvious (timing, synchronization, resource lifetime).
24+
- Keep code style consistent with existing file formatting and naming.
25+
- Do not add dependencies unless they are necessary and justified.
26+
27+
## Verification checklist
28+
29+
When changing code, run what is feasible in the environment:
30+
31+
1. Configure/build with CMake.
32+
2. Run a short headless benchmark (`--frames` small) and verify JSON output is written.
33+
3. Confirm no obvious regressions in CLI arguments or scene dispatch.
34+
35+
If GPU execution is not available, state what could not be validated.
36+
37+
## Key files
38+
39+
- `src/main.cpp`: Vulkan setup, scene execution, timing collection, JSON output.
40+
- `CMakeLists.txt`: targets, shader compilation/install, window mode options.
41+
- `scripts/run_bench.sh`: scripted benchmark runs in Docker.
42+
- `scripts/nsight_capture.sh`: Nsight Systems capture helper.
43+
- `scripts/collect_system_info.sh`: host/container environment capture.
44+
- `README.md`: user-facing usage and run instructions.
45+
46+
## Common pitfalls
47+
48+
- Do not assume window mode is available; respect `VK_BENCH_HAS_WINDOW`.
49+
- Keep shader lookup behavior intact (`VK_BENCH_SHADER_DIR`, executable-local shaders, fallback paths).
50+
- Ensure Vulkan objects are destroyed in reverse-lifetime order on every exit path.

CMakeLists.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
include(cmake/compile_shaders.cmake)
10+
11+
option(VK_BENCH_ENABLE_WINDOW "Enable window mode support (requires GLFW)" ON)
12+
option(VK_BENCH_FETCH_GLFW
13+
"Download and build GLFW if it is not available on the system" ON)
14+
15+
set(VK_BENCH_HAS_WINDOW OFF)
16+
set(VK_BENCH_GLFW_TARGET "")
17+
18+
if (VK_BENCH_ENABLE_WINDOW)
19+
find_package(glfw3 QUIET)
20+
21+
if (glfw3_FOUND)
22+
set(VK_BENCH_HAS_WINDOW ON)
23+
set(VK_BENCH_GLFW_TARGET glfw)
24+
message(STATUS "Using system glfw3 package")
25+
elseif (VK_BENCH_FETCH_GLFW)
26+
include(FetchContent)
27+
FetchContent_Declare(
28+
glfw
29+
GIT_REPOSITORY https://github.com/glfw/glfw.git
30+
GIT_TAG 3.4
31+
)
32+
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
33+
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
34+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
35+
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
36+
FetchContent_MakeAvailable(glfw)
37+
set(VK_BENCH_HAS_WINDOW ON)
38+
set(VK_BENCH_GLFW_TARGET glfw)
39+
message(STATUS "Using fetched GLFW (3.4)")
40+
else()
41+
message(STATUS
42+
"glfw3 not found and VK_BENCH_FETCH_GLFW=OFF: windowed rendering disabled, use --headless")
43+
endif()
44+
else()
45+
message(STATUS "VK_BENCH_ENABLE_WINDOW=OFF: windowed rendering disabled, use --headless")
46+
endif()
47+
48+
set(SHADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/shaders")
49+
set(SPIRV_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders")
50+
file(TO_CMAKE_PATH "${SPIRV_DIR}" SPIRV_DIR_CMAKE)
51+
vk_compile_slang_shaders(SHADER_OUTPUTS vk-bench-shaders "${SHADER_DIR}" "${SPIRV_DIR}")
52+
53+
add_executable(vk-bench src/main.cpp)
54+
target_include_directories(vk-bench PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
55+
target_compile_definitions(vk-bench PRIVATE VK_BENCH_SHADER_DIR="${SPIRV_DIR_CMAKE}")
56+
target_link_libraries(vk-bench PRIVATE Vulkan::Vulkan)
57+
if (VK_BENCH_HAS_WINDOW)
58+
target_link_libraries(vk-bench PRIVATE ${VK_BENCH_GLFW_TARGET})
59+
target_compile_definitions(vk-bench PRIVATE VK_BENCH_HAS_WINDOW=1)
60+
else()
61+
target_compile_definitions(vk-bench PRIVATE VK_BENCH_HAS_WINDOW=0)
62+
endif()
63+
64+
add_dependencies(vk-bench vk-bench-shaders)
65+
66+
install(TARGETS vk-bench RUNTIME DESTINATION bin)
67+
install(FILES ${SHADER_OUTPUTS} DESTINATION bin/shaders)

CMakeSettings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "x64-Debug",
5+
"generator": "Ninja",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [ "msvc_x64_x64" ],
8+
"buildRoot": "${projectDir}\\out\\build\\${name}",
9+
"installRoot": "${projectDir}\\out\\install\\${name}",
10+
"cmakeCommandArgs": "",
11+
"buildCommandArgs": "",
12+
"ctestCommandArgs": "",
13+
"debuggerCommandArguments": "--scene triangle --frames 300 --vsync 0"
14+
}
15+
]
16+
}

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM nvidia/cuda:13.1.1-cudnn-devel-ubuntu24.04
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
build-essential \
5+
cmake \
6+
pkg-config \
7+
libvulkan1 \
8+
libvulkan-dev \
9+
vulkan-tools \
10+
mesa-vulkan-drivers \
11+
curl \
12+
ca-certificates \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
ARG SLANG_VERSION=2026.3.1
16+
RUN set -eux; \
17+
mkdir -p /opt/slang; \
18+
curl -fsSL -o /tmp/slang.tar.gz \
19+
"https://github.com/shader-slang/slang/releases/download/v${SLANG_VERSION}/slang-${SLANG_VERSION}-linux-x86_64.tar.gz"; \
20+
tar -xzf /tmp/slang.tar.gz -C /opt/slang; \
21+
rm -f /tmp/slang.tar.gz; \
22+
SLANGC_PATH="$(find /opt/slang -type f -name slangc -perm -111 | head -n 1)"; \
23+
test -n "$SLANGC_PATH"; \
24+
install -m 0755 "$SLANGC_PATH" /usr/local/bin/slangc; \
25+
SLANG_LIB_DIR="$(dirname "$(find /opt/slang -type f -name 'libslang-compiler.so*' | head -n 1)")"; \
26+
test -n "$SLANG_LIB_DIR"; \
27+
echo "$SLANG_LIB_DIR" > /etc/ld.so.conf.d/slang.conf; \
28+
ldconfig; \
29+
slangc -version
30+
31+
WORKDIR /workspace
32+
COPY CMakeLists.txt /workspace/CMakeLists.txt
33+
COPY cmake /workspace/cmake
34+
COPY src /workspace/src
35+
COPY include /workspace/include
36+
COPY shaders /workspace/shaders
37+
RUN cmake -S /workspace -B /workspace/build -DCMAKE_BUILD_TYPE=Release \
38+
-DVK_BENCH_ENABLE_WINDOW=OFF \
39+
-DVK_BENCH_FETCH_GLFW=OFF \
40+
-DSLANGC=/usr/local/bin/slangc \
41+
&& cmake --build /workspace/build --config Release -j"$(nproc)" \
42+
&& install -m 0755 /workspace/build/vk-bench /usr/local/bin/vk-bench \
43+
&& install -d /usr/local/bin/shaders \
44+
&& cp /workspace/build/shaders/*.spv /usr/local/bin/shaders/
45+
46+
COPY docker/entrypoint.sh /entrypoint.sh
47+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)