Skip to main content

Crate strided_kernel

Crate strided_kernel 

Source
Expand description

Cache-optimized kernels for strided multidimensional array operations.

This crate is a Rust port of Julia’s Strided.jl and StridedViews.jl libraries, providing efficient operations on strided multidimensional array views.

§Core Types

§Primary API (view-based, Julia-compatible)

§Map Operations

§Reduce Operations

§Basic Operations

§Example

use strided_kernel::{StridedView, StridedViewMut, StridedArray, Identity, map_into};

// Create a column-major array (Julia default)
let src = StridedArray::<f64>::from_fn_col_major(&[2, 3], |idx| {
    (idx[0] * 10 + idx[1]) as f64
});
let mut dest = StridedArray::<f64>::col_major(&[2, 3]);

// Map with view-based API
map_into(&mut dest.view_mut(), &src.view(), |x| x * 2.0).unwrap();
assert_eq!(dest.get(&[1, 2]), 24.0); // (1*10 + 2) * 2

§Cache Optimization

The library uses Julia’s blocking strategy for cache efficiency:

  • Dimensions are sorted by stride magnitude for optimal memory access
  • Operations are blocked into tiles fitting L1 cache (BLOCK_MEMORY_SIZE = 32KB)
  • Contiguous arrays use fast paths bypassing the blocking machinery

Modules§

view
Julia-like dynamic-rank strided view types.

Structs§

Adjoint
Adjoint operation: f(x) = adjoint(x) = conj(transpose(x)) For scalar numbers, this is conj.
ConcatenatePlan
A compiled multi-input concatenate traversal.
Conj
Complex conjugate operation: f(x) = conj(x)
CopyPlan
A compiled copy traversal for one (dims, dst_strides, src_strides) layout pair.
DynamicSlicePlan
A compiled fixed-window dynamic-slice traversal.
DynamicUpdateSlicePlan
A compiled dynamic-update-slice traversal.
ErasedConcatenatePlan
Dtype-erased concatenate wrapper.
ErasedCopyPlan
Dtype-erased wrapper around CopyPlan.
ErasedDynamicSlicePlan
Dtype-erased fixed-window dynamic-slice wrapper.
ErasedDynamicUpdateSlicePlan
Dtype-erased dynamic-update-slice wrapper.
ErasedFusedPlan
Dtype-erased single-output wrapper around FusedPlan.
ErasedGatherPlan
Dtype-erased gather wrapper.
ErasedPadPlan
Dtype-erased pad wrapper.
ErasedRawStridedMut
Borrowed dtype-erased raw strided output layout.
ErasedRawStridedPtr
Pointer-backed dtype-erased input used by one-shot write entry points.
ErasedRawStridedRef
Borrowed dtype-erased raw strided input layout.
ErasedRawStridedUninitMut
Borrowed dtype-erased raw strided output whose reachable elements may be uninitialized.
ErasedReducePlan
Dtype-erased reduction wrapper.
ErasedReversePlan
Dtype-erased reverse wrapper.
ErasedScatterPlan
Dtype-erased additive scatter wrapper.
ErasedSlicePlan
Dtype-erased static-slice wrapper.
ExecContext
Caller-selected execution policy for prepared kernel replay.
FusedInst
One SSA instruction in a FusedPlan.
FusedPlan
Topologically ordered fused elementwise SSA DAG.
GatherPlan
A compiled gather traversal for one value layout, index layout, and output layout.
GatherSpec
Gather configuration shared by generic and erased replay.
Identity
Identity operation: f(x) = x
PadPlan
A compiled pad traversal.
RawStridedMut
Borrowed raw strided output layout.
RawStridedRef
Borrowed raw strided input layout.
ReversePlan
A compiled reverse traversal over selected axes.
ScatterPlan
A compiled additive scatter traversal.
ScatterSpec
Scatter configuration shared by generic and erased replay.
SlicePlan
A compiled static-slice traversal.
StridedArray
Owned strided multidimensional array.
StridedView
Dynamic-rank immutable strided view with lazy element operations.
StridedViewMut
Dynamic-rank mutable strided view.
Transpose
Transpose operation: f(x) = transpose(x) For scalar numbers, this is identity. For matrix elements, this would transpose each element.

Enums§

CompareOp
Runtime comparison selected once before entering the element loop.
ErasedMapOp
Runtime unary operation for erased_map_into.
ErasedZipOp
Runtime binary operation for erased_zip_into.
ExecutionPolicy
Controls how a strided operation may use CPU threads.
FusedOp
Runtime scalar operation for a fused elementwise plan.
KernelDType
Dtypes supported by dtype-erased kernel entry points.
ReduceOp
Runtime reduction operation for dtype-erased full reductions.
StridedError
Errors that can occur during strided array operations.

Constants§

BLOCK_MEMORY_SIZE
Block memory size for cache-optimized iteration (L1 cache target).
CACHE_LINE_SIZE
Cache line size in bytes.
RAW_FUSED_RANK_LIMIT
Maximum rank fused on the stack before falling back to the view kernels.

Traits§

ComposableElementOp
Trait for element operations that support type-level composition.
Compose
Helper trait for composing two ElementOp types.
ElementOp
Trait for element-wise operations applied to strided views.
ElementOpApply
Trait for types that support element operations (conj, transpose, adjoint).
FusedScalar
Scalar types supported by fused_elementwise_into.
GatherIndex
Index scalar types accepted by GatherPlan.
KernelStorageElement
A scalar type that can safely witness storage for an erased kernel view.
MaybeSend
Equivalent to Send when parallel is enabled; blanket-impl otherwise.
MaybeSendSync
Equivalent to Send + Sync when parallel is enabled; blanket-impl otherwise.
MaybeSimdOps
Trait for types that may have SIMD-accelerated sum/dot operations.
MaybeSync
Equivalent to Sync when parallel is enabled; blanket-impl otherwise.

Functions§

add
Element-wise addition: dest[i] += src[i].
axpy
AXPY: dest[i] = alpha * src[i] + dest[i].
axpy_conj_raw
dest = alpha * conj(src) + dest over borrowed raw strided layouts.
axpy_raw
dest = alpha * src + dest over borrowed raw strided layouts.
batched_outer_product_into
Compute dest[lhs_free..., rhs_free..., batch...] = lhs[lhs_free..., batch...] * rhs[rhs_free..., batch...].
batched_outer_product_into_uninit
Compute a batched outer product into a fully overwritten uninitialized output.
broadcast_mul_into
Broadcasted element-wise multiplication: dest[i] = a[i] * b[i].
broadcast_mul_into_uninit
Broadcast and multiply into a fully overwritten uninitialized output.
col_major_strides
Compute column-major strides (Julia default: first index varies fastest).
compare_into
Compare two ordered views elementwise into a Boolean destination.
compare_into_uninit
Compare two views into a fully overwritten uninitialized Boolean output.
copy_conj
Copy with complex conjugation: dest[i] = conj(src[i]).
copy_into
Copy elements from source to destination: dest[i] = src[i].
copy_into_col_major
Copy elements from src to dst, optimized for col-major destination.
copy_scale
Copy with scaling: dest[i] = scale * src[i].
copy_scale_conj_raw
dest = scale * conj(src) over borrowed raw strided layouts.
copy_scale_raw
dest = scale * src over borrowed raw strided layouts.
copy_transpose_scale_into
Copy with transpose and scaling: dest[j,i] = scale * src[i,j].
dot
Dot product: sum(OpA::apply(a[i]) * OpB::apply(b[i])).
erased_map_into
Apply one runtime-selected unary operation without compiling a plan.
erased_zip_into
Apply one runtime-selected binary operation without compiling a plan.
fma
Fused multiply-add: dest[i] += OpA::apply(a[i]) * OpB::apply(b[i]).
fused_elementwise_into
Evaluate a runtime-DAG elementwise plan into one or more destinations.
map_into
Apply a function element-wise from source to destination.
mul
Element-wise multiplication: dest[i] *= src[i].
mul_into
Element-wise multiplication: dest[i] = a[i] * b[i].
mul_into_uninit
Multiply two views into a fully overwritten uninitialized output.
reduce
Full reduction with map function: reduce(init, op, map.(src)).
reduce_axis
Reduce along a single axis, returning a new StridedArray.
row_major_strides
Compute row-major strides (C default: last index varies fastest).
sum
Sum all elements: sum(src).
symmetrize_conj_into
Conjugate-symmetrize a square matrix: dest = (src + conj(src^T)) / 2.
symmetrize_into
Symmetrize a square matrix: dest = (src + src^T) / 2.
with_execution_policy
Execute operation under an explicit strided-kernel execution policy.
zip_map2_into
Binary element-wise operation: dest[i] = f(a[i], b[i]).
zip_map3_into
Ternary element-wise operation: dest[i] = f(a[i], b[i], c[i]).
zip_map4_into
Quaternary element-wise operation: dest[i] = f(a[i], b[i], c[i], e[i]).

Type Aliases§

Result
Result type for strided array operations.