pub fn multi_margin_loss_forward<T: Triton, const BLOCK_SIZE: i32>(
input_ptr: T::Pointer<f32>,
targets_ptr: T::Pointer<i32>,
out_ptr: T::Pointer<f32>,
_n_rows: i32,
n_cols: i32,
margin: f32,
)where
T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>,
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::Pointer<i32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<i32>>>,
T::Tensor<i32>: Tensor<i32, 1>,Expand description
Multi-margin loss forward (per-row).
out[n] = (1/n_cols) * sum_{j != target[n]} max(0, margin - x[n,target] + x[n,j])
Computed as:
(sum_all max(0, margin - x_t + x_j) - max(0, margin)) / n_cols
Grid: [n_rows, 1, 1] — one CTA per row.
BLOCK_SIZE must equal next_power_of_two(n_cols).