Skip to content

Don't empty the CUDA cache inside match() - #154

Open
ducha-aiki wants to merge 1 commit into
Parskatt:mainfrom
ducha-aiki:match-keep-allocator-cache
Open

ducha-aiki wants to merge 1 commit into
Parskatt:mainfrom
ducha-aiki:match-keep-allocator-cache

Conversation

@ducha-aiki

Copy link
Copy Markdown

RegressionMatcher.match() calls torch.cuda.empty_cache() between the coarse and the upsampled pass whenever it is given paths or PIL images (the default usage). PyTorch's caching allocator would otherwise reuse the blocks freed by the coarse pass. Returning them to the driver means every call pays cudaFree/cudaMalloc again for the upsampled pass and, mostly, for the ~3 GB cdist buffers of the KDE in the sample() call that usually follows.

This PR removes that call. Outputs are unchanged. Callers that share the GPU with other processes can still call torch.cuda.empty_cache() themselves.

Measurements. RTX 4090, torch 2.14.0 + CUDA 13.0, roma_outdoor(device) defaults (560/864, symmetric), match(path_A, path_B) followed by sample(warp, certainty, num=10000). 100 outdoor pairs (IMC 2021 PhotoTourism, reichstag), torch.manual_seed(0), mean over pairs 6–100, two repeats each:

local corr branch match() ms sample() ms 100 pairs, s peak allocated GB peak reserved GB
fused-local-corr main 459 163 62.9 7.51 10.3
fused-local-corr this PR 385 52 44.6 (1.41×) 7.51 11.0
native fallback main 569 163 73.8 7.51 13.4
native fallback this PR 426 52 48.6 (1.52×) 7.51 15.5
  • Warp, certainty and the sampled matches/certainties are bitwise identical to main for all 100 pairs, and across repeats.
  • Peak allocated memory is unchanged. Peak reserved memory grows by 0.7–2.1 GB, because cached blocks are no longer released in the middle of the call.
  • fused-local-corr 0.3.211 was built from its source for torch 2.14; the published wheel pins torch==2.11.0.

Written by Claude (Opus 5.5) on behalf of @ducha-aiki

match() emptied the CUDA cache before the upsampled pass, so every call
re-allocated the upsample activations and the ~3 GB KDE buffers of the
following sample() from the driver. Outputs are unchanged; match()+sample()
is 1.4-1.5x faster on an RTX 4090.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ducha-aiki

ducha-aiki commented Oct 13, 2026 •

Copy link
Copy Markdown
Author

Here is my full list of tried RoMa speed-ups
image

@Parskatt

This branch has not been deployed

No deployments
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.

1 participant