Skip to content
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

use from_blob to avoid memcpy #4118

Merged
merged 3 commits into from
Jun 28, 2021
Merged

Conversation

cyyever
Copy link
Contributor

@cyyever cyyever commented Jun 25, 2021

No description provided.

@datumbox datumbox requested a review from andfoy June 28, 2021 15:05
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

The changes seem reasonable to me.

@andfoy have also a look if your don't mind. Thx!

@andfoy
Copy link
Contributor

andfoy commented Jun 28, 2021

Good to see that ::free fixes the issues related to ownership when using from_blob

@datumbox datumbox merged commit 4a3b947 into pytorch:master Jun 28, 2021
@cyyever cyyever deleted the fix_jpeg_encode branch June 29, 2021 02:59
@fmassa
Copy link
Member

fmassa commented Jun 29, 2021

Nice, thanks for doing this and handling the deleter!

@cyyever cyyever restored the fix_jpeg_encode branch June 29, 2021 17:18
@cyyever cyyever deleted the fix_jpeg_encode branch July 1, 2021 11:03

return outTensor;
auto out_tensor =
torch::from_blob(jpegBuf, {(long)jpegSize}, ::free, options);
Copy link
Member

Choose a reason for hiding this comment

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

This line is raising the following clang-tidy warning in our internal CI:

There's an unchecked dereference of an object that is nullable. Make sure you null-check the object before you call methods on it, pass it as non-nullable parameter, or dereference it. If you are sure the the object cannot be nullptr, make it explicit with CHECK_NOTNULL() or assert(). jpegBuf is nullable.

Looks like jpegBuf is set above in jpeg_mem_dest, but I couldn't find any relevant docs about this function to know what happens if the allocation fails.

Copy link
Member

Choose a reason for hiding this comment

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

I think if we have errors the setjmp that we do in https://github.com/pytorch/vision/pull/4118/files#diff-dfb505641c632421ae5cc17a4398fe0e3a47c436f62825e88ba2b0aebf497d5eR37 will kick in and the check that jpegBuf != nullptr, so maybe this clang-tidy error is a false-positive.

Still let's keep an eye on this

facebook-github-bot pushed a commit that referenced this pull request Jul 1, 2021
Summary:

Reviewed By: NicolasHug

Differential Revision: D29516853

fbshipit-source-id: 88d8c3962204071883317d1b2eb383900d90d430

Co-authored-by: Nicolas Hug <nicolashug@fb.com>
Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants