CUDA : cours    travaux pratiques

Configuration d'une machine avec CUDA sous Ubnutu 22.04

A partir d'une configuration de base d'Ubuntu 22.04, on dispose normalement de gcc/g++ en version 11.3.0.

Il est nécessaire d'installer un driver CUDA, notamment le driver 520.56.06 depuis le dépot standard d'Ubuntu.

Une fois installé, vous devriez voir le driver en utilisant la commande modinfo :

richer@richer:~\$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

richer@richer:~\$ modinfo nvidia | head
filename:       /lib/modules/5.15.0-52-generic/kernel/nvidia-520/nvidia.ko
firmware:       nvidia/520.56.06/gsp.bin
alias:          char-major-195-*
version:        520.56.06

richer@richer:~\$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.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.

Installer ensuite le CUDA Toolkit, j'ai téléchargé la version 11.8.0_520.61.05 sur le site de NVidia

richer@richer:~\$ sudo sh cuda_11.8.0_520.61.05_linux.run

L'installation du Toolkit permet aussi d'installer d'autres logiciels ainsi qu'un driver. Il ne faut pas installer le driver puisque cela a déjà était fait dans l'étape précédente. Il faut donc décocher l'installation du driver dans le menu correspondant.

Après installation on obtient :

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.8/

Please make sure that
 -   PATH includes /usr/local/cuda-11.8/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.8/lib64, or, add /usr/local/cuda-11.8/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 520.00 is required for CUDA 11.8 functionality to work.
To install the driver using this installer, run the following command, replacing  with the name of this run file:
    sudo .run --silent --driver

Il faut modifier le fichier ~/.bashrc et ajouter le chemin d'accès dans le PATH :

export PATH=/usr/local/cuda-11.8/bin:\$PATH

puis exécuter les commandes suivantes :

richer@richer:~\$ source ~/.bashrc

richer@richer:~\$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0