Hello. I’m reading C++ source code and quite confused by two classes related to RelayIR - RelayExpr and RelayExprNode. I’m wondering what’s the relationship between these two types? Since RelayExpr can be cast to RelayExprNode* by the method “get()”, and RelayExprNode can be cast to RelayExpr by the method “GetRef()”, why would we use these two diffrent types to represent one thing? Are they representing things in two levels or so? When will tvm use the former and when the latter?
I don’t quite understand the phrase “managed reference”. Could anyone explain it to me? Really appreciate your help!
RelayExprNode
represents the ObjectPtr
in the AST. The same node might need to be referenced at different places across code base, and so the RelayExpr
is a reference counted object that points to the RelayExprNode
. You can think of RelayExpr
as a type of shared_ptr to the underlying node. This allows us to pass and copy the reference as needed, without worrying about memory management.
The best place I found to understand TVM’s Object system in depth was first at the docs here and then the comments at the Object.h
file here