오늘의 인기 글
최근 글
최근 댓글
Today
Total
04-30 00:02
관리 메뉴

우노

[DL] Tensorflow GPU 확인 및 사용 방법 본문

AI/Deep Learning

[DL] Tensorflow GPU 확인 및 사용 방법

운호(Noah) 2022. 7. 19. 15:12

GPU 확인 방법

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())
  • 해당 환경에선, CPU 와 GPU:0 이 탐색된 것을 확인할 수 있습니다.

      [name: "/device:CPU:0"
      device_type: "CPU"
      memory_limit: 268435456
      locality {
      }
      incarnation: 1415685393377422244
      , name: "/device:GPU:0"
      device_type: "GPU"
      memory_limit: 17739145216
      locality {
        bus_id: 1
        links {
        }
      }
      incarnation: 16708498359240107799
      physical_device_desc: "device: 0, name: Xavier, pci bus id: 0000:00:00.0, compute capability: 7.2"
      ]

GPU 사용 방법

import os

os.environ["CUDA_VISIBLE_DEVICES"]="0"
  • os.environ["CUDA_VISIBLE_DEVICES"]에 사용하고자 하는 GPU의 번호를 할당하면 됩니다.
    • 위의 예시에서는 GPU:0 이 사용됩니다.
    • CPU 강제 사용을 원한다면, 번호를 -1 로 할당하면 됩니다.
  • 해당 코드 아래 부분은 모두 GPU로 실행됩니다.
Comments