Is there a way to check if mxnet uses my gpu?
Check if mxnet
have listed the gpu.
import mxnet as mx
mx.context.num_gpus()
To use the library, make sure to pass the argument mx.gpu(0)
where the context is required. The 0
is the gpu indice, in the case of multi-gpus, there will be more indices.
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!')