StorageUtils.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <c10/core/Storage.h>
  3. #include <c10/core/StorageImpl.h>
  4. #include <c10/util/intrusive_ptr.h>
  5. namespace at {
  6. class TensorBase;
  7. // Here we define a series of utils to create/manipulate ATen backed
  8. // c10 storage implementations.
  9. /**
  10. * Create a new shared memory storage impl managed by file descriptor
  11. *
  12. * @param size size in bytes
  13. */
  14. C10_EXPORT c10::intrusive_ptr<c10::StorageImpl> new_shm_fd_storage(size_t size);
  15. /**
  16. * Copy src to dst
  17. * Caller must guarantee the validness of the storage objects
  18. * during the entire copy process, esp. when it's async.
  19. *
  20. * This can probably live in c10 namespace later if needed,
  21. * but for now keep it in at to keep implementation simple.
  22. *
  23. * @param dst dst tensor
  24. * @param src src tensor
  25. * @param non_blocking (default false) whether this operation blocks caller
  26. */
  27. C10_EXPORT void storage_copy(
  28. c10::Storage& dst,
  29. const c10::Storage& src,
  30. bool non_blocking = false);
  31. /**
  32. * In place change the storage to shm based.
  33. *
  34. * This is only applicable to CPU tensors not already shared.
  35. * Otherwise, it's a no op to mirror the THP tensor behavior:
  36. * https://pytorch.org/docs/stable/generated/torch.Tensor.share_memory_.html
  37. *
  38. * @param t a tensor
  39. */
  40. C10_EXPORT void share_memory_(TensorBase& t);
  41. } // namespace at