主要内容:
- 使用tensorflow查询机器上是否存在可用的gpu设备
- 使用tensorflow获取可用的gpu设备编号
- tensorflow对GPU设备的编码
使用tensorflow查询机器上是否存在可用的gpu设备
def is_gpu_available(cuda_only=True):
"""
code from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/test.py
Returns whether TensorFlow can access a GPU.
Args:
cuda_only: limit the search to CUDA gpus.
Returns:
True iff a gpu device of the requested kind is available.
"""
from tensorflow.python.client import device_lib as _device_lib
if cuda_only:
<