3 #include <ATen/Backtrace.h> 4 #include <ATen/core/functional.h> 5 #include <ATen/core/stack.h> 6 #include <c10/util/Exception.h> 7 #include <torch/csrc/WindowsTorchApiMacro.h> 8 #include <torch/csrc/autograd/function_hook.h> 9 #include <torch/csrc/autograd/variable.h> 10 #include <torch/csrc/jit/constants.h> 11 #include <torch/csrc/jit/ir.h> 12 #include <torch/csrc/jit/tracing_state.h> 13 #include <torch/csrc/utils/variadic.h> 19 #include <unordered_map> 26 using ::c10::ivalue::List;
27 using ::c10::ivalue::Shared;
30 using ::c10::ivalue::Future;
31 using ::c10::ivalue::Tuple;
33 using ::c10::ivalue::BoolList;
34 using ::c10::ivalue::DoubleList;
35 using ::c10::ivalue::GenericList;
36 using ::c10::ivalue::IntList;
37 using ::c10::ivalue::TensorList;
39 using ::c10::ivalue::ConstantString;
42 using variable_list = std::vector<Variable>;
44 TORCH_API
void recordSourceLocation(Node* n);
45 TORCH_API
void setRecordSourceLocation(
void (*v)(Node*));
50 TORCH_API
void setValueTrace(
const IValue& v, Value* value);
52 TORCH_API
void delValueTrace(
const Variable& var);
54 TORCH_API std::function<void()> pauseTracing();
56 TORCH_API Value* getValueTrace(
const IValue& var);
58 TORCH_API Value* getNestedValueTrace(
const IValue& v);
60 TORCH_API Value* getOutputTrace(
61 const std::shared_ptr<TracingState>& state,
64 TORCH_API Value* getNestedOutputTrace(
65 const std::shared_ptr<TracingState>& state,
68 TORCH_API std::pair<std::shared_ptr<TracingState>, Stack> enter(Stack inputs);
70 TORCH_API
void exit(
const Stack& outputs);
72 TORCH_API
void abandon();
76 TORCH_API
void addInputs(Node* n,
const char* name, int64_t value);
77 TORCH_API
void addInputs(
81 TORCH_API
void addInputs(Node* n,
const char* name,
bool value);
82 TORCH_API
void addInputs(Node* n,
const char* name,
double value);
83 TORCH_API
void addInputs(Node* n,
const char* name,
const at::Scalar& value);
84 TORCH_API
void addInputs(
88 TORCH_API
void addInputs(Node* n,
const char* name,
const at::Tensor& value);
89 TORCH_API
void addInputs(Node* n,
const char* name,
at::IntArrayRef value);
90 TORCH_API
void addInputs(
94 bool allow_undefined =
false);
95 TORCH_API
void addInputs(
98 const ArrayRef<double>& value);
99 TORCH_API
void addInputs(
102 const std::vector<double>& value);
103 TORCH_API
void addInputs(Node* n,
const char* name,
const std::string& value);
104 TORCH_API
void addInputs(
108 TORCH_API
void addInputs(
112 TORCH_API
void addInputs(Node* n,
const char* name,
at::Device value);
113 TORCH_API
void addInputs(Node* n,
const char* name, at::Layout value);
114 TORCH_API
void addInputs(Node* n,
const char* name, at::ScalarType value);
115 TORCH_API
void addInputs(
119 TORCH_API
void addInputs(Node* n,
const char* name,
at::Generator* value);
122 TORCH_API
void addInputs(
125 const std::vector<T>& value);
127 template<
typename K,
typename V>
128 TORCH_API
void addInputs(
131 const std::unordered_map<K, V>& value);
137 const std::vector<T>& value) {
138 AT_ERROR(
"Tracing a list of arbitrary type is currently not supported!");
140 template<
typename K,
typename V>
144 const std::unordered_map<K, V>& value) {
145 AT_ERROR(
"Tracing a dict of arbitrary types is currently not supported!");
149 void addInputs(Node* n,
const char* name, std::array<bool, N> value) {
150 throw std::runtime_error(
151 "Found an unsupported argument type in the JIT tracer. File a bug report.");
154 TORCH_API
void ensureUniqueIfOutOfPlaced(
160 typename = torch::enable_if_t<
161 (!std::is_convertible<torch::decay_t<T>,
at::TensorList>::value &&
162 !std::is_convertible<torch::decay_t<T>,
at::Tensor>::value)>>
163 void addOutput(Node* node,
T&&) {
165 "Found an unsupported argument type ",
166 c10::demangle_type<T>(),
167 " in the JIT tracer. File a bug report.");
169 TORCH_API
void addOutput(Node* node,
const at::Tensor& tensor);
170 TORCH_API
void setOutput(Value* value,
const at::Tensor& output);
171 TORCH_API
void addOutput(Node* node,
const std::vector<at::Tensor>& list);
173 TORCH_API autograd::Variable getSizeOf(
174 const autograd::Variable& var,
Scalar represents a 0-dimensional tensor which contains a single element.
Represents a a compute device on which a tensor is located.
Variable A Variable augments a Tensor with the ability to interact in our autograd machinery...