Last active
November 27, 2020 21:46
-
-
Save HeinrichAD/eea00d50c5702cbf63082983b6a2d763 to your computer and use it in GitHub Desktop.
Google Colab Processor Unit / Runtime Type Detector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from os import environ | |
class PU(Enum): | |
""" | |
Google Colab Processor Unit / Runtime Type Detector. | |
""" | |
CPU = 1 | |
GPU = 2 | |
TPU = 3 | |
def isCPU(): | |
return not (PU.isGPU() or PU.isTPU()) | |
def isGPU(): | |
return environ["COLAB_GPU"] == '1' | |
def isTPU(): | |
return "TPU_NAME" in environ | |
def getPU(): | |
return PU.GPU if PU.isGPU() else PU.TPU if PU.isTPU() else PU.CPU |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment