행위

파이썬 gpu 정보

DB CAFE

thumb_up 추천메뉴 바로가기


1 파이썬에서 GPU 정보와 GPU 사용 유무 확인[편집]

1.1 파이토치 이용 torch[편집]

  • 파이토치 설치 확인
pip install torch
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.get_device_name(torch.cuda.current_device()))

1.1.1 파이토치 방법 2[편집]

from torch import cuda
assert cuda.is_available()
assert cuda.device_count() > 0
print(cuda.get_device_name(cuda.current_device()))

1.2 텐서플로우 이용 tensorflow[편집]

  • 텐서플로우 설치 확인
pip install tensorflow
import tensorflow as tf
tf.__version__

1.2.1 텐서플로우 방법 2 : 모든 사용 가능한 GPU List 보기[편집]

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

1.2.2 방법 3[편집]

tf.config.list_physical_devices('GPU')

1.2.3 방법 4[편집]

tf.config.experimental.list_physical_devices('GPU')

1.2.4 방법 5[편집]

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)

1.3 방법 3 : 케라스 이용 confirm Keras sees the GPU[편집]

from keras import backend
assert len(backend.tensorflow_backend._get_available_gpus()) > 0

1.4 주로 사용하는 GPU 확인 조회 코드[편집]

import tensorflow as tf
from tensorflow.python.client import device_lib

device_lib.list_local_devices()
tf.config.list_physical_devices('GPU')

1.5 주로 사용하는 인식한 GPU 개수 출력 코드[편집]

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))