packed_width: Columns in the concatenated S/M row.
block_rows: Flattened matrix rows per program, unrelated to token chunk size.
save_matrix: Whether a later round consumes compact M.
"""
rows = tl.program_id(0) * block_rows + tl.arange(0, block_rows)
cols = tl.arange(0, state_width)
offsets = rows[:, None] * packed_width + cols[None, :]
left = tl.load(product + offsets, rows[:, None] < row_count, 0)
old = tl.load(previous + offsets, rows[:, None] < row_count, 0)
tl.store(product + offsets, left + old, rows[:, None] < row_count)
if save_matrix:
right = tl.load(product + offsets + state_width, rows[:, None] < row_count, 0)
tl.store(matrix + rows[:, None] * state_width + cols[None, :], right, rows[:, None] < row_count)
@triton.jit
def kda_rd_finish_to_state_kernel(
product: tl.tensor, previous: tl.tensor, matrix: tl.tensor, state: tl.tensor,
row_count: tl.constexpr, state_width: tl.constexpr, packed_width: tl.constexpr,
block_rows: tl.constexpr, save_matrix: tl.constexpr,
) -> None: