-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Attempt to prevent concurrent update in Map #9842
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
Conversation
|
Hey @d-smirnov for this PR! Iterator invalidation is a problem that exists for multiple languages, and a general rule of thumb is to avoid modifying a container when iterating it - even though STL impl guarantees that for associative containers, inserting a new element doesn't invalidate iterators that point to existing elements. I personally got bitten by this issue once in the past year, and thus am supportive of more careful checks. However, runtime check is neither sufficient (consider the multi-threaded case) nor efficient (incur runtime overhead). Therefore, I was wondering if you might want to update this PR with the following changes:
|
Will proceed with NDEBUG |
|
@junrushao1994
Could you advise on this, please? |
|
Thanks @d-smirnov for trying this out! TBH I don't have much experience on which macro to use. @tqchen do you have any ideas? Thanks in advance! |
|
TVM_LOG_DEBUG might be a good candidate given it is used to control DCHECK etc. I agree that iterator concurrent update is a problem of stl containers as well so we should not include the code in a prod mode. |
|
@tqchen Since we virtually have no NDEBUG macro available (due to LLVM issue), could a separate debug macro (i.e. TVM_DEBUG or similar) be considered instead to be present in pre-processor if @junrushao1994 I might be wrong but it looks like Array does not need this type of checks. Could you advise on this, please |
|
@d-smirnov Thanks for investigating in the Array implementation! The particular case I encountered in the past year is that when iterating an Array, changing its contents might lead to segfault, so it might make sense to protect Array as well :-) |
|
The counter doesn't need to be atomic. The structure is not thread-safe anyways, so making the counter atomic doesn't do much. |
|
@kparzysz-quic ok that's a fair point! |
|
@d-smirnov want to update this PR? i believe we can remove the atomic counter and then it seems like it could be ready to merge after that. |
Calling Map::Set invalidates exising iterators to protect from using already deleted data due to re-hashing Change-Id: Ib6b580758e74c8b77ed560932d87b643bd6c9402
Now uses TVM_LOG_DEBUG Map state_marker made atomic Change-Id: I090c4b33e6edaa977cccba11f8d1c6ff3fbca430
Change-Id: I7bd930cb52d58ca10fd49a5fe8f5d48b3e955d0a
|
@areusch I removed atomics. My concerns are mostly about "dormant state" of this changes due to usage of TVM_LOG_DEBUG requires extra efforts. |
|
@kparzysz-quic and I were discussing updating the LLVM used in CI to have |
|
let's discuss whether we think we can enable USE_RELAY_DEBUG in CI, since otherwise this PR is essentially a no-op. i think this would require us to either create ci_cpu_asserts and run the unittests there, or to decide that ci_cpu or ci_i386 should be dedicated to running with asserts/USE_RELAY_DEBUG on. i sort of favor creating ci_cpu_asserts...thoughts @tqchen @driazati @leandron ? |
|
I'd also be in favor of having a more stringent build like |
|
ok so let's merge this given the group discussion about moving towards a CI image that has more asserts and USE_RELAY_DEBUG enabled. |
|
@areusch @driazati Hi guys, thanks for your contribution to TVM. I think I found a bug related with this PR. After merging this branch to main, the cpp tests are going to be failed with segfault. Here are the logs. All the failed cases are raised when using map. When I revert this patch, CPP tests were passed. |


Calling Map::Set invalidates existing iterators to protect from
using already deleted data due to re-hashing
Related to the issue fixed here