StorageUtils.h 1.5 KB

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