Skip to main content

nll_loss_forward

Function nll_loss_forward 

Source
pub fn nll_loss_forward<T: Triton>(
    log_probs_ptr: T::Pointer<f32>,
    targets_ptr: T::Pointer<i32>,
    out_ptr: T::Pointer<f32>,
    _n_rows: i32,
    n_cols: i32,
)
where T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>, T::Pointer<i32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<i32>>>, T::Pointer<f32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<f32>>> + AddOffsets<i32, 1, T::Tensor<i32>, Output = T::Tensor<T::Pointer<f32>>>, T::Tensor<i32>: Tensor<i32, 1>,
Expand description

NLL loss forward: out[n] = -log_prob[n, target[n]].

Grid: [n_rows, 1, 1] — one CTA per batch element.

The flat index pid * n_cols + target is computed entirely in T::Tensor<i32> space (from T::full + T::load arithmetic), avoiding any conversion to T::I32Tensor. A separate AddOffsets bound on T::Pointer<_> for T::Tensor<i32> covers the indexed load and store.