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