Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion vortex-cuda/src/kernel/encodings/bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ where
let device_patches = if let Some(patches) = patches {
let mut device_patches = load_device_patches(&patches, ctx).await?;
if let Some(range) = patch_range {
slice_device_patches(&patches, range, &mut device_patches);
slice_device_patches(range, &mut device_patches).await?;
}
Some(device_patches)
} else {
Expand Down Expand Up @@ -243,6 +243,7 @@ mod tests {
use rstest::rstest;
use vortex::array::IntoArray;
use vortex::array::arrays::PrimitiveArray;
use vortex::array::arrays::slice::SliceKernel;
use vortex::array::assert_arrays_eq;
use vortex::array::dtype::NativePType;
use vortex::array::optimizer::ArrayOptimizer;
Expand Down Expand Up @@ -785,4 +786,66 @@ mod tests {

Ok(())
}

/// Decode a lazy slice of a BitPacked array whose patches were already sliced on the CPU,
/// exercising `load_device_patches` + `slice_device_patches` end to end on CUDA.
#[rstest]
#[case::same_chunk_nonzero_within(100..3000, 150..800)]
#[case::cross_chunk_nonzero_base_and_within(1200..4500, 1000..2200)]
#[case::cross_chunk_aligned_boundary(1200..4500, 848..1872)]
#[crate::test]
fn test_cuda_bitunpack_gpu_slice_of_cpu_sliced_patches(
#[case] cpu_range: Range<usize>,
#[case] gpu_range: Range<usize>,
) -> VortexResult<()> {
let mut ctx = SESSION.create_execution_ctx();
let mut cuda_ctx = CudaSession::create_execution_ctx(&crate::cuda_session())
.vortex_expect("failed to create execution context");

let patch_positions = [
50usize, 200, 900, 1050, 1500, 1900, 2100, 2600, 3100, 4100, 4900,
];
let values: Buffer<u32> = (0u32..5120)
.map(|i| {
if patch_positions.contains(&(i as usize)) {
1000 + i
} else {
i % 512
}
})
.collect();
let bitpacked = BitPacked::encode(
&PrimitiveArray::new(values, NonNullable).into_array(),
9,
&mut ctx,
)?;

// First slice pushed into BitPacked on CPU so its Patches have nonzero offset / base.
let cpu_sliced =
<BitPacked as SliceKernel>::slice(bitpacked.as_view(), cpu_range, &mut ctx)?
.vortex_expect("BitPacked SliceKernel should slice patched array");
let cpu_bp = cpu_sliced.as_::<BitPacked>();
let cpu_patches = cpu_bp
.patches()
.vortex_expect("CPU-sliced BitPacked should retain patches");
assert!(cpu_patches.offset() > 0);
assert!(cpu_patches.offset_within_chunk().unwrap_or_default() > 0);

// Second slice stays lazy so BitPackedExecutor routes it through slice_device_patches.
let gpu_sliced = cpu_sliced.slice(gpu_range)?;

let gpu_result = block_on(async {
BitPackedExecutor
.execute(gpu_sliced.clone(), &mut cuda_ctx)
.await
.vortex_expect("GPU decompression failed")
.into_host(cuda_ctx.execution_ctx())
.await
.map(|a| a.into_array())
})?;

assert_arrays_eq!(gpu_result, gpu_sliced, &mut ctx);

Ok(())
}
}
Loading
Loading