Score:2

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver -- kernel headers for 5.16.2

de flag

I'm trying setup my Lenovo Legion 5 Pro w/ Ubuntu 20.04.3 LTS machine so that I can use my GPU (Nvidia Geforce RTX 3070 8GB) for machine learning, for example with PyTorch. However, even after re-installing the NVidia drivers several times, it looks like it is still not visible, as running nvidia-smi gives the following:

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA 
driver. Make sure that the latest NVIDIA driver is installed and running.

I have looked at several solutions out there (this, this, this, this) and nothing works until now. But I think that the problem is caused by the kernel I'm using.

Running nvcc --version gives the following output:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

ls /usr/src | grep nvidia outputs nvidia-470.86

When I try to run these commands from here, i.e.

sudo apt install dkms
sudo dkms install -m nvidia -v 470.86

I get the following error:

Error! Your kernel headers for kernel 5.16.2-051602-generic cannot be found.
Please install the linux-headers-5.16.2-051602-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located

Now, linux-headers-5.16.2-051602-generic doesn't exist, but I already have linux-headers-generic installed.

Do you have any suggestions about what I could try to fix this? Thanks a lot!

N0rbert avatar
zw flag
Why do you running mainline kernel? Do you have it preinstalled? Nvidia driver will not compile for mainline kernel, you have to use `linux-image-generic-hwe-20.04` instead.
Score:2
zw flag

You have to remove mainline kernel and install normal HWE instead by using commands below

sudo apt-get autopurge $(dpkg -l | grep 5.16.2-051602 | awk '{print $2}')

sudo apt-get install linux-image-generic-hwe-20.04 linux-headers-generic-hwe-20.04

then reboot and install 470 driver using Software & Updates (software-properties-gtk).

CubeHead avatar
de flag
The laptop didn't come with the mainline kernel, but the default out of the box Ubuntu installation for this laptop was quite buggy (no wifi, no brightness adjustment, screen glitches etc) and some people were saying that they managed to solve the problems with this (eg [here](https://www.reddit.com/r/linux_gaming/comments/mmptqi/lenovo_legion_5_ubuntu_2004_final_guide_dream/) ). I'll try what you suggested and come back, thanks a lot for the response!
CubeHead avatar
de flag
It worked, thanks a lot!
CubeHead avatar
de flag
If others coming here later are interested: installed the kernel above + the 470 nvidia driver + CUDA 11.6
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.