Skip to content

Commit c946da9

Browse files
committed
more compact benchmarks
Signed-off-by: Alexander Droste <alexander.droste@protonmail.com>
1 parent a3224e4 commit c946da9

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

vortex-cuda/benches/arrow_validity_cuda.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ unsafe fn release_arrow_device_array(array: &mut ArrowDeviceArray) {
5353
}
5454
}
5555

56+
async fn device_validity_buffer(
57+
len: usize,
58+
validity_offset: usize,
59+
ctx: &mut CudaExecutionCtx,
60+
) -> VortexResult<(usize, BufferHandle)> {
61+
let validity_bits = BitBuffer::collect_bool(len + validity_offset, |idx| idx % 3 != 0)
62+
.slice(validity_offset..validity_offset + len);
63+
let (validity_offset, _, validity_buffer) = validity_bits.into_inner();
64+
Ok((
65+
validity_offset,
66+
ctx.ensure_on_device(BufferHandle::new_host(validity_buffer))
67+
.await?,
68+
))
69+
}
70+
5671
async fn primitive_with_device_bool_validity(
5772
len: usize,
5873
validity_offset: usize,
@@ -63,12 +78,8 @@ async fn primitive_with_device_bool_validity(
6378
.ensure_on_device(BufferHandle::new_host(values.into_byte_buffer()))
6479
.await?;
6580

66-
let validity_bits = BitBuffer::collect_bool(len + validity_offset, |idx| idx % 3 != 0);
67-
let validity_bits = validity_bits.slice(validity_offset..validity_offset + len);
68-
let (validity_offset, _, validity_buffer) = validity_bits.into_inner();
69-
let validity_buffer = ctx
70-
.ensure_on_device(BufferHandle::new_host(validity_buffer))
71-
.await?;
81+
let (validity_offset, validity_buffer) =
82+
device_validity_buffer(len, validity_offset, ctx).await?;
7283
let validity =
7384
BoolArray::new_handle(validity_buffer, validity_offset, len, Validity::NonNullable)
7485
.into_array();
@@ -146,17 +157,12 @@ fn benchmark_arrow_validity_repack(c: &mut Criterion) {
146157
b.iter_custom(|iters| {
147158
let timed = TimedLaunchStrategy::default();
148159
let timer = timed.timer();
149-
150-
let mut cuda_ctx =
151-
CudaSession::create_execution_ctx(&vortex_cuda::cuda_session())
152-
.vortex_expect("failed to create execution context")
153-
.with_launch_strategy(Arc::new(timed));
154-
let source = BitBuffer::collect_bool(len + INPUT_OFFSET, |idx| idx % 3 != 0);
155-
let sliced = source.slice(INPUT_OFFSET..INPUT_OFFSET + len);
156-
let (input_offset, _, input_buffer) = sliced.into_inner();
157-
let input_buffer =
158-
block_on(cuda_ctx.ensure_on_device(BufferHandle::new_host(input_buffer)))
159-
.vortex_expect("failed to copy validity input to device");
160+
let mut cuda_ctx = CudaSession::create_execution_ctx(&VortexSession::empty())
161+
.vortex_expect("failed to create execution context")
162+
.with_launch_strategy(Arc::new(timed));
163+
let (input_offset, input_buffer) =
164+
block_on(device_validity_buffer(len, INPUT_OFFSET, &mut cuda_ctx))
165+
.vortex_expect("failed to create validity fixture");
160166

161167
for _ in 0..iters {
162168
let output = test_harness::repack_arrow_validity_buffer(
@@ -193,17 +199,12 @@ fn benchmark_arrow_validity_count_nulls(c: &mut Criterion) {
193199
b.iter_custom(|iters| {
194200
let timed = TimedLaunchStrategy::default();
195201
let timer = timed.timer();
196-
197202
let mut cuda_ctx = CudaSession::create_execution_ctx(&VortexSession::empty())
198203
.vortex_expect("failed to create execution context")
199204
.with_launch_strategy(Arc::new(timed));
200-
let source = BitBuffer::collect_bool(len + ARROW_OFFSET, |idx| {
201-
idx >= ARROW_OFFSET && idx % 3 != 0
202-
});
203-
let (_, _, input_buffer) = source.into_inner();
204-
let input_buffer =
205-
block_on(cuda_ctx.ensure_on_device(BufferHandle::new_host(input_buffer)))
206-
.vortex_expect("failed to copy validity input to device");
205+
let (_, input_buffer) =
206+
block_on(device_validity_buffer(len, ARROW_OFFSET, &mut cuda_ctx))
207+
.vortex_expect("failed to create validity fixture");
207208

208209
for _ in 0..iters {
209210
let null_count = test_harness::count_arrow_validity_nulls(

0 commit comments

Comments
 (0)