Skip to content

Commit 30ebc09

Browse files
committed
Merge develop
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 85e79fb commit 30ebc09

File tree

35 files changed

+374
-373
lines changed

35 files changed

+374
-373
lines changed

encodings/alp/src/alp/array.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ impl VTable for ALPVTable {
140140
)
141141
}
142142

143-
fn batch_execute(array: &ALPArray, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
144-
let encoded_vector = array.encoded().batch_execute(ctx)?;
143+
fn bind_kernel(array: &ALPArray, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
144+
let encoded_vector = array.encoded().bind_kernel(ctx)?;
145145

146146
let patches_vectors = if let Some(patches) = array.patches() {
147147
Some((
148-
patches.indices().batch_execute(ctx)?,
149-
patches.values().batch_execute(ctx)?,
148+
patches.indices().bind_kernel(ctx)?,
149+
patches.values().bind_kernel(ctx)?,
150150
patches
151151
.chunk_offsets()
152152
.as_ref()
153-
.map(|co| co.batch_execute(ctx))
153+
.map(|co| co.bind_kernel(ctx))
154154
.transpose()?,
155155
))
156156
} else {

encodings/fastlanes/src/bitpacking/vtable/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl VTable for BitPackedVTable {
172172
)
173173
}
174174

175-
fn batch_execute(array: &BitPackedArray, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
175+
fn bind_kernel(array: &BitPackedArray, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
176176
Ok(unpack_to_primitive_vector(array).freeze().into())
177177
}
178178
}

encodings/sequence/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl VTable for SequenceVTable {
268268
))
269269
}
270270

271-
fn batch_execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
271+
fn bind_kernel(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
272272
Ok(match_each_native_ptype!(array.ptype(), |P| {
273273
let base = array.base().cast::<P>();
274274
let multiplier = array.multiplier().cast::<P>();

vortex-array/src/array/mod.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ use crate::expr::stats::Precision;
5555
use crate::expr::stats::Stat;
5656
use crate::expr::stats::StatsProviderExt;
5757
use crate::hash;
58+
use crate::kernel::KernelRef;
59+
use crate::kernel::ValidateKernel;
5860
use crate::serde::ArrayChildren;
5961
use crate::stats::StatsSetRef;
6062
use crate::vtable::ArrayId;
@@ -194,7 +196,7 @@ pub trait Array:
194196
-> VortexResult<Option<Output>>;
195197

196198
/// Invoke the batch execution function for the array to produce a canonical vector.
197-
fn batch_execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector>;
199+
fn bind_kernel(&self, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef>;
198200
}
199201

200202
impl Array for Arc<dyn Array> {
@@ -302,8 +304,8 @@ impl Array for Arc<dyn Array> {
302304
self.as_ref().invoke(compute_fn, args)
303305
}
304306

305-
fn batch_execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
306-
self.as_ref().batch_execute(ctx)
307+
fn bind_kernel(&self, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
308+
self.as_ref().bind_kernel(ctx)
307309
}
308310
}
309311

@@ -377,7 +379,11 @@ impl dyn Array + '_ {
377379
pub fn execute(&self, session: &VortexSession) -> VortexResult<Vector> {
378380
let mut ctx = ExecutionCtx::new(session.clone());
379381

380-
let result = self.batch_execute(&mut ctx)?;
382+
// NOTE(ngates): in the future we can choose a different mode of execution, or run
383+
// optimization here, etc.
384+
let kernel = self.bind_kernel(&mut ctx)?;
385+
let result = kernel.execute()?;
386+
381387
vortex_ensure!(
382388
result.len() == self.len(),
383389
"Result length mismatch for {}",
@@ -698,18 +704,17 @@ impl<V: VTable> Array for ArrayAdapter<V> {
698704
<V::ComputeVTable as ComputeVTable<V>>::invoke(&self.0, compute_fn, args)
699705
}
700706

701-
fn batch_execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
702-
let result = V::batch_execute(&self.0, ctx)?;
703-
704-
// This check is so cheap we always run it. Whereas DType checks we only do in debug builds.
705-
vortex_ensure!(result.len() == self.len(), "Result length mismatch");
706-
#[cfg(debug_assertions)]
707-
vortex_ensure!(
708-
vortex_vector::vector_matches_dtype(&result, self.dtype()),
709-
"Executed vector dtype mismatch",
710-
);
711-
712-
Ok(result)
707+
fn bind_kernel(&self, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
708+
let kernel = V::bind_kernel(&self.0, ctx)?;
709+
if cfg!(debug_assertions) {
710+
Ok(Box::new(ValidateKernel::new(
711+
kernel,
712+
self.dtype().clone(),
713+
self.len(),
714+
)))
715+
} else {
716+
Ok(kernel)
717+
}
713718
}
714719
}
715720

vortex-array/src/arrays/bool/vtable/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use vortex_dtype::DType;
66
use vortex_error::VortexExpect;
77
use vortex_error::VortexResult;
88
use vortex_error::vortex_bail;
9-
use vortex_vector::Vector;
109
use vortex_vector::bool::BoolVector;
1110

1211
use crate::DeserializeMetadata;
@@ -31,6 +30,8 @@ mod visitor;
3130

3231
pub use operator::BoolMaskedValidityRule;
3332

33+
use crate::kernel::KernelRef;
34+
use crate::kernel::ready;
3435
use crate::vtable::ArrayId;
3536
use crate::vtable::ArrayVTable;
3637

@@ -106,8 +107,10 @@ impl VTable for BoolVTable {
106107
BoolArray::try_new(buffer, metadata.offset as usize, len, validity)
107108
}
108109

109-
fn batch_execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
110-
Ok(BoolVector::new(array.bit_buffer().clone(), array.validity_mask()).into())
110+
fn bind_kernel(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
111+
Ok(ready(
112+
BoolVector::new(array.bit_buffer().clone(), array.validity_mask()).into(),
113+
))
111114
}
112115
}
113116

vortex-array/src/arrays/chunked/vtable/mod.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::ToCanonical;
1818
use crate::arrays::ChunkedArray;
1919
use crate::arrays::PrimitiveArray;
2020
use crate::execution::ExecutionCtx;
21+
use crate::kernel::Kernel;
22+
use crate::kernel::KernelRef;
2123
use crate::serde::ArrayChildren;
2224
use crate::validity::Validity;
2325
use crate::vtable;
@@ -36,6 +38,9 @@ mod visitor;
3638

3739
vtable!(Chunked);
3840

41+
#[derive(Debug)]
42+
pub struct ChunkedVTable;
43+
3944
impl VTable for ChunkedVTable {
4045
type Array = ChunkedArray;
4146

@@ -125,15 +130,31 @@ impl VTable for ChunkedVTable {
125130
})
126131
}
127132

128-
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
129-
let mut vector = VectorMut::with_capacity(array.dtype(), 0);
130-
for chunk in array.chunks() {
131-
let chunk_vector = chunk.batch_execute(ctx)?;
133+
fn bind_kernel(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
134+
Ok(Box::new(ChunkedKernel {
135+
chunks: array
136+
.chunks
137+
.iter()
138+
.map(|c| c.bind_kernel(ctx))
139+
.try_collect()?,
140+
dtype: array.dtype.clone(),
141+
}))
142+
}
143+
}
144+
145+
#[derive(Debug)]
146+
struct ChunkedKernel {
147+
chunks: Vec<KernelRef>,
148+
dtype: DType,
149+
}
150+
151+
impl Kernel for ChunkedKernel {
152+
fn execute(self: Box<Self>) -> VortexResult<Vector> {
153+
let mut vector = VectorMut::with_capacity(&self.dtype, 0);
154+
for chunk in self.chunks {
155+
let chunk_vector = chunk.execute()?;
132156
vector.extend_from_vector(&chunk_vector);
133157
}
134158
Ok(vector.freeze())
135159
}
136160
}
137-
138-
#[derive(Debug)]
139-
pub struct ChunkedVTable;

vortex-array/src/arrays/constant/vtable/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ use vortex_error::vortex_bail;
88
use vortex_scalar::Scalar;
99
use vortex_scalar::ScalarValue;
1010
use vortex_vector::ScalarOps;
11-
use vortex_vector::Vector;
1211
use vortex_vector::VectorMutOps;
1312

1413
use crate::EmptyMetadata;
1514
use crate::arrays::ConstantArray;
1615
use crate::execution::ExecutionCtx;
16+
use crate::kernel::KernelRef;
17+
use crate::kernel::kernel;
1718
use crate::serde::ArrayChildren;
1819
use crate::vtable;
1920
use crate::vtable::ArrayId;
@@ -85,11 +86,9 @@ impl VTable for ConstantVTable {
8586
Ok(ConstantArray::new(scalar, len))
8687
}
8788

88-
fn batch_execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
89-
Ok(array
90-
.scalar()
91-
.to_vector_scalar()
92-
.repeat(array.len())
93-
.freeze())
89+
fn bind_kernel(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
90+
let scalar = array.scalar().to_vector_scalar();
91+
let len = array.len();
92+
Ok(kernel(move || Ok(scalar.clone().repeat(len).freeze())))
9493
}
9594
}

vortex-array/src/arrays/decimal/vtable/mod.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use vortex_error::VortexResult;
1313
use vortex_error::vortex_bail;
1414
use vortex_error::vortex_ensure;
1515
use vortex_scalar::DecimalType;
16-
use vortex_vector::Vector;
1716
use vortex_vector::decimal::DVector;
1817

1918
use crate::DeserializeMetadata;
@@ -38,6 +37,8 @@ mod visitor;
3837

3938
pub use operator::DecimalMaskedValidityRule;
4039

40+
use crate::kernel::KernelRef;
41+
use crate::kernel::kernel;
4142
use crate::vtable::ArrayId;
4243
use crate::vtable::ArrayVTable;
4344

@@ -124,31 +125,38 @@ impl VTable for DecimalVTable {
124125
})
125126
}
126127

127-
fn batch_execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
128+
fn bind_kernel(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
128129
use vortex_dtype::BigCast;
129130

130131
match_each_decimal_value_type!(array.values_type(), |D| {
131132
// TODO(ngates): we probably shouldn't convert here... Do we allow larger P/S for a
132133
// given physical type, because we know that our values actually fit?
133134
let min_value_type = DecimalType::smallest_decimal_value_type(&array.decimal_dtype());
134135
match_each_decimal_value_type!(min_value_type, |E| {
135-
// Copy from D to E, possibly widening, possibly narrowing
136-
let values = Buffer::<E>::from_trusted_len_iter(
137-
array
138-
.buffer::<D>()
139-
.iter()
140-
.map(|d| <E as BigCast>::from(*d).vortex_expect("Decimal cast failed")),
141-
);
142-
143-
Ok(unsafe {
144-
DVector::<E>::new_unchecked(
145-
// TODO(ngates): this is too small?
146-
PrecisionScale::new_unchecked(array.precision(), array.scale()),
147-
values,
148-
array.validity_mask(),
149-
)
150-
}
151-
.into())
136+
let decimal_dtype = array.decimal_dtype();
137+
let buffer = array.buffer::<D>();
138+
let validity_mask = array.validity_mask();
139+
140+
Ok(kernel(move || {
141+
// Copy from D to E, possibly widening, possibly narrowing
142+
let values =
143+
Buffer::<E>::from_trusted_len_iter(buffer.iter().map(|d| {
144+
<E as BigCast>::from(*d).vortex_expect("Decimal cast failed")
145+
}));
146+
147+
Ok(unsafe {
148+
DVector::<E>::new_unchecked(
149+
// TODO(ngates): this is too small?
150+
PrecisionScale::new_unchecked(
151+
decimal_dtype.precision(),
152+
decimal_dtype.scale(),
153+
),
154+
values,
155+
validity_mask,
156+
)
157+
}
158+
.into())
159+
}))
152160
})
153161
})
154162
}

vortex-array/src/arrays/extension/vtable/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use vortex_buffer::BufferHandle;
1111
use vortex_dtype::DType;
1212
use vortex_error::VortexResult;
1313
use vortex_error::vortex_bail;
14-
use vortex_vector::Vector;
1514

1615
use crate::EmptyMetadata;
1716
use crate::arrays::extension::ExtensionArray;
1817
use crate::execution::ExecutionCtx;
18+
use crate::kernel::KernelRef;
1919
use crate::serde::ArrayChildren;
2020
use crate::vtable;
2121
use crate::vtable::ArrayId;
@@ -78,8 +78,8 @@ impl VTable for ExtensionVTable {
7878
Ok(ExtensionArray::new(ext_dtype.clone(), storage))
7979
}
8080

81-
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
82-
array.storage().batch_execute(ctx)
81+
fn bind_kernel(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
82+
array.storage().bind_kernel(ctx)
8383
}
8484
}
8585

vortex-array/src/arrays/filter/vtable.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use vortex_error::VortexResult;
1212
use vortex_error::vortex_bail;
1313
use vortex_mask::Mask;
1414
use vortex_scalar::Scalar;
15-
use vortex_vector::Vector;
1615

1716
use crate::Array;
1817
use crate::ArrayBufferVisitor;
@@ -26,6 +25,8 @@ use crate::Precision;
2625
use crate::arrays::LEGACY_SESSION;
2726
use crate::arrays::filter::array::FilterArray;
2827
use crate::execution::ExecutionCtx;
28+
use crate::kernel::KernelRef;
29+
use crate::kernel::kernel;
2930
use crate::serde::ArrayChildren;
3031
use crate::stats::StatsSetRef;
3132
use crate::vectors::VectorIntoArray;
@@ -93,9 +94,10 @@ impl VTable for FilterVTable {
9394
})
9495
}
9596

96-
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
97-
let child = array.child.batch_execute(ctx)?;
98-
Ok(Filter::filter(&child, &array.mask))
97+
fn bind_kernel(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<KernelRef> {
98+
let child = array.child.bind_kernel(ctx)?;
99+
let mask = array.mask.clone();
100+
Ok(kernel(move || Ok(Filter::filter(&child.execute()?, &mask))))
99101
}
100102
}
101103

@@ -125,7 +127,9 @@ impl BaseArrayVTable<FilterVTable> for FilterVTable {
125127
impl CanonicalVTable<FilterVTable> for FilterVTable {
126128
fn canonicalize(array: &FilterArray) -> Canonical {
127129
let vector =
128-
FilterVTable::batch_execute(array, &mut ExecutionCtx::new(LEGACY_SESSION.clone()))
130+
FilterVTable::bind_kernel(array, &mut ExecutionCtx::new(LEGACY_SESSION.clone()))
131+
.vortex_expect("Canonicalize should be fallible")
132+
.execute()
129133
.vortex_expect("Canonicalize should be fallible");
130134
vector.into_array(array.dtype()).to_canonical()
131135
}

0 commit comments

Comments
 (0)