moose icon indicating copy to clipboard operation
moose copied to clipboard

Pass values by reference instead of clone

Open mortendahl opened this issue 3 years ago • 2 comments

Kernel functions currently take ownership of Values, which means we clone these every time they are sent between operations. This is wasteful in several ways:

  • if a value is only flowing to a single operation so ownership could simply be moved
  • operators do not generally mutate their inputs and would work just as well with borrowed values
  • certain operators, such as HostRorateRightOp and HostIndexAxisOp, are inherently just projecting their inputs

A likely solution to all three would be to pass Arcs around instead, which can already be freely shared between tasks. Note that there are also specialized structs, such as ndarray::ArcArray, that we could consider using directly. It would also be interesting to consider support for passing around ndarray::ArrayView for projections.

mortendahl avatar Sep 02 '21 11:09 mortendahl

cc @voronaam just to make you aware about this one; some of the ops in https://github.com/tf-encrypted/runtime/pull/508 would likely benefit non-trivially from this since a lot of projection operations are being used

mortendahl avatar Sep 02 '21 11:09 mortendahl

This was mostly done for AsyncSession and SyncSession by switching to ArcArray, but something similar could be done for SymbolicSession to potentially reduce Moose compilation time

mortendahl avatar Mar 04 '22 11:03 mortendahl