-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Object] Introduce POD-C Compliant tvm::Map #5740
[Object] Introduce POD-C Compliant tvm::Map #5740
Conversation
Maybe we should get rid of __builtin_clz as it is the slow path anyway |
@junrushao1994 +1 |
Some actionable items per offline discussion with @tqchen: A1. We move things back to include/tvm/node, instead of runtime. This is mainly due to the concern of keeping tvm runtime minimal. Once we find a strong use case that really need HashMap to exist in tvm runtime, we can bring it back. So it requires some amount of work. I will turn it back to draft until the work is done :-) |
A1 and A2 is done over the commits above |
A4 is done with the last commit |
A3 is done over the last commits |
@zhiics @icemelon9 could you guys take another look? much appreciated! |
Summary of the change:
|
@tqchen Just responded to all the review comments, added test cases and code comments, could you take another look? |
@zhiics please take another look and https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only some nitpicks. Otherwise, LGTM.
@zhiics Could you take another look? Thanks! |
THanks @junrushao1994 @zhiics ! |
Related discussion: https://discuss.tvm.ai/t/discuss-runtime-array-containers-array-adt-string/4582.
This PR introduces
tvm::Map
andtvm::MapNode
:MapNode
is a POD-C compliant alternative to `std::unordered_map<ObjectRef, ObjectRef>;Map
is the shared reference to the container which implements copy-on-write semantics.Features
tvm::Map
tvm::MapNode
is kept to be mutable and iterableBreaking changes
MapNode
no longer has the fieldstd::unordered_map<ObjectRef, ObjectRef> data
, and all its methods currently used are implemented toMapNode
itselfMapNode
is natively supported directly via interfaces likeMapNode::begin()
Performance
To show that the introduction of
tvm::Map
won't hurt performance, I also did some rough benchmark on my laptop on the success insertion performance.Hardware: MacBook Pro (16-inch, 2019)
Memory: 8 GB * 2, DDR4, 2667 MHz
CPU: Intel i7-9750H CPU @ 2.60GHz
OS: macOS Catalina 10.15.5
Compiler: Apple clang version 11.0.3 (clang-1103.0.32.62)
tvm::MapNode
std::unordered_map
Scripts are available on gist. Note that the measured time may depend on operation, randomness, cache line, compiler, etc.
Credits
We use [1] for placing an item on a table of size of power-of-2. We learned that triangle numbers that could iterate through the power-of-2-sized table through [2]. The idea that linked list can be placed in the same table is learned from [3].
[1] Fibonacci Hashing: https://programmingpraxis.com/2018/06/19/fibonacci-hash/
[2] Quadratic probing with triangle numbers: https://fgiesen.wordpress.com/2015/02/22/triangular-numbers-mod-2n/
[3] Flat hash map: https://github.com/skarupke/flat_hash_map
Thank you @mbrookhart for the valuable discussion!
Also CC @tqchen @icemelon9 @yzhliu @zhiics @comaniac @kevinthesun @jwfromm @jroesch if you guys are interested.