-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathmain.rs
More file actions
208 lines (177 loc) · 6.22 KB
/
main.rs
File metadata and controls
208 lines (177 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#![allow(unused_imports)]
use std::fs::File;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Instant;
use clap::Parser;
use futures::StreamExt;
use object_store::aws::AmazonS3Builder;
use object_store::path::Path as ObjectPath;
use tracing::Instrument;
use tracing_perfetto::PerfettoLayer;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::Layer;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use url::Url;
use vortex::VortexSessionDefault;
use vortex::error::VortexResult;
use vortex::error::vortex_bail;
use vortex::file::OpenOptionsSessionExt;
use vortex::io::session::RuntimeSessionExt;
use vortex::session::VortexSession;
use vortex_cuda::CudaSession;
use vortex_cuda::PinnedByteBufferPool;
use vortex_cuda::PooledFileReadAt;
use vortex_cuda::PooledObjectStoreReadAt;
use vortex_cuda::TracingLaunchStrategy;
use vortex_cuda::VortexCudaStreamPool;
use vortex_cuda::executor::CudaArrayExt;
use vortex_cuda::layout::register_cuda_layout;
use vortex_cuda_macros::cuda_available;
use vortex_cuda_macros::cuda_not_available;
#[derive(Parser)]
#[command(
name = "gpu-scan-bench",
about = "Benchmark GPU scans of CUDA-compatible Vortex files from S3 or local storage"
)]
struct Cli {
/// S3 URI (s3://bucket/path) or local path to a CUDA-compatible .vortex file.
source: String,
/// Number of scan iterations.
#[arg(long, default_value_t = 1)]
iterations: usize,
/// Path to write Perfetto trace output. If omitted, no trace file is written.
#[arg(long)]
perfetto: Option<PathBuf>,
/// Output logs as JSON.
#[arg(long)]
json: bool,
}
#[cuda_not_available]
fn main() {}
#[cuda_available]
#[tokio::main]
async fn main() -> VortexResult<()> {
let cli = Cli::parse();
// Setup tracing
let perfetto_guard = if let Some(ref perfetto_path) = cli.perfetto {
let perfetto_file = File::create(perfetto_path)?;
Some(PerfettoLayer::new(perfetto_file).with_debug_annotations(true))
} else {
None
};
if cli.json {
let log_layer = tracing_subscriber::fmt::layer()
.json()
.with_span_events(FmtSpan::NONE)
.with_ansi(false);
let mut registry = tracing_subscriber::registry()
.with(log_layer.with_filter(EnvFilter::from_default_env()));
if let Some(perfetto) = perfetto_guard {
registry.with(perfetto).init();
} else {
registry.init();
}
} else {
let log_layer = tracing_subscriber::fmt::layer()
.pretty()
.with_span_events(FmtSpan::NONE)
.with_ansi(false)
.event_format(tracing_subscriber::fmt::format().with_target(true));
let mut registry = tracing_subscriber::registry()
.with(log_layer.with_filter(EnvFilter::from_default_env()));
if let Some(perfetto) = perfetto_guard {
registry.with(perfetto).init();
} else {
registry.init();
}
}
let session = VortexSession::default();
register_cuda_layout(&session);
let mut cuda_ctx = CudaSession::create_execution_ctx(&session)?
.with_launch_strategy(Arc::new(TracingLaunchStrategy));
let pool = Arc::new(PinnedByteBufferPool::new(Arc::clone(
cuda_ctx.stream().context(),
)));
let cuda_stream =
VortexCudaStreamPool::new(Arc::clone(cuda_ctx.stream().context()), 1).get_stream()?;
let handle = session.handle();
// Parse source and create reader
let reader: Arc<dyn vortex::io::VortexReadAt> = if cli.source.starts_with("s3://") {
let url = Url::parse(&cli.source)?;
let bucket = url
.host_str()
.ok_or_else(|| vortex::error::vortex_err!("S3 URL missing bucket name"))?;
let path = ObjectPath::from(url.path());
let store: Arc<dyn object_store::ObjectStore> = Arc::new(
AmazonS3Builder::from_env()
.with_bucket_name(bucket)
.build()?,
);
Arc::new(PooledObjectStoreReadAt::new(
store,
path,
handle,
Arc::clone(&pool),
cuda_stream,
))
} else {
let path = PathBuf::from(&cli.source);
Arc::new(PooledFileReadAt::open(
&path,
handle,
Arc::clone(&pool),
cuda_stream,
)?)
};
// Run benchmark iterations
let mut iteration_times = Vec::with_capacity(cli.iterations);
for iteration in 0..cli.iterations {
let start = Instant::now();
let gpu_file = session.open_options().open(Arc::clone(&reader)).await?;
let mut batches = gpu_file.scan()?.into_array_stream()?;
let mut chunk = 0;
while let Some(next) = batches.next().await.transpose()? {
let len = next.len();
let span = tracing::info_span!(
"batch execution",
iteration = iteration,
chunk = chunk,
len = len,
);
async {
next.execute_cuda(&mut cuda_ctx).await?;
VortexResult::Ok(())
}
.instrument(span)
.await?;
chunk += 1;
}
let elapsed = start.elapsed();
iteration_times.push(elapsed);
tracing::info!(
"Iteration {}/{}: {:.3}s",
iteration + 1,
cli.iterations,
elapsed.as_secs_f64()
);
}
// Print summary
let total: std::time::Duration = iteration_times.iter().sum();
let avg = total / iteration_times.len() as u32;
// Get file size for throughput
let file_size = reader.size().await?;
let throughput_mbs = (file_size as f64 / (1024.0 * 1024.0)) / avg.as_secs_f64();
eprintln!();
eprintln!("=== Benchmark Results ===");
eprintln!("Source: {}", cli.source);
eprintln!("Iterations: {}", cli.iterations);
eprintln!("Avg time: {:.3}s", avg.as_secs_f64());
eprintln!("File size: {:.2} MB", file_size as f64 / (1024.0 * 1024.0));
eprintln!("Throughput: {throughput_mbs:.2} MB/s");
Ok(())
}