-
Notifications
You must be signed in to change notification settings - Fork 48
Avoid silently wrong results on 10bit CUDA #777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NicolasHug
wants to merge
2
commits into
main
Choose a base branch
from
cuda10bits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,10 +196,48 @@ void CudaDeviceInterface::convertAVFrameToFrameOutput( | |
UniqueAVFrame& avFrame, | ||
FrameOutput& frameOutput, | ||
std::optional<torch::Tensor> preAllocatedOutputTensor) { | ||
// We check that avFrame->format == AV_PIX_FMT_CUDA. This only ensures the | ||
// AVFrame is on GPU memory. It can be on CPU memory if the video isn't | ||
// supported by NVDEC for whatever reason: NVDEC falls back to CPU decoding in | ||
// this case, and our check fails. | ||
// TODO: we could send the frame back into the CPU path, and rely on | ||
// swscale/filtergraph to run the color conversion to properly output the | ||
// frame. | ||
TORCH_CHECK( | ||
avFrame->format == AV_PIX_FMT_CUDA, | ||
"Expected format to be AV_PIX_FMT_CUDA, got " + | ||
std::string(av_get_pix_fmt_name((AVPixelFormat)avFrame->format))); | ||
"Expected format to be AV_PIX_FMT_CUDA, got ", | ||
(av_get_pix_fmt_name((AVPixelFormat)avFrame->format) | ||
? av_get_pix_fmt_name((AVPixelFormat)avFrame->format) | ||
: "unknown"), | ||
". When that happens, it is probably because the video is not supported by NVDEC. " | ||
"Try using the CPU device instead. " | ||
"If the video is 10bit, we are tracking 10bit support in " | ||
"https://github.com/pytorch/torchcodec/issues/776"); | ||
|
||
// Above we checked that the AVFrame was on GPU, but that's not enough, we | ||
// also need to check that the AVFrame is in AV_PIX_FMT_NV12 format (8 bits), | ||
// because this is what the NPP color conversion routines expect. | ||
// TODO: we should investigate how to can perform color conversion for | ||
// non-8bit videos. This is supported on CPU. | ||
TORCH_CHECK( | ||
avFrame->hw_frames_ctx != nullptr, | ||
"The AVFrame does not have a hw_frames_ctx. " | ||
"That's unexpected, please report this to the TorchCodec repo."); | ||
|
||
AVPixelFormat actualFormat = | ||
reinterpret_cast<AVHWFramesContext*>(avFrame->hw_frames_ctx->data) | ||
->sw_format; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got tripped up reading this because I'm not used to seeing a hwFramesCtx = reinterpret_cast<AVHWFramesContext*>(avFrame->hw_frames_ctx->data);
AVPixelFormat actualFormat = hwFramesCtx->sw_format; Also: TIL that |
||
TORCH_CHECK( | ||
actualFormat == AV_PIX_FMT_NV12, | ||
"The AVFrame is ", | ||
(av_get_pix_fmt_name(actualFormat) ? av_get_pix_fmt_name(actualFormat) | ||
: "unknown"), | ||
", but we expected AV_PIX_FMT_NV12. This typically happens when " | ||
"the video isn't 8bit, which is not supported on CUDA at the moment. " | ||
"Try using the CPU device instead. " | ||
"If the video is 10bit, we are tracking 10bit support in " | ||
"https://github.com/pytorch/torchcodec/issues/776"); | ||
|
||
auto frameDims = | ||
getHeightAndWidthFromOptionsOrAVFrame(videoStreamOptions, avFrame); | ||
int height = frameDims.height; | ||
|
Binary file not shown.
Binary file not shown.
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create an issue to track.