Skip to content

Commit a6e9cd3

Browse files
committed
views
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent ede8ae7 commit a6e9cd3

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

vortex-file/benches/bench_read.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
#![allow(clippy::unwrap_used)]
55

66
use std::fs::File;
7+
use std::mem;
78
use std::sync::Arc;
89

910
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
1011
use cudarc::cufile::Cufile;
11-
use cudarc::driver::{CudaContext, CudaSlice, CudaStream};
12+
use cudarc::driver::{CudaContext, CudaSlice, CudaStream, CudaView};
1213
use futures::TryStreamExt;
1314
use rand::prelude::IteratorRandom;
1415
use rand::{Rng, rng};
@@ -89,6 +90,10 @@ fn benchmark_gpu_scan(c: &mut Criterion) {
8990
let file = File::open(bench_file_name).unwrap();
9091

9192
let file_device_slice = read_file_to_device(&cuda_ctx.default_stream(), file);
93+
// SAFETY: This is only fine because the callers of this function will be dropped before this segment source is dropped
94+
let device_view = unsafe {
95+
mem::transmute::<CudaView<'_, u8>, CudaView<'static, u8>>(file_device_slice.as_view())
96+
};
9297

9398
group.throughput(Throughput::Bytes((len * size_of::<u32>() * 2) as u64));
9499
group.bench_function(*label, |b| {
@@ -102,7 +107,7 @@ fn benchmark_gpu_scan(c: &mut Criterion) {
102107
cuda_ctx.clone(),
103108
Arc::new(FileGpuSegmentSource::new(
104109
vx_file.footer.segment_map().clone(),
105-
file_device_slice.clone(),
110+
device_view,
106111
)),
107112
)
108113
.vortex_unwrap()
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use std::mem;
54
use std::sync::Arc;
65

7-
use cudarc::driver::{CudaSlice, CudaView};
6+
use cudarc::driver::CudaView;
87
use vortex_error::VortexExpect;
98
use vortex_layout::segments::{GpuSegmentFuture, GpuSegmentSource, SegmentId};
109

1110
use crate::SegmentSpec;
1211

1312
pub struct FileGpuSegmentSource {
1413
segments: Arc<[SegmentSpec]>,
15-
contents: CudaSlice<u8>,
14+
contents: CudaView<'static, u8>,
1615
}
1716

1817
impl FileGpuSegmentSource {
19-
pub fn new(segments: Arc<[SegmentSpec]>, contents: CudaSlice<u8>) -> Self {
18+
pub fn new(segments: Arc<[SegmentSpec]>, contents: CudaView<'static, u8>) -> Self {
2019
FileGpuSegmentSource { segments, contents }
2120
}
22-
23-
#[inline]
24-
fn contents(&self) -> CudaView<'static, u8> {
25-
// SAFETY: This is only fine because the callers of this function will be dropped before this segment source is dropped
26-
unsafe {
27-
mem::transmute::<CudaView<'_, u8>, CudaView<'static, u8>>(self.contents.as_view())
28-
}
29-
}
3021
}
3122

3223
impl GpuSegmentSource for FileGpuSegmentSource {
@@ -40,6 +31,6 @@ impl GpuSegmentSource for FileGpuSegmentSource {
4031
let off_usize = usize::try_from(spec.offset).vortex_expect("offset must fit usize");
4132
let len_usize = usize::try_from(spec.length).vortex_expect("length must fit usize");
4233

43-
Ok(self.contents().slice(off_usize..(off_usize + len_usize)))
34+
Ok(self.contents.slice(off_usize..(off_usize + len_usize)))
4435
}
4536
}

0 commit comments

Comments
 (0)