PrefaceRecently I'm learning how to install and use PaddlePaddle on various graphics card driver versions, so I'm also learning how to install and uninstall CUDA and CUDNN in Ubuntu. During the learning process, I'm also recording the learning process. While providing learning for everyone, it is also strengthening your own memory. This article takes uninstalling CUDA 8.0 and CUDNN 7.05 as an example, and installing CUDA 10.0 and CUDNN 7.4.2 as an example. Install the graphics driverDisable nouveau driver sudo vim /etc/modprobe.d/blacklist.conf Add at the end of the text: blacklist nouveau options nouveau modeset=0 Then execute: sudo update-initramfs -u After restarting, execute the following command. If there is no screen output, it means that nouveau is disabled successfully: lsmod | grep nouveau Download Driver Download address from official website: https://www.nvidia.cn/Download/index.aspx?lang=cn , download the corresponding version of the graphics card driver according to your graphics card, for example, my graphics card is RTX2070: After the download is complete, you will get an installation package. The file names of different versions may be different: NVIDIA-Linux-x86_64-410.93.run Uninstall the old driver The following operations need to be performed in the command interface. Execute the following shortcut keys to enter the command interface and log in: Ctrl-Alt+F1 Execute the following command to disable the X-Window service, otherwise the graphics driver cannot be installed: sudo service lightdm stop Execute the following three commands to uninstall the original graphics driver: sudo apt-get remove --purge nvidia* sudo chmod +x NVIDIA-Linux-x86_64-410.93.run sudo ./NVIDIA-Linux-x86_64-410.93.run --uninstall Installing New Drivers You can install a new driver by directly executing the driver file. The default setting is fine: sudo ./NVIDIA-Linux-x86_64-410.93.run Execute the following command to start the X-Window service: sudo service lightdm start Finally, execute the restart command to restart the system: reboot Note: If repeated logins occur after the system restarts, in most cases the wrong version of the graphics driver is installed. You need to download the graphics card version corresponding to the one installed on your machine. Uninstall CUDAWhy did I uninstall CUDA at the beginning? This is because I changed the graphics card to RTX2070, and the originally installed CUDA 8.0 and CUDNN 7.0.5 could not be used normally. I needed to install CUDA 10.0 and CUDNN 7.4.2, so I had to uninstall the original CUDA first. Note that the following commands are all performed under the root user. Uninstalling CUDA is very simple, just one command is enough. The main execution is the uninstall script that comes with CUDA. Readers need to find the uninstall script according to their own CUDA version: sudo /usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl After uninstalling, there are still some residual folders, which were previously installed with CUDA 8.0. You can delete them all together: sudo rm -rf /usr/local/cuda-8.0/ This will uninstall CUDA. Install CUDAInstalled CUDA and CUDNN versions:
The following installation steps are all performed under the root user. Download and install CUDA We can download it on the official website: CUDA10 download page, After the download is complete, grant execution permissions to the file: chmod +x cuda_10.0.130_410.48_linux.run Execute the installation package to start the installation: ./cuda_10.0.130_410.48_linux.run After starting the installation, you need to read the instructions. You can press (Do you agree to the terms? You must agree to continue the installation) accept/decline/quit: accept (Do not install the driver here, because the latest driver has been installed. Otherwise, an old version of the graphics driver may be installed, resulting in repeated logins) Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48? (y)es/(n)o/(q)uit: n Install the CUDA 10.0 Toolkit? (Do you want to install CUDA 10? This must be installed.) (y)es/(n)o/(q)uit: y Enter Toolkit Location (installation path, use the default, just press Enter) [ default is /usr/local/cuda-10.0 ]: Do you want to install a symbolic link at /usr/local/cuda? (Agree to create a soft link) (y)es/(n)o/(q)uit: y Install the CUDA 10.0 Samples? (No need to install the test, it is already there) (y)es/(n)o/(q)uit: n Installing the CUDA Toolkit in /usr/local/cuda-10.0 ... After the installation is complete, you can configure their environment variables and add the following configuration information to the end of export CUDA_HOME=/usr/local/cuda-10.0 export LD_LIBRARY_PATH=${CUDA_HOME}/lib64 export PATH=${CUDA_HOME}/bin:${PATH} Finally, use the command You can use the command test@test:~$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130 Test whether the installation is successfulExecute the following commands: cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery make ./deviceQuery Normal output: ./deviceQuery Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "GeForce RTX 2070" CUDA Driver Version / Runtime Version 10.0 / 10.0 CUDA Capability Major/Minor version number: 7.5 Total amount of global memory: 7950 MBytes (8335982592 bytes) (36) Multiprocessors, (64) CUDA Cores/MP: 2304 CUDA Cores GPU Max Clock rate: 1620 MHz (1.62 GHz) Memory Clock rate: 7001 Mhz Memory Bus Width: 256-bit L2 Cache Size: 4194304 bytes Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384) Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 1024 Maximum number of threads per block: 1024 Max dimension size of a thread block (x,y,z): (1024, 1024, 64) Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535) Maximum memory pitch: 2147483647 bytes Texture alignment: 512 bytes Concurrent copy and kernel execution: Yes with 3 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Alignment requirement for Surfaces: Yes Device has ECC support: Disabled Device supports Unified Addressing (UVA): Yes Device supports Compute Preemption: Yes Supports Cooperative Kernel Launch: Yes Supports MultiDevice Co-op Kernel Launch: Yes Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0 Compute Mode: < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) > deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.0, CUDA Runtime Version = 10.0, NumDevs = 1 Result = PASS Download and install CUDNN Go to the official download website of CUDNN: https://developer.nvidia.com/rdp/cudnn-download, then click Download to start selecting the download version. Of course, you still need to log in before downloading. The version selection interface is as follows. We choose After downloading, it is a compressed package, as follows: cudnn-10.0-linux-x64-v7.4.2.24.tgz Then decompress it with the following command: tar -zxvf cudnn-10.0-linux-x64-v7.4.2.24.tgz After decompression, you can get the following files: cuda/include/cudnn.h cuda/NVIDIA_SLA_cuDNN_Support.txt cuda/lib64/libcudnn.so cuda/lib64/libcudnn.so.7 cuda/lib64/libcudnn.so.7.4.2 cuda/lib64/libcudnn_static.a Use the following two commands to copy these files to the CUDA directory: cp cuda/lib64/* /usr/local/cuda-10.0/lib64/ cp cuda/include/* /usr/local/cuda-10.0/include/ After the copy is complete, you can use the following command to view the version information of CUDNN: cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 Test installation results At this point, the installation of CUDA 10 and CUDNN 7.4.2 has been completed. You can install the corresponding GPU version of Pytorch to test whether it can be used normally. Install as follows: pip3 install https://download.pytorch.org/whl/cu100/torch-1.0.0-cp35-cp35m-linux_x86_64.whl pip3 install torchvision Then test the installation using the following procedure: import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim import torch.backends.cudnn as cudnn from torchvision import datasets, transforms class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, 320) x = F.relu(self.fc1(x)) x = F.dropout(x, training=self.training) x = self.fc2(x) return F.log_softmax(x, dim=1) def train(model, device, train_loader, optimizer, epoch): model.train() for batch_idx, (data, target) in enumerate(train_loader): data, target = data.to(device), target.to(device) optimizer.zero_grad() output = model(data) loss = F.nll_loss(output, target) loss.backward() optimizer.step() if batch_idx % 10 == 0: print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format( epoch, batch_idx * len(data), len(train_loader.dataset), 100. * batch_idx / len(train_loader), loss.item())) def main(): cudnn.benchmark = True torch.manual_seed(1) device = torch.device("cuda") kwargs = {'num_workers': 1, 'pin_memory': True} train_loader = torch.utils.data.DataLoader( datasets.MNIST('../data', train=True, download=True, transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,)) ])), batch_size=64, shuffle=True, **kwargs) model = Net().to(device) optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.5) for epoch in range(1, 11): train(model, device, train_loader, optimizer, epoch) if __name__ == '__main__': main() If the following information is output normally, it proves that it has been installed:
Referenceshttps://developer.nvidia.com https://www.cnblogs.com/luofeel/p/8654964.html This is the end of this article about how to install and uninstall CUDA and CUDNN on Ubuntu. For more information about how to install and uninstall CUDA and CUDNN on Ubuntu, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Full analysis of MySQL INT type
>>: Vue.js $refs usage case explanation
1. Same IP address, different port numbers Virtua...
During the development process, I often encounter...
I have been using MySQL recently. The article mys...
mysqlslap Common parameter description –auto-gene...
Table of contents 1.mysqldump Execution process: ...
Today I looked at some things related to data bac...
Table of contents Preface 1. What is phantom read...
One demand Generally speaking, a company has mult...
Prepare the ingredients as shown above (ps: hadoo...
1. Installation version details Server: MariaDB S...
Related articles: 9 practical tips for creating we...
This article records the installation and configu...
Preface Today, a developer gave me feedback that ...
Table of contents describe accomplish The project...
Background: Linux server file upload and download...