EmptyTensor.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #pragma once
  2. #include <ATen/core/TensorBase.h>
  3. namespace at::detail {
  4. inline void check_size_nonnegative(ArrayRef<int64_t> size) {
  5. for (const auto& x : size) {
  6. TORCH_CHECK(
  7. x >= 0,
  8. "Trying to create tensor with negative dimension ",
  9. x,
  10. ": ",
  11. size);
  12. }
  13. }
  14. inline void check_size_nonnegative(ArrayRef<c10::SymInt> size) {
  15. for (const auto& x : size) {
  16. TORCH_CHECK(
  17. x.expect_size(__FILE__, __LINE__),
  18. "Trying to create tensor with negative dimension ",
  19. x,
  20. ": ",
  21. size);
  22. }
  23. }
  24. TORCH_API size_t computeStorageNbytesContiguous(
  25. IntArrayRef sizes,
  26. size_t itemsize,
  27. size_t storage_offset = 0);
  28. TORCH_API SymInt computeStorageNbytesContiguous(
  29. SymIntArrayRef sizes,
  30. const SymInt& itemsize,
  31. const SymInt& storage_offset = 0);
  32. TORCH_API size_t computeStorageNbytes(
  33. IntArrayRef sizes,
  34. IntArrayRef strides,
  35. size_t itemsize,
  36. size_t storage_offset = 0);
  37. TORCH_API SymInt computeStorageNbytes(
  38. SymIntArrayRef sizes,
  39. SymIntArrayRef strides,
  40. const SymInt& itemsize,
  41. const SymInt& storage_offset = 0);
  42. TORCH_API TensorBase empty_generic(
  43. IntArrayRef size,
  44. c10::Allocator* allocator,
  45. c10::DispatchKeySet ks,
  46. ScalarType scalar_type,
  47. std::optional<c10::MemoryFormat> memory_format_opt);
  48. TORCH_API TensorBase empty_generic_symint(
  49. SymIntArrayRef size,
  50. c10::Allocator* allocator,
  51. c10::DispatchKeySet ks,
  52. ScalarType scalar_type,
  53. std::optional<c10::MemoryFormat> memory_format_opt);
  54. TORCH_API TensorBase empty_strided_generic(
  55. IntArrayRef size,
  56. IntArrayRef stride,
  57. c10::Allocator* allocator,
  58. c10::DispatchKeySet ks,
  59. ScalarType scalar_type);
  60. TORCH_API TensorBase empty_strided_symint_generic(
  61. SymIntArrayRef size,
  62. SymIntArrayRef stride,
  63. c10::Allocator* allocator,
  64. c10::DispatchKeySet ks,
  65. ScalarType scalar_type);
  66. TORCH_API TensorBase empty_cpu(
  67. IntArrayRef size,
  68. ScalarType dtype,
  69. bool pin_memory = false,
  70. std::optional<c10::MemoryFormat> memory_format_opt = c10::nullopt);
  71. TORCH_API TensorBase empty_cpu(
  72. IntArrayRef size,
  73. std::optional<ScalarType> dtype_opt,
  74. std::optional<Layout> layout_opt,
  75. std::optional<Device> device_opt,
  76. std::optional<bool> pin_memory_opt,
  77. std::optional<c10::MemoryFormat> memory_format_opt);
  78. TORCH_API TensorBase empty_cpu(IntArrayRef size, const TensorOptions& options);
  79. TORCH_API TensorBase empty_strided_cpu(
  80. IntArrayRef size,
  81. IntArrayRef stride,
  82. ScalarType dtype,
  83. bool pin_memory = false);
  84. TORCH_API TensorBase empty_strided_cpu(
  85. IntArrayRef size,
  86. IntArrayRef stride,
  87. std::optional<ScalarType> dtype_opt,
  88. std::optional<Layout> layout_opt,
  89. std::optional<Device> device_opt,
  90. std::optional<bool> pin_memory_opt);
  91. TORCH_API TensorBase empty_strided_cpu(
  92. IntArrayRef size,
  93. IntArrayRef stride,
  94. const TensorOptions& options);
  95. TORCH_API TensorBase empty_meta(
  96. IntArrayRef size,
  97. ScalarType dtype,
  98. std::optional<c10::MemoryFormat> memory_format_opt = c10::nullopt);
  99. TORCH_API TensorBase empty_meta(
  100. IntArrayRef size,
  101. std::optional<ScalarType> dtype_opt,
  102. std::optional<Layout> layout_opt,
  103. std::optional<Device> device_opt,
  104. std::optional<bool> pin_memory_opt,
  105. std::optional<c10::MemoryFormat> memory_format_opt);
  106. TORCH_API TensorBase empty_symint_meta(
  107. SymIntArrayRef size,
  108. std::optional<ScalarType> dtype_opt,
  109. std::optional<Layout> layout_opt,
  110. std::optional<Device> device_opt,
  111. std::optional<bool> pin_memory_opt,
  112. std::optional<c10::MemoryFormat> memory_format_opt);
  113. TORCH_API TensorBase empty_meta(IntArrayRef size, const TensorOptions& options);
  114. TORCH_API TensorBase
  115. empty_strided_meta(IntArrayRef size, IntArrayRef stride, ScalarType dtype);
  116. TORCH_API TensorBase empty_strided_meta(
  117. IntArrayRef size,
  118. IntArrayRef stride,
  119. std::optional<ScalarType> dtype_opt,
  120. std::optional<Layout> layout_opt,
  121. std::optional<Device> device_opt,
  122. std::optional<bool> pin_memory_opt);
  123. TORCH_API TensorBase empty_strided_meta(
  124. IntArrayRef size,
  125. IntArrayRef stride,
  126. const TensorOptions& options);
  127. TORCH_API TensorBase empty_strided_symint_meta(
  128. SymIntArrayRef size,
  129. SymIntArrayRef stride,
  130. ScalarType dtype);
  131. TORCH_API TensorBase empty_strided_symint_meta(
  132. SymIntArrayRef size,
  133. SymIntArrayRef stride,
  134. std::optional<ScalarType> dtype_opt,
  135. std::optional<Layout> layout_opt,
  136. std::optional<Device> device_opt,
  137. std::optional<bool> pin_memory_opt);
  138. TORCH_API TensorBase empty_strided_symint_meta(
  139. SymIntArrayRef size,
  140. SymIntArrayRef stride,
  141. const TensorOptions& options);
  142. } // namespace at::detail