Skip to content
fn

accumulate_into

void accumulate_into(int & dst, const int & src)

Accumulate src into dst element-wise (dst += src).

Handles all three Storage variants:

  • CpuStorage / CpuStorage — hand-written typed loop for F32 / F64 / I32 / I64.
  • GpuStorage / GpuStorage — MLX add followed by rewrap.
  • SharedStorage variants — obtain a CpuStorage view of the shared region and delegate to the CPU path.

Parameters

dstStorage&
Accumulator buffer; modified in place.
srcconst Storage&
Buffer to add into dst.

Raises

DtypeMismatch
dst and src have different element dtypes.
DeviceMismatch
dst and src belong to different device categories.

Notes

The most common caller is AccumulateGrad, which uses this to fold each newly-arrived gradient into a leaf's running .grad.