AI(Artificial Intelligence)/DL(Deep Learning)

[๊ฐœ๋ฐœ ํ™˜๊ฒฝ] ์œˆ๋„์šฐ(Windows)์— Tensorflow-gpu ์„ค์น˜(NVIDIA driver, CUDA Toolkit, cuDNN ์„ค์น˜)

ํƒฑ์ ค 2021. 1. 18. 20:52

GPU๋ฅผ ์ด์šฉํ•ด ๋ชจ๋ธ์„ ํ•™์Šต์‹œํ‚ค๋ฉด ํ•™์Šต ์†๋„๊ฐ€ ๋งค์šฐ๋งค์šฐ๋งค์šฐ ๋น ๋ฅด๋‹ค.

๊ทธ๋ž˜์„œ ๋”ฅ๋Ÿฌ๋‹์€ ๋ชจ๋ธ GPU๊ฐ€ ์—†์œผ๋ฉด ํ•™์Šต์‹œํ‚ค๊ธฐ ์–ด๋ ค์›€.

 

๊ทผ๋ฐ ์ฒ˜์Œ ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ ๋Œ๋ฆด ๋•Œ ๋‚˜๋ฅผ ์ •๋ง ์• ๋จน์ด๋˜..^^ tensorflow-gpu ์„ค์น˜

๊ทธ ๋• ๊ฒฐ๊ตญ ํฌ๊ธฐํ•˜๊ณ  ๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„ ์ ‘์†ํ•ด์„œ ๊น”์•˜์—ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋‹ค์‹œํ•ด๋ณด๋‹ˆ ์ž˜ ๋ผ์„œ ๋ฐฉ๋ฒ• ๊ณต์œ  ์ฐจ ์˜ฌ๋ฆฌ๋Š” ๊ธ€

 

+++++++  ์ปดํŒŒ์ผ๋Ÿฌ ํ™˜๊ฒฝ์„ ์œ„ํ•œ Visual Studio ์„ค์น˜ํ•ด์•ผํ•จ

Visual Studio 2019 ๋ฒ„์ „์ด๋‚˜ 2017 ๋ฒ„์ „ ๋‹ค์šด๋ฐ›๊ธฐ!

docs.microsoft.com/ko-kr/visualstudio/releases/2019/release-notes

 

Visual Studio 2019 ๋ฒ„์ „ 16.8 ๋ฆด๋ฆฌ์Šค ์ •๋ณด

Visual Studio 2019 ๋ฒ„์ „ 16.8์˜ ์ตœ์‹  ๊ธฐ๋Šฅ, ๋ฒ„๊ทธ ์ˆ˜์ • ๋ฐ ์ง€์›์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.

docs.microsoft.com

1. ์•„๋‚˜์ฝ˜๋‹ค ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

2. Tensorflow ์„ค์น˜

3. CUDA ์„ค์น˜

  • ๋‚ด GPU ๋ชจ๋ธ ํ™•์ธํ•˜๊ธฐ

  • NVIDIA driver ์„ค์น˜

  • CUDA Toolkit ์„ค์น˜

4. cuDNN ์„ค์น˜

5. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •

6. ์„ค์น˜ ํ™•์ธ

 

โ€ป ์„ค์น˜ํ•  ๋•Œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ๊ฑด tensorflow, CUDA, cuDNN ๋ผ๋ฆฌ์˜ ๋ฒ„์ „ ํ˜ธํ™˜์ด๋‹ค.

www.tensorflow.org/install/source_windows

 

Windows์˜ ์†Œ์Šค์—์„œ ๋นŒ๋“œ  |  TensorFlow

์†Œ์Šค์—์„œ TensorFlow pip ํŒจํ‚ค์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ  Windows์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ์ฐธ๊ณ : ์ž˜ ํ…Œ์ŠคํŠธ๋˜๊ณ  ์‚ฌ์ „ ๋นŒ๋“œ๋œ Windows ์‹œ์Šคํ…œ์šฉ TensorFlow ํŒจํ‚ค์ง€๊ฐ€ ์ด๋ฏธ ์ œ๊ณต๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Windows์šฉ ์„ค์ • ๋‹ค์Œ ๋นŒ๋“œ ๋„๊ตฌ๋ฅผ ์„ค์น˜

www.tensorflow.org

์ด ํŽ˜์ด์ง€์—์„œ ๊ฐ์ž ์ž๊ธฐ๊ฐ€ ์›ํ•˜๋Š” ๋ฒ„์ „ ๊ผญ ๊ธฐ์–ตํ•˜๊ธฐ !!!

 

์ฐธ๊ณ ๋กœ ์ด ๊ธ€์—์„œ ์„ค์น˜ํ•  ๋ฒ„์ „์€ ↓

 


1. ์•„๋‚˜์ฝ˜๋‹ค ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

์•„๋‚˜์ฝ˜๋‹ค ํ”„๋กฌํŠธ(Anaconda Prompt) ์‹คํ–‰์ฐฝ ์—ด๊ณ  ์ž…๋ ฅ

conda create -n [๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ฆ„] python=3.7 # python version 3.7์œผ๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

conda create -n tf python=3.7.6 # python version 3.7.6์œผ๋กœ tf๋ผ๋Š” ์ด๋ฆ„์˜ ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

 ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์œ„์ฒ˜๋Ÿผ ์ƒ์„ฑํ•œ ํ›„, activate ๋ช…๋ น์œผ๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ํ™œ์„ฑํ™”ํ•œ๋‹ค.

conda activate [๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ฆ„]

conda activate tf # tf๋ผ๋Š” ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”ํ•˜๊ธฐ

2. Tensorflow ์„ค์น˜

์•„๋‚˜์ฝ˜๋‹ค ํ”„๋กฌํŠธ(Anaconda Prompt)์—์„œ ์œ„์ฒ˜๋Ÿผ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ํ™œ์„ฑํ™”ํ•œ ํ›„, ๊ทธ ๊ฐ€์ƒํ™˜๊ฒฝ์— tensorflow๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

์ด ๋•Œ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ฒ„์ „์„ ์„ ํƒํ•˜์—ฌ ์„ค์น˜ํ•ด์•ผ ๋‚˜์ค‘์— ๋ฌธ์ œ๊ฐ€ ์—†์ด ์„ค์น˜๊ฐ€ ์ž˜ ๋œ๋‹ค.

pip install tensorflow==2.0.0
pip install tensorflow-gpu==2.0.0

3. CUDA ์„ค์น˜

  • ๋‚ด GPU ๋ชจ๋ธ ํ™•์ธํ•˜๊ธฐ

์‹œ์ž‘์—์„œ ์žฅ์น˜๊ด€๋ฆฌ์ž ๊ฒ€์ƒ‰ 

์žฅ์น˜๊ด€๋ฆฌ์ž - ๋””์Šคํ”Œ๋ ˆ์ด ์–ด๋Œ‘ํ„ฐ์— ์žˆ๋Š” ๋ชฉ๋ก์ด ๋‚ด GPU ์‚ฌ์–‘์ด๋‹ค.

์ด์ œ ์ด ์‚ฌ์–‘์— ๋งž๋Š” NVIDIA driver๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

 

NVIDIA ๋“œ๋ผ์ด๋ฒ„ ๋‹ค์šด๋กœ๋“œ

 

www.nvidia.com

์œ„์˜ ์ฃผ์†Œ๋กœ ๋“ค์–ด๊ฐ€ ๋ฐฉ๊ธˆ ํ™•์ธํ•œ gpu์‚ฌ์–‘์— ๋งž๊ฒŒ ๊ฒ€์ƒ‰ํ•ด์ค€๋‹ค.

์ด๋ ‡๊ฒŒ ๊ฒ€์ƒ‰ํ•œ ํ›„ ๋‹ค์šด๋กœ๋“œ next, next, ๋‹ค์Œ,, ์ €์ฉŒ๊ตฌ,,  ๋ˆŒ๋Ÿฌ์„œ ์„ค์น˜์™„๋ฃŒํ•œ๋‹ค.

 

  • CUDA Toolkit ์„ค์น˜

์ด ๋•Œ ๋˜ ์ค‘์š”ํ•œ ๊ฒŒ ๊ณ„์† ๋งํ–ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ tensorflow gpu์™€ ํ˜ธํ™˜๋˜๋Š” ๋ฒ„์ „์„ ์„ค์น˜ํ•ด์•ผํ•œ๋‹ค๋Š” ์ .

tensorflow-gpu 2.0.0์€ CUDA 10.0์„ ์ง€์›ํ•˜๋ฏ€๋กœ ๊ณจ๋ผ์„œ ์„ค์น˜ํ•ด์ฃผ์—ˆ๋‹ค.

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

4. cuDNN ์„ค์น˜

https://developer.nvidia.com/cudnn

 

NVIDIA cuDNN

NVIDIA cuDNN The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, nor

developer.nvidia.com

์ด์ œ ๊ณ ์ง€๊ฐ€ ๋ˆˆ์•ž์ด๋‹ค.

cuDNN์€ ์šฐ์„  ํšŒ์›๊ฐ€์ž…์„ ํ•ด์•ผํ•œ๋‹ค.

ํšŒ์› ๊ฐ€์ž… ํ›„ Download๋ฅผ ๋ˆŒ๋Ÿฌ ๋˜ ๋ฒ„์ „์— ํ˜ธํ™˜๋˜๊ฒŒ ์„ค์น˜ํ•ด์ค€๋‹ค. (CUDA 10๊ณผ ํ˜ธํ™˜๋˜๋Š” ๋ฒ„์ „์ธ cuDNN 7.4 ์„ค์น˜ํ•จ)

 

5. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •

์‹œ์ž‘์—์„œ '์‹œ์Šคํ…œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํŽธ์ง‘' ๊ฒ€์ƒ‰

 

ํ™˜๊ฒฝ๋ณ€์ˆ˜ ํด๋ฆญ ํ›„

Path์— ์„ธ ๊ฐ€์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

 

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin

์ด๋ ‡๊ฒŒ ํ™˜๊ฒฝ๋ณ€์ˆ˜๊นŒ์ง€ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ์™„์„ฑ~

 

6. ์„ค์น˜ ํ™•์ธ

conda activate tf # tensorflow ์„ค์น˜ํ•œ ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”
python # python ์‹คํ–‰

์•„๋‚˜์ฝ˜๋‹ค ํ”„๋กฌํŠธ(Anaconda Prompt)๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”์‹œํ‚จ ํ›„ ๊ทธ ํ™˜๊ฒฝ์—์„œ python ์‹คํ–‰

import tensorflow as tf

tf.__version__

์ž…๋ ฅํ–ˆ์„ ๋•Œ ๋ฐ‘์˜ ํ™”๋ฉด์ฒ˜๋Ÿผ ๋œจ๋ฉด ๊ทธ๋ƒฅ tenorflow๋Š” ์„ค์น˜ ์™„๋ฃŒ

Successfully opened dynamic library cudart ์ด๋Ÿฐ ๋ฌธ๊ตฌ๊ฐ€ ์•ˆ๋œจ๊ณ  failed opened์ด ๋œฌ๋‹ค๋ฉด ๋ฒ„์ „ ํ˜ธํ™˜์ด ์•ˆ ๋˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ๋‹ค์‹œ ํ™•์ธ ํ›„ ์žฌ์„ค์น˜ํ•ด์•ผํ•œ๋‹ค.

 

์ด์ œ ์ค‘์š”ํ•œ tensorflow gpu ํ™•์ธ

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

์ž…๋ ฅํ•ด์„œ ๋ฐ‘์˜ ํ™”๋ฉด์ฒ˜๋Ÿผ CPU, GPU๊ฐ€ ๋ชจ๋‘ ๋œจ๋ฉด ์™„๋ฒฝํ•œ ์„ค์น˜ ๋~

↓Tensorflow gpu ์„ค์น˜ ํ™•์ธ ์•„๋‚˜์ฝ˜๋‹ค ํ”„๋กฌํŠธ ๋ชจ์Šต

728x90