forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymInt.h
More file actions
60 lines (50 loc) · 1.77 KB
/
SymInt.h
File metadata and controls
60 lines (50 loc) · 1.77 KB
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
#pragma once
#include <c10/macros/Macros.h>
#include <c10/util/Exception.h>
namespace c10 {
// `SymInt` is a C++ wrapper class around int64_t data_ which and is used to
// represent concrete dimension values.
//
// `SymInt` is also a data type in Pytorch that can be used in function schemas
// to enable tracing.
//
// `SymInt` is introduced to enable tracing arithmetic
// operations on symbolic integers (e.g. sizes). Tracing symbolic sizes will
// allow LTC and AOTAutograd representing dynamic shapes in expression graphs
// faithfully without baking in concrete dimension values.
//
// To trace the operations, SymInt will overload arithmetic operators (e.g. +, -, *)
// and will provide overloads taking SymInt for commonly used math functions.
//
// SymInt will be extenteded to represent a union structure Union[int64_t, SymbolicIntNode*]
// which will be implemented as a single packed int64_t field named data_.
//
// data_ can be either a plain int64_t or (1 << 63 | `index`). `index` points to
// SymbolicIntNode* that will be responsible for constructing an IR node for
// a traced operation to represent it in LTC or Fx graphs.
class TORCH_API SymInt {
public:
SymInt(int64_t d):
data_(d) {};
int64_t expect_int() const {
// we are dealing with concrete ints only for now
return data_;
}
bool is_symbolic() const {
return false;
}
bool operator==(const SymInt& p2) const
{
return data_ == p2.data_;
}
SymInt operator+(SymInt sci) const {
return data_ + sci.data_;
}
int64_t data() const {
return data_;
}
private:
int64_t data_;
};
TORCH_API std::ostream& operator<<(std::ostream& os, SymInt s);
}