[GPU] GPU 연결 확인 방법
GPU가 탑재되어 있는 노트북이라고 하더라도 자동적으로 GPU를 써서 코드가 돌아가는 것은 아니다. 따로 드라이버를 깔고 CUDA를 설치하는 등 여러 가지 것들을 세팅해 주고 나서야 비싼 GPU를 사용할 수 있다! 내 컴퓨터에서 지금 돌릴 코드가 GPU에서 돌아가는지를 확인해 보기 위한 여러 방법들을 살펴보자!
torch version 1
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.get_device_name(torch.cuda.current_device()))
torch version2
from torch import cuda
assert cuda.is_available()
assert cuda.device_count() > 0
print(cuda.get_device_name(cuda.current_device()))
tensorflow version
import tensorflow as tf
tf.__version__
모든 사용가능한 GPU 리스트 보기
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
tf.config.experimental.list_physical_devices('GPU')
tf.debugging.set_log_device_placement(True)
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
Keras
from keras import backend
assert len(backend.tensorflow_backend._get_available_gpus()) > 0
주로 사용하는 코드
import tensorflow as tf
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
tf.config.list_physical_devices('GPU')
인식한 GPU 개수 출력
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
나는 맨 아래 두 개의 코드를 주로 사용해서 GPU가 잘 세팅이 되었는지 확인하는데, 출력에 CPU만 나오거나 인식한 GPU 개수가 0이 나오면 세팅을 다시 확인해 봐야 한다.
이번에 NVIDIA Quadro T2000로 워크스테이션에 세팅을 했었는데, 버전 이슈가 있어서 조만간 NVIDIA GeForce GTX 1050을 세팅해 보며 다시 한번 잘 익혀야겠다.
그리고 맥북프로에서도 GPU 세팅을 해야 해서 GPU 설치 방법도 다음에 포스팅해야겠다!
참고 : https://koos808.tistory.com/86
Author And Source
이 문제에 관하여([GPU] GPU 연결 확인 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@hanakim120/GPU-GPU-연결-확인-방법저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)