Skip to content

Conversation

@NicolasHug
Copy link
Contributor

Up until now, the preAllocatedOutputTensor parameter of our low-level decoding functions was only considered for swscale. It is now honored in all cases, i.e. when filtergraph is used.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 2024
@ahmadsharif1
Copy link
Contributor

Can you add a TODO to write a test that confirms the data_ptr in the pre-allocated tensor is the same as the return value in both color-conversion library cases? Otherwise this can regress and we would not know any better.

Doesn't have to be this diff. You can do it later.

Comment on lines 897 to 898
// decoded frame directly into `preAllocatedtensor.data_ptr()`. That's not
// possible with filtegraph, leading to an extra copy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's impossible with filtergraph -- we just don't know and I haven't investigated this further.

If ffmpeg allows us to pass in pre-allocated frames to filtergraph we can do this more efficiently for filtergraph too. I would add a TODO to investigate and fix this for filtergraph later.

auto preAllocatedOutputTensor = torch::empty({270, 480, 3}, {torch::kUInt8});

std::unique_ptr<VideoDecoder> ourDecoder =
createDecoderFromPath(path, GetParam());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So compilation fails on this line because I assume GetParam is only valid within a TEST_P function.

@ahmadsharif1 @scotts any tip on how to write this test over both swscale and filtergraph without just duplicating the code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not experienced in GTEST, but looking through the docs, you may want to make a test fixture that accepts the color conversion library as an option: https://google.github.io/googletest/advanced.html#value-parameterized-tests

I'm not sure if you can extended the current one (on line 41), or make a new one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could call getparam from the parent and pass it down here?

The other way of doing this is parameterized classes but that seems overkill to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I tried a few things, but couldn't get it to work (new kind of error each time). I just went for duplicating the whole thing, I hope that's OK. We already have some duplicated tests in this class.

@NicolasHug NicolasHug merged commit 650e8bf into meta-pytorch:main Oct 28, 2024
40 checks passed
@NicolasHug NicolasHug deleted the pre_allocated_tensor branch October 28, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants