Cuda installation issues on Ubuntu 22.04 laptop

I followed the instructions from the following link (I have Ubuntu 22.04 installed on a separate SSD on a Lenovo Legion5 pro with a mobile RTX 4070) :

Everything went fine, but the simple code example at the end didn’t work; the return said CPU only. I checked nvidia-smi and got an error (see below). Following is the output of a command line session. Any idea what I did wrong and what to do?

ken@ken-Legion-Pro-5:~$ sudo lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation Device 2860 (rev a1)
ken@ken-Legion-Pro-5:~$ dkms status
nvidia/535.86.05, 6.2.0-26-generic, x86_64: installed

ken@ken-Legion-Pro-5:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

ken@ken-Legion-Pro-5:~$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ken@ken-Legion-Pro-5:~$ g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ken@ken-Legion-Pro-5:~$ dkms status
nvidia/535.86.05, 6.2.0-26-generic, x86_64: installed


ken@ken-Legion-Pro-5:~$ lspci -nnk | grep -i vga -A3
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:2860] (rev a1)
	Subsystem: Lenovo Device [17aa:3b5a]
	Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
01:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:22bd] (rev a1)

ken@ken-Legion-Pro-5:~$ nvidia-smi
NVIDIA-SMI has failed because it couldnt communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running

Fyi, I also tried an Anaconda installation where I created a conda environment with Python 3.9 and installed Pytorch. A simple check of torch.cuda.is_available() failed. One thing that struck me is that the 4070 is listed as NVIDIA Corporation Device 2860, which seems strange.

Finally got it installed (cuda toolkit 12.2, driver 535.104.05) and working. The following was a huge help (especially for a novice):
https://www.youtube.com/watch?v=ttxtV966jyQ
Had to try it several times before getting it to work. I took the advice in the video to just reinstall Ubuntu each time rather than try to purge cuda. In the end, I was able to download, compile, and run the samples. I initially had trouble with samples that required graphics where I got the following error: “OpenGL GLX extension not supported by display”. This puzzled me for some time, but I eventually solved it by a bios setting (switching from hybrid graphics to discrete graphics). All good now.