Ubuntu 22.04에 CUDA를 사용하도록 Tensorflow 설치하는 방법을 다룹니다.
2022. 12. 2 최초작성
CUDA 설치
다음 포스트를 참고하여 CUDA 설치를 진행하세요.
Ubuntu 22.04에 CUDA 설치하는 방법
https://webnautes.tistory.com/1765
Tensorflow 설치
1. pip 명령을 사용하여 tensorflow 패키지를 설치합니다.
$ pip3 install tensorflow-gpu
아래와 같은 메시지가 보인다면 다음 명령으로 python3-pip를 설치한 후, tensorflow-gpu 패키지를 다시 설치하세요.
sudo apt install python3-pip
2. python에서 tensorflow 모듈을 불러와서 설치가 제대로 되었는지 확인해봅니다.
webnautes@webnautes-laptop:~$ python3
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
3. 텐서플로우 모듈을 로드합니다.
>>> import tensorflow as tf
2022-12-02 21:11:19.548370: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-12-02 21:11:20.332318: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda-11.8/lib64/
2022-12-02 21:11:20.332402: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda-11.8/lib64/
2022-12-02 21:11:20.332417: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
빨간색으로 표시한 경고는 아래 링크에 따르면 무시해도 된다고 합니다.
4. 글 작성 시점에서 설치된 버전은 2.11.0입니다.
>>> tf.__version__
'2.11.0'
5. 텐서플로우에서 GPU를 사용하는지 체크합니다.
>>> tf.config.list_physical_devices('GPU')
6. 빨간색으로 표시한 것처럼 출력 마지막에 GPU가 출력되어야 합니다.
2022-12-02 21:16:31.431705: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-12-02 21:16:31.591544: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-12-02 21:16:31.591870: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]