1 #include "torch/csrc/jit/operator.h" 2 #include "torch/csrc/jit/custom_operator.h" 4 #include "torch/csrc/autograd/profiler.h" 5 #include "torch/csrc/autograd/generated/variable_factories.h" 8 #include <ATen/core/functional.h> 9 #include <ATen/core/interned_strings.h> 18 #include <unordered_map> 19 #include <unordered_set> 34 namespace torch {
namespace jit {
36 using autograd::Variable;
37 using autograd::variable_list;
63 std::vector<Tensor> toListOfOptionalTensor(
const IValue& v) {
65 auto vlist = v.toGenericListRef();
66 std::vector<Tensor> res;
68 for (
const IValue &v: vlist) {
69 res.emplace_back(toOptionalTensor(v));
75 std::array<bool, N> as_bool_array(
const std::vector<bool>& vec) {
76 std::array<bool, N> res;
77 AT_ASSERT(vec.size() == N);
78 std::copy(vec.begin(), vec.end(), res.begin());
82 RegisterOperators reg({
84 "aten::get_device(Tensor self) -> int",
86 autograd::profiler::RecordFunction record(
"get_device");
87 auto result = at::get_device(
88 (std::move(peek(stack, 0, 1))).toTensor()
91 pack(stack, std::move(result));
96 "aten::storage_offset(Tensor self) -> int",
98 autograd::profiler::RecordFunction record(
"storage_offset");
99 auto result = ((std::move(peek(stack, 0, 1))).toTensor()).storage_offset();
101 pack(stack, std::move(result));
Scalar represents a 0-dimensional tensor which contains a single element.
RAII guard that sets a certain default device in its constructor, and changes it back to the device t...