forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSymNodeImpl.h
218 lines (211 loc) · 5.79 KB
/
SymNodeImpl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#pragma once
#include <c10/macros/Export.h>
#include <c10/util/ArrayRef.h>
#include <c10/util/Exception.h>
#include <c10/util/Optional.h>
#include <c10/util/intrusive_ptr.h>
#include <cstdint>
#include <ostream>
#include <string>
namespace c10 {
class SymNodeImpl;
using SymNode = c10::intrusive_ptr<SymNodeImpl>;
// When you add a method, you also need to edit
// torch/csrc/jit/python/init.cpp
// torch/csrc/utils/python_symnode.h
// c10/core/ConstantSymNodeImpl.h
class C10_API SymNodeImpl : public c10::intrusive_ptr_target {
public:
~SymNodeImpl() override = default;
template <typename T>
c10::intrusive_ptr<T> dyn_cast() const {
return c10::intrusive_ptr<T>::reclaim_copy(dynamic_cast<T*>(this));
}
// these could be pure virtual when we implement LTC versions
virtual bool is_int() {
TORCH_CHECK(false, "NYI");
};
virtual bool is_bool() {
TORCH_CHECK(false, "NYI");
};
virtual bool is_float() {
TORCH_CHECK(false, "NYI");
};
virtual bool is_nested_int() const {
return false;
};
virtual SymNode add(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sub(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode mul(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode truediv(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode pow(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode floordiv(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode mod(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode eq(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode ne(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode gt(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode lt(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode le(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode ge(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode ceil() {
TORCH_CHECK(false, "NYI");
};
virtual SymNode floor() {
TORCH_CHECK(false, "NYI");
};
virtual SymNode neg() {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_min(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_max(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_or(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_and(const SymNode& other) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_not() {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_ite(const SymNode& then_val, const SymNode& else_val) {
TORCH_CHECK(false, "NYI");
};
// NB: self is ignored here, only the arguments are used
virtual SymNode is_contiguous(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode is_channels_last_contiguous_2d(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode is_channels_last_contiguous_3d(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode is_channels_last_strides_2d(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode is_channels_last_strides_3d(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode is_non_overlapping_and_dense(
ArrayRef<SymNode> sizes,
ArrayRef<SymNode> strides) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode clone() {
TORCH_CHECK(false, "NYI");
};
virtual SymNode sym_float() {
TORCH_CHECK(false, "NYI");
}
virtual SymNode wrap_int(int64_t num) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode wrap_float(double num) {
TORCH_CHECK(false, "NYI");
};
virtual SymNode wrap_bool(bool num) {
TORCH_CHECK(false, "NYI");
};
virtual int64_t guard_int(const char* file, int64_t line) {
TORCH_CHECK(false, "NYI");
};
virtual bool guard_bool(const char* file, int64_t line) {
TORCH_CHECK(false, "NYI");
};
virtual double guard_float(const char* file, int64_t line) {
TORCH_CHECK(false, "NYI");
};
virtual bool guard_size_oblivious(const char* file, int64_t line) {
// No improvement for unbacked SymBools by default, replace this
// with a better implementation!
return guard_bool(file, line);
}
virtual bool expect_true(const char* file, int64_t line) {
// No improvement for unbacked SymBools by default, replace this
// with a better implementation!
return guard_bool(file, line);
};
virtual bool expect_size(const char* file, int64_t line) {
// No improvement for unbacked SymInts by default, replace this
// with a better implementation!
return ge(wrap_int(0))->guard_bool(file, line);
};
virtual int64_t int_() {
TORCH_CHECK(false, "NYI");
};
virtual bool bool_() {
TORCH_CHECK(false, "NYI");
};
virtual bool has_hint() {
TORCH_CHECK(false, "NYI");
};
virtual std::string str() {
TORCH_CHECK(false, "NYI");
};
virtual c10::optional<int64_t> nested_int() {
return c10::nullopt;
}
virtual c10::optional<int64_t> nested_int_coeff() {
return c10::nullopt;
}
virtual c10::optional<int64_t> constant_int() {
return c10::nullopt;
}
virtual c10::optional<bool> constant_bool() {
return c10::nullopt;
}
virtual c10::optional<int64_t> maybe_as_int() {
return c10::nullopt;
}
virtual bool is_constant() {
return false;
}
virtual bool is_symbolic() {
return true;
}
std::ostream& operator<<(std::ostream& os) {
os << str();
return os;
}
};
} // namespace c10