python类list_local_devices()的实例源码

sg_main.py 文件源码 项目:sugartensor 作者: buriburisuri 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def sg_gpus():
    r""" Gets current available GPU nums

    Returns:
      A integer : total # of GPUs available
    """
    global _gpus

    if _gpus is None:
        local_device_protos = device_lib.list_local_devices()
        _gpus = len([x.name for x in local_device_protos if x.device_type == 'GPU'])

    return max(_gpus, 1)


#
# context helpers
#
tf_utils.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def has_gpu() -> bool:
    """Check if TensorFlow can access GPU.

    The test is based on
        https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/test.py
    ...but we are interested only in CUDA GPU devices.

    Returns:
        True, if TF can access the GPU
    """
    # pylint: disable=global-statement
    global __HAS_GPU_RESULT
    # pylint: enable=global-statement
    if __HAS_GPU_RESULT is None:
        __HAS_GPU_RESULT = any((x.device_type == 'GPU')
                               for x in _device_lib.list_local_devices())
    return __HAS_GPU_RESULT
tf_utils.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def has_gpu() -> bool:
    """Check if TensorFlow can access GPU.

    The test is based on
        https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/test.py
    ...but we are interested only in CUDA GPU devices.

    Returns:
        True, if TF can access the GPU
    """
    # pylint: disable=global-statement
    global __HAS_GPU_RESULT
    # pylint: enable=global-statement
    if __HAS_GPU_RESULT is None:
        __HAS_GPU_RESULT = any((x.device_type == 'GPU')
                               for x in _device_lib.list_local_devices())
    return __HAS_GPU_RESULT
tf_utils.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def has_gpu() -> bool:
    """Check if TensorFlow can access GPU.

    The test is based on
        https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/test.py
    ...but we are interested only in CUDA GPU devices.

    Returns:
        True, if TF can access the GPU
    """
    # pylint: disable=global-statement
    global __HAS_GPU_RESULT
    # pylint: enable=global-statement
    if __HAS_GPU_RESULT is None:
        __HAS_GPU_RESULT = any((x.device_type == 'GPU')
                               for x in _device_lib.list_local_devices())
    return __HAS_GPU_RESULT
communication_utils.py 文件源码 项目:OwlPy 作者: mateuszzwierzycki 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()

    values = ""
    counter = 0
    length = len(local_device_protos)

    for device in local_device_protos:
        if device.device_type == "GPU":
            description = "Found " + device.physical_device_desc
            values += description
            if counter < length - 1: values += "\n"
        counter += 1

    # return [x.name for x in local_device_protos if x.device_type == 'GPU']
    return values


# this is taken from the C++ header file
# const int INFO = 0;            // base_logging::INFO;
# const int WARNING = 1;         // base_logging::WARNING;
# const int ERROR = 2;           // base_logging::ERROR;
# const int FATAL = 3;           // base_logging::FATAL;
# const int NUM_SEVERITIES = 4;  // base_logging::NUM_SEVERITIES;
tf.py 文件源码 项目:imageCrack 作者: mario1oreo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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:
        return any((x.device_type == 'GPU')
                   for x in _device_lib.list_local_devices())
    else:
        return any((x.device_type == 'GPU' or x.device_type == 'SYCL')
                   for x in _device_lib.list_local_devices())
gpu.py 文件源码 项目:AVSR-Deep-Speech 作者: pandeydivesh15 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_available_gpus():
    r"""
    Returns the number of GPUs available on this system.
    """
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']
utils.py 文件源码 项目:CausalGAN 作者: mkocaoglu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type=='GPU']
utils.py 文件源码 项目:CausalGAN 作者: mkocaoglu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type=='GPU']
run_dqn_ram.py 文件源码 项目:deep-q-learning 作者: alvinwan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']
run_dqn_atari.py 文件源码 项目:deep-q-learning 作者: alvinwan 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']
utils.py 文件源码 项目:tfutils 作者: neuroailab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']
keras_utils.py 文件源码 项目:AutoSleepScorerDev 作者: skjerns 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_available_gpus():
    """
    The function does what its name says. Simple as that.
    """
    local_device_protos = device_lib.list_local_devices()
    return len([x.name for x in local_device_protos if x.device_type == 'GPU'])
tf_utils.py 文件源码 项目:minos 作者: guybedo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_available_gpus():
    try:
        from tensorflow.python.client import device_lib
        local_device_protos = device_lib.list_local_devices()
        return [x.name for x in local_device_protos if x.device_type == 'GPU']
    except Exception as ex:
        logging.error(
            'Error while trying to list available GPUs: %s' % str(ex))
        return list()
run_dqn_ram.py 文件源码 项目:rl_algorithms 作者: DanielTakeshi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']
run_dqn_atari.py 文件源码 项目:rl_algorithms 作者: DanielTakeshi 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']
utils.py 文件源码 项目:rl_algorithms 作者: DanielTakeshi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_tf_session():
    """ Returning a session. Set options here (e.g. for GPUs) if desired. """
    tf.reset_default_graph()
    tf_config = tf.ConfigProto(inter_op_parallelism_threads=1,
                               intra_op_parallelism_threads=1)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
    session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

    def get_available_gpus():
        from tensorflow.python.client import device_lib
        local_device_protos = device_lib.list_local_devices()
        return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']

    print("AVAILABLE GPUS: ", get_available_gpus())
    return session
bc.py 文件源码 项目:rl_algorithms 作者: DanielTakeshi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_tf_session():
    """ Returning a session. Set options here if desired. """
    tf.reset_default_graph()
    tf_config = tf.ConfigProto(inter_op_parallelism_threads=1,
                               intra_op_parallelism_threads=1)
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
    session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

    def get_available_gpus():
        from tensorflow.python.client import device_lib
        local_device_protos = device_lib.list_local_devices()
        return [x.physical_device_desc for x in local_device_protos if x.device_type == 'GPU']

    print("AVAILABLE GPUS: ", get_available_gpus())
    return session
show_gpu_count.py 文件源码 项目:MachineLearningTutorial 作者: SpikeKing 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_available_gpus():
    """
    ??GPU????nvidia-smi
    ?????????ps aux | grep PID
    :return: GPU??
    """
    local_device_protos = device_lib.list_local_devices()
    print "all: %s" % [x.name for x in local_device_protos]
    print "gpu: %s" % [x.name for x in local_device_protos if x.device_type == 'GPU']
utils.py 文件源码 项目:MixtureOfExperts 作者: krishnakalyan3 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_available_gpus():
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']
utils.py 文件源码 项目:RFHO 作者: lucfra 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_available_devices(gpu_only=False):
    from tensorflow.python.client import device_lib
    local_device_protos = device_lib.list_local_devices()
    if gpu_only: return [x.name for x in local_device_protos if x.device_type == 'GPU']
    else: return [x.name for x in local_device_protos]
_multigpu.py 文件源码 项目:keras_experiments 作者: avolkov1 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_available_gpus(ngpus=-1):
    '''
    :param int ngpus: GPUs max to use. Default -1 means all gpus.
    :returns: List of gpu devices. Ex.: ['/gpu:0', '/gpu:1', ...]
    '''
    local_device_protos = device_lib.list_local_devices()
    gpus_list = [x.name for x in local_device_protos if x.device_type == 'GPU']
    return gpus_list[:ngpus] if ngpus > -1 else gpus_list
gputools.py 文件源码 项目:tensorflow-layer-library 作者: bioinf-jku 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self):
        self.devices = device_lib.list_local_devices()
        self.cpus = [x.name for x in self.devices if x.device_type == 'CPU']
        self.gpus = [x.name for x in self.devices if x.device_type == 'GPU']
        self.iterate_cpus = it.cycle(self.cpus)
        self.iterate_gpus = it.cycle(self.gpus)
util.py 文件源码 项目:tefla 作者: openAGI 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_num_gpu():
    """Get number of available GPUs

    Returns:
        a `int`, available GPUs in CUDA_VISIBLE_DEVICES, or in the system.
    """
    env = os.environ.get('CUDA_VISIBLE_DEVICES', None)
    if env is not None:
        return len(env.split(','))
    from tensorflow.python.client import device_lib
    device_protos = device_lib.list_local_devices()
    gpus = [x.name for x in device_protos if x.device_type == 'GPU']
    return len(gpus)
parallelizer.py 文件源码 项目:main 作者: rmkemker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _get_available_gpus(self):
        """Get available GPUs."""
        from tensorflow.python.client import device_lib
        local_device_protos = device_lib.list_local_devices()
        return [int(x.name[-1]) for x in local_device_protos if x.device_type == 'GPU']
model_deploy.py 文件源码 项目:shuttleNet 作者: shiyemin 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_available_gpus():
  local_device_protos = device_lib.list_local_devices()
  return [x.name for x in local_device_protos if x.device_type == 'GPU']
__init__.py 文件源码 项目:yolo-tf 作者: ruiminshen 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']
tensorflow_solver.py 文件源码 项目:hyper-engine 作者: maxim5 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def tf_is_gpu():
  local_devices = device_lib.list_local_devices()
  return len([x for x in local_devices if x.device_type == 'GPU']) > 0
graph_template.py 文件源码 项目:stuff 作者: yaroslavvb 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def count_gpus():
  from tensorflow.python.client import device_lib
  count = 0
  for device in device_lib.list_local_devices():
    if device.device_type == "GPU":
      count+=1
  return count
multi_gpu.py 文件源码 项目:mnist-multi-gpu 作者: normanheckscher 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']


问题


面经


文章

微信
公众号

扫码关注公众号