-
Notifications
You must be signed in to change notification settings - Fork 193
Optimize run-end decode kernel with chunked splat stores #8915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
joseph-isaacs
wants to merge
13
commits into
develop
Choose a base branch
from
claude/runend-decompression-perf-5yrfqs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dca76c3
Add primitive run-end decode benchmarks
claude eb8ccd9
Optimize run-end primitive decode with chunked splat stores
claude f4e48c5
Defeat per-run memset idiom in run-end splat with u128 word stores
claude 61d1604
Split run-end splat into byte and wide-element store paths
claude d94d33a
Apply rustfmt to run-end decode kernel
claude 2cf35ab
Randomize decode bench data, pin mimalloc, add differential decode test
claude 29767da
Dispatch long run-end fills to an out-of-line fill routine
claude 161c079
Make the first splat chunk unconditional in run-end decode
claude 2e0d546
Remove mimalloc global allocator from run-end decode benches
claude 6280ecf
Add distribution-sweep ablation for run-end decode
claude 345f8cd
Drop the byte word-splat from run-end decode; it was slower
claude 29f6883
Grow long run-end fills by doubling memcpy
claude 57175be
Fill byte-uniform long runs with memset
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Ablation benchmark: isolates each change to the run-end decode kernel so every change is | ||
| //! justified by its own numbers, all measured in one binary run over identical randomized | ||
| //! inputs at a spread of average run lengths. | ||
| //! | ||
| //! The intermediate kernels live in `shared/decode_variants.rs`; see that file for what each | ||
| //! stage (`v0`..`v3`, `n0`..`n3`) contains. For a sweep of the *data distributions* each | ||
| //! change is sensitive to (run length, element width, validity density) see | ||
| //! `run_end_decode_distribution`. | ||
|
|
||
| #![expect(clippy::cast_possible_truncation)] | ||
|
|
||
| use std::fmt; | ||
|
|
||
| use divan::Bencher; | ||
| use vortex_array::arrays::PrimitiveArray; | ||
| use vortex_array::dtype::NativePType; | ||
| use vortex_array::dtype::Nullability; | ||
| use vortex_buffer::Buffer; | ||
| use vortex_mask::Mask; | ||
| use vortex_runend::compress::runend_decode_typed_primitive; | ||
| use vortex_runend::trimmed_ends_iter; | ||
|
|
||
| #[path = "shared/decode_variants.rs"] | ||
| mod decode_variants; | ||
|
|
||
| use decode_variants::decode_n2; | ||
| use decode_variants::decode_v0; | ||
| use decode_variants::decode_v1; | ||
| use decode_variants::decode_v2; | ||
|
|
||
| fn main() { | ||
| divan::main(); | ||
| } | ||
|
|
||
| const SEED: u64 = 0x5eed; | ||
| const DENSITY: f64 = 0.9; | ||
|
|
||
| #[derive(Clone, Copy)] | ||
| struct Args { | ||
| total_length: usize, | ||
| avg_run_length: usize, | ||
| } | ||
|
|
||
| impl fmt::Display for Args { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{}_{}", self.total_length, self.avg_run_length) | ||
| } | ||
| } | ||
|
|
||
| const ARGS: &[Args] = &[ | ||
| Args { | ||
| total_length: 65_536, | ||
| avg_run_length: 2, | ||
| }, | ||
| Args { | ||
| total_length: 65_536, | ||
| avg_run_length: 8, | ||
| }, | ||
| Args { | ||
| total_length: 65_536, | ||
| avg_run_length: 64, | ||
| }, | ||
| Args { | ||
| total_length: 65_536, | ||
| avg_run_length: 1024, | ||
| }, | ||
| ]; | ||
|
|
||
| fn data<T: NativePType + From<u8>>( | ||
| args: Args, | ||
| ) -> (Buffer<u32>, Buffer<T>, vortex_buffer::BitBuffer) { | ||
| // Uniform 1..=(2*avg-1) has mean `avg`; matches the distribution bench's convention. | ||
| decode_variants::make_data::<T>( | ||
| SEED, | ||
| args.total_length, | ||
| 2 * args.avg_run_length - 1, | ||
| DENSITY, | ||
| ) | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn v0_original<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, _) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone())) | ||
| .bench_refs(|(ends, values)| { | ||
| let (buf, validity) = decode_v0( | ||
| trimmed_ends_iter(ends.as_slice(), 0, args.total_length), | ||
| values.as_slice(), | ||
| Mask::new_true(values.len()), | ||
| args.total_length, | ||
| ); | ||
| PrimitiveArray::new(buf, validity) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn v1_slice_loop<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, _) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone())) | ||
| .bench_refs(|(ends, values)| { | ||
| let (buf, validity) = decode_v1(ends.as_slice(), values.as_slice(), args.total_length); | ||
| PrimitiveArray::new(buf, validity) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn v2_chunk_stores<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, _) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone())) | ||
| .bench_refs(|(ends, values)| { | ||
| let (buf, validity) = decode_v2(ends.as_slice(), values.as_slice(), args.total_length); | ||
| PrimitiveArray::new(buf, validity) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn v3_shipped<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, _) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone())) | ||
| .bench_refs(|(ends, values)| { | ||
| runend_decode_typed_primitive( | ||
| ends.as_slice(), | ||
| 0, | ||
| values.as_slice(), | ||
| Mask::new_true(values.len()), | ||
| Nullability::NonNullable, | ||
| args.total_length, | ||
| ) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn n0_original<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, run_validity) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone(), run_validity.clone())) | ||
| .bench_refs(|(ends, values, run_validity)| { | ||
| let (buf, validity) = decode_v0( | ||
| trimmed_ends_iter(ends.as_slice(), 0, args.total_length), | ||
| values.as_slice(), | ||
| Mask::from_buffer(run_validity.clone()), | ||
| args.total_length, | ||
| ); | ||
| PrimitiveArray::new(buf, validity) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn n2_chunk_stores<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, run_validity) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone(), run_validity.clone())) | ||
| .bench_refs(|(ends, values, run_validity)| { | ||
| let (buf, validity) = decode_n2( | ||
| ends.as_slice(), | ||
| values.as_slice(), | ||
| run_validity, | ||
| args.total_length, | ||
| ); | ||
| PrimitiveArray::new(buf, validity) | ||
| }); | ||
| } | ||
|
|
||
| #[divan::bench(types = [u8, u32, u64], args = ARGS)] | ||
| fn n3_shipped<T: NativePType + From<u8>>(bencher: Bencher, args: Args) { | ||
| let (ends, values, run_validity) = data::<T>(args); | ||
| bencher | ||
| .with_inputs(|| (ends.clone(), values.clone(), run_validity.clone())) | ||
| .bench_refs(|(ends, values, run_validity)| { | ||
| runend_decode_typed_primitive( | ||
| ends.as_slice(), | ||
| 0, | ||
| values.as_slice(), | ||
| Mask::from_buffer(run_validity.clone()), | ||
| Nullability::Nullable, | ||
| args.total_length, | ||
| ) | ||
| }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this method now trimmed_ends_iter