/usr/local/lib64/python3.6/site-packages/torch/include/torch/csrc/jit/ir
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/torch/csrc/jit/ir/attributes.h (4997B)
#pragma once
#include
#include
#include
#include
#include
namespace c10 {
struct Type;
using TypePtr = std::shared_ptr;
} // namespace c10
namespace torch {
namespace jit {
using ::c10::Symbol;
constexpr int max_tensor_display_size = 10;
enum class AttributeKind {
f,
fs,
c,
cs,
i,
is,
s,
ss,
t,
ts,
g,
gs,
ty,
tys,
ival
};
static inline const char* toString(AttributeKind kind) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
static const char* names[] = {
"f",
"c",
"cs",
"fs",
"i",
"is",
"s",
"ss",
"t",
"ts",
"g",
"gs",
"ty",
"tys",
"ival"};
AT_ASSERT(size_t(kind) < sizeof(names) / sizeof(*names));
return names[int(kind)];
}
struct AttributeValue {
AttributeValue(Symbol name) : name(name) {}
using Ptr = std::unique_ptr;
Symbol name;
virtual AttributeKind kind() const = 0;
virtual Ptr clone() const = 0;
virtual ~AttributeValue() = default;
};
template
struct ScalarAttributeValue : public AttributeValue {
using ConstructorType = T;
using ValueType = T;
ScalarAttributeValue(Symbol name, ConstructorType value_)
: AttributeValue(name), value_(std::move(value_)) {}
ValueType& value() {
return value_;
}
Ptr clone() const override {
return Ptr(new ScalarAttributeValue(name, value_));
}
AttributeKind kind() const override {
return Kind;
}
private:
ValueType value_;
};
template
struct VectorAttributeValue : public AttributeValue {
using ConstructorType = std::vector;
using ValueType = std::vector;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
VectorAttributeValue(Symbol name, ConstructorType value_)
: AttributeValue(name), value_(std::move(value_)) {}
ValueType& value() {
return value_;
}
AttributeKind kind() const override {
return Kind;
}
std::unique_ptr clone() const override {
auto copy = value_;
return Ptr(new VectorAttributeValue(name, std::move(copy)));
}
private:
ValueType value_;
};
using ComplexAttr =
ScalarAttributeValue, AttributeKind::c>;
using ComplexValsAttr =
VectorAttributeValue, AttributeKind::cs>;
using FloatAttr = ScalarAttributeValue;
using FloatsAttr = VectorAttributeValue;
using IntAttr = ScalarAttributeValue;
using IntsAttr = VectorAttributeValue;
using StringAttr = ScalarAttributeValue;
using StringsAttr = VectorAttributeValue;
using TensorAttr = ScalarAttributeValue;
using TensorsAttr = VectorAttributeValue;
using TypeAttr = ScalarAttributeValue;
using TypesAttr = VectorAttributeValue;
using IValueAttr = ScalarAttributeValue;
struct Graph;
// We special case Graph attributes like this because we want to ensure that
// Graph::copy() is called when we clone() these attributes.
struct TORCH_API GraphAttr : public AttributeValue {
using ConstructorType = std::shared_ptr;
using ValueType = std::shared_ptr;
GraphAttr(Symbol name, ConstructorType value_)
: AttributeValue(name), value_(std::move(value_)) {}
ValueType& value() {
return value_;
}
Ptr clone() const override;
AttributeKind kind() const override {
return AttributeKind::g;
}
private:
std::shared_ptr value_;
};
struct TORCH_API GraphsAttr : public AttributeValue {
using ConstructorType = std::vector>;
using ValueType = std::vector>;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
GraphsAttr(Symbol name, ConstructorType value_)
: AttributeValue(name), value_(std::move(value_)) {}
ValueType& value() {
return value_;
}
AttributeKind kind() const override {
return AttributeKind::gs;
}
std::unique_ptr clone() const override;
private:
ValueType value_;
};
struct IRAttributeError : public std::exception {
IRAttributeError(Symbol name, bool defined) {
std::stringstream ss;
// NOLINTNEXTLINE(bugprone-branch-clone)
if (!defined) {
ss << "required keyword attribute '" << name.toUnqualString()
<< "' is undefined";
} else {
ss << "required keyword attribute '" << name.toUnqualString()
<< "' has the wrong type";
}
msg = ss.str();
}
const char* what() const noexcept override {
return msg.c_str();
}
private:
std::string msg;
};
} // namespace jit
} // namespace torch