33
44pub mod allocation;
55mod bind;
6- mod input;
76mod toposort;
87
9- use std:: any:: Any ;
108use std:: hash:: { BuildHasher , Hash , Hasher } ;
119
12- use crate :: pipeline:: bit_view:: { BitView , BitViewExt } ;
13- use crate :: pipeline:: driver:: allocation:: { allocate_vectors, OutputTarget } ;
14- use crate :: pipeline:: driver:: bind:: bind_kernels;
15- use crate :: pipeline:: driver:: toposort:: topological_sort;
16- use crate :: pipeline:: { ElementPosition , Kernel , KernelCtx , PipelineInputs , PipelineVector , N } ;
17- use crate :: { Array , ArrayEq , ArrayHash , ArrayOperator , ArrayRef , ArrayVisitor , Precision } ;
1810use itertools:: Itertools ;
19- use vortex_dtype:: { DType , NativePType } ;
20- use vortex_error:: { vortex_bail , VortexExpect , VortexResult } ;
11+ use vortex_dtype:: DType ;
12+ use vortex_error:: { VortexResult , vortex_bail } ;
2113use vortex_mask:: Mask ;
2214use vortex_utils:: aliases:: hash_map:: { HashMap , RandomState } ;
2315use vortex_vector:: { Vector , VectorMut , VectorMutOps } ;
2416
17+ use crate :: pipeline:: bit_view:: { BitView , BitViewExt } ;
18+ use crate :: pipeline:: driver:: allocation:: { OutputTarget , allocate_vectors} ;
19+ use crate :: pipeline:: driver:: bind:: bind_kernels;
20+ use crate :: pipeline:: driver:: toposort:: topological_sort;
21+ use crate :: pipeline:: { ElementPosition , Kernel , KernelCtx , N , PipelineInputs , PipelineVector } ;
22+ use crate :: { Array , ArrayEq , ArrayHash , ArrayOperator , ArrayRef , ArrayVisitor , Precision } ;
23+
2524/// A pipeline driver takes a Vortex array and executes it into a canonical vector.
2625///
2726/// The driver builds up a DAG of pipeline nodes from the array tree up to the edges of this
@@ -50,6 +49,7 @@ struct Node {
5049 // This node's underlying array.
5150 array : ArrayRef ,
5251 /// The type of pipeline node.
52+ #[ allow( dead_code) ] // TODO(ngates): pipeline execute does not yet use this
5353 kind : NodeKind ,
5454 // The indices of the pipelined children nodes in the `nodes` vector.
5555 children : Vec < NodeId > ,
@@ -68,8 +68,8 @@ enum NodeKind {
6868 /// A source node provides input to the pipeline by writing into mutable output vectors one
6969 /// batch at a time.
7070 Source ,
71+ /// A transform node takes pipelined inputs from its children and produces output vectors
7172 Transform ,
72- Zip ,
7373}
7474
7575impl PipelineDriver {
@@ -247,21 +247,21 @@ impl Pipeline {
247247 // The number of _full_ chunks we need to process.
248248 let nchunks = selection. len ( ) / N ;
249249 for _ in 0 ..nchunks {
250- self . step ( & mut self . ctx , & BitView :: all_true ( ) , & mut output) ?;
250+ self . step ( & BitView :: all_true ( ) , & mut output) ?;
251251 }
252252
253253 // Now process the final partial chunk, if any.
254254 let remaining = selection. len ( ) % N ;
255255 if remaining > 0 {
256256 let selection_view = BitView :: with_prefix ( remaining) ;
257- self . step ( & mut self . ctx , & selection_view, & mut output) ?;
257+ self . step ( & selection_view, & mut output) ?;
258258 }
259259 }
260260 Mask :: Values ( mask_values) => {
261261 // Loop over each chunk of N elements in the mask as a bit view.
262262 let selection_bits = mask_values. bit_buffer ( ) ;
263263 for selection_view in selection_bits. iter_bit_views ( ) {
264- self . step ( & mut self . ctx , & selection_view, & mut output) ?;
264+ self . step ( & selection_view, & mut output) ?;
265265 }
266266 }
267267 }
@@ -270,12 +270,7 @@ impl Pipeline {
270270 }
271271
272272 /// Perform a single step of the pipeline.
273- fn step (
274- & self ,
275- ctx : & mut KernelCtx ,
276- selection : & BitView ,
277- output : & mut VectorMut ,
278- ) -> VortexResult < ( ) > {
273+ fn step ( & mut self , selection : & BitView , output : & mut VectorMut ) -> VortexResult < ( ) > {
279274 // Loop over the kernels in toposorted execution order
280275 for & node_idx in self . exec_order . iter ( ) {
281276 let kernel = & mut self . kernels [ node_idx] ;
@@ -284,12 +279,12 @@ impl Pipeline {
284279 // take the intermediate vector and write into that.
285280 match & self . output_targets [ node_idx] {
286281 OutputTarget :: ExternalOutput => {
287- let output_len = output. len ( ) ;
288- let position = kernel. step ( ctx, selection, output) ?;
289- if output. len ( ) != output_len + N {
282+ let prev_output_len = output. len ( ) ;
283+ let position = kernel. step ( & self . ctx , selection, output) ?;
284+ if output. len ( ) != prev_output_len + N {
290285 vortex_bail ! (
291286 "Kernel produced incorrect number of output elements, expected {}, got {}" ,
292- output_len + N ,
287+ prev_output_len + N ,
293288 output. len( )
294289 ) ;
295290 }
@@ -304,16 +299,15 @@ impl Pipeline {
304299 ElementPosition :: Compact => {
305300 // The output is already compacted, we just need to adjust the length
306301 // to cover only the selected elements.
307- assert ! ( selection. true_count( ) <= N ) ;
308- unsafe { output. set_len ( output_len + selection. true_count ( ) ) }
302+ output. truncate ( prev_output_len + selection. true_count ( ) ) ;
309303 }
310304 }
311305 }
312306 OutputTarget :: IntermediateVector ( vector_id) => {
313- let mut out_vector = VectorMut :: from ( ctx. take_output ( vector_id) ) ;
307+ let mut out_vector = VectorMut :: from ( self . ctx . take_output ( vector_id) ) ;
314308 out_vector. clear ( ) ;
315309
316- let position = kernel. step ( ctx, selection, & mut out_vector) ?;
310+ let position = kernel. step ( & self . ctx , selection, & mut out_vector) ?;
317311 if out_vector. len ( ) != N {
318312 vortex_bail ! (
319313 "Kernel produced incorrect number of output elements, expected {}, got {}" ,
@@ -325,7 +319,7 @@ impl Pipeline {
325319 // Wrap the output vector back into a PipelineVector, indicating which position
326320 // the elements are in.
327321 let out_vector = PipelineVector :: from_position ( position, out_vector) ;
328- ctx. replace_output ( vector_id, out_vector)
322+ self . ctx . replace_output ( vector_id, out_vector)
329323 }
330324 } ;
331325 }
0 commit comments