Fix NVDEC -> NPP
CUDA stream sync issue
#868
Merged
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.
This PR fixes a CUDA stream synchronization bug between NVDEC (the decoder) and NPP (the color-conversion).
I hope this is a also the fix for an issue that was originally discovered by @ronghanghu with https://fburl.com/oay62aq2.
For context:
The bug can be reproduced with this snippet:
What we're observing is that sometimes, the decoded frame
i
is actually the same asi - 1
. That's a side-effect of the original stream sync bug. How? I'm not entirely sure, it may be related to how the pytorch CUDA caching allocator works, but IDK. What I do know is that this snippet consistently fails onmain
and consistently succeeds with this PR.While working on this, I discovered an interesting (and sad) piece of trivia: the NVDEC stream is hardcoded by FFmpeg to always be the default stream. This means that doing something like this:
will always use the default stream for the decoding. That's sad. That's not really expected. But there's nothing we can do about it. Only NPP will be relying on the newly created stream.
This is orthogonal to the bug: the bug still exists regardless of this fact.