2

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!

CubeHead
  • 123
  • 4
  • 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. – N0rbert Jan 22 '22 at 19:50

1 Answers1

2

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).

N0rbert
  • 99,918
  • 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 ). I'll try what you suggested and come back, thanks a lot for the response! – CubeHead Jan 22 '22 at 20:05
  • It worked, thanks a lot! – CubeHead Jan 23 '22 at 11:52
  • 1
    If others coming here later are interested: installed the kernel above + the 470 nvidia driver + CUDA 11.6 – CubeHead Jan 23 '22 at 11:53