MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
GpuAccel.cpp
Go to the documentation of this file.
1#include "GpuAccel.hpp"
2
4Bool_t g_available = kFALSE;
5Bool_t g_initialized = kFALSE;
6std::mutex g_sort_mutex;
7Int_t g_sort_active = 0;
8
9Bool_t GpuAccel::Init() {
10 if (g_initialized)
11 return g_available;
12 g_initialized = kTRUE;
13
14 if (!Constants::cfg.USE_GPU_ACCELERATION)
15 return kFALSE;
16
17 // Absolute path to the tooling GPU lib, injected at build by the Makefile
18 // (it lives with the tooling, not the dataset). Falls back to a bare name
19 // resolved via LD_LIBRARY_PATH if the macro is somehow undefined.
20#ifndef MUSIC_GPU_LIB
21#define MUSIC_GPU_LIB "libgpuaccel.so"
22#endif
23 void *lib = dlopen(MUSIC_GPU_LIB, RTLD_LAZY);
24 if (!lib) {
25 std::cerr << "[GPU] Library not found, using CPU fallback: " << dlerror()
26 << std::endl;
27 return kFALSE;
28 }
29
30 g_sort = (GpuAccel::SortFunc)dlsym(lib, "gpu_sort_hits_by_timestamp");
31 g_available = (g_sort != nullptr) ? kTRUE : kFALSE;
32
33 if (g_available)
34 std::cout << "[GPU] Acceleration loaded successfully." << std::endl;
35 else
36 std::cerr << "[GPU] Symbols missing, using CPU fallback." << std::endl;
37
38 return g_available;
39}
40
41Bool_t GpuAccel::Available() { return g_available; }
42
44
46 std::lock_guard<std::mutex> lk(g_sort_mutex);
47 if (g_sort_active >= Constants::cfg.MAX_GPU_CONCURRENT_SORTS)
48 return kFALSE;
50 return kTRUE;
51}
52
54 std::lock_guard<std::mutex> lk(g_sort_mutex);
56}
Bool_t g_initialized
Definition GpuAccel.cpp:5
Int_t g_sort_active
Definition GpuAccel.cpp:7
Bool_t g_available
Definition GpuAccel.cpp:4
std::mutex g_sort_mutex
Definition GpuAccel.cpp:6
#define MUSIC_GPU_LIB
GpuAccel::SortFunc g_sort
Definition GpuAccel.cpp:3
static Bool_t TryAcquireSortSlot()
Claim one of the concurrent GPU sort slots.
Definition GpuAccel.cpp:45
static Bool_t Init()
Load the GPU library and resolve the sort symbol.
Definition GpuAccel.cpp:9
static void ReleaseSortSlot()
Give back a slot claimed by TryAcquireSortSlot().
Definition GpuAccel.cpp:53
static SortFunc GetSort()
The resolved sort entry point.
Definition GpuAccel.cpp:43
int(* SortFunc)(void *, long long)
Signature of the sort entry point: buffer, element count, status.
Definition GpuAccel.hpp:24
static Bool_t Available()
Whether the kernel loaded successfully.
Definition GpuAccel.cpp:41
const DatasetConfig & cfg
The active dataset's configuration, flat block.