|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 3 | + |
| 4 | +#![allow(clippy::unwrap_used)] |
| 5 | + |
| 6 | +use std::sync::Arc; |
| 7 | + |
| 8 | +use criterion::{Criterion, Throughput, criterion_group, criterion_main}; |
| 9 | +use cudarc::driver::CudaContext; |
| 10 | +use futures::TryStreamExt; |
| 11 | +use tokio::runtime::Runtime; |
| 12 | +use vortex_array::arrays::{ChunkedArray, StructArray}; |
| 13 | +use vortex_array::{ArrayRef, IntoArray}; |
| 14 | +use vortex_buffer::Buffer; |
| 15 | +use vortex_error::VortexUnwrap; |
| 16 | +use vortex_file::{FileGpuSegmentSource, VortexOpenOptions, VortexWriteOptions}; |
| 17 | + |
| 18 | +// Data sizes: 1GB, 2.5GB, 5GB, 10GB |
| 19 | +// These are approximate sizes in bytes, accounting for bit-packing compression |
| 20 | +const DATA_SIZES: &[(usize, &str)] = &[ |
| 21 | + (268_435_456, "1GB"), // ~1GB when unpacked (268M * 4 bytes) |
| 22 | +]; |
| 23 | + |
| 24 | +#[allow(clippy::cast_possible_truncation)] |
| 25 | +fn make_test_array(len: usize) -> ArrayRef { |
| 26 | + let numbers = ChunkedArray::from_iter([ |
| 27 | + (0..len / 2) |
| 28 | + .map(|i| (i as u32) % 64) |
| 29 | + .collect::<Buffer<u32>>() |
| 30 | + .into_array(), |
| 31 | + (0..len / 2) |
| 32 | + .map(|i| (i as u32) % 64) |
| 33 | + .collect::<Buffer<u32>>() |
| 34 | + .into_array(), |
| 35 | + ]) |
| 36 | + .into_array(); |
| 37 | + let floats = ChunkedArray::from_iter([ |
| 38 | + (0..len / 2) |
| 39 | + .map(|i| (i % 2) as f32 + 0.1) |
| 40 | + .collect::<Buffer<f32>>() |
| 41 | + .into_array(), |
| 42 | + (0..len / 2) |
| 43 | + .map(|i| (i % 2) as f32 + 4.1) |
| 44 | + .collect::<Buffer<f32>>() |
| 45 | + .into_array(), |
| 46 | + ]) |
| 47 | + .into_array(); |
| 48 | + |
| 49 | + StructArray::from_fields(&[("numbers", numbers), ("floats", floats)]) |
| 50 | + .vortex_unwrap() |
| 51 | + .into_array() |
| 52 | +} |
| 53 | + |
| 54 | +fn benchmark_gpu_scan(c: &mut Criterion) { |
| 55 | + let runtime = Runtime::new().unwrap(); |
| 56 | + let mut group = c.benchmark_group("gpu_scan"); |
| 57 | + |
| 58 | + group.sample_size(10); |
| 59 | + let bench_file_name = "/tmp/test-vx/bench_out.vortex"; |
| 60 | + |
| 61 | + for (len, label) in DATA_SIZES { |
| 62 | + let len = len.next_multiple_of(1024); |
| 63 | + let array = make_test_array(len); |
| 64 | + |
| 65 | + runtime.block_on(async { |
| 66 | + VortexWriteOptions::default() |
| 67 | + .write( |
| 68 | + tokio::fs::File::create(bench_file_name).await.unwrap(), |
| 69 | + array.to_array_stream(), |
| 70 | + ) |
| 71 | + .await |
| 72 | + .unwrap(); |
| 73 | + }); |
| 74 | + |
| 75 | + let cuda_ctx = CudaContext::new(0).unwrap(); |
| 76 | + cuda_ctx.set_blocking_synchronize().unwrap(); |
| 77 | + group.throughput(Throughput::Bytes((len * size_of::<u32>() * 2) as u64)); |
| 78 | + group.bench_function(*label, |b| { |
| 79 | + b.to_async(&runtime).iter_with_large_drop(async || { |
| 80 | + let file = std::fs::File::open(bench_file_name).unwrap(); |
| 81 | + let vx_file = VortexOpenOptions::new() |
| 82 | + .open(bench_file_name) |
| 83 | + .await |
| 84 | + .vortex_unwrap(); |
| 85 | + let stream = vx_file |
| 86 | + .gpu_scan( |
| 87 | + cuda_ctx.clone(), |
| 88 | + Arc::new(FileGpuSegmentSource::new( |
| 89 | + vx_file.footer.segment_map().clone(), |
| 90 | + cuda_ctx.default_stream(), |
| 91 | + file, |
| 92 | + )), |
| 93 | + ) |
| 94 | + .vortex_unwrap() |
| 95 | + .into_array_stream() |
| 96 | + .vortex_unwrap() |
| 97 | + .try_collect::<Vec<_>>() |
| 98 | + .await |
| 99 | + .vortex_unwrap(); |
| 100 | + stream |
| 101 | + |
| 102 | + // VortexOpenOptions::new() |
| 103 | + // .open(bench_file_name) |
| 104 | + // .await |
| 105 | + // .vortex_unwrap() |
| 106 | + // .gpu_scan(ctx.clone()) |
| 107 | + // .vortex_unwrap() |
| 108 | + // .into_array_stream() |
| 109 | + // .vortex_unwrap() |
| 110 | + // .try_collect::<Vec<_>>() |
| 111 | + // .await |
| 112 | + // .vortex_unwrap() |
| 113 | + }); |
| 114 | + }); |
| 115 | + } |
| 116 | + |
| 117 | + group.finish(); |
| 118 | +} |
| 119 | + |
| 120 | +criterion_group!(benches, benchmark_gpu_scan); |
| 121 | + |
| 122 | +criterion_main!(benches); |
0 commit comments