Skip to content

Commit 8bc0df8

Browse files
authored
Fix: handle validity in bitpack pipeline kernel (#5330)
Forgot to handle this before --------- Signed-off-by: Connor Tsui <[email protected]>
1 parent 6e49a95 commit 8bc0df8

File tree

5 files changed

+246
-141
lines changed

5 files changed

+246
-141
lines changed

encodings/fastlanes/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ harness = false
8484
test = false
8585

8686
[[bench]]
87-
name = "pipeline_bitpacking_kernel"
87+
name = "pipeline_rle"
8888
harness = false
8989
test = false
9090

9191
[[bench]]
92-
name = "pipeline_rle"
92+
name = "pipeline_v2_bitpacking_basic"
9393
harness = false
9494
test = false

encodings/fastlanes/benches/pipeline_bitpacking_kernel.rs

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
#![allow(clippy::unwrap_used)]
5+
#![allow(unexpected_cfgs)]
6+
7+
use divan::Bencher;
8+
use mimalloc::MiMalloc;
9+
use rand::prelude::StdRng;
10+
use rand::{Rng, SeedableRng};
11+
use vortex_array::arrays::PrimitiveArray;
12+
use vortex_fastlanes::BitPackedArray;
13+
14+
#[global_allocator]
15+
static GLOBAL: MiMalloc = MiMalloc;
16+
17+
pub fn main() {
18+
divan::main();
19+
}
20+
21+
// Cross product of NUM_ELEMENTS and VALIDITY_PCT.
22+
const BENCH_PARAMS: &[(usize, f64)] = &[
23+
(1_000, 0.5),
24+
(1_000, 1.0),
25+
(10_000, 0.5),
26+
(10_000, 1.0),
27+
(100_000, 0.5),
28+
(100_000, 1.0),
29+
(1_000_000, 0.5),
30+
(1_000_000, 1.0),
31+
(10_000_000, 0.5),
32+
(10_000_000, 1.0),
33+
];
34+
35+
#[divan::bench(args = BENCH_PARAMS)]
36+
fn bitpack_pipeline_unpack(bencher: Bencher, (num_elements, validity_pct): (usize, f64)) {
37+
bencher
38+
.with_inputs(|| {
39+
let mut rng = StdRng::seed_from_u64(42);
40+
41+
// Create array with randomized validity.
42+
// Keep values small enough to fit in the bit width (0-1023 for 10 bits).
43+
let values = (0..num_elements).map(|_| {
44+
let is_valid = rng.random_bool(validity_pct);
45+
is_valid.then(|| rng.random_range(0u32..1024))
46+
});
47+
48+
let primitive = PrimitiveArray::from_option_iter(values).to_array();
49+
50+
// Encode with 10-bit width (supports values up to 1023).
51+
let bitpacked = BitPackedArray::encode(&primitive, 10).unwrap();
52+
53+
bitpacked.to_array()
54+
})
55+
.bench_local_values(|array| array.execute().unwrap());
56+
}
57+
58+
#[divan::bench(args = BENCH_PARAMS)]
59+
fn bitpack_canonical_unpack(bencher: Bencher, (num_elements, validity_pct): (usize, f64)) {
60+
bencher
61+
.with_inputs(|| {
62+
let mut rng = StdRng::seed_from_u64(42);
63+
64+
// Create array with randomized validity.
65+
// Keep values small enough to fit in the bit width (0-1023 for 10 bits).
66+
let values = (0..num_elements).map(|_| {
67+
let is_valid = rng.random_bool(validity_pct);
68+
is_valid.then(|| rng.random_range(0u32..1024))
69+
});
70+
71+
let primitive = PrimitiveArray::from_option_iter(values).to_array();
72+
73+
// Encode with 10-bit width (supports values up to 1023).
74+
let bitpacked = BitPackedArray::encode(&primitive, 10).unwrap();
75+
76+
bitpacked.to_array()
77+
})
78+
.bench_local_values(|array| array.to_canonical());
79+
}

0 commit comments

Comments
 (0)