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

CMakeLists and C++ files refactoring. #2446

Closed
wants to merge 7 commits into from

Conversation

vcarpani
Copy link
Contributor

@vcarpani vcarpani commented Jul 9, 2020

This PR refactors the CMakeLists file and the C++ files, to make it easier to package the C++ version of this library.

The main problem is due to the usage of INTERFACE_INCLUDE_DIRECTORIES in the CMakeLists file, since it is not advisable to populate the INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES of a target with paths for dependencies. That would hard-code into installed packages the include directory paths for dependencies as found on the machine the package was made on [source].

Changes:

  • Moved cpp headers to cinclude folder.
  • Refactor cpp source files to account for the move of headers file.
  • Use cmake include_directories instead of INTERFACE_INCLUDE_DIRECTORIES

There is still some work to be done on the ROCM version of the python library.

@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #2446 into master will decrease coverage by 1.88%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2446      +/-   ##
==========================================
- Coverage   70.65%   68.77%   -1.89%     
==========================================
  Files          94       94              
  Lines        7897     7897              
  Branches     1241     1241              
==========================================
- Hits         5580     5431     -149     
- Misses       1934     2076     +142     
- Partials      383      390       +7     
Impacted Files Coverage Δ
torchvision/ops/_register_onnx_ops.py 50.00% <0.00%> (-28.95%) ⬇️
torchvision/io/_video_opt.py 21.25% <0.00%> (-26.25%) ⬇️
torchvision/models/detection/transform.py 78.33% <0.00%> (-17.23%) ⬇️
torchvision/ops/poolers.py 85.14% <0.00%> (-11.89%) ⬇️
torchvision/ops/boxes.py 73.33% <0.00%> (-11.12%) ⬇️
torchvision/datasets/video_utils.py 68.48% <0.00%> (-7.28%) ⬇️
torchvision/__init__.py 71.87% <0.00%> (-6.25%) ⬇️
torchvision/models/detection/roi_heads.py 77.23% <0.00%> (-5.11%) ⬇️
torchvision/models/detection/rpn.py 89.69% <0.00%> (-3.44%) ⬇️
torchvision/io/video.py 68.63% <0.00%> (-1.19%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86b6c3e...6f45098. Read the comment docs.

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.

Hi,

Thanks for the PR!

Just so that I understand a bit better, in this PR do you target the models or the operators most specifically?
I don't have much experience with CMake, so I won't be able to review this PR. Also, how does it compare to #2253 ?

Maybe @bmanga could have a look?

CMakeLists.txt Outdated
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(torchvision)
set(CMAKE_CXX_STANDARD 14)
set(TORCHVISION_VERSION 0.6.0)
set(TORCHVISION_VERSION 0.5.0)
Copy link
Member

Choose a reason for hiding this comment

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

this seems like an unwanted change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry for the typo

@vcarpani
Copy link
Contributor Author

Hi,

Thanks for the PR!

Just so that I understand a bit better, in this PR do you target the models or the operators most specifically?
I don't have much experience with CMake, so I won't be able to review this PR. Also, how does it compare to #2253 ?

Maybe @bmanga could have a look?

Hi, thanks for the quick feedback!

This PR targets all the C++ code, a part from decoder, image and video_reader. It is not directly related with #2253, but if #2253 gets merged before this, this PR is going to need some more work or viceversa.

@vcarpani
Copy link
Contributor Author

Any news on this?

@bmanga
Copy link
Contributor

bmanga commented Jul 30, 2020

Hi @vcarpani, can you edit the PR message to list all the changes you made? Thanks!

CMakeLists.txt Outdated

# Gather source files.
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 a fan of these kinds of comments, they don't add anything valuable.

CMakeLists.txt Outdated
Comment on lines 43 to 66
"${CMAKE_CURRENT_BINARY_DIR}/TorchVisionConfig.cmake"
INSTALL_DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR}
)

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/TorchVisionConfigVersion.cmake
VERSION ${TORCHVISION_VERSION}
COMPATIBILITY AnyNewerVersion)
VERSION ${TORCHVISION_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TorchVisionConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/TorchVisionConfigVersion.cmake
DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR})
${CMAKE_CURRENT_BINARY_DIR}/TorchVisionConfigVersion.cmake
DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR}
)

# Install library.
install(TARGETS ${PROJECT_NAME}
EXPORT TorchVisionTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
EXPORT TorchVisionTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(EXPORT TorchVisionTargets
NAMESPACE TorchVision::
DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR})
NAMESPACE TorchVision::
DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

These all look like unrelated formatting changes. I'd say stick to the current style, and if you want to propose a different one do so in a different PR.

@vcarpani
Copy link
Contributor Author

Hi @bmanga, last commit should solve your comments, plus I added the list of changes to the description of the PR

@fmassa
Copy link
Member

fmassa commented Aug 3, 2020

Naive question: would it be possible to avoid moving the header files into a new directory and concentrate the changes only into CMakeLists?

@vcarpani
Copy link
Contributor Author

vcarpani commented Aug 3, 2020

Naive question: would it be possible to avoid moving the header files into a new directory and concentrate the changes only into CMakeLists?

From my knowledge of CMake not, but I could look into that somewhere this week. From my point of view about C++, it is always nice to have a clear split between headers and sources and CMake makes it really easy to do that

@fmassa
Copy link
Member

fmassa commented Aug 3, 2020

The reason why I'm asking is because this change will require some internal changes as well to torchvision, and in PyTorch they do mix headers and implementation in the same folder, so I would say I would prefer if we could keep it that way, specially given that in the current state of the code the implementation lives in header files.

@bmanga
Copy link
Contributor

bmanga commented Aug 4, 2020

@vcarpani have you tried to include_directories(torchvision/csrc)?

@vcarpani
Copy link
Contributor Author

vcarpani commented Aug 4, 2020

@bmanga that would probably work (it is also the same approach the pytorch uses), but it is also quite horrible, since you would also get the cpp files in the include directories

@bmanga
Copy link
Contributor

bmanga commented Aug 4, 2020

@vcarpani if you mean during installation, you can specify a PATTERN for cmake's install command.

@vcarpani
Copy link
Contributor Author

vcarpani commented Aug 4, 2020

@bmanga, yes I was referring to that, since it forces you to specify the installation pattern, while it is much simpler if you have only .h or .hpp files in the include_directories

@bmanga
Copy link
Contributor

bmanga commented Aug 5, 2020

@vcarpani I understand your point and I agree in principle, however I don't think it's a worthwhile change as of now. I'd suggest to go for the include_directories(torchvision/csrc) + install pattern for this PR. It should address the problem with INTERFACE_INCLUDE_DIRECTORIES and be minimally disruptive.

@fmassa
Copy link
Member

fmassa commented Aug 5, 2020

I agree with @bmanga comment, @vcarpani could you change your PR to do what @bmanga proposed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants