Skip to content

Commit 61f0db3

Browse files
authored
Async gpu std example (#315)
## Summary Adds `examples/async_gpu_std/`, a counterpart to `examples/async_gpu_launch` that demonstrates the same double-buffered async CPU+GPU optical photon pattern but **using only C++ stdlib primitives** _ no `G4TaskGroup`, no `G4Mutex`. The GPU worker is a plain `std::thread` driven by `std::mutex` + `std::condition_variable` + a bounded `std::queue<GPUTask>`. ## What's in it | file | purpose | |---|---| | `async_gpu_std.h` | `GPUTaskManager` (worker thread, bounded queue, backpressure), Cerenkov + multi-component scintillation genstep paths, `PhotonSD`, sync/async `RunAction` | | `async_gpu_std.cpp` | `main()` with manual argv parsing, physics list, action initialization | | `CMakeLists.txt` | standalone `find_package(eic-opticks)` build (also pulls `glm` first to work around the missing `find_dependency(glm)` in the installed eic-opticks Config.cmake) | | `apex.gdml` | bundled detector geometry (no external references) | | `run.mac` | `setStackPhotons false` on Cerenkov + Scintillation, 100 beam-on events | | `run.sh` | reads inputs from the example dir; `--sync` / `--async` (default) flags | ## Architecture vs `async_gpu_launch` | concern | async_gpu_launch | async_gpu_std | |---|---|---| | worker thread | `G4TaskGroup<void,void>` | `std::thread` | | mutex | `G4Mutex` / `G4AutoLock` | `std::mutex` | | wakeups | implicit via task group | `std::condition_variable` | | queue | implicit | `std::queue<GPUTask>` (bounded) | | backpressure | none | `GPU_MAX_QUEUE_SIZE` (default 3) | Simulation behavior is otherwise identical _ Cerenkov + 3-component scintillation gensteps, sphoton `.npy` hit dumps per batch.
1 parent a8570f0 commit 61f0db3

6 files changed

Lines changed: 1694 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(async_gpu_std LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
# Order matters: pull in glm before eic-opticks because the installed
10+
# eic-opticks::SysRap target's link interface references glm::glm but the
11+
# package's Config.cmake does not declare it as a dependency.
12+
find_package(glm REQUIRED)
13+
find_package(eic-opticks REQUIRED)
14+
find_package(Geant4 REQUIRED ui_all vis_all)
15+
find_package(Threads REQUIRED)
16+
17+
add_executable(async_gpu_std async_gpu_std.cpp async_gpu_std.h)
18+
target_link_libraries(async_gpu_std
19+
eic-opticks::G4CX
20+
eic-opticks::SysRap
21+
eic-opticks::U4
22+
${Geant4_LIBRARIES}
23+
Threads::Threads
24+
)
25+
26+
install(TARGETS async_gpu_std)

0 commit comments

Comments
 (0)