torch/csrc/jit/passes/common_subexpression_elimination.cpp
// Check whether two nodes have the same attributes in CSE.
// This function may be too conservative for general use.
// Do NOT support t/ts/g/gs attributes.
// If t/ts are supported, CONSTANT node comparison may need to consider device.
Check whether two nodes have the same attributes in CSE.
This function may be too conservative for general use.
Do NOT support t/ts/g/gs attributes.
If t/ts are supported, CONSTANT node comparison may need to consider device.
Check whether two nodes have the same attributes in CSE . This function may be too conservative for general use . Do NOT support t / ts / g / gs attributes . If t / ts are supported CONSTANT node comparison may need to consider device .
bool attributesEqualCSE(const Node* lhs, const Node* rhs) {
  JIT_ASSERT(lhs != nullptr);
  JIT_ASSERT(rhs != nullptr);
  if (lhs->hasAttributes() != rhs->hasAttributes()) return false;
  if (!lhs->hasAttributes() && !rhs->hasAttributes()) return true;
  auto lnames = lhs->attributeNames();
  auto rnames = rhs->attributeNames();
  std::sort(lnames.begin(), lnames.end());
  std::sort(rnames.begin(), rnames.end());
  if (lnames != rnames) return false;
  for (auto name : lnames) {
    if (lhs->kindOf(name) != rhs->kindOf(name)) return false;
    #define COMPARE_ATTRIBUTEVALUE(type) \
      case AttributeKind::type: \
        { if (lhs->type(name) != rhs->type(name)) return false; } break;
    switch(lhs->kindOf(name)) {
      COMPARE_ATTRIBUTEVALUE(f)
      COMPARE_ATTRIBUTEVALUE(fs)
      COMPARE_ATTRIBUTEVALUE(i)
      COMPARE_ATTRIBUTEVALUE(is)
      COMPARE_ATTRIBUTEVALUE(s)
      COMPARE_ATTRIBUTEVALUE(ss)
      case AttributeKind::t: {
        if (!tensorEqual(lhs->t(name), rhs->t(name))) return false;
        break;
      }
      case AttributeKind::ts: {
        if (!tensorListEqual(lhs->ts(name), rhs->ts(name))) return false;
        break;
      }
      case AttributeKind::g:
      case AttributeKind::gs:
        return false;
    }
    #undef COMPARE_ATTRIBUTEVALUE
  }
  return true;
}
bool attributesEqualCSE ( const Node * lhs , const Node * rhs ) { JIT_ASSERT ( lhs != nullptr ) ; JIT_ASSERT ( rhs != nullptr ) ; if ( lhs -> hasAttributes ( ) != rhs -> hasAttributes ( ) ) return false ; if ( ! lhs -> hasAttributes ( ) && ! rhs -> hasAttributes ( ) ) return true ; auto lnames = lhs -> attributeNames ( ) ; auto rnames = rhs -> attributeNames ( ) ; std :: sort ( lnames . begin ( ) , lnames . end ( ) ) ; std :: sort ( rnames . begin ( ) , rnames . end ( ) ) ; if ( lnames != rnames ) return false ; for ( auto name : lnames ) { if ( lhs -> kindOf ( name ) != rhs -> kindOf ( name ) ) return false ; #define COMPARE_ATTRIBUTEVALUE ( type )  \
      case AttributeKind::type: \
        { if (lhs->type(name) != rhs->type(name)) return false; } break; switch ( lhs -> kindOf ( name ) ) { COMPARE_ATTRIBUTEVALUE ( f ) COMPARE_ATTRIBUTEVALUE ( fs ) COMPARE_ATTRIBUTEVALUE ( i ) COMPARE_ATTRIBUTEVALUE ( is ) COMPARE_ATTRIBUTEVALUE ( s ) COMPARE_ATTRIBUTEVALUE ( ss ) case AttributeKind :: t : { if ( ! tensorEqual ( lhs -> t ( name ) , rhs -> t ( name ) ) ) return false ; break ; } case AttributeKind :: ts : { if ( ! tensorListEqual ( lhs -> ts ( name ) , rhs -> ts ( name ) ) ) return false ; break ; } case AttributeKind :: g : case AttributeKind :: gs : return false ; } #undef  COMPARE_ATTRIBUTEVALUE } return true ; }
Check whether two nodes have the same attributes in CSE.
Check whether two nodes have the same attributes in CSE .
// One has attributes, the other does not. // Neither has attributes.