-
Notifications
You must be signed in to change notification settings - Fork 204
Implement RowFn row execution #9353
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7e7c83
Implement RowFn row execution
connortsui20 eb4a7c0
Refine RowFn row execution
connortsui20 8e5e171
address review comments
connortsui20 6f16c60
Address remaining RowFn review comments
connortsui20 d65a9da
final touches
connortsui20 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Row-loop execution for owned outputs and output sinks. | ||
| //! | ||
| //! [`owned`] stores one independent value per row and reduces compact failure evidence. [`sink`] | ||
| //! drives output builders whose row handles may share batch state. Both return [`RowExecution`], | ||
| //! which distinguishes a completed array from a deferred error that batch validity may suppress. | ||
|
|
||
| mod owned; | ||
| pub(super) use owned::execute_owned; | ||
| pub(super) use owned::execute_owned_infallible; | ||
|
|
||
| mod outcome; | ||
| pub use outcome::RowExecution; | ||
|
|
||
| mod sink; | ||
| pub(super) use sink::execute_sink; | ||
| pub(super) use sink::execute_sink_valid_rows; |
43 changes: 43 additions & 0 deletions
43
vortex-array/src/scalar_fn/unstable/row/execute/outcome.rs
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,43 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! The result of a completed row loop before batch-level null handling. | ||
| //! | ||
| //! [`RowExecution`] preserves deferred failure evidence until batch execution can determine whether | ||
| //! the failing payload belonged to a valid row. | ||
|
|
||
| use vortex_error::VortexError; | ||
| use vortex_error::VortexResult; | ||
|
|
||
| use crate::ArrayRef; | ||
|
|
||
| /// The outcome of a row loop before batch execution decides whether an error is observable. | ||
| /// | ||
| /// Together with the surrounding [`VortexResult`], this represents three outcomes: | ||
| /// | ||
| /// - `Err(error)` is a non-retryable execution or immediate row error. | ||
| /// - [`Output`](Self::Output) is a successful row loop. | ||
| /// - [`DeferredError`](Self::DeferredError) is failure evidence from a completed row loop. | ||
| /// | ||
| /// A dense loop can evaluate null payloads, so its deferred error is not always observable. Batch | ||
| /// execution can retry only valid rows to discard errors caused by null payloads. A plain | ||
| /// `VortexResult<ArrayRef>` cannot distinguish these errors from failures that a retry cannot fix. | ||
| /// | ||
| /// Once execution is known to contain only valid rows, converting this outcome into a | ||
| /// `VortexResult<ArrayRef>` turns [`DeferredError`](Self::DeferredError) into an ordinary error. | ||
| pub enum RowExecution { | ||
| /// The successfully built, full-length output column. | ||
| Output(ArrayRef), | ||
|
|
||
| /// An error constructed from failure evidence reduced across a completed row loop. | ||
| DeferredError(VortexError), | ||
| } | ||
|
|
||
| impl From<RowExecution> for VortexResult<ArrayRef> { | ||
| fn from(execution: RowExecution) -> Self { | ||
| match execution { | ||
| RowExecution::Output(output) => Ok(output), | ||
| RowExecution::DeferredError(error) => Err(error), | ||
| } | ||
| } | ||
| } |
123 changes: 123 additions & 0 deletions
123
vortex-array/src/scalar_fn/unstable/row/execute/owned.rs
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,123 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Executes row kernels that return one independent owned value per row. | ||
| //! | ||
| //! [`execute_owned`] decodes inputs once, prepares constant state, writes into spare vector | ||
| //! capacity, and reduces compact failure evidence without putting error construction in the hot | ||
| //! loop. [`execute_owned_infallible`] removes that failure path for infallible kernels. | ||
|
|
||
| use std::ops::BitOrAssign; | ||
|
|
||
| use vortex_compute::lane_kernels::IndexedSourceExt; | ||
| use vortex_error::VortexResult; | ||
| use vortex_error::vortex_ensure; | ||
|
|
||
| use super::RowExecution; | ||
| use crate::ExecutionCtx; | ||
| use crate::scalar_fn::ExecutionArgs; | ||
| use crate::scalar_fn::unstable::row::FailureEvidence; | ||
| use crate::scalar_fn::unstable::row::IndexedElementTuple; | ||
| use crate::scalar_fn::unstable::row::OutputElement; | ||
| use crate::scalar_fn::unstable::row::ViewLen; | ||
| use crate::scalar_fn::unstable::row::visitor::assert_owned_output_needs_no_drop; | ||
|
|
||
| /// Zero-sized failure accumulator for infallible owned visits. | ||
| #[derive(Clone, Copy, Default)] | ||
| struct NoFailure; | ||
|
|
||
| impl BitOrAssign for NoFailure { | ||
| fn bitor_assign(&mut self, _rhs: Self) {} | ||
| } | ||
|
|
||
| /// Decode every input column, then store one output per row from an infallible kernel. | ||
| pub(crate) fn execute_owned_infallible<Args, Out, Prepared>( | ||
| args: &dyn ExecutionArgs, | ||
| ctx: &mut ExecutionCtx, | ||
| prepare: impl FnOnce(Args::ConstElems<'_>) -> Prepared, | ||
| apply: impl Fn(&Prepared, Args::Elems<'_>) -> Out, | ||
| ) -> VortexResult<RowExecution> | ||
| where | ||
| Args: IndexedElementTuple, | ||
| Out: OutputElement, | ||
| { | ||
| execute_owned::<Args, Out, Prepared, NoFailure>( | ||
| args, | ||
| ctx, | ||
| prepare, | ||
| move |prepared, args| (apply(prepared, args), NoFailure), | ||
| |_| Ok(()), | ||
| ) | ||
| } | ||
|
|
||
| /// Decode every input column, then store outputs and combine per-row failure evidence. | ||
| pub(crate) fn execute_owned<Args, Out, Prepared, Fail>( | ||
| args: &dyn ExecutionArgs, | ||
| ctx: &mut ExecutionCtx, | ||
| prepare: impl FnOnce(Args::ConstElems<'_>) -> Prepared, | ||
| apply: impl Fn(&Prepared, Args::Elems<'_>) -> (Out, Fail), | ||
| finish_failure: impl FnOnce(Fail) -> VortexResult<()>, | ||
| ) -> VortexResult<RowExecution> | ||
| where | ||
| Args: IndexedElementTuple, | ||
| Out: OutputElement, | ||
| Fail: FailureEvidence, | ||
| { | ||
| // The output vector stays at length zero until every slot is initialized so that an unwind | ||
| // abandons partially initialized spare capacity. This no-drop assertion proves that no | ||
| // initialized value requires a destructor to run. | ||
| const { assert_owned_output_needs_no_drop::<Out>() }; | ||
|
|
||
| let columns = Args::decode(args, ctx)?; | ||
| let prepared = prepare(Args::const_values(&columns)); | ||
|
|
||
| let row_count = args.row_count(); | ||
| let mut values = Vec::<Out>::with_capacity(row_count); | ||
| let output = &mut values.spare_capacity_mut()[..row_count]; | ||
|
|
||
| let failure = if let Some(views) = Args::views_if_no_consts(&columns) { | ||
| // Keep this validation beside the views so LLVM sees their common length here. | ||
| vortex_ensure!( | ||
| Args::ARITY == 0 || views.len() == row_count, | ||
| "a decoded row input does not address exactly {row_count} rows", | ||
| ); | ||
|
|
||
| // SAFETY: the tuple length check proved every non-nullary view addresses exactly | ||
| // `row_count` rows immediately above. Nullary tuples do not access an input view. | ||
| let source = unsafe { Args::indexed_source(views, row_count) }; | ||
|
|
||
| source.map_checked_into(output, |elements| apply(&prepared, elements)) | ||
| } else { | ||
| // Keep this proof branch-local. Shared validation prevents LLVM from specializing this | ||
| // loop for each batch-constant arrangement, leaving it scalar under multiple CGUs without | ||
| // LTO. | ||
| vortex_ensure!( | ||
| Args::decoded_lens_match(&columns, row_count), | ||
| "a decoded row input does not address exactly {row_count} rows", | ||
| ); | ||
|
|
||
| let mut accumulated = Fail::default(); | ||
|
|
||
| // Iterate over `output` directly. A `0..row_count` range reuses the address-taken value | ||
| // from the validation error formatter and retains an output bounds check. | ||
| for (index, slot) in output.iter_mut().enumerate() { | ||
| // LLVM unswitches the batch-constant checks in `Args::get` before vectorizing the loop. | ||
| let (value, row_failure) = apply(&prepared, Args::get(&columns, index)); | ||
|
|
||
| slot.write(value); | ||
| accumulated |= row_failure; | ||
| } | ||
|
|
||
| accumulated | ||
| }; | ||
|
|
||
| // SAFETY: normal completion of either execution path initializes `0..row_count` exactly | ||
| // once, and `values` was allocated with at least `row_count` capacity. | ||
| unsafe { values.set_len(row_count) }; | ||
|
|
||
| // Defer failures so batch execution can retry with only valid rows. | ||
| match finish_failure(failure) { | ||
| Ok(()) => Ok(RowExecution::Output(Out::build(values))), | ||
| Err(error) => Ok(RowExecution::DeferredError(error)), | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.