Skip to content

Commit 6bcb083

Browse files
committed
Add single-stream CUDA benchmark fast path
Signed-off-by: Joe Isaacs <2413449+joseph-isaacs@users.noreply.github.com>
1 parent a441e7b commit 6bcb083

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

benchmarks/compress-bench/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use vortex::utils::aliases::hash_map::HashMap;
2525
use vortex_bench::Engine;
2626
use vortex_bench::Format;
2727
use vortex_bench::LogFormat;
28+
#[cfg(feature = "cuda")]
29+
use vortex_bench::SESSION;
2830
use vortex_bench::Target;
2931
use vortex_bench::compress::CompressMeasurements;
3032
use vortex_bench::compress::CompressOp;
@@ -52,6 +54,8 @@ use vortex_bench::public_bi::PBIDataset::Food;
5254
use vortex_bench::public_bi::PBIDataset::HashTags;
5355
use vortex_bench::setup_logging_and_tracing_with_format;
5456
use vortex_bench::v3;
57+
#[cfg(feature = "cuda")]
58+
use vortex_cuda::CudaSession;
5559

5660
#[derive(Parser, Debug)]
5761
#[command(version, about, long_about = None)]
@@ -130,6 +134,11 @@ async fn main() -> anyhow::Result<()> {
130134
direct_io: args.gpu_direct_io,
131135
});
132136

137+
#[cfg(feature = "cuda")]
138+
if gpu.is_some() {
139+
SESSION.register(CudaSession::try_single_stream()?);
140+
}
141+
133142
let (formats, ops) = if gpu.is_some() {
134143
(
135144
vec![Format::Parquet, Format::OnDiskVortex],

vortex-cuda/src/session.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ impl CudaSession {
114114
}
115115
}
116116

117+
/// Creates a single-stream CUDA session using device 0, with event tracking disabled.
118+
///
119+
/// Every execution context created from this session shares the same stream. This avoids
120+
/// cudarc's per-buffer events, which are only needed to synchronize buffer use across streams.
121+
pub fn try_single_stream() -> VortexResult<Self> {
122+
// cudarc panics rather than returning an error when the CUDA driver library cannot be
123+
// loaded, so catch any unwind here to uphold this constructor's no-panic contract.
124+
match catch_unwind(AssertUnwindSafe(|| -> VortexResult<Self> {
125+
let context = CudaContext::new(0)
126+
.map_err(|err| vortex_err!("failed to initialize CUDA device 0: {err}"))?;
127+
// SAFETY: this context is private to a session whose pool contains exactly one stream,
128+
// and event tracking is disabled before any device buffers can be allocated.
129+
unsafe { context.disable_event_tracking() };
130+
let this = Self::with_stream_pool_capacity(context, 1);
131+
initialize_cuda(&this);
132+
Ok(this)
133+
})) {
134+
Ok(result) => result,
135+
Err(_) => Err(vortex_err!(
136+
"failed to initialize CUDA: the driver library is unavailable"
137+
)),
138+
}
139+
}
140+
117141
/// Creates a new CUDA execution context.
118142
pub fn create_execution_ctx(
119143
vortex_session: &vortex::session::VortexSession,

0 commit comments

Comments
 (0)