MUSIC
unknown
Analysis for the MUSIC active-target ionization chamber
Toggle main menu visibility
Loading...
Searching...
No Matches
GpuAccel.cpp
Go to the documentation of this file.
1
#include "
GpuAccel.hpp
"
2
3
GpuAccel::SortFunc
g_sort
=
nullptr
;
4
Bool_t
g_available
= kFALSE;
5
Bool_t
g_initialized
= kFALSE;
6
std::mutex
g_sort_mutex
;
7
Int_t
g_sort_active
= 0;
8
9
Bool_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
41
Bool_t
GpuAccel::Available
() {
return
g_available
; }
42
43
GpuAccel::SortFunc
GpuAccel::GetSort
() {
return
g_sort
; }
44
45
Bool_t
GpuAccel::TryAcquireSortSlot
() {
46
std::lock_guard<std::mutex> lk(
g_sort_mutex
);
47
if
(
g_sort_active
>=
Constants::cfg
.MAX_GPU_CONCURRENT_SORTS)
48
return
kFALSE;
49
g_sort_active
++;
50
return
kTRUE;
51
}
52
53
void
GpuAccel::ReleaseSortSlot
() {
54
std::lock_guard<std::mutex> lk(
g_sort_mutex
);
55
g_sort_active
--;
56
}
g_initialized
Bool_t g_initialized
Definition
GpuAccel.cpp:5
g_sort_active
Int_t g_sort_active
Definition
GpuAccel.cpp:7
g_available
Bool_t g_available
Definition
GpuAccel.cpp:4
g_sort_mutex
std::mutex g_sort_mutex
Definition
GpuAccel.cpp:6
MUSIC_GPU_LIB
#define MUSIC_GPU_LIB
g_sort
GpuAccel::SortFunc g_sort
Definition
GpuAccel.cpp:3
GpuAccel.hpp
GpuAccel::TryAcquireSortSlot
static Bool_t TryAcquireSortSlot()
Claim one of the concurrent GPU sort slots.
Definition
GpuAccel.cpp:45
GpuAccel::Init
static Bool_t Init()
Load the GPU library and resolve the sort symbol.
Definition
GpuAccel.cpp:9
GpuAccel::ReleaseSortSlot
static void ReleaseSortSlot()
Give back a slot claimed by TryAcquireSortSlot().
Definition
GpuAccel.cpp:53
GpuAccel::GetSort
static SortFunc GetSort()
The resolved sort entry point.
Definition
GpuAccel.cpp:43
GpuAccel::SortFunc
int(* SortFunc)(void *, long long)
Signature of the sort entry point: buffer, element count, status.
Definition
GpuAccel.hpp:24
GpuAccel::Available
static Bool_t Available()
Whether the kernel loaded successfully.
Definition
GpuAccel.cpp:41
Constants::cfg
const DatasetConfig & cfg
The active dataset's configuration, flat block.
tooling
src
GpuAccel.cpp
Generated by
1.17.0