microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Improve memory use of fold #800

Open awf opened 3 years ago

awf commented 3 years ago

https://github.com/microsoft/knossos-ksc/blob/59f0954f5f31b6cd6ab9b3fe140cb197209b6576/src/runtime/knossos.h#L1419

fold is now:

  z = input
  for i..
    z = f(alloc, z, v[i])
  return z

should be one of

  mark()
  z = input
  for i..
    z = f(alloc, z, v[i])
  reset()
  return copydown(z)

or

  mark()
  z = input
  for i..
    z = f(alloc, z, v[i])
    if heap getting full:
      reset()
      z = copydown(z)

  reset()
  return copydown(z)