Search code examples
tensorflowgpumxnet

Is there a way to check if mxnet uses my gpu?


Can I see what are the available GPUs with mxnet?

Is there something similar for TensorFlow's

tf.test.gpu_device_name()

in mxnet?


Solution

  • The definitive way to check if your GPU is being utilized is by using nvidia-smi command. My favorite arguments are:

    nvidia-smi --query-gpu=timestamp,name,pci.bus_id,driver_version,pstate,pcie.link.gen.max,pcie.link.gen.current,temperature.gpu,utilization.gpu,utilization.memory,memory.total,memory.free,memory.used --format=csv -l 1
    

    If you just want to test if gpu support is available (which is what tf.test.gpu_device_name()) does, the following function can help:

    import mxnet as mx 
    def gpu_device(gpu_number=0):
        try:
            _ = mx.nd.array([1, 2, 3], ctx=mx.gpu(gpu_number))
        except mx.MXNetError:
            return None
        return mx.gpu(gpu_number)
    

    This function returns None if the requested gpu device isn't available, or returns the relevant context if gpu device is available. You can also use this function to check if there is any support for GPU on this system:

    if not gpu_device():
        print('No GPU device found!')