Created
March 3, 2020 10:04
-
-
Save cabral/e3f804dbc4f7ca74b2715521da15911b to your computer and use it in GitHub Desktop.
This file contains 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
gpus = tf.config.experimental.list_physical_devices('GPU') | |
if gpus: | |
try: | |
# Restrict TensorFlow to only use the fourth GPU | |
tf.config.experimental.set_visible_devices(gpus[0], 'GPU') | |
# Currently, memory growth needs to be the same across GPUs | |
for gpu in gpus: | |
tf.config.experimental.set_memory_growth(gpu, True) | |
logical_gpus = tf.config.experimental.list_logical_devices('GPU') | |
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") | |
except RuntimeError as e: | |
# Memory growth must be set before GPUs have been initialized | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment