Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory

boingboing·2022년 4월 11일
0
post-thumbnail

개념

cuda가 라이브러리라면 cuda toolkit은 cuda로 gpu 프로그래밍할 때 쉽게 해주는 소프트웨어다.

현상

안녕하세요~
gpu를 사용해서 keras를 돌리려고 하는데
2022-04-06 15:14:53.600331: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
이런 식으로 나와서요.....
conda 환경에서 cuda를 설치해봤는데도 안 돼서 그러는데 혹시 sudo 권한으로 cuda를 설치해주실 수 있을까요?
아니면 다른 방법이 있을까요...?

원인

cuda 라이브러리가 읎어서 발생함.

해결

  1. 우선 다 삭제한다.
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt remove --autoremove nvidia-cuda-toolkit
sudo apt remove --autoremove nvidia-*


sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean

sudo rm -rf /usr/local/cuda*
  1. 이후 CUDA 설치.
sudo apt update
sudo add-apt-repository ppa:graphics-drivers
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'

sudo apt update
sudo apt install cuda-10-1
sudo apt install libcudnn7
  1. 환경변수 설정 (PATH, LD_LIBRARY_PATH)
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
  1. 환경변수 설정 확인
    source ~/.bashrc

문제 다시 발생.

  • 위의 에러는 해결되었으나

    Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-10.0/extras/CUPTI/lib64:/usr/local/cuda-10.0/lib64

발생.

https://github.com/tensorflow/tensorflow/issues/45930
https://www.tensorflow.org/install/gpu#install_cuda_with_apt
https://stackoverflow.com/questions/63199164/how-to-install-libcusolver-so-11[중요] 이거 참고함.

libcudart.so.11.0에 11.0을 link를 걸어줌. (원래 11.0이라는건 없다고 한다-ㅈ-;;)
링크 걸 때 파일 이름을 잘못 적어서 .... 개고생함 휴.. 파일 이름 확인 잘 하자.

문제 다시 발생.

  • 위의 에러는 해결되었으나..
    해결된 줄 알았는데

GPU가 동작을 안한다..!!!

nvdia-smi에는 version 11, nvcc로 확인해보니 Cuda 9로 사용되고 있었음. ㅇ<-<

Cuda 10으로 깐 줄았는데 알고보니 제대로 안깔림..ㅠㅠ..망했어요!!!!!!

인터넷에 돌아다니는 파편적인 정보로 대충 때울려다가 망했다.

공식 문서

  • 차근차근 공식문서 읽어보기.ㅠㅠ

1. System Requirements

  • 현재 설치된 그래픽 드라이버 버전. (430.64) CUDA 10.1, 10.2 까는덴 문제 없다.

  • 커널 모듈 드라이버 버전이 510.60 이상임 -> CUDA 버전 전부 다된다. ... CUDA 버전 제한없다.

  • Running a CUDA application requires the system with at least one CUDA capable GPU and a driver that is compatible with the CUDA Toolkit.

  • 그래픽 카드마다 설치가 가능한 CUDA와 cuDNN 버전이 다를 수 있다.

    -> 7.5만 되는 줄 알았는데 다른 예제들 보니 RTX 2080이랑 Cuda 10 호환 되긴 하는듯..?ㅠ??..정확히 모르겠다.

  • CUDA 설치 시 최소 그래픽 Driver 버전이 존재한다.

- CUDA-capable GPU
- A supported version of Linux with a gcc compiler and toolchain
- NVIDIA CUDA Toolkit (available at https://developer.nvidia.com/cuda-downloads)
  • NVIDIA 버전 확인
    cat /proc/driver/nvidia/version
    Kernel Module을 확인하면 된다.

NVRM version: NVIDIA UNIX x86_64 Kernel Module 510.60.02 Wed Mar 16 11:24:05 UTC 2022
GCC version: gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

우리의 driver version이 510.60임 -> 10.1은 무조건 호환성이 맞다.

2. Pre-installation Actions


  • Verify the system has a CUDA-capable GPU.
  • Verify the system is running a supported version of Linux.
  • Verify the system has gcc installed.
  • Verify the system has the correct kernel headers and development packages installed.

  • it is best to manually ensure the correct version of the kernel headers and development packages are installed prior to installing the CUDA Drivers, as well as whenever you change the kernel version.

2.1. Verify You Have a CUDA-Capable GPU
lspci | grep -i nvidia

2.2. Verify You Have a Supported Version of Linux
uname -m && cat /etc/*release

2.3. Verify the System Has gcc Installed
gcc --version

2.4. Verify the System has the Correct Kernel Headers and Development Packages Installed
uname -r
This is the version of the kernel headers and development packages that must be installed prior to installing the CUDA Drivers.

  • 커널 헤더와 개발 패키지들은, CUDA Driver 설치 전에 반드시 설치 되어야 한다.

The kernel headers and development packages for the currently running kernel can be installed with:
sudo apt-get install linux-headers-$(uname -r)
(OK)

2.5. Download the NVIDIA CUDA Toolkit.

3. Package Manager Installation

  • Setup the correct CUDA PPA on your system
  • Cuda 설치에 필요한 패키지를 추가하고, cuda를 설치한다.
- Download the NVIDIA CUDA Toolkit.
- Handle conflicting installation methods.

https://gist.github.com/Mahedi-61/2a2f1579d4271717d421065168ce6a73
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
https://medium.com/@exesse/cuda-10-1-installation-on-ubuntu-18-04-lts-d04f89287130

0개의 댓글