vortex_compute/lane_kernels/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Elementwise lane kernels over indexed sources.
5//!
6//! Replaces `&[T]` with an [`IndexedSource`] trait: each lane read is
7//! `unsafe fn get_unchecked(i) -> Item`, independent across iterations. For `&[T]`
8//! this inlines to the same indexed load as the slice kernel; for [`LaneZip`]`(&[A], &[B])`
9//! it gives two independent indexed reads per lane — both shapes the auto-vectorizer
10//! handles.
11//!
12//! The module is split into:
13//!
14//! - [`source`] — the [`IndexedSource`] trait, [`LaneZip`], and read-only adapters.
15//! - [`sink`] — the [`IndexedSink`] trait and [`ReinterpretSink`].
16//! - [`map_into`] — out-of-place kernels via [`IndexedSourceExt`] (writes into a
17//! caller-provided `&mut [MaybeUninit<R>]`).
18//! - [`map_in_place`] — in-place kernels via [`IndexedSinkExt`] (writes back through
19//! the sink itself).
20//!
21//! The kernels never allocate. Both kernel families handle a mask with a non-byte-aligned
22//! offset and with a logical `len` shorter than the underlying byte buffer, via
23//! `BitBuffer::chunks`.
24
25pub mod map_in_place;
26pub mod map_into;
27pub mod sink;
28pub mod source;
29
30pub use map_in_place::IndexedSinkExt;
31pub use map_into::IndexedSourceExt;
32pub use sink::IndexedSink;
33pub use sink::ReinterpretSink;
34pub use source::IndexedSource;
35pub use source::LaneZip;
36
37/// Loop-tiling chunk length for the **no-mask** kernels ([`IndexedSourceExt::map_into`],
38/// [`IndexedSourceExt::try_map_into`], [`IndexedSinkExt::map_into_in_place`]).
39///
40/// This is a pure tuning knob: those kernels split the lane range into
41/// `len / CHUNK_LEN` full chunks plus a remainder, so any value yields correct
42/// results and only the codegen/tiling changes. Vary it to tune performance.
43///
44/// It does **not** apply to the masked or bit-packed kernels: those consume one
45/// [`BitBuffer::chunks`] u64 validity word per chunk and pack per-lane fail bits
46/// with `<< bit_idx` into a `u64`, so their chunk length is locked to 64.
47///
48/// [`BitBuffer::chunks`]: vortex_buffer::BitBuffer::chunks
49pub(crate) const CHUNK_LEN: usize = 64;