EnzymeAD / Reactant.jl

MIT License
54 stars 4 forks source link

Can I compile in-place functions? #152

Closed gdalle closed 2 hours ago

gdalle commented 2 hours ago

There's no such example in the readme, but will I run into trouble if I try to compile an in-place function f!(y, x)?

wsmoses commented 2 hours ago

Yup!

wsmoses commented 2 hours ago

Sorry I meant to say “yes that is supported”

mofeing commented 1 hour ago

@gdalle check out the "buffer donation" tests https://github.com/EnzymeAD/Reactant.jl/blob/main/test/buffer_donation.jl

Buffer Donation means that the XLA buffer we are passing as an argument will no longer be available after the call to the function, so it can reuse that buffer for the result if the shapes are the same... which is exactly what happens on a in-place mutation when you reformulate it as a SSA code.