본문 바로가기
Naver Clould with BitCamp/Aartificial Intelligence

Environment Settings for GPU usage

by HJ0216 2023. 1. 21.

본 환경: IDE:VS code, Language:Python

 

GPU 사용을 위한 환경 설정

 

1. Google: Nvdia Driver DownLoad

 

2. Google: Cuba DownLoad(v.11.4.4)

 

3. Google: cuDNN DownLoad

login(Sign in required)

Archived relaesae

Version에 맞는 cuDNN Download

 

4. D drive 내 'program' 폴더 생성
program 폴더 내에 해당 파일(다운로드 받은 파일 3개) 복사
(Ncvidia Driver) 527.56-desktop-win10-win11-64bit-international-dch-whql
(cuda) cuda_11.4.4_472.50_windows
(cuDNN) cudnn-11.4-windows-x64-v8.2.4.15

D drive -> 프로그램 폴더 내
4.1. (Nvidia Driver) 527.56-desktop-win10-win11-64bit-international-dch-whql 실행
→ driver만 설치, 사용자 정의 설치, 전체 설치

4.2. (cuda) cuda_11.4.4_472.50_windows
→ 동의 및 계속, 사용자 정의 설치
⚠️ Cuda 내 VS Integration 설치 제외, samples 설치 제외, Documentation 제외
GeForce 설치 제외
Component * 2 설치 제외

4.3. (cuDNN)cudnn-11.4-windows-x64-v8.2.4.15.zip
D drive에 zip 파일 풀기

4.4. C Drive -> 보기: 파일 확장명, 숨김 항목 표시 클릭
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4
→ NVIDIA GPU Computing Toolkit\CUDA\v11.4 확인
⚠️ 가장 최신 버전의 CUDA가 아닌 가장 최근에 다운 받은 버전이 실행됨

4.5. D Drive에 담긴 프로그램 폴더 내 Cuda 폴더 내 파일 4개
(bin, include, lib, NVIDIA_SLA_cuDNN_Support.txt)를 
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4에 복사해서 덮어쓰기

 

⭐ 설치 확인
cmd
nvidia-smi: 그래픽 드라이버 설치 확인
nvcc -V or nvcc --version : cuda ver 확인

 

⭐ GPU를 활용한 가상환경 만들기
anaconda prompt
conda create -n tf274gpu python=3.9.15 anaconda
conda env list: 가상환경 리스트 조회(⚠️ Base에서 확인)
activate tf274gpu
pip install tensorflow-gpu==2.7.4

VS code

Interpreter: 가상 환경 설정 tf274gpu 선택 후 Source Code 실행

# gpu_test.py

import tensorflow as tf
print(tf.__version__) # 2.7.4

gpus = tf.config.experimental.list_physical_devices('GPU')
# experimental: experimental method
# list_physical_devices 물리적인 장치 리스트
print(gpus)
# [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
# Nvidia GPU만 출력됨(intel 내장형 GPU 출력 X)


if(gpus):
    print("GPU is running.")
else:
    print("GPU isn't running.")
# on GPU: GPU is running.
# on CPU: gpus=[], GPU isn't running.

gpus를 사용한 가상환경일 경우,

print(type(gpus)) # <class 'list'>

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

print(len(gpus)) = 1

-> 1개의 element가 있는 list 

비어있지 않은 리스트이므로 true 반환

그러므로 "GPU is running." 출력

 

Python에서의 boolean 기준

Value Descirption Boolean
"" 빈 String False (공백이 아니고 비어있지 않은 문자열은 True)
" " 공백만 있는 String False (공백이 아니고 비어있지 않은 문자열은 True)
"abc" 값이 있는 String True
[] 빈 List False (공백이 아니고 비어있지 않은 리스트는 True)
[1, 2] 값이 있는 List False (공백이 아니고 비어있지 않은 리스트는 True)
1 숫자 1 True
0 숫자 0 False (0이 아닌 모든 숫자는 True)
-1 숫자 -1 True
{} 비어있는 dictionaty False (공백이 아니고 비어있지 않은 dictionary는 True)
() 비어있는튜플 False (공백이 아니고 비어있지 않은 Tuple은 True)

* list: 자료 구조 형태의 하나로 순서가 있는 수정가능한 객체의 집합

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

* tuple: 자료 구조 형태의 하나로 순서가 있는 집합(수정 불가능)

tuple = (1, 2, 3, 4, 5)

 

 

 

소스 코드

🔗 HJ0216/TIL

 

참고 자료

📑 [Python] 리스트, 튜플