4

As of Sept 2022, Nvidia still has not officially supported cuda toolkit on Fedora 36. The particular part missing is support for gcc12, which Fedora 36 defaults to. One solution to use nvcc on fedora is to go to fedora mirrors and download Fedora 35. However, I'd like to know how to getting nvcc to work on Fedora 36.

There's an RPM fusion wiki page on cuda, though some of the info is still somewhat difficult to find.

The fedora 35 cuda repo is complete and has all the necessary files, but (as of Sept 2022) the equivalent fedora 36 nvidia cuda repo exists but seems incomplete, in particular it's missing the rpm files that start with cuda-11....

xdavidliu
  • 333
  • 3
  • 15

1 Answers1

4

Update August 2023:

It's been about a year since I posted my question, and today the latest Fedora 38 has gcc13, while the latest supported cuda toolkit by Nvidia is Fedora 37 with gcc12. The instructions above still work, though I want to add some more context when using CLion.

The Jetbrains documentation suggest to edit CMAKE settings within CLion, but that did not work for me at all. Instead, what worked for me was to put the following in ~/.bash_profile (not .bashrc because I think that's just for terminals) and then log out and log back in:

PATH="$PATH:/usr/local/cuda/bin"
CUDAHOSTCXX='/home/linuxbrew/.linuxbrew/bin/g++-12'; export CUDAHOSTCXX

I installed Cuda toolkit 12.2 using the local runfile, not with the rpm repo methods, since those gave me scary messages about package incompatibilities. When running the runfile, I make sure to uncheck "install driver" in the little command line GUI they provide (which kinda resembles a debian installer in "low-graphics" mode). That way it doesn't clobber the rpmfusion akmod nvidia driver I already had installed.

Original answer:

First, install fedora 36, and choose to enable third party repos when asked.

Then (from the RPM fusion nvidia howto page):

sudo dnf install akmod-nvidia
sudo dnf install xorg-x11-drv-nvidia-cuda

then wait a minute or two until modinfo -F version nvidia gives a non-error output.

Then, reboot so that Nvidia drivers will take effect over Nouveau. Then, (From RPM cuda fusion howto page):

sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/fedora35/x86_64/cuda-fedora35.repo
sudo dnf clean all
sudo dnf module disable nvidia-driver
sudo dnf -y install cuda

The 35 in first line is intentional. Also, the module disable line does not disable your existing akmod nvidia driver that you just installed, but rather prevents the next line from installing Nvidia's dkms driver over your existing driver.

After this, /usr/local/cuda/bin/nvcc will be available, but if you try to run it on a .cu file, it will complain that "gcc 12 is not supported". It gives you a flag to ignore this and just go ahead anyways, but to get rid of this warning, we can do the following to quickly obtain gcc-11: Credit goes to a comment in this reddit thread.

First, Install homebrew using their instructions. I just used the default location, which was /home/linuxbrew, but if you wanted, you could install in a custom location like your home directory. Then do brew install gcc@11. Finally, nvcc will work without complaints if you directly tell it to use gcc-11 using the -ccbin flag, for example:

/usr/local/cuda/bin/nvcc -ccbin g++-11 foo.cu -o foo

If you don't want to pollute your default path with brew's gcc-11 for some reason, you can explicitly tell nvcc to always use brew's gcc-11 using an env variable. For example, put the following in ~/bash_profile and then logout and login:

export NVCC_PREPEND_FLAGS='-ccbin /home/linuxbrew/.linuxbrew/bin/g++-11'
xdavidliu
  • 333
  • 3
  • 15