Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVMScript] Add object path tracing to StructuralEqual #12101

Merged
merged 5 commits into from
Aug 3, 2022

Conversation

gbonik
Copy link
Contributor

@gbonik gbonik commented Jul 14, 2022

Motivation: when two IR objects fail a structural equality check, currently there is no easy way to find out which part of the IR caused the mismatch. In this PR, we modify the StructuralEqual infrastructure to also optionally return a pair of ObjectPath objects that point to the mismatch. (See #11977). In the upcoming PRs, we will pass these paths to the TIR printer, so that it could highlight the mismatch location nicely.

Tracking issue: #11912

cc @yelite @junrushao1994

src/node/reflection.cc Outdated Show resolved Hide resolved
Motivation: when two IR objects fail a structural equality check, currently there is no easy way to
find out which part of the IR caused the mismatch. In this PR, we modify the `StructuralEqual`
infrastructure to also optionally return a pair of `ObjectPath` objects that point to the mismatch.
(See apache#11977). In the upcoming PRs, we will pass these paths to the
TIR printer, so that it could highlight the mismatch location nicely.

Tracking issue: apache#11912
Comment on lines +311 to +317
static void GetPathsFromAttrAddressesAndStoreMismatch(const void* lhs_address,
const void* rhs_address,
const PathTracingData* tracing_data);

template <typename T>
static bool CompareAttributeValues(const T& lhs, const T& rhs,
const PathTracingData* tracing_data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - do you think it would make more sense to move those two methods to the cc file? The primary concern I'm having is that CompareAttributeValues is a templated method whose instantiation is all inside a cc file. If we care about visibility, we could introduce a friend class SEqualReducerHelper which has those two methods as static members

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the actual concern about having a function template declared in the header?

I don't have a strong opinion, can move these to a helper friend class if you prefer it that way.

Copy link
Member

@junrushao junrushao Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no concrete problem in this particular case AFAICT - because template instantiation is only defined and used in a single cc file.

On the other hand, in more generic usecases, we would prefer template instantiation being defined in header files so that it's discoverable by the compiler when multiple cc files refer to this method.

Therefore, it's somehow a personal preference (so it's subjective, not any general requirement) that I either define both instantiation and declaration in header file, or both in cc files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I mostly understand your point, but I'm missing one thing: why is this specific to function templates? For example, the non-template helper function GetPathsFromAttrAddressesAndStoreMismatch just above is also private but we have to put its declaration in the header file, because it is a static function in our class (which we need because of C++ visibility rules).

Even if we go with the SEqualReducerHelper approach, we still need to leak some details in the header file because we need to either declare it as a static class or as a friend class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my personal (again it's just subjective) preference is that we hide anything that's not intended to be publicly used, except for non-static methods when it requires some boilerplate code (adding helper friend classes / methods). If a method is in a header file, I would prefer to document it more or less to make it easier for others to catch up

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks pretty good! Let's fix some nitpicks and then get it merged!

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@junrushao junrushao merged commit 39ffe0a into apache:main Aug 3, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
Motivation: when two IR objects fail a structural equality check, currently there is no easy way to
find out which part of the IR caused the mismatch. In this PR, we modify the `StructuralEqual`
infrastructure to also optionally return a pair of `ObjectPath` objects that point to the mismatch.
(See apache#11977). In the upcoming PRs, we will pass these paths to the
TIR printer, so that it could highlight the mismatch location nicely.

Tracking issue: apache#11912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants