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