Skip to content

Augment CMakeLists.txt & Fix generated config file #6396

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

Merged
merged 3 commits into from
Aug 11, 2022
Merged

Augment CMakeLists.txt & Fix generated config file #6396

merged 3 commits into from
Aug 11, 2022

Conversation

laitingsheng
Copy link
Contributor

I hope this simple fix could pass the CI tests (as a follow-up of #6378 and #5602).

Resolves #5863.

@laitingsheng
Copy link
Contributor Author

Apologies for the misleading conclusion I made in the last PR (#6378). I finally realised that LibPNG and LibJPEG were not statically linked to the TorchVision target. It's necessary to instruct CMake to use FindXXX to search for the correct dynamic libraries in the output CMake configuration files.

Because I believe the actual dynamic libraries in use were installed by conda, adding Python target to the linkage dependency will coincidentally provide the correct search path of shared objects for LibPNG and LibJPEG, thus the original generated configuration file is working anyway.

@datumbox datumbox requested a review from fmassa August 11, 2022 08:04
@datumbox
Copy link
Contributor

@laitingsheng Thank you very much for your patience and tenacity to fix this. Your changes seem good to me. The CI is failing due to network problems, so this seems unrelated. I've manually restarted the failing jobs but if that persists we might have to restart all CI jobs to confirm everything works as expected.

@fmassa @bmanga If you could have also a look on the propose changes, I would appreciate it.

@laitingsheng
Copy link
Contributor Author

laitingsheng commented Aug 11, 2022

Thank you very much for your patience and tenacity to fix this.

My pleasure!

The last commit should be working correctly now.

@laitingsheng laitingsheng changed the title Fix generated CMake file for USE_PYTHON=OFF Augment CMakeLists.txt & Fix generated config file Aug 11, 2022
Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Changes LGTM (although I'm not a CMake expert).

Thanks!

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.

LGTM, thanks a lot for your work @laitingsheng.

I've pinged a couple of people that have more experience with CMake to let us know what they think. I'll merge immediately after I get their input. I apologise for any delay, please bear with me; it shouldn't take long.

Copy link

@Nayef211 Nayef211 left a comment

Choose a reason for hiding this comment

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

Changes LGTM as well!

As a followup item, we noticed that the torchtext build failed when CUDA enabled torch is installed in the build environment (see pytorch/text#1797). The fix involved linking the torchtext.so lib with specific libraries from torch (see this PR) instead of doing find_package(Torch REQUIRED) (which is how torchvision is currently setup). I'm wondering if torchvision build ever ran into a similar failure?

@datumbox datumbox merged commit ae83114 into pytorch:main Aug 11, 2022
@datumbox
Copy link
Contributor

@Nayef211 Thanks a lot for giving your insights and expertise. We've never tried that, possibly because of lack of expertise working with CMake. Are there any other benefits from linking against specific torch libraries? I would love to understand the pros/cons to perhaps follow up/adopting a similar approach as TorchText.

@laitingsheng Merged, thanks a lot for your contribution!

@laitingsheng
Copy link
Contributor Author

laitingsheng commented Aug 11, 2022

Merged, thanks a lot for your contribution!

@datumbox My pleasure!

we noticed that the torchtext build failed when CUDA enabled torch is installed in the build environment

@Nayef211 I don't think this is the case for torchvision as torchvision requires CUDA if it's available, which follows what the Torch library requires. I think someone has pointed out that torchtext doesn't need CUDA even if the Torch library in use is compiled and linked against CUDA. If the torch library has been instructed to link against CUDA, the TORCH_LIBRARIES variable will always include the torch_cuda target (which requires CUDA), and I guess this is the root cause of the problem.

@Nayef211
Copy link

If the torch library has been instructed to link against CUDA, the TORCH_LIBRARIES variable will always include the torch_cuda target (which requires CUDA), and I guess this is the root cause of the problem.

@laitingsheng thanks for the insight and I think you're spot on here. I wasn't too familiar with how torchvision was handling building with CUDA. If it requires CUDA if it's available then this error shouldn't affect torchvision. 😄

facebook-github-bot pushed a commit that referenced this pull request Aug 24, 2022
Summary:
* Fix generated CMake file

* Make optional dependencies consistent

Reviewed By: datumbox

Differential Revision: D38824245

fbshipit-source-id: d573c2f044396b35ef9d836fee353b0e81cbeecc

Co-authored-by: Vasilis Vryniotis <[email protected]>
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.

Python dependency added to TorchVisionConfig.cmake despite building with -DUSE_PYTHON=off
5 participants