refactor: simplify operator cache fast path - #920
Draft
voltjia wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CacheKey::Matchesreturn booleans directly and short-circuit on the first mismatch.find-> construct ->emplacemiss path, removing the temporary null entry and manual rollback.Motivation
This PR is stacked on #858 and keeps its two-entry thread-local hot path intact. It removes incidental complexity without giving up the measured hot-path improvement.
The
try_emplacemiss path in #858 inserts{key, nullptr}before constructing the operator and retains the returned iterator acrossMake. If construction re-enters the same cache, a same-key call can observe the incomplete entry, while a different-key insertion can rehash the map and invalidate the retained iterator.Constructing before
emplaceleaves the map unchanged on failure and avoids using a map iterator across operator construction, so the explicittry/eraserecovery is no longer needed.Type of Change
feat- new feature / new operator / new platformfix- bug fixperf- performance improvement (no behavioral change)refactor- code restructuring without behavior changetest- adding or fixing tests onlydocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changesPlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
NVIDIA A100-SXM4-80GB, fixed container image
dd94fce2f83a, the InfiniRT prefix documented by #858, and explicitCMAKE_CUDA_ARCHITECTURES=80:Push checks on
dff02818914f2524371431142149a269a144bac0:Test Results on Supported Platforms
Benchmark / Performance Impact
Three revisions were built in the same environment:
2cfb526080395a9ffeab319ad5c382e8260773d4, before perf: avoid redundant operator cache lookups #858.a27876625c9f8ddb7ae8dc0580ffc01aa60c6142, the current perf: avoid redundant operator cache lookups #858 implementation.dff02818914f2524371431142149a269a144bac0, this simplification.Each comparison used seven paired
A-B-C-C-B-Ablocks. Each process reported the median of nine rounds; block ratios use geometric means and 20,000-sample paired bootstrap 95% confidence intervals. Negative deltas mean the later revision is faster.The isolated C++ cache benchmark confirms that #858's two intended hot patterns remain faster after this simplification:
The NVIDIA benchmark times Python-to-InfiniOps host submission with CUDA synchronization outside each timed loop:
The primary map-hit interval was widened by host noise despite its favorable point estimate, so it is reported unchanged. A predeclared independent confirmation used seven fresh
B-C-C-Bblocks and 15 rounds per process; it passed without selecting or reusing primary blocks.The separate A -> B results are reported only to show the gain introduced by #858; they are not combined with B -> C. The simplification preserves the repeated and alternating hot-path improvements. The only intentional cost is a second hash-table probe on first insertion; existing-map fallback hits and hot hits are unchanged.
Notes for Reviewers
CacheKeyBuilderspecializations withoutMatchesstill fall back to full key construction and hash-table lookup.unordered_mapinsertion and rehash preserve element pointers; cache invalidation clears the map and resets both pointers.cache.lookupcoversfind, whilecache.constructcovers construction and insertion. Range names and counts are unchanged.perf/operator-call-cache-fast-path.