멀티 GPU 시스템에서 하나의 GPU만 사용하기
2022. 2. 16. 01:18ㆍ프로그래밍/Keras
방법 1
tf.debugging.set_log_device_placement(True)
try:
# 유효하지 않은 GPU 장치를 명시
with tf.device('/device:GPU:2'):
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)
except RuntimeError as e:
print(e)
GPU 사용하기 | TensorFlow Core
도움말 Kaggle에 TensorFlow과 그레이트 배리어 리프 (Great Barrier Reef)를 보호하기 도전에 참여 GPU 사용하기 Note: 이 문서는 텐서플로 커뮤니티에서 번역했습니다. 커뮤니티 번역 활동의 특성상 정확한
www.tensorflow.org
방법 2
아래의 코드를 맨 처음 부분에 넣어주면 됨.
Ex> os.environ["CUDA_VISIBLE_DEVICES"]="0" , GPU 0를 사용하겠음 선언.
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
tf.config.experimental.set_memory_growth(gpus[0], True)
except RuntimeError as e:
print(e)