Skip to content

Commit d96ce58

Browse files
committed
automate workflow with github actions
1 parent 96fd479 commit d96ce58

3 files changed

Lines changed: 63 additions & 9 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Windows CPU OpenCL Benchmark
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
benchmark:
10+
runs-on: windows-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v4
15+
16+
# ---- Install OpenCL CPU runtime and build tools ----
17+
- name: Install OpenCL SDK and CMake
18+
run: |
19+
choco install opencl-sdk -y
20+
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y
21+
22+
- name: Install Python dependencies
23+
run: |
24+
pip install --upgrade pip
25+
pip install pyopencl numpy pandas matplotlib
26+
27+
# ---- Configure and build the C++ project ----
28+
- name: Configure project (CMake with MSVC)
29+
run: |
30+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
31+
32+
- name: Build Release
33+
run: |
34+
cmake --build build --config Release
35+
36+
# ---- Run your Python benchmark automation ----
37+
- name: Run Benchmark Script
38+
run: |
39+
python automation/benchmark.py 0
40+
41+
# ---- Upload benchmark results ----
42+
- name: Upload Results
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: windows-cpu-opencl-results
46+
path: automation/

CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(opencl_bench)
33

4-
set(CMAKE_CXX_STANDARD 17) # Use C++17
4+
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

7-
set(OpenCL_INCLUDE_DIR "")
8-
set(OpenCL_LIBRARY "")
9-
10-
11-
include_directories(${OpenCL_INCLUDE_DIR})
7+
# Let CMake find OpenCL automatically
8+
find_package(OpenCL REQUIRED)
129

1310
add_executable(benchmark src/benchmark.cpp)
1411

15-
target_link_libraries(benchmark ${OpenCL_LIBRARY})
12+
# Include OpenCL headers
13+
target_include_directories(benchmark PRIVATE ${OpenCL_INCLUDE_DIRS})
14+
15+
# Link OpenCL library
16+
target_link_libraries(benchmark PRIVATE ${OpenCL_LIBRARIES})

automation/run_benchmarks.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66
import pyopencl as cl
77
import matplotlib.pyplot as plt
88
import pandas as pd
9+
import platform
910

1011
# Define path to the benchmark executable
1112
SCRIPT_DIR = Path(__file__).parent.parent
12-
BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "benchmark.exe"
1313
SAVE_DIR = SCRIPT_DIR / "automation" / "benchmark_results.csv"
1414

15+
if platform.system() == "Windows":
16+
BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "benchmark.exe"
17+
if not BENCHMARK_EXECUTABLE.exists():
18+
BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "Release" / "benchmark.exe"
19+
else:
20+
BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "benchmark"
21+
1522

1623
# Automatically detect all GPU devices
1724
def get_gpu_devices():
1825
platforms = cl.get_platforms()
19-
devices = [dev for p in platforms for dev in p.get_devices(device_type=cl.device_type.GPU)]
26+
devices = [dev for p in platforms for dev in p.get_devices(device_type=cl.device_type.ALL)]
2027

2128
for i, dev in enumerate(devices):
2229
print(f"{i}: {dev.name}")

0 commit comments

Comments
 (0)