본문 바로가기
  • Machine Learning Paper Reviews (Mostly NLP)
Coding Details

[Machine Learning Basics] nvidia-driver, CUDA Toolkit

by wlqmfl 2023. 8. 29.

I recently received a server which GPU were available, and found out how to go through GPU settings.

 

Content
1. Connecting to (SSH) server with VSCode
2. Installing GPU driver (nvidia-driver)
3. Installing CUDA

 

1. Connecting to SSH server with VSCode (with password, not the SECRET_KEY)

 VSCode seems to be the predominant code editor. VSCode has numerous extensions for such things like Git, Remote-SSH, Go-Live, and so on. You can download VSCode at https://code.visualstudio.com.

 

First of all, install the "Remote - SSH" extension in Visual Studio Code. You can do this by navigating to the Extensions view by clicking on the square icon on the left sidebar or by pressing Ctrl+Shift+X. Search for "Remote - SSH" and install the extension.

 

Second, open the command palette by pressing Cmd+Shift+P. This will open a text box at the top of the window. In the command palette, type "Remote-SSH: Connect to Host" and select this option from the dropdown that appears. A list of options will show up.

 

 

Choose "Add New SSH Host..." if you're connecting to a new SSH host for the first time. This will open a new text box in which you can enter the SSH connection information. Go to ".../.ssh/config" and add the following information:

Host XXX.XXX.XXX.XXX
    HostName XXX.XXX.XXX.XXX
    User /*Probably 'root'*/

 

Finally, you can enter the server by clicking your server name, and then entering the password.

 

2. nvidia-driver

You should start with:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python3-pip

 

After you successfully installed pip3, you manually install gpu driver by typing:

$ sudo apt-get install ubuntu-drivers-common
$ ubuntu-drivers devices
$ sudo ubuntu-drivers autoinstall

 

Check if you successfully got the driver:

$ sudo reboot
$ nvidia-smi

This image is what you should get.

 

3. CUDA

Go to https://developer.nvidia.com/cuda-toolkit-archive in order to install CUDA Toolkit. I downloaded Toolkit 11.8:

$wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
$ sudo sh cuda_11.8.0_520.61.05_linux.run

(Note that in most of the case, Operating System: linux, Architecture: x86_64, Distribution: Ubuntu, Version: 20.04, Intaller Type: runfile (local))

 

Then, go to .bashrc and add the following rows to do the CUDA_PATH settings:

export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

 

Lastly, check if the CUDA has been successfully installed:

$ source ~/.bashrc
$ nvcc -V

CUDA installation complete

 

You are done. Try:

$ python3
>> import torch
>> t = torch.rand(10).to("cuda")
>> print(t)
tensor([0.3170, 0.9243, 0.4765, 0.5617, 0.3952, 0.8225, 0.4612, 0.7638, 0.3209, 0.5149], device='cuda:0')

 

Reference

https://velog.io/@hun_dev/개발-환경-GCP에서-GPU를-이용해-개발해보자-03

 

[개발 환경] GCP에서 GPU를 이용해 개발해보자! - 03

지난 게시글에서는 GCP에서 GPU를 할당받고 VM 인스턴스를 생성해보았습니다. 이번 게시글에서는 GPU 설정을 진행해보도록 하겠습니다.

velog.io

https://code.visualstudio.com

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

https://developer.nvidia.com/cuda-toolkit-archive

 

CUDA Toolkit Archive

Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production

developer.nvidia.com