Skip to main content

IndexingKind

Enum IndexingKind 

Source
#[non_exhaustive]
#[repr(u16)]
pub enum IndexingKind { Gather = 0, GatherBackward = 1, ScatterAdd = 2, IndexSelect = 3, IndexSelectBackward = 4, MaskedFill = 5, MaskedFillBackward = 6, OneHot = 7, Nonzero = 8, Scatter = 9, IndexAdd = 10, }
Expand description

Indexing / scatter / gather op discriminant — Category L from the comprehensive plan.

Stored as u16 in crate::KernelSku::op when category == OpCategory::Indexing. Phase 7 Milestone 7.3 wires:

  • Self::Gather (FW + BW): out[i] = src[index[i]] along a dim.
  • Self::ScatterAdd: out[index[i]] += updates[i] along a dim (atomicAdd, dup-safe).
  • Self::IndexSelect (FW + BW): out[..., j, ...] = src[..., idx[j], ...] with a 1-D i32 idx tensor.
  • Self::MaskedFill (FW + BW): out[i] = mask[i] ? value : src[i].
  • Self::OneHot (FW only — non-differentiable): out[..., c] = 1 if c == src[...] else 0.
  • Self::Nonzero (FW only): coordinates where input != 0, returned as an [k, rank] i32 table plus a count.

Index dtype is i32 only in the trailblazer (i64 deferred). Out-of-bounds and negative indices are treated as no-ops (the kernel skips them — PyTorch-style negative wrap-around is deferred).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Gather = 0

gather(src, dim, index)out[..., j, ...] = src[..., index[..., j, ...], ...] along the specified gather dimension. PyTorch torch.gather.

§

GatherBackward = 1

Gradient of Self::Gather: scatters dout into dsrc along the gather dim with atomicAdd (dup-safe). Different signature from Self::ScatterAdd because the dst is dsrc and the index pattern matches the FW gather coordinates exactly.

§

ScatterAdd = 2

scatter_add(out, dim, index, updates)out[..., index[..., j, ...], ...] += updates[..., j, ...] (atomicAdd). PyTorch torch.scatter_add_.

§

IndexSelect = 3

index_select(src, dim, idx)out[..., j, ...] = src[..., idx[j], ...] with a 1-D i32 idx tensor. Faster / simpler than gather when the index tensor is 1-D. PyTorch torch.index_select.

§

IndexSelectBackward = 4

Gradient of Self::IndexSelect: scatter-add dout into dsrc along select_dim using idx (atomicAdd).

§

MaskedFill = 5

masked_fill(src, mask, value)out[i] = mask[i] ? value : src[i]. PyTorch torch.Tensor.masked_fill.

§

MaskedFillBackward = 6

Gradient of Self::MaskedFill: dsrc[i] = mask[i] ? 0 : dout[i]. value is a non-differentiable scalar.

§

OneHot = 7

one_hot(src, num_classes)out[indices..., c] = 1 if c == src[indices...] else 0. Input dtype is i32 (class indices); output dtype is configurable. PyTorch torch.nn.functional.one_hot. Non-differentiable.

§

Nonzero = 8

nonzero(x) — coordinates where x != 0. Returns an [k, rank] i32 coordinate table plus a count. PyTorch torch.nonzero. Output ordering is NOT row-major (atomic-counter races); callers that need sorted output sort afterward.

§

Scatter = 9

scatter(out, dim, index, updates)out[..., index[..., j, ...], ...] = updates[..., j, ...] (NO accumulation; last writer wins on duplicate-target races). PyTorch torch.scatter_ (the in-place pure-assign variant). Distinct from Self::ScatterAdd. Phase 39 (Fuel 6c.4 Gap 5).

§

IndexAdd = 10

index_add(dst, dim, idx, src)dst[idx[i], ...] += src[i, ...] along add_dim (atomicAdd-Σ). PyTorch torch.Tensor.index_add_. Algorithmically identical to Self::IndexSelectBackward but exposed under a non-autograd- flavored name (and with broader dtype coverage). Phase 39 (Fuel 6c.4 Gap 5).

Trait Implementations§

Source§

impl Clone for IndexingKind

Source§

fn clone(&self) -> IndexingKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for IndexingKind

Source§

impl Debug for IndexingKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for IndexingKind

Source§

impl Hash for IndexingKind

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for IndexingKind

Source§

fn eq(&self, other: &IndexingKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for IndexingKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.