Mikolaj / horde-ad

Higher Order Reverse Derivatives Efficiently - Automatic Differentiation library based on the paper "Provably correct, asymptotically efficient, higher-order reverse-mode automatic differentiation"
BSD 3-Clause "New" or "Revised" License
31 stars 6 forks source link

Implement automatic sharing for the surface language code #102

Open Mikolaj opened 1 year ago

Mikolaj commented 1 year ago

That would happen whenever a Tensor class code is instantiated to the Ast instance, in the same step that vectorization happens (I'm not sure how these two would interleave). This would transform any code written by the user from scratch, as well as any code we pretty-print, loosing sharing, and the user copy-pastes and feeds to GHC (perhaps in the same repl session, so any impurity needs to be re-entrant).

I think this is really hard, but fortunately Tom says others did it already:

This is interesting. I'd like it to work without tlet in horde-ad as well. How does Accelerate do it?

Stable names to get global sharing, then the typed sharing recovery algorithm to convert to local sharing. Accelerate literature calls this whole procedure "sharing recovery" instead of just the second half.

Mikolaj commented 1 year ago

@tomsmeding notes:

tomsmeding commented 1 year ago

The data-reify package implements what we have taken to calling "global sharing". I believe Gill '09 does not discuss conversion from global sharing to local sharing, which hoas-conv implements in its Convert.hs. (It does the global sharing detection in Sharing.hs.) If anyone wants the Accelerate paper but doesn't have access, feel free to send me an email.