Skip to main content

flatten_backward

Function flatten_backward 

Source
pub fn flatten_backward<T: Triton, D: Num, const BLOCK_B: i32, const BLOCK_N: i32>(
    dy_ptr: T::Pointer<D>,
    dx_ptr: T::Pointer<D>,
    B: i32,
    N: i32,
    stride_dxb: i32,
    stride_dxn: i32,
)
Expand description

Copy a contiguous row-major [B, N] gradient back to an output buffer with arbitrary strides.

This is the backward pass of the flatten operation. The gradient dy arrives as a contiguous row-major tensor (the upstream gradient matches the contiguous forward output); this kernel writes it back to dx using the original input strides so that the gradient is in the same memory layout as the forward input. When the forward input was already row-major contiguous this is again a simple memcpy; when the forward input used a different layout the kernel performs the inverse reordering.