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

Migrate to FindCUDAToolkit.cmake #2833

Open
SomeoneSerge opened this issue Jul 20, 2023 · 14 comments
Open

Migrate to FindCUDAToolkit.cmake #2833

SomeoneSerge opened this issue Jul 20, 2023 · 14 comments

Comments

@SomeoneSerge
Copy link

SomeoneSerge commented Jul 20, 2023

Main idea

NVIDIA considers FindCUDA.cmake (find_package(CUDA)) deprecated: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#importing-tarballs-into-cmake. The common approach to consume cudatoolkit today is to use FindCUDAToolkit.cmake (find_package(CUDAToolkit COMPONENTS cudart cublas ...)).

Aside from FindCUDA being obsolete, there are notable differences between the modules: e.g. FindCUDAToolkit.cmake allows its CUDAToolkit_ROOT variable to take the form of a list of paths, and this way it supports splayed installations of cudatoolkit, where different components (cudart, cublas, ...) may reside in different prefixes (as is the case e.g. in nixpkgs)

Other sci-comp projects are moving away from FindCUDA.cmake too, e.g. pytorch/pytorch#76082

Thanks!

Anything else?

No response

@SomeoneSerge SomeoneSerge moved this to 📋 Backlog in CUDA Team Jul 20, 2023
@davisking
Copy link
Owner

Yeah, we will update eventually. We are on cmake 3.8 right now and that's a feature only in 3.17 or newer. Lots of dlib users update their tooling slowly, so dlib has to update slowly too :|

@jakirkham
Copy link

Would it make sense to have branch logic for these 2 cases? Namely

  • If CMake is 3.17+, use find_package(CUDAToolkit)
  • If CMake is older, fallback to find_package(CUDA)

Maybe another option would be to vendor FindCUDAToolkit.cmake

cc @robertmaynard (in case you have thoughts/suggestions here)

@SomeoneSerge
Copy link
Author

I like the idea of introducing FindCUDAToolkit.cmake support earlier. I find branching preferable to vendoring because it's a risk of divergence. E.g. pytorch vendors a copy, but their API already deviates from kitware's (the former doesn't accept lists in CUDAToolkit_ROOT). There are projects that went with branching too (list tbd)

@robertmaynard
Copy link

Replacing FindCUDA fully with FindCUDAToolkit will require also switching from the previous use of cuda_add_library ( and CUDA_NVCC_FLAGS ) to the first class CUDA language support in CMake ( add_library(example source.cu) ).

This kind of change makes it harder to support switching between pre and post 3.17. I would recommend making a clean break when possible, especially given that CMake 3.27 introduces a policy to remove FindCUDA entirely.

CMake does offer apt.kitware.com for ubuntu users that want to to get the latest version of CMake on older Ubuntu releases. The CMake binaries from cmake.org are built to support seriously old distro's as well, so they can be dropped onto machines which only provide 3.8 via the official package manager.

@Tobias-Fischer
Copy link

Tobias-Fischer commented Jan 10, 2024

@davisking
Copy link
Owner

Yeah if it can just branch on cmake version without being a big mess that would be cool. I personally have newer cmake on my system. Maybe we could start to require cmake 3.17 for dlib. It bothers me though that, for example, Ubuntu 22.04 then wouldn't work with its version of cmake and I know plenty of people are still on stuff that old.

Is this a big deal to not have the newer thing right now?

@Tobias-Fischer
Copy link

CUDA12 is (as far as I know) not supported with the old FindCUDA.

@robertmaynard
Copy link

Ubuntu 22.04 then wouldn't work with its version of cmake and I know plenty of people are still on stuff that old.

Ubuntu 22.04 provides CMake 3.22.
Ubuntu 20.04 provides CMake 3.16
Ubuntu 18.04 provides CMake 3.10

The upside is for 20.04 and 22.04 the apt.kitware.com repository can be used to get latest cmake releases ( officially blessed by CMake ). Ubuntu 18.04 users would need to download the pre-build cmake binaries and install them manually.

@davisking
Copy link
Owner

Uh, yeah, alright. I've come around. It's not like people have to pull the latest dlib if they are on an old OS anyway and it would be real convenient for multiple reasons to upgrade CMake. So one of you want to put up a PR that switches to cleaner cuda cmake rules and uses cmake 3.17? :)

@Tobias-Fischer
Copy link

I don't have the capacity at the moment, but basically everything required is in https://github.com/conda-forge/dlib-feedstock/blob/cf9148326a7ad74c1dd519c2d3d5dc2912f9697c/recipe/use_new_cudatoolkit.patch (just needs a bump of the cmake_minimum_version).

@davisking
Copy link
Owner

davisking commented Jan 26, 2024 via email

@Tobias-Fischer
Copy link

Yes, it’s all in the patch except for setting the correct minimum cmake version

@pfeatherstone
Copy link
Contributor

I did have a branch at some point in the past that cleaned up all of dlib's cmake stuff including CUDA. I can try to revive that at some point.

@davisking
Copy link
Owner

Yeah. I think I'm fine with switching the required version of cmake to a higher version. So if there is some good stuff to be had by doing that then send me a PR :)

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

Successfully merging a pull request may close this issue.

6 participants