Skip to main content

strided_basic/
execution.rs

1//! Execution contract for operation-family implementations.
2//!
3//! This module is the shared kernel-extension interface, not a public mirror
4//! of implementation modules. Prevalidated entries require the caller to prove
5//! the exact destination geometry and every omitted shape check. A layout marker
6//! alone does not prove those obligations. Ordinary callers should use the
7//! checked APIs at the crate root. Every family that can fan out takes the same
8//! [`Exec`] placement token as its last parameter.
9//!
10//! # Examples
11//!
12//! ```
13//! use strided_basic::{Exec, StridedArray, execution::*};
14//! let src = StridedArray::<f64>::col_major(&[2]);
15//! let mut dst = StridedArray::<f64>::col_major(&[2]);
16//! let marker = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
17//! // SAFETY: both arrays have shape [2], distinct storage, and the checked layout.
18//! unsafe { map_into_validated(&mut dst.view_mut(), &src.view(), |x| x, marker, Exec::serial()) }.unwrap();
19//! ```
20//!
21//! A marker alone does not make the prevalidated entry safe to call:
22//!
23//! ```compile_fail,E0133
24//! use strided_basic::{Exec, StridedArray, execution::*};
25//! let src = StridedArray::<f64>::col_major(&[2]);
26//! let mut dst = StridedArray::<f64>::col_major(&[2]);
27//! let marker = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
28//! map_into_validated(&mut dst.view_mut(), &src.view(), |x| x, marker, Exec::serial()).unwrap();
29//! ```
30pub use crate::cost::{parallel_width, tree_width, KernelClass};
31pub use crate::erased_common::{
32    check_dtype, check_static_indexing_dtype, erased_view, validate_uninit_no_overlap,
33};
34pub use crate::kernel::{ensure_same_shape, KernelPlan, SMALL_TENSOR_THRESHOLD};
35pub use crate::layout_check::is_injective_layout;
36pub use crate::map_view::{
37    validate_destination_layout, validate_destination_layout_without_alloc,
38    ValidatedDestinationLayout,
39};
40pub use crate::threading::{parallel_map_reduce, SendPtr};
41
42use crate::{ElementOp, Exec, InlineVec, OperandVec, Result, StridedView, StridedViewMut};
43
44/// Prevalidated build plan fused for kernel-family implementations.
45///
46/// # Safety
47/// All rank-indexed arrays must have matching lengths and a valid destination
48/// index (when present). Shape products, stride magnitudes, cost arithmetic,
49/// and every intermediate offset used by planning/iteration must be representable.
50/// Iteration blocks must be positive and offsets must correspond to the supplied
51/// layouts; threaded partitioning additionally requires positive
52/// costs. Callback memory accesses must be valid for each generated
53/// block, with disjoint mutable regions when partitions execute concurrently.
54///
55/// # Examples
56///
57/// ```
58/// use strided_basic::execution::*;
59/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
60/// let (dims, _, plan) = unsafe { build_plan_fused(&[2, 3], &[&[1, 2]], Some(0), 8) };
61/// assert_eq!(dims.iter().product::<usize>(), 6);
62/// assert_eq!(plan.block.len(), dims.len());
63/// ```
64#[inline]
65pub unsafe fn build_plan_fused(
66    dims: &[usize],
67    strides_list: &[&[isize]],
68    dest_index: Option<usize>,
69    elem_size: usize,
70) -> (InlineVec<usize>, OperandVec<InlineVec<isize>>, KernelPlan) {
71    // SAFETY: the caller supplies the same invariants as the owning checked entry.
72    crate::kernel::build_plan_fused(dims, strides_list, dest_index, elem_size)
73}
74
75/// Prevalidated build plan fused small for kernel-family implementations.
76///
77/// # Safety
78/// All rank-indexed arrays must have matching lengths and a valid destination
79/// index (when present). Shape products, stride magnitudes, cost arithmetic,
80/// and every intermediate offset used by planning/iteration must be representable.
81/// Iteration blocks must be positive and offsets must correspond to the supplied
82/// layouts; threaded partitioning additionally requires positive
83/// costs. Callback memory accesses must be valid for each generated
84/// block, with disjoint mutable regions when partitions execute concurrently.
85///
86/// # Examples
87///
88/// ```
89/// use strided_basic::execution::*;
90/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
91/// let (dims, _, _) = unsafe { build_plan_fused_small(&[2, 3], &[&[1, 2]]) };
92/// assert_eq!(dims.iter().product::<usize>(), 6);
93/// ```
94#[inline]
95pub unsafe fn build_plan_fused_small(
96    dims: &[usize],
97    strides_list: &[&[isize]],
98) -> (InlineVec<usize>, OperandVec<InlineVec<isize>>, KernelPlan) {
99    // SAFETY: the caller supplies the same invariants as the owning checked entry.
100    crate::kernel::build_plan_fused_small(dims, strides_list)
101}
102
103/// Prevalidated for each inner block preordered for kernel-family implementations.
104///
105/// # Safety
106/// All rank-indexed arrays must have matching lengths and a valid destination
107/// index (when present). Shape products, stride magnitudes, cost arithmetic,
108/// and every intermediate offset used by planning/iteration must be representable.
109/// Iteration blocks must be positive and offsets must correspond to the supplied
110/// layouts; threaded partitioning additionally requires positive
111/// costs. Callback memory accesses must be valid for each generated
112/// block, with disjoint mutable regions when partitions execute concurrently.
113///
114/// # Examples
115///
116/// ```
117/// use strided_basic::execution::*;
118/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
119/// let mut count = 0;
120/// unsafe { for_each_inner_block_preordered(&[4], &[4], &[vec![1]], &[0], |_, n, _| { count += n; Ok(()) }) }.unwrap();
121/// assert_eq!(count, 4);
122/// ```
123///
124/// # Errors
125/// Forwards errors from the owning kernel or callback; callers must still
126/// satisfy the safety contract before invoking this prevalidated entry.
127#[inline]
128pub unsafe fn for_each_inner_block_preordered<S: AsRef<[isize]>, F>(
129    dims: &[usize],
130    blocks: &[usize],
131    strides: &[S],
132    initial_offsets: &[isize],
133    f: F,
134) -> Result<()>
135where
136    F: FnMut(&[isize], usize, &[isize]) -> Result<()>,
137{
138    // SAFETY: the caller supplies the same invariants as the owning checked entry.
139    crate::kernel::for_each_inner_block_preordered::<S, F>(
140        dims,
141        blocks,
142        strides,
143        initial_offsets,
144        f,
145    )
146}
147
148/// Prevalidated map into validated for kernel-family implementations.
149///
150/// # Safety
151/// All input shapes must match the destination. `validated` must have been
152/// obtained for this destination's current geometry, proving injectivity;
153/// possessing a marker from another layout is not sufficient. View/descriptor
154/// bounds and aliasing contracts must continue to hold throughout replay.
155///
156/// # Examples
157///
158/// ```
159/// use strided_basic::execution::*;
160/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
161/// use strided_basic::StridedArray;
162/// let src = StridedArray::<f64>::from_parts(vec![2.0; 2], &[2], &[1], 0).unwrap();
163/// let mut dst = StridedArray::<f64>::col_major(&[2]);
164/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
165/// unsafe { map_into_validated(&mut dst.view_mut(), &src.view(), |a| a, checked, strided_basic::Exec::serial()) }.unwrap();
166/// assert_eq!(dst.get(&[1]), 2.0);
167/// ```
168///
169/// # Errors
170/// Forwards errors from the owning kernel or callback; callers must still
171/// satisfy the safety contract before invoking this prevalidated entry.
172#[inline]
173pub unsafe fn map_into_validated<D: Copy + Send + Sync, A: Copy + Send + Sync, Op: ElementOp<A>>(
174    dest: &mut StridedViewMut<D>,
175    src: &StridedView<A, Op>,
176    f: impl crate::MapFn<A, D>,
177    validated: ValidatedDestinationLayout,
178    exec: Exec<'_>,
179) -> Result<()> {
180    // SAFETY: the caller supplies the same invariants as the owning checked entry.
181    crate::map_view::map_into_validated::<D, A, Op>(dest, src, f, validated, exec)
182}
183
184/// Prevalidated zip map2 into validated for kernel-family implementations.
185///
186/// # Safety
187/// All input shapes must match the destination. `validated` must have been
188/// obtained for this destination's current geometry, proving injectivity;
189/// possessing a marker from another layout is not sufficient. View/descriptor
190/// bounds and aliasing contracts must continue to hold throughout replay.
191///
192/// # Examples
193///
194/// ```
195/// use strided_basic::execution::*;
196/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
197/// use strided_basic::StridedArray;
198/// let src = StridedArray::<f64>::from_parts(vec![2.0; 2], &[2], &[1], 0).unwrap();
199/// let mut dst = StridedArray::<f64>::col_major(&[2]);
200/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
201/// unsafe { zip_map2_into_validated(&mut dst.view_mut(), &src.view(), &src.view(), |a, b| a + b, checked, strided_basic::Exec::serial()) }.unwrap();
202/// assert_eq!(dst.get(&[1]), 4.0);
203/// ```
204///
205/// # Errors
206/// Forwards errors from the owning kernel or callback; callers must still
207/// satisfy the safety contract before invoking this prevalidated entry.
208#[inline]
209pub unsafe fn zip_map2_into_validated<
210    D: Copy + Send + Sync,
211    A: Copy + Send + Sync,
212    B: Copy + Send + Sync,
213    OpA: ElementOp<A>,
214    OpB: ElementOp<B>,
215>(
216    dest: &mut StridedViewMut<D>,
217    a: &StridedView<A, OpA>,
218    b: &StridedView<B, OpB>,
219    f: impl Fn(A, B) -> D + Sync,
220    validated: ValidatedDestinationLayout,
221    exec: Exec<'_>,
222) -> Result<()> {
223    // SAFETY: the caller supplies the same invariants as the owning checked entry.
224    crate::map_view::zip_map2_into_validated::<D, A, B, OpA, OpB>(dest, a, b, f, validated, exec)
225}
226
227/// Prevalidated zip map3 into validated for kernel-family implementations.
228///
229/// # Safety
230/// All input shapes must match the destination. `validated` must have been
231/// obtained for this destination's current geometry, proving injectivity;
232/// possessing a marker from another layout is not sufficient. View/descriptor
233/// bounds and aliasing contracts must continue to hold throughout replay.
234///
235/// # Examples
236///
237/// ```
238/// use strided_basic::execution::*;
239/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
240/// use strided_basic::StridedArray;
241/// let src = StridedArray::<f64>::from_parts(vec![2.0; 2], &[2], &[1], 0).unwrap();
242/// let mut dst = StridedArray::<f64>::col_major(&[2]);
243/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
244/// unsafe { zip_map3_into_validated(&mut dst.view_mut(), &src.view(), &src.view(), &src.view(), |a, b, c| a + b + c, checked, strided_basic::Exec::serial()) }.unwrap();
245/// assert_eq!(dst.get(&[1]), 6.0);
246/// ```
247///
248/// # Errors
249/// Forwards errors from the owning kernel or callback; callers must still
250/// satisfy the safety contract before invoking this prevalidated entry.
251#[inline]
252pub unsafe fn zip_map3_into_validated<
253    D: Copy + Send + Sync,
254    A: Copy + Send + Sync,
255    B: Copy + Send + Sync,
256    C: Copy + Send + Sync,
257    OpA: ElementOp<A>,
258    OpB: ElementOp<B>,
259    OpC: ElementOp<C>,
260>(
261    dest: &mut StridedViewMut<D>,
262    a: &StridedView<A, OpA>,
263    b: &StridedView<B, OpB>,
264    c: &StridedView<C, OpC>,
265    f: impl Fn(A, B, C) -> D + Sync,
266    validated: ValidatedDestinationLayout,
267    exec: Exec<'_>,
268) -> Result<()> {
269    // SAFETY: the caller supplies the same invariants as the owning checked entry.
270    crate::map_view::zip_map3_into_validated::<D, A, B, C, OpA, OpB, OpC>(
271        dest, a, b, c, f, validated, exec,
272    )
273}
274
275/// Prevalidated zip map4 into validated for kernel-family implementations.
276///
277/// # Safety
278/// All input shapes must match the destination. `validated` must have been
279/// obtained for this destination's current geometry, proving injectivity;
280/// possessing a marker from another layout is not sufficient. View/descriptor
281/// bounds and aliasing contracts must continue to hold throughout replay.
282///
283/// # Examples
284///
285/// ```
286/// use strided_basic::execution::*;
287/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
288/// use strided_basic::StridedArray;
289/// let src = StridedArray::<f64>::from_parts(vec![2.0; 2], &[2], &[1], 0).unwrap();
290/// let mut dst = StridedArray::<f64>::col_major(&[2]);
291/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
292/// unsafe { zip_map4_into_validated(&mut dst.view_mut(), &src.view(), &src.view(), &src.view(), &src.view(), |a, b, c, d| a + b + c + d, checked, strided_basic::Exec::serial()) }.unwrap();
293/// assert_eq!(dst.get(&[1]), 8.0);
294/// ```
295///
296/// # Errors
297/// Forwards errors from the owning kernel or callback; callers must still
298/// satisfy the safety contract before invoking this prevalidated entry.
299#[inline]
300#[allow(clippy::too_many_arguments)]
301pub unsafe fn zip_map4_into_validated<
302    D: Copy + Send + Sync,
303    A: Copy + Send + Sync,
304    B: Copy + Send + Sync,
305    C: Copy + Send + Sync,
306    E: Copy + Send + Sync,
307    OpA: ElementOp<A>,
308    OpB: ElementOp<B>,
309    OpC: ElementOp<C>,
310    OpE: ElementOp<E>,
311>(
312    dest: &mut StridedViewMut<D>,
313    a: &StridedView<A, OpA>,
314    b: &StridedView<B, OpB>,
315    c: &StridedView<C, OpC>,
316    e: &StridedView<E, OpE>,
317    f: impl Fn(A, B, C, E) -> D + Sync,
318    validated: ValidatedDestinationLayout,
319    exec: Exec<'_>,
320) -> Result<()> {
321    // SAFETY: the caller supplies the same invariants as the owning checked entry.
322    crate::map_view::zip_map4_into_validated::<D, A, B, C, E, OpA, OpB, OpC, OpE>(
323        dest, a, b, c, e, f, validated, exec,
324    )
325}
326
327/// Prevalidated map raw into validated for kernel-family implementations.
328///
329/// # Safety
330/// All input shapes must match the destination. `validated` must have been
331/// obtained for this destination's current geometry, proving injectivity;
332/// possessing a marker from another layout is not sufficient. View/descriptor
333/// bounds and aliasing contracts must continue to hold throughout replay.
334///
335/// # Examples
336///
337/// ```
338/// use strided_basic::execution::*;
339/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
340/// use strided_basic::{RawStridedRef, RawStridedMut, Identity};
341/// let values = [2.0_f64; 2];
342/// let src = RawStridedRef::new(&values, &[2], &[1], 0).unwrap();
343/// let mut output = [0.0; 2];
344/// let mut dst = RawStridedMut::new(&mut output, &[2], &[1], 0).unwrap();
345/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
346/// unsafe { map_raw_into_validated::<f64, f64, Identity>(&mut dst, &src, |a| a, checked, strided_basic::Exec::serial()) }.unwrap();
347/// assert_eq!(output, [2.0; 2]);
348/// ```
349///
350/// # Errors
351/// Forwards errors from the owning kernel or callback; callers must still
352/// satisfy the safety contract before invoking this prevalidated entry.
353#[inline]
354pub unsafe fn map_raw_into_validated<
355    D: Copy + Send + Sync,
356    A: Copy + Send + Sync,
357    Op: ElementOp<A>,
358>(
359    dest: &mut crate::RawStridedMut<'_, D>,
360    src: &crate::RawStridedRef<'_, A>,
361    f: impl Fn(A) -> D + Sync,
362    validated: ValidatedDestinationLayout,
363    exec: Exec<'_>,
364) -> Result<()> {
365    // SAFETY: the caller supplies the same invariants as the owning checked entry.
366    crate::map_view::map_raw_into_validated::<D, A, Op>(dest, src, f, validated, exec)
367}
368
369/// Prevalidated zip map2 raw into validated for kernel-family implementations.
370///
371/// # Safety
372/// All input shapes must match the destination. `validated` must have been
373/// obtained for this destination's current geometry, proving injectivity;
374/// possessing a marker from another layout is not sufficient. View/descriptor
375/// bounds and aliasing contracts must continue to hold throughout replay.
376///
377/// # Examples
378///
379/// ```
380/// use strided_basic::execution::*;
381/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
382/// use strided_basic::{RawStridedRef, RawStridedMut, Identity};
383/// let values = [2.0_f64; 2];
384/// let src = RawStridedRef::new(&values, &[2], &[1], 0).unwrap();
385/// let mut output = [0.0; 2];
386/// let mut dst = RawStridedMut::new(&mut output, &[2], &[1], 0).unwrap();
387/// let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
388/// unsafe { zip_map2_raw_into_validated::<f64, f64, f64, Identity, Identity>(&mut dst, &src, &src, |a, b| a + b, checked, strided_basic::Exec::serial()) }.unwrap();
389/// assert_eq!(output, [4.0; 2]);
390/// ```
391///
392/// # Errors
393/// Forwards errors from the owning kernel or callback; callers must still
394/// satisfy the safety contract before invoking this prevalidated entry.
395#[inline]
396pub unsafe fn zip_map2_raw_into_validated<
397    D: Copy + Send + Sync,
398    A: Copy + Send + Sync,
399    B: Copy + Send + Sync,
400    OpA: ElementOp<A>,
401    OpB: ElementOp<B>,
402>(
403    dest: &mut crate::RawStridedMut<'_, D>,
404    a: &crate::RawStridedRef<'_, A>,
405    b: &crate::RawStridedRef<'_, B>,
406    f: impl Fn(A, B) -> D + Sync,
407    validated: ValidatedDestinationLayout,
408    exec: Exec<'_>,
409) -> Result<()> {
410    // SAFETY: the caller supplies the same invariants as the owning checked entry.
411    crate::map_view::zip_map2_raw_into_validated::<D, A, B, OpA, OpB>(
412        dest, a, b, f, validated, exec,
413    )
414}
415
416/// Prevalidated compute costs for kernel-family implementations.
417///
418/// # Safety
419/// All rank-indexed arrays must have matching lengths and a valid destination
420/// index (when present). Shape products, stride magnitudes, cost arithmetic,
421/// and every intermediate offset used by planning/iteration must be representable.
422/// Iteration blocks must be positive and offsets must correspond to the supplied
423/// layouts; threaded partitioning additionally requires positive
424/// costs. Callback memory accesses must be valid for each generated
425/// block, with disjoint mutable regions when partitions execute concurrently.
426///
427/// # Examples
428///
429/// ```
430/// use strided_basic::execution::*;
431/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
432/// let costs = unsafe { compute_costs(&[vec![1, 4], vec![1, 8]]) };
433/// assert_eq!(costs.as_slice(), [2, 8]);
434/// ```
435#[inline]
436pub unsafe fn compute_costs<S: AsRef<[isize]>>(all_strides: &[S]) -> InlineVec<isize> {
437    // SAFETY: the caller supplies the same invariants as the owning checked entry.
438    crate::fuse::compute_costs::<S>(all_strides)
439}
440
441/// Prevalidated mapreduce threaded for kernel-family implementations.
442///
443/// `class` is the serial cost class of the leaf (see [`KernelClass`]); every node
444/// of the split runs in parallel only when a fork of its region pays for that
445/// class.
446///
447/// # Safety
448/// All rank-indexed arrays must have matching lengths and a valid destination
449/// index (when present). Shape products, stride magnitudes, cost arithmetic,
450/// and every intermediate offset used by planning/iteration must be representable.
451/// Iteration blocks must be positive and offsets must correspond to the supplied
452/// layouts; threaded partitioning additionally requires positive
453/// costs. Callback memory accesses must be valid for each generated
454/// block, with disjoint mutable regions when partitions execute concurrently.
455///
456/// # Examples
457///
458/// ```
459/// use strided_basic::execution::*;
460/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
461/// use std::sync::atomic::{AtomicUsize, Ordering};
462/// let count = AtomicUsize::new(0);
463/// unsafe { mapreduce_threaded(&[4], &[4], &[vec![1]], &[0], &[2], KernelClass::Map, strided_basic::Exec::serial(), &|dims, _, _, _| { count.fetch_add(dims.iter().product::<usize>(), Ordering::Relaxed); Ok(()) }) }.unwrap();
464/// assert_eq!(count.load(Ordering::Relaxed), 4);
465/// ```
466///
467/// # Errors
468/// Forwards errors from the owning kernel or callback; callers must still
469/// satisfy the safety contract before invoking this prevalidated entry.
470#[inline]
471pub unsafe fn mapreduce_threaded<S: AsRef<[isize]>, F>(
472    dims: &[usize],
473    blocks: &[usize],
474    strides_list: &[S],
475    offsets: &[isize],
476    costs: &[isize],
477    class: KernelClass,
478    exec: Exec<'_>,
479    f: &F,
480) -> Result<()>
481where
482    F: Fn(&[usize], &[usize], &[&[isize]], &[isize]) -> Result<()> + Sync,
483{
484    // SAFETY: the caller supplies the same invariants as the owning checked entry.
485    crate::threading::mapreduce_threaded::<S, F>(
486        dims,
487        blocks,
488        strides_list,
489        offsets,
490        costs,
491        class,
492        exec,
493        f,
494    )
495}
496
497/// Full-overwrite indexed replay for an operation-family adapter.
498///
499/// # Safety
500/// The adapter must reject input/output overlap before creating the input
501/// references. All descriptor allocation and initialization contracts must
502/// remain valid for the call. Output slots may be uninitialized; the owning
503/// plan retains its checked layout/index validation and private initialization
504/// receipt. No initialized reference to the output backing may be formed.
505/// Gather into uninitialized output without exposing an initialization receipt.
506///
507/// # Examples
508///
509/// ```
510/// use strided_basic::{RawStridedRef, RawStridedMut};
511/// use strided_basic::execution::*;
512/// use core::mem::MaybeUninit;
513/// use strided_basic::{GatherPlan, GatherSpec};
514/// let spec = GatherSpec { offset_dims: vec![], collapsed_slice_dims: vec![0], start_index_map: vec![0], index_vector_dim: 1, slice_sizes: vec![1] };
515/// let plan = GatherPlan::compile(&[3], &[1], &[2, 1], &[1, 2], &[2], &[1], spec).unwrap();
516/// let src = RawStridedRef::new(&[1_i32, 2, 3], &[3], &[1], 0).unwrap();
517/// let indices = RawStridedRef::new(&[0_i32, 2], &[2, 1], &[1, 2], 0).unwrap();
518/// let mut values = [MaybeUninit::<i32>::uninit(); 2];
519/// let mut dst = RawStridedMut::new(&mut values, &[2], &[1], 0).unwrap();
520/// // SAFETY: input and output allocations are disjoint and layouts match the plan.
521/// unsafe { gather_into_uninit(&plan, &mut dst, &src, &indices, strided_basic::Exec::serial()) }.unwrap();
522/// assert_eq!(unsafe { values[1].assume_init() }, 3);
523/// ```
524///
525/// # Errors
526/// Forwards the plan layout/index validation errors before successful overwrite.
527#[inline]
528pub unsafe fn gather_into_uninit<T, I>(
529    plan: &crate::GatherPlan,
530    dest: &mut crate::RawStridedMut<'_, core::mem::MaybeUninit<T>>,
531    operand: &crate::RawStridedRef<'_, T>,
532    start_indices: &crate::RawStridedRef<'_, I>,
533    exec: Exec<'_>,
534) -> Result<()>
535where
536    T: Copy + Send + Sync,
537    I: crate::GatherIndex,
538{
539    plan.execute_uninit(dest, operand, start_indices, exec)
540}
541
542/// Full-overwrite indexed replay for an operation-family adapter.
543///
544/// # Safety
545/// The adapter must reject input/output overlap before creating the input
546/// references. All descriptor allocation and initialization contracts must
547/// remain valid for the call. Output slots may be uninitialized; the owning
548/// plan retains its checked layout/index validation and private initialization
549/// receipt. No initialized reference to the output backing may be formed.
550///
551/// # Examples
552///
553/// ```
554/// use strided_basic::execution::*;
555/// // SAFETY: the example supplies matching bounded layouts and disjoint storage.
556/// use strided_basic::{DynamicSlicePlan, RawStridedRef, RawStridedMut};
557/// use core::mem::MaybeUninit;
558/// let plan = DynamicSlicePlan::compile(&[3], &[1], &[1], &[1], &[2], &[1], &[2]).unwrap();
559/// let src = RawStridedRef::new(&[1_i32, 2, 3], &[3], &[1], 0).unwrap();
560/// let starts = RawStridedRef::new(&[1_i32], &[1], &[1], 0).unwrap();
561/// let mut values = [MaybeUninit::<i32>::uninit(); 2];
562/// let mut dst = RawStridedMut::new(&mut values, &[2], &[1], 0).unwrap();
563/// unsafe { dynamic_slice_into_uninit(&plan, &mut dst, &src, &starts, strided_basic::Exec::serial()) }.unwrap();
564/// assert_eq!(unsafe { values[1].assume_init() }, 3);
565/// ```
566///
567/// # Errors
568/// Forwards errors from the owning kernel or callback; callers must still
569/// satisfy the safety contract before invoking this prevalidated entry.
570#[inline]
571pub unsafe fn dynamic_slice_into_uninit<T, I>(
572    plan: &crate::DynamicSlicePlan,
573    dest: &mut crate::RawStridedMut<'_, core::mem::MaybeUninit<T>>,
574    operand: &crate::RawStridedRef<'_, T>,
575    starts: &crate::RawStridedRef<'_, I>,
576    exec: Exec<'_>,
577) -> Result<()>
578where
579    T: Copy + Send + Sync,
580    I: crate::GatherIndex,
581{
582    plan.execute_uninit(dest, operand, starts, exec)
583}
584
585/// Full-overwrite indexed replay for an operation-family adapter.
586///
587/// # Safety
588/// The adapter must reject input/output overlap before creating the input
589/// references. All descriptor allocation and initialization contracts must
590/// remain valid for the call. Output slots may be uninitialized; the owning
591/// plan retains its checked layout/index validation and private initialization
592/// receipt. No initialized reference to the output backing may be formed.
593/// Copy the operand and overwrite its selected window.
594///
595/// # Examples
596///
597/// ```
598/// use strided_basic::{RawStridedRef, RawStridedMut};
599/// use strided_basic::execution::*;
600/// use core::mem::MaybeUninit;
601/// use strided_basic::DynamicUpdateSlicePlan;
602/// let plan = DynamicUpdateSlicePlan::compile(&[3], &[1], &[1], &[1], &[1], &[1], &[3], &[1]).unwrap();
603/// let src = RawStridedRef::new(&[1_i32, 2, 3], &[3], &[1], 0).unwrap();
604/// let update = RawStridedRef::new(&[9_i32], &[1], &[1], 0).unwrap();
605/// let starts = RawStridedRef::new(&[1_i32], &[1], &[1], 0).unwrap();
606/// let mut values = [MaybeUninit::<i32>::uninit(); 3];
607/// let mut dst = RawStridedMut::new(&mut values, &[3], &[1], 0).unwrap();
608/// // SAFETY: all inputs are initialized and disjoint from the matching output.
609/// unsafe { dynamic_update_into_uninit(&plan, &mut dst, &src, &update, &starts, strided_basic::Exec::serial()) }.unwrap();
610/// assert_eq!(unsafe { values[1].assume_init() }, 9);
611/// ```
612///
613/// # Errors
614/// Forwards the plan layout/index validation errors.
615#[inline]
616pub unsafe fn dynamic_update_into_uninit<'a, T, I>(
617    plan: &crate::DynamicUpdateSlicePlan,
618    dest: &'a mut crate::RawStridedMut<'a, core::mem::MaybeUninit<T>>,
619    operand: &crate::RawStridedRef<'_, T>,
620    update: &crate::RawStridedRef<'_, T>,
621    starts: &crate::RawStridedRef<'_, I>,
622    exec: Exec<'_>,
623) -> Result<()>
624where
625    T: Copy + Send + Sync,
626    I: crate::GatherIndex,
627{
628    plan.execute_uninit(dest, operand, update, starts, exec)
629}
630
631/// Full-overwrite indexed replay for an operation-family adapter.
632///
633/// # Safety
634/// The adapter must reject input/output overlap before creating the input
635/// references. All descriptor allocation and initialization contracts must
636/// remain valid for the call. Output slots may be uninitialized; the owning
637/// plan retains its checked layout/index validation and private initialization
638/// receipt. No initialized reference to the output backing may be formed.
639/// Copy the operand before additive scatter into its initialized logical slots.
640///
641/// # Examples
642///
643/// ```
644/// use strided_basic::{RawStridedRef, RawStridedMut};
645/// use strided_basic::execution::*;
646/// use core::mem::MaybeUninit;
647/// use strided_basic::{ScatterPlan, ScatterSpec};
648/// let spec = ScatterSpec { update_window_dims: vec![], inserted_window_dims: vec![0], scatter_dims_to_operand_dims: vec![0], index_vector_dim: 1 };
649/// let plan = ScatterPlan::compile(&[3], &[1], &[1, 1], &[1, 1], &[1], &[1], &[3], &[1], spec).unwrap();
650/// let src = RawStridedRef::new(&[1_i32, 2, 3], &[3], &[1], 0).unwrap();
651/// let update = RawStridedRef::new(&[9_i32], &[1], &[1], 0).unwrap();
652/// let indices = RawStridedRef::new(&[1_i64], &[1, 1], &[1, 1], 0).unwrap();
653/// let mut values = [MaybeUninit::<i32>::uninit(); 3];
654/// let mut dst = RawStridedMut::new(&mut values, &[3], &[1], 0).unwrap();
655/// // SAFETY: all inputs are initialized and disjoint from the matching output.
656/// unsafe { scatter_into_uninit(&plan, &mut dst, &src, &indices, &update, i32::wrapping_add, strided_basic::Exec::serial()) }.unwrap();
657/// assert_eq!(unsafe { values[1].assume_init() }, 11);
658/// ```
659///
660/// # Errors
661/// Forwards the plan layout/index validation errors.
662#[inline]
663pub unsafe fn scatter_into_uninit<'a, T, I>(
664    plan: &crate::ScatterPlan,
665    dest: &'a mut crate::RawStridedMut<'a, core::mem::MaybeUninit<T>>,
666    operand: &crate::RawStridedRef<'_, T>,
667    scatter_indices: &crate::RawStridedRef<'_, I>,
668    updates: &crate::RawStridedRef<'_, T>,
669    combine: fn(T, T) -> T,
670    exec: Exec<'_>,
671) -> Result<()>
672where
673    T: Copy + core::ops::Add<Output = T> + Send + Sync,
674    I: crate::GatherIndex,
675{
676    plan.execute_uninit(dest, operand, scatter_indices, updates, combine, exec)
677}