Machine Learning/TensorFlow

[Machine Learning] Tensorflow GPU

데이터 세상 2021. 3. 31. 20:08

NVIDIA Graphic Card Driver

  • 장착된 그래픽 카드에 맞춰 그래픽카드 드라이브 설치

www.nvidia.co.kr/Download/Find.aspx?lang=kr

 

NVIDIA Driver 다운로드 - 고급 검색

SD Studio 드라이버 Studio 드라이버는 핵심 주요 크리에이티브 애플리케이션에 최상의 경험을 제공합니다. NVIDIA는 최고의 크리에이티브한 애플리케이션에 중점을 둔 광범위한 테스트를 시행하며,

www.nvidia.co.kr

호환되는 CUDA와 cuDNN 버전은 아래 링크에서 확인할 수 있다.

 

Tensorflow 버전 확인

$ python
> import tensorflow as tf
> tf.__version__
'2.4.1'

Cuda Install

  • PC 환경에 맞는 옵션 선택해서 Cuda 다운로드 및 설치

developer.nvidia.com/cuda-downloads

 

CUDA Toolkit 11.2 Update 2 Downloads

Select Target Platform Click on the green buttons that describe your target platform. Only supported platforms will be shown. By downloading and using the software, you agree to fully comply with the terms and conditions of the CUDA EULA. Operating System

developer.nvidia.com

 

Cuda (Compute Unified Device Architecture, 쿠다)

  • 그래픽 처리 장치(GPU)에서 수행하는 (병렬 처리) 알고리즘을 C 프로그래밍 언어를 비롯한 산업 표준 언어를 사용하여 작성할 수 있도록 하는 GPGPU 기술
    • GPGPU: General-Purpose Computing on Graphics Processing Units
  • 엔비디아가 개발해오고 있으며 이 아키텍처를 사용하려면 엔비디아 GPU와 특별한 스트림 처리 드라이버가 필요
  • CUDA 플랫폼은 GPU의 가상 명령어셋과 병령 처리 요소들을 사용할 수 있도록 만들어주는 소프트웨어 레이어

 

cuDNN Install

  • 설치된 Cuda 버전에 맞는 Cudnn 다운로드(회원 가입 필수)
  • 다운로드 파일의 압축을 풀고 NVIDIA GPU Computing Toolkit\CUDA\vX.X (X.X: 설치버전) 내에 폴더 전체 복사해서 붙여넣기
  • 예시 경로: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2

developer.nvidia.com/rdp/cudnn-archive

 

cuDNN Archive

NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.

developer.nvidia.com

 

cuDNN (Compute Unified Deep Neural Network)

  • 딥 뉴럴 네트워크를 구성하고 학습시킬 수 있는 라이브러리
  • 컨볼루션, 풀링, 소프트맥스, 활성함수로 ReLU, Sigmoid, TANH, 텐서 변형 함수, LRN,LCN,배치노멀라이제이션 기능들이 포함되어 있으며 해당 기능들의 포워드, 백워드(학습)을 모두 지원해주는 API
  • cuDNN을 이용하면 CAFFE나 Tensorflow 등의 라이브러리를 사용하지 않고도 C++ CUDA로 직접 deep neural network을 구성하고 학습 가능

 

Tensorflow 실행 시 XLA 관련 오류 발생 시

Not creating XLA devices, tf_xla_enable_xla_devices not set
# 환경 변수 설정
export XLA_FLAGS="--xla_gpu_cuda_data_dir=path/to/cuda"
export TF_XLA_FLAGS="--xla_gpu_cuda_data_dir=path/to/cuda"

# python script에서 환경 변수 로딩
os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'

 

Tensorflow Device 목록 확인

# tensorflow GPU 드라이브 리스트 목록 확인
import tensorflow as tf
tf.config.list_physical_devices('GPU')

# tesorflow 드라이브 리스트 목록 전체 확인
from tensorflow.python.client import device_lib
device_lib.list_local_devices()

 

 


References

반응형