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

Add reflection for std::unordered_map to support hashing global circular buffers #15797

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

tt-aho
Copy link
Contributor

@tt-aho tt-aho commented Dec 6, 2024

Ticket

Link to Github Issue

Problem description

Need to support hashing the GlobalCircularBuffer object in order to be consumed by ops, which has an unordered_map.

What's changed

Add hashing support for std::map and std::unordered_map.

Checklist

@tt-aho tt-aho force-pushed the aho/hash-global-cb branch from ee9faa4 to a5e4724 Compare December 8, 2024 17:37
@tt-aho tt-aho changed the title Add reflection for std::map to support hashing global circular buffers Add reflection for std::unordered_map to support hashing global circular buffers Dec 8, 2024
@tt-aho tt-aho force-pushed the aho/hash-global-cb branch from a5e4724 to 7210be5 Compare December 9, 2024 14:29
Copy link
Member

@ayerofieiev-tt ayerofieiev-tt left a comment

Choose a reason for hiding this comment

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

lgtm. definitely needs metal team review.

// Combine using xor so that the hash is order invariant
// Alternative could be to sort the keys before hashing
for (const auto& [key, value] : object) {
hash ^= hash_objects(seed, key, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be a bit worried by this, possibly introduces some extra hash collisions. I would prefer to sort them instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I will change to sort instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sminakov-tt I've updated to sort first then hash the same way as std::map. Let me know if this looks okay now.

@tt-aho tt-aho force-pushed the aho/hash-global-cb branch from 7210be5 to d4109d1 Compare December 9, 2024 23:00
@tt-aho tt-aho merged commit c2c2b16 into main Dec 10, 2024
32 checks passed
@tt-aho tt-aho deleted the aho/hash-global-cb branch December 10, 2024 07:11
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.

4 participants