-
Notifications
You must be signed in to change notification settings - Fork 211
Pack Boolean RowFn output directly #9620
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| #![expect( | ||
| clippy::cast_possible_truncation, | ||
| reason = "benchmark fixtures reduce values below 1024 before narrowing" | ||
| )] | ||
|
|
||
| use std::marker::PhantomData; | ||
| use std::sync::LazyLock; | ||
|
|
||
| use divan::Bencher; | ||
| use divan::counter::ItemsCount; | ||
| use mimalloc::MiMalloc; | ||
| use vortex_array::ArrayRef; | ||
| use vortex_array::IntoArray; | ||
| use vortex_array::VortexSessionExecute; | ||
| use vortex_array::array_session; | ||
| use vortex_array::arrays::ConstantArray; | ||
| use vortex_array::arrays::PrimitiveArray; | ||
| use vortex_array::dtype::DType; | ||
| use vortex_array::dtype::NativePType; | ||
| use vortex_array::scalar_fn::EmptyOptions; | ||
| use vortex_array::scalar_fn::ScalarFnId; | ||
| use vortex_array::scalar_fn::VecExecutionArgs; | ||
| use vortex_array::scalar_fn::unstable::row::RowFn; | ||
| use vortex_array::scalar_fn::unstable::row::RowVisitor; | ||
| use vortex_array::scalar_fn::unstable::row::execute_rows; | ||
| use vortex_error::VortexExpect; | ||
| use vortex_error::VortexResult; | ||
| use vortex_session::VortexSession; | ||
| use vortex_session::registry::CachedId; | ||
|
|
||
| #[global_allocator] | ||
| static GLOBAL: MiMalloc = MiMalloc; | ||
|
|
||
| fn main() { | ||
| LazyLock::force(&SESSION); | ||
| divan::main(); | ||
| } | ||
|
|
||
| static SESSION: LazyLock<VortexSession> = LazyLock::new(array_session); | ||
|
|
||
| const ROWS: usize = 1 << 14; | ||
|
|
||
| const INPUT_SHAPES: &[InputShape] = &[ | ||
| InputShape::PerRowPerRow, | ||
| InputShape::PerRowConstant, | ||
| InputShape::ConstantPerRow, | ||
| ]; | ||
|
|
||
| #[derive(Clone, Copy, Debug)] | ||
| enum InputShape { | ||
| PerRowPerRow, | ||
| PerRowConstant, | ||
| ConstantPerRow, | ||
| } | ||
|
|
||
| trait BenchPrimitive: NativePType { | ||
| fn per_row(offset: usize) -> ArrayRef; | ||
|
|
||
| fn constant() -> ArrayRef; | ||
| } | ||
|
|
||
| impl BenchPrimitive for i32 { | ||
| fn per_row(offset: usize) -> ArrayRef { | ||
| PrimitiveArray::from_iter((0..ROWS).map(|index| ((index + offset) % 1024) as i32)) | ||
| .into_array() | ||
| } | ||
|
|
||
| fn constant() -> ArrayRef { | ||
| ConstantArray::new(512_i32, ROWS).into_array() | ||
| } | ||
| } | ||
|
|
||
| impl BenchPrimitive for i64 { | ||
| fn per_row(offset: usize) -> ArrayRef { | ||
| PrimitiveArray::from_iter((0..ROWS).map(|index| ((index + offset) % 1024) as i64)) | ||
| .into_array() | ||
| } | ||
|
|
||
| fn constant() -> ArrayRef { | ||
| ConstantArray::new(512_i64, ROWS).into_array() | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| struct InfallibleBool<T>(PhantomData<T>); | ||
|
|
||
| impl<T: BenchPrimitive> RowFn for InfallibleBool<T> { | ||
| type Options = EmptyOptions; | ||
|
|
||
| const ARG_NAMES: &'static [&'static str] = &["lhs", "rhs"]; | ||
| const INFALLIBLE: bool = true; | ||
|
|
||
| fn id(&self) -> ScalarFnId { | ||
| static ID: CachedId = CachedId::new("bench.row_fn_output.infallible_bool"); | ||
| *ID | ||
| } | ||
|
|
||
| fn dispatch<V: RowVisitor>( | ||
| &self, | ||
| _options: &Self::Options, | ||
| _args: &[DType], | ||
| visitor: V, | ||
| ) -> VortexResult<V::VisitResult> { | ||
| visitor.visit::<(T, T), bool>(|(lhs, rhs)| lhs.is_lt(rhs)) | ||
| } | ||
| } | ||
|
|
||
| #[vortex_bench_support::cpu_features] | ||
| #[divan::bench(types = [i32, i64], args = INPUT_SHAPES)] | ||
| fn infallible_bool<T: BenchPrimitive>(bencher: Bencher, &shape: &InputShape) { | ||
| let function = InfallibleBool::<T>(PhantomData); | ||
| let args = match shape { | ||
| InputShape::PerRowPerRow => vec![T::per_row(0), T::per_row(1)], | ||
| InputShape::PerRowConstant => vec![T::per_row(0), T::constant()], | ||
| InputShape::ConstantPerRow => vec![T::constant(), T::per_row(1)], | ||
| }; | ||
| let args = VecExecutionArgs::new(args, ROWS); | ||
|
|
||
| bencher | ||
| .counter(ItemsCount::new(ROWS)) | ||
| .with_inputs(|| (&args, SESSION.create_execution_ctx())) | ||
| .bench_refs(|(args, ctx)| { | ||
| execute_rows(&function, &EmptyOptions, *args, ctx) | ||
| .vortex_expect("row execution should succeed in benchmark") | ||
| }); | ||
| } | ||
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
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.
can you explain these
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.
its just the args shape? I feel like its pretty clear...