Repository navigation
Conversation
Each thread chooses the cuDNN convolution algorithms by benchmarking them on the first input it gets for a given stride, padding and filter height and width. It then reuses them for later inputs with that stride, padding and filter height and width, whatever the shape of the input and the number of filters. But the workspace an algorithm needs can grow a lot with those: for 3x3 filters with a stride and padding of 1, CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED needed 10.7 MiB for 16 filters on a 3x63x63 input, and 12.4 GiB for 36 filters on a 52x1023x1023 input (cuDNN 9.0 on an RTX 4080). So algorithms chosen for a small input can make a later, larger one run out of GPU memory. set_dnn_choose_algorithms_per_input_shape(true), off by default, makes each combination of input shape and number of filters get algorithms of its own. The cache of the chosen algorithms now keeps the 1000 most recently used entries of each thread, so it can't grow without limit when there are many input shapes.
All three algorithms of a convolution, forward, backward data and backward filters, were benchmarked when it was set up. So a network that only makes predictions benchmarked backward algorithms it never uses, and a transposed convolution, whose forward pass is a backward data pass, benchmarked a forward algorithm it never uses. Now each is taken from the cache or benchmarked the first time the call that needs it is made.
Contributor
Author
|
The flaky Python test addressed separately in #3163. |
…lution-algorithm-when-first-needed # Conflicts: # dlib/cuda/cudnn_dlibapi.cpp # dlib/dnn/core_abstract.h
Owner
|
Awesome |
This was referenced Oct 3, 2026
reunanen
deleted the
choose-each-convolution-algorithm-when-first-needed
branch
October 3, 2026 06:38
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.
All three algorithms of a convolution, forward, backward data and backward filters, were benchmarked when it was set up. So a network that only makes predictions benchmarked backward algorithms it never uses, and a transposed convolution, whose forward pass is a backward data pass, benchmarked a forward algorithm it never uses. Now each is taken from the cache or benchmarked the first time the call that needs it is made.
Builds on #3161; only the last commit is new here.