Skip to content

Commit 17df9df

Browse files
committed
add CompressorConfig and clean up builder interfaces
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 5d0d627 commit 17df9df

15 files changed

Lines changed: 108 additions & 154 deletions

File tree

fuzz/fuzz_targets/file_io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use vortex_array::dtype::StructFields;
1717
use vortex_array::expr::lit;
1818
use vortex_array::expr::root;
1919
use vortex_array::scalar_fn::fns::operators::Operator;
20+
use vortex_btrblocks::BtrBlocksCompressorBuilder;
2021
use vortex_buffer::ByteBufferMut;
2122
use vortex_error::VortexExpect;
2223
use vortex_error::vortex_panic;
@@ -59,12 +60,11 @@ fuzz_target!(|fuzz: FuzzFileAction| -> Corpus {
5960

6061
let write_options = match compressor_strategy {
6162
CompressorStrategy::Default => SESSION.write_options(),
62-
CompressorStrategy::Compact => {
63-
let strategy = WriteStrategyBuilder::default()
64-
.with_compact_encodings()
65-
.build();
66-
SESSION.write_options().with_strategy(strategy)
67-
}
63+
CompressorStrategy::Compact => SESSION.write_options().with_strategy(
64+
WriteStrategyBuilder::default()
65+
.with_btrblocks_builder(BtrBlocksCompressorBuilder::default().with_compact())
66+
.build(),
67+
),
6868
};
6969

7070
let mut full_buff = ByteBufferMut::empty();

vortex-bench/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use tpcds::TpcDsBenchmark;
2626
use tpch::benchmark::TpcHBenchmark;
2727
pub use utils::file::*;
2828
pub use utils::logging::*;
29+
use vortex::compressor::BtrBlocksCompressorBuilder;
2930
use vortex::error::VortexExpect;
3031
use vortex::error::vortex_err;
3132
use vortex::file::VortexWriteOptions;
@@ -231,7 +232,7 @@ impl CompactionStrategy {
231232
match self {
232233
CompactionStrategy::Compact => options.with_strategy(
233234
WriteStrategyBuilder::default()
234-
.with_compact_encodings()
235+
.with_btrblocks_builder(BtrBlocksCompressorBuilder::default().with_compact())
235236
.build(),
236237
),
237238
CompactionStrategy::Default => options,

vortex-btrblocks/public-api.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,13 @@ impl vortex_btrblocks::BtrBlocksCompressorBuilder
614614

615615
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::build(self) -> vortex_btrblocks::BtrBlocksCompressor
616616

617-
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::exclude(self, ids: impl core::iter::traits::collect::IntoIterator<Item = vortex_compressor::scheme::SchemeId>) -> Self
617+
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::exclude_schemes(self, ids: impl core::iter::traits::collect::IntoIterator<Item = vortex_compressor::scheme::SchemeId>) -> Self
618+
619+
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::only_cuda_compatible(self) -> Self
618620

619621
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::with_compact(self) -> Self
620622

621-
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::with_new_scheme(self, scheme: &'static dyn vortex_compressor::scheme::Scheme) -> Self
623+
pub fn vortex_btrblocks::BtrBlocksCompressorBuilder::with_scheme(self, scheme: &'static dyn vortex_compressor::scheme::Scheme) -> Self
622624

623625
impl core::clone::Clone for vortex_btrblocks::BtrBlocksCompressorBuilder
624626

vortex-btrblocks/src/builder.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub const ALL_SCHEMES: &[&dyn Scheme] = &[
6767
///
6868
/// By default, all schemes in [`ALL_SCHEMES`] are enabled. Feature-gated schemes (Pco, Zstd)
6969
/// are not in `ALL_SCHEMES` and must be added explicitly via
70-
/// [`with_new_scheme`](BtrBlocksCompressorBuilder::with_new_scheme) or
70+
/// [`with_scheme`](BtrBlocksCompressorBuilder::with_scheme) or
7171
/// [`with_compact`](BtrBlocksCompressorBuilder::with_compact).
7272
///
7373
/// # Examples
@@ -79,9 +79,9 @@ pub const ALL_SCHEMES: &[&dyn Scheme] = &[
7979
/// // Default compressor with all schemes in ALL_SCHEMES.
8080
/// let compressor = BtrBlocksCompressorBuilder::default().build();
8181
///
82-
/// // Exclude specific schemes.
82+
/// // Remove specific schemes.
8383
/// let compressor = BtrBlocksCompressorBuilder::default()
84-
/// .exclude([IntDictScheme.id()])
84+
/// .exclude_schemes([IntDictScheme.id()])
8585
/// .build();
8686
/// ```
8787
#[derive(Debug, Clone)]
@@ -100,13 +100,13 @@ impl Default for BtrBlocksCompressorBuilder {
100100
impl BtrBlocksCompressorBuilder {
101101
/// Adds an external compression scheme not in [`ALL_SCHEMES`].
102102
///
103-
/// This allows encoding crates outside of `vortex-btrblocks` to register their own schemes with
104-
/// the compressor.
103+
/// This allows encoding crates outside of `vortex-btrblocks` to register their own schemes
104+
/// with the compressor.
105105
///
106106
/// # Panics
107107
///
108108
/// Panics if a scheme with the same [`SchemeId`] is already present.
109-
pub fn with_new_scheme(mut self, scheme: &'static dyn Scheme) -> Self {
109+
pub fn with_scheme(mut self, scheme: &'static dyn Scheme) -> Self {
110110
assert!(
111111
!self.schemes.iter().any(|s| s.id() == scheme.id()),
112112
"scheme {:?} is already present in the builder",
@@ -128,19 +128,42 @@ impl BtrBlocksCompressorBuilder {
128128
/// Panics if any of the compact schemes are already present.
129129
#[cfg(feature = "zstd")]
130130
pub fn with_compact(self) -> Self {
131-
// This should be fast since we don't have that many schemes.
132-
let builder = self.with_new_scheme(&string::ZstdScheme);
131+
let builder = self.with_scheme(&string::ZstdScheme);
133132

134133
#[cfg(feature = "pco")]
135134
let builder = builder
136-
.with_new_scheme(&integer::PcoScheme)
137-
.with_new_scheme(&float::PcoScheme);
135+
.with_scheme(&integer::PcoScheme)
136+
.with_scheme(&float::PcoScheme);
138137

139138
builder
140139
}
141140

142-
/// Excludes the specified compression schemes by their [`SchemeId`].
143-
pub fn exclude(mut self, ids: impl IntoIterator<Item = SchemeId>) -> Self {
141+
/// Excludes schemes without CUDA kernel support and adds Zstd for string compression.
142+
///
143+
/// With the `unstable_encodings` feature, buffer-level Zstd compression is used which
144+
/// preserves the array buffer layout for zero-conversion GPU decompression. Without it,
145+
/// interleaved Zstd compression is used.
146+
#[cfg(feature = "zstd")]
147+
pub fn only_cuda_compatible(self) -> Self {
148+
let builder = self.exclude_schemes([
149+
integer::SparseScheme.id(),
150+
rle::RLE_INTEGER_SCHEME.id(),
151+
rle::RLE_FLOAT_SCHEME.id(),
152+
float::NullDominatedSparseScheme.id(),
153+
string::StringDictScheme.id(),
154+
string::FSSTScheme.id(),
155+
]);
156+
157+
#[cfg(feature = "unstable_encodings")]
158+
let builder = builder.with_scheme(&string::ZstdBuffersScheme);
159+
#[cfg(not(feature = "unstable_encodings"))]
160+
let builder = builder.with_scheme(&string::ZstdScheme);
161+
162+
builder
163+
}
164+
165+
/// Removes the specified compression schemes by their [`SchemeId`].
166+
pub fn exclude_schemes(mut self, ids: impl IntoIterator<Item = SchemeId>) -> Self {
144167
let ids: HashSet<_> = ids.into_iter().collect();
145168
self.schemes.retain(|s| !ids.contains(&s.id()));
146169
self

vortex-btrblocks/src/canonical_compressor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use crate::CascadingCompressor;
2525
/// // Default compressor - all schemes allowed.
2626
/// let compressor = BtrBlocksCompressor::default();
2727
///
28-
/// // Exclude specific schemes using the builder.
28+
/// // Remove specific schemes using the builder.
2929
/// let compressor = BtrBlocksCompressorBuilder::default()
30-
/// .exclude([IntDictScheme.id()])
30+
/// .exclude_schemes([IntDictScheme.id()])
3131
/// .build();
3232
/// ```
3333
#[derive(Clone)]

vortex-btrblocks/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
//! // Default compressor with all schemes enabled.
4747
//! let compressor = BtrBlocksCompressor::default();
4848
//!
49-
//! // Configure with builder to exclude specific schemes.
49+
//! // Remove specific schemes using the builder.
5050
//! let compressor = BtrBlocksCompressorBuilder::default()
51-
//! .exclude([IntDictScheme.id()])
51+
//! .exclude_schemes([IntDictScheme.id()])
5252
//! .build();
5353
//! ```
5454
//!

vortex-cuda/gpu-scan-cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use vortex::VortexSessionDefault;
2121
use vortex::array::ToCanonical;
2222
use vortex::array::arrays::Dict;
2323
use vortex::buffer::ByteBufferMut;
24+
use vortex::compressor::BtrBlocksCompressorBuilder;
2425
use vortex::error::VortexResult;
2526
use vortex::file::OpenOptionsSessionExt;
2627
use vortex::file::WriteOptionsSessionExt;
@@ -92,7 +93,7 @@ async fn main() -> VortexResult<()> {
9293
#[cuda_available]
9394
fn cuda_write_strategy() -> Arc<dyn vortex::layout::LayoutStrategy> {
9495
WriteStrategyBuilder::default()
95-
.with_cuda_compatible_encodings()
96+
.with_btrblocks(BtrBlocksCompressorBuilder::default().only_cuda_compatible())
9697
.with_flat_strategy(Arc::new(CudaFlatLayoutStrategy::default()))
9798
.build()
9899
}

vortex-file/public-api.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,10 @@ pub fn vortex_file::WriteStrategyBuilder::build(self) -> alloc::sync::Arc<dyn vo
346346

347347
pub fn vortex_file::WriteStrategyBuilder::with_allow_encodings(self, allow_encodings: vortex_array::session::ArrayRegistry) -> Self
348348

349-
pub fn vortex_file::WriteStrategyBuilder::with_compact_encodings(self) -> Self
349+
pub fn vortex_file::WriteStrategyBuilder::with_btrblocks_builder(self, builder: vortex_btrblocks::builder::BtrBlocksCompressorBuilder) -> Self
350350

351351
pub fn vortex_file::WriteStrategyBuilder::with_compressor<C: vortex_layout::layouts::compressed::CompressorPlugin>(self, compressor: C) -> Self
352352

353-
pub fn vortex_file::WriteStrategyBuilder::with_cuda_compatible_encodings(self) -> Self
354-
355353
pub fn vortex_file::WriteStrategyBuilder::with_field_writer(self, field: impl core::convert::Into<vortex_array::dtype::field::FieldPath>, writer: alloc::sync::Arc<dyn vortex_layout::strategy::LayoutStrategy>) -> Self
356354

357355
pub fn vortex_file::WriteStrategyBuilder::with_flat_strategy(self, flat: alloc::sync::Arc<dyn vortex_layout::strategy::LayoutStrategy>) -> Self

0 commit comments

Comments
 (0)