23 #ifndef TVM_NODE_STRUCTURAL_EQUAL_H_ 24 #define TVM_NODE_STRUCTURAL_EQUAL_H_ 40 bool operator()(
const double& lhs,
const double& rhs)
const {
42 constexpr
double atol = 1e-9;
43 if (lhs == rhs)
return true;
44 double diff = lhs - rhs;
45 return diff > -atol && diff < atol;
48 bool operator()(
const int64_t& lhs,
const int64_t& rhs)
const {
return lhs == rhs; }
49 bool operator()(
const uint64_t& lhs,
const uint64_t& rhs)
const {
return lhs == rhs; }
50 bool operator()(
const int& lhs,
const int& rhs)
const {
return lhs == rhs; }
51 bool operator()(
const bool& lhs,
const bool& rhs)
const {
return lhs == rhs; }
52 bool operator()(
const std::string& lhs,
const std::string& rhs)
const {
return lhs == rhs; }
54 template <typename ENum, typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
55 bool operator()(
const ENum& lhs,
const ENum& rhs)
const {
70 static constexpr
const char* _type_key =
"ObjectPathPair";
106 using BaseValueEqual::operator();
126 struct PathTracingData;
144 virtual bool SEqualReduce(
const ObjectRef& lhs,
const ObjectRef& rhs,
bool map_free_vars,
168 virtual void MarkGraphNode() = 0;
183 : handler_(handler), tracing_data_(tracing_data), map_free_vars_(map_free_vars) {}
191 bool operator()(
const double& lhs,
const double& rhs)
const;
192 bool operator()(
const int64_t& lhs,
const int64_t& rhs)
const;
193 bool operator()(
const uint64_t& lhs,
const uint64_t& rhs)
const;
194 bool operator()(
const int& lhs,
const int& rhs)
const;
195 bool operator()(
const bool& lhs,
const bool& rhs)
const;
196 bool operator()(
const std::string& lhs,
const std::string& rhs)
const;
199 template <typename ENum, typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
201 using Underlying =
typename std::underlying_type<ENum>::type;
202 static_assert(std::is_same<Underlying, int>::value,
203 "Enum must have `int` as the underlying type");
204 return EnumAttrsEqual(static_cast<int>(lhs), static_cast<int>(rhs), &lhs, &rhs);
231 ICHECK(IsPathTracingEnabled()) <<
"Path tracing must be enabled when calling this function";
232 return ObjectAttrsEqual(lhs, rhs, map_free_vars_, &paths);
254 template <
typename T>
256 if (tracing_data_ ==
nullptr) {
259 if (lhs.
size() != rhs.
size())
return false;
260 for (
size_t i = 0; i < lhs.
size(); ++i) {
261 if (!(
operator()(lhs[i], rhs[i])))
return false;
269 return (*
this)(lhs_obj, rhs_obj);
279 handler_->MarkGraphNode();
282 return lhs == rhs || map_free_vars_;
306 bool EnumAttrsEqual(
int lhs,
int rhs,
const void* lhs_address,
const void* rhs_address)
const;
311 static void GetPathsFromAttrAddressesAndStoreMismatch(
const void* lhs_address,
312 const void* rhs_address,
313 const PathTracingData* tracing_data);
315 template <
typename T>
316 static bool CompareAttributeValues(
const T& lhs,
const T& rhs,
317 const PathTracingData* tracing_data);
322 const PathTracingData* tracing_data_ =
nullptr;
324 bool map_free_vars_ =
false;
328 #endif // TVM_NODE_STRUCTURAL_EQUAL_H_ ObjectPath lhs_path
Definition: structural_equal.h:65
SEqualReducer::PathTracingData PathTracingData
Definition: structural_equal.h:171
bool operator()(const uint64_t &lhs, const uint64_t &rhs) const
Definition: structural_equal.h:49
bool operator()(const std::string &lhs, const std::string &rhs) const
Definition: structural_equal.h:52
Pair of ObjectPaths, one for each object being tested for structural equality.
Definition: structural_equal.h:63
bool operator()(const double &lhs, const double &rhs) const
Definition: structural_equal.h:40
bool FreeVarEqualImpl(const runtime::Object *lhs, const runtime::Object *rhs) const
Implementation for equality rule of var type objects(e.g. TypeVar, tir::Var).
Definition: structural_equal.h:277
bool operator()(const int &lhs, const int &rhs) const
Definition: structural_equal.h:50
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
bool operator()(const DataType &lhs, const DataType &rhs) const
Definition: structural_equal.h:53
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
bool operator()(const bool &lhs, const bool &rhs) const
Definition: structural_equal.h:51
base class of all object containers.
Definition: object.h:167
bool operator()(const ENum &lhs, const ENum &rhs) const
Definition: structural_equal.h:55
Content-aware structural equality comparator for objects.
Definition: structural_equal.h:103
Runtime Array container types.
bool operator()(const int64_t &lhs, const int64_t &rhs) const
Definition: structural_equal.h:48
bool IsPathTracingEnabled() const
Check if this reducer is tracing paths to the first mismatch.
Definition: structural_equal.h:289
size_t size() const
Definition: array.h:418
Runtime primitive data type.
Definition: data_type.h:41
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
bool operator()(const ENum &lhs, const ENum &rhs) const
Definition: structural_equal.h:200
bool operator()(const Array< T > &lhs, const Array< T > &rhs) const
Reduce condition to comparison of two arrays.
Definition: structural_equal.h:255
Defines the Functor data structures.
SEqualReducer(Handler *handler, const PathTracingData *tracing_data, bool map_free_vars)
Constructor with a specific handler.
Definition: structural_equal.h:182
Base class of all object reference.
Definition: object.h:511
Definition: structural_equal.h:74
Internal handler that defines custom behaviors..
Definition: structural_equal.h:130
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
ObjectPath rhs_path
Definition: structural_equal.h:66
bool operator()(const ObjectRef &lhs, const ObjectRef &rhs, const ObjectPathPair &paths) const
Reduce condition to comparison of two objects.
Definition: structural_equal.h:230
Definition: object_path.h:122
Equality definition of base value class.
Definition: structural_equal.h:38
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
Handler * operator->() const
Definition: structural_equal.h:286