BVLC / caffe

Caffe: a fast open framework for deep learning.
http://caffe.berkeleyvision.org/
Other
34.03k stars 18.7k forks source link

How to check GPU or CUDA exist before set gpu model #6825

Closed haikuoyao closed 5 years ago

haikuoyao commented 5 years ago

Anyone knows, how can I check if GPU or CUDA exists before setting gpu model

if CUDA or GPU Check ?
        caffe.set_mode_gpu()
        caffe.set_device(0)

Thanks.

ravibanger commented 5 years ago

In C/C++ you can use the function get_gpus(). But this function is not part of the caffe library. This needs to be explicitly implemented.

haikuoyao commented 5 years ago

@ravibanger Thanks a lot. I just do this in my python code

def is_available():

    """
        Check NVIDIA with nvidia-smi command
        Returning code 0 if no error, it means NVIDIA is installed
        Other codes mean not installed
    """
    code = os.system('nvidia-smi')
    return code == 0