Skip to content

Commit

Permalink
FastLanes bitpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Mar 2, 2024
1 parent 3468a6c commit e99feaf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fastlanez-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
println!("cargo:rustc-link-lib=fastlanez");

rerun_if_changed(&buildrs_dir.join("build.rs"));
WalkDir::new(&fastlanez_dir.join("src"))
WalkDir::new(fastlanez_dir.join("src"))
.into_iter()
.filter_map(|e| e.ok())
.for_each(|e| rerun_if_changed(e.path()));
Expand Down
4 changes: 2 additions & 2 deletions fastlanez-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::mem::{size_of, MaybeUninit};
use std::mem::{MaybeUninit, size_of};

use arrayref::array_mut_ref;
use seq_macro::seq;
Expand Down Expand Up @@ -58,7 +58,7 @@ where
output: &'a mut [MaybeUninit<u8>],
) -> Result<&'a [u8], UnsupportedBitWidth>;

fn try_bitpack_into<'a>(
fn try_bitpack_into(
input: &[Self; 1024],
width: u8,
output: &mut Vec<u8>,
Expand Down
10 changes: 5 additions & 5 deletions vortex-fastlanes/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use arrayref::array_ref;
use log::debug;

use fastlanez_sys::TryBitPack;
use vortex::array::{Array, ArrayRef};
use vortex::array::downcast::DowncastArrayBuiltin;
use vortex::array::primitive::PrimitiveArray;
use vortex::array::{Array, ArrayRef};
use vortex::compress::{CompressConfig, CompressCtx, Compressor, EncodingCompression};
use vortex::ptype::{NativePType, PType};
use vortex::scalar::ListScalarVec;
Expand Down Expand Up @@ -109,7 +109,7 @@ where
let mut output = Vec::with_capacity(num_chunks * bit_width * 128);

// Loop over all but the last chunk.
(0..num_chunks - 1).into_iter().for_each(|i| {
(0..num_chunks - 1).for_each(|i| {
let start_elem = i * 1024;
let chunk: &[T; 1024] = array_ref![array, start_elem, 1024];
TryBitPack::try_bitpack_into(chunk, bit_width as u8, &mut output).unwrap();
Expand All @@ -130,7 +130,7 @@ fn bitpack_patches(_parray: &PrimitiveArray, _bit_width: u8) -> ArrayRef {

/// Assuming exceptions cost 1 value + 1 u32 index, figure out the best bit-width to use.
/// We could try to be clever, but we can never really predict how the exceptions will compress.
fn best_bit_width(ptype: &PType, bit_width_freq: &Vec<usize>) -> u8 {
fn best_bit_width(ptype: &PType, bit_width_freq: &[usize]) -> u8 {
let len: usize = bit_width_freq.iter().sum();
let bytes_per_exception = ptype.byte_width() + 4;

Expand All @@ -155,16 +155,16 @@ fn best_bit_width(ptype: &PType, bit_width_freq: &Vec<usize>) -> u8 {
best_width as u8
}

fn num_exceptions(bit_width: u8, bit_width_freq: &Vec<usize>) -> usize {
fn num_exceptions(bit_width: u8, bit_width_freq: &[usize]) -> usize {
bit_width_freq[(bit_width + 1) as usize..].iter().sum()
}

#[cfg(test)]
mod test {
use std::collections::HashSet;

use vortex::array::primitive::PrimitiveEncoding;
use vortex::array::Encoding;
use vortex::array::primitive::PrimitiveEncoding;

use super::*;

Expand Down

0 comments on commit e99feaf

Please sign in to comment.