Add ImageCacheKey::lock_hash() so cache locking derives from the key #1146
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 619 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1146"
general
weight: 0.35
gigony
Implements #1066, addressing @mkepa-nv's review note on #1034:
The problem
The cuslide2 tile path built a key from
(ifd_hash, tile_index)and then, on an adjacent line, computed a separateindex_hashfrom those same two values by hand:The same tile was described two different ways with nothing tying them together, so changing one would silently not reach the other.
Worth being explicit about why that is worse than ordinary duplication: the hash only selects which mutex of the pool guards an entry, so a divergence would not fail loudly or immediately.
lock()andunlock()would simply operate on different mutexes, and the tile would be decoded and inserted with no lock actually held. That is a latent data race, not a crash.The change
ImageCacheKey::lock_hash()derives the value from the key, and cuslide2 passeskey->lock_hash()to its lock guard. The formula is exactly the one the IFD readers computed inline, so every tile still maps onto the mutex it mapped to before — no behavioural change.Scope
Deliberately limited to cuslide2, the file the review comment was on. Two other places derive a lock hash by hand and are left alone:
ifd.cppkeeps itsindex_hashbecause aPROF_SCOPED_RANGEprofiling marker consumes it earlier in the function, before any key exists.NvJpegProcessorderives its lock hash withsplitmix64(index)in bothrequest()andwait_for_processing().Both are self-consistent today, so converting them would change which mutex a tile maps to without any functional gain, on a code path I cannot test here.
lock_hash()is available to them whenever that code is next touched with tests to back the change.Tests
cpp/tests/test_image_cache.cppcovers the invariants callers actually depend on rather than restating the implementation:Verification
-fsyntax-onlyagainst the project's owncompile_commands.jsonforimage_cache.cpp,ifd.cppand the new test, which compiles under the test target's-Werror -Wall -Wextra. All clean.I also executed the test assertions standalone, since compiling a test proves nothing about whether it passes:
The distinct-slot property holds across pool sizes 8 through 256, so the assertion is not overfit to the single size the test uses.
Unrelated issue noticed nearby, not fixed here
While tracing the key's hashing I found that
PerProcessImageCache's equality comparator ignoresfile_hash:https://github.com/rapidsai/cucim/blob/main/cpp/src/cache/image_cache_per_process.cpp#L25-L29
std::hashfor the same key does combine both fields, so two keys differing only infile_hashnormally land in different buckets and the comparator is never asked. But bucket assignment ishash % bucket_count, so a collision is possible, and when it happens this returns a tile belonging to a different image or IFD.SharedMemoryImageCache's comparator does compare both fields, which suggests this one is an oversight rather than intentional.Left out of this PR since it is a separate defect with its own behavioural risk. Happy to file it as its own issue if you agree it is one.