Make Future store Storages instead of references to DataPtrs (#60470)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/60470
A Future needs to know what DataPtrs are used by its value, but it isn't always able to extract them (and even when it is, that's expensive) so they're cached. DataPtrs are kinda like unique_ptrs (movable only, cannot be copied) hence the Future can only hold _references_ to them. The Future's value, however, is unfortunately mutable (we'd wish that weren't the case, but we don't think we can prevent that), which means the tensor/storage that owned that DataPtr might be deleted and thus the DataPtr could be freed. This means our cached reference becomes stale! Which leads to all kinds of disaster, like reading garbage data or segfaulting.
Luckily all the DataPtrs we were dealing with were held inside Storages, which have a shared_ptr semantics, thus allowing us to hold a strong pointer to them which ensures they're kept alive.
ghstack-source-id: 132177396
Test Plan: CI
Reviewed By: mrshenli
Differential Revision: D29303570
fbshipit-source-id: d814754806fa58b24e45269e97d768485ef972ba