GPU 관련 Error 해결 : NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver.
Ubuntu를 사용하다가 인스턴스를 중지하고 시작해서 사용하는경우가 드문데, 이런경우 GPU Driver가 종종 초기화 되거나 설치가 되어있어도 위와 같은 communicate 오류가 발생한다.
구글링 및 경험 결과 해결 방법을 기록한다.
nvidia-driver 삭제 및 cuda 를 깨끗하게 지우고, 재설치하는것이 기본이다. 그 이후로는 터미널에서 보여주는 log를 참고하여 해결한다.
1. 먼저 자신의 환경에 있는 nvidia 관련 설치본을 모두 삭제한다.
sudo apt remove --purge nvidia*
2. 리눅스 커널을 위한 header file들을 설치한다.
sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
linux-hwe-5.15-headers-5.15.0-33
The following NEW packages will be installed:
linux-headers-5.15.0-33-generic linux-hwe-5.15-headers-5.15.0-33
0 upgraded, 2 newly installed, 0 to remove and 40 not upgraded.
3. driver를 재설치한다.
sudo sh cuda_11.4.4_470.82.01_linux.run
Installation failed. See log at /var/log/cuda-installer.log for details.
하지만 여전히 설치에 실패했고, cuda-installer.log 를 확인해본다.
4. cuda-installer.log 확인
vi /var/log/cuda-installer.log
[INFO]: Driver not installed.
[INFO]: Checking compiler version...
[INFO]: gcc location: /usr/bin/gcc
[INFO]: gcc version: gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
[INFO]: Initializing menu
[INFO]: Setup complete
[INFO]: Components to install:
[INFO]: Driver
[INFO]: 470.82.01
[INFO]: Executing NVIDIA-Linux-x86_64-470.82.01.run --ui=none --no-questions --accept-license --disable-nouveau --no-cc-version-check --install-libglvnd 2>&1
[INFO]: Finished with code: 36096
[ERROR]: Install of driver component failed.
[ERROR]: Install of 470.82.01 failed, quitting
~
gcc 는 설치되어있고 Nvidia driver run 파일을 위와같은 옵션을 주고 실행하라고 한다.
5. Nvidia 홈페이지에서 제품에 맞는 드라이버를 다운로드 한후 아래와 같이 옵션을 주고 설치를 시도한다.
sudo sh ./NVIDIA-Linux-x86_64-470.129.06.run --ui=none --no-questions --accept-license --disable-nouveau --no-cc-version-check --install-libglvnd --run-nvidia-xconfig 2>&1
...
Installation of the kernel module for the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version 470.129.06) is now complete.
6. 인스턴스를 Reboot한다.
7. nvidia-smi 명령어를 입력하여 정상 설치를 확인한다. (설치완료!!!!)