Caffe2 - C++ API
A deep learning, cross platform ML framework
input_buffer.h
1 #pragma once
2 
3 // The InputBuffer class accumulates a list of Variables for use by a
4 // function. It implements logic to avoid modifying the passed
5 // values in-place (adding an input twice will accumulate the result).
6 // This behaviour is needed and used only in backward graphs.
7 
8 #include <vector>
9 #include <utility>
10 #include <memory>
11 #include <ATen/ATen.h>
12 
13 #include <torch/csrc/autograd/variable.h>
14 
15 namespace torch { namespace autograd {
16 
17 struct InputBuffer {
18  explicit InputBuffer(size_t size)
19  : buffer(size) {}
20  InputBuffer(const InputBuffer& other) = delete;
21  InputBuffer(InputBuffer&& other) = default;
22  InputBuffer& operator=(InputBuffer&& other) = default;
23 
24  // Accumulates the variable at a specified index.
25  void add(size_t pos, Variable var);
26 
27  at::Device device() const;
28 
29  Variable operator[](size_t pos) { return buffer[pos]; }
30 
31  // Returns the inputs as a list of variables. Destroys given InputBuffer.
32  static std::vector<Variable> variables(InputBuffer&& g);
33 
34 private:
35  std::vector<Variable> buffer;
36 };
37 
38 }} // namespace torch::autograd
Represents a a compute device on which a tensor is located.
Definition: Device.h:30
Variable A Variable augments a Tensor with the ability to interact in our autograd machinery...
Definition: variable.h:85
Definition: jit_type.h:17