EmptyTensor.h 4.2 KB

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