Good morning,
I have matlab version 2022b and I would like to disable the system GPU from the matlab application so that it does not recognise it and runs the programs only using the cpu. Could you tell me if it is possible to do it and how to do it? I would like to do it from the application itself, as disabling the gpu from the system is more laborious and I just want matlab to not recognise it.
Thank you.

Respuestas (3)

Joss Knight
Joss Knight el 15 de En. de 2023

2 votos

As soon as you start MATLAB type
setenv CUDA_VISIBLE_DEVICES -1
MATLAB will no longer recognise any GPU for computation.

2 comentarios

Walter Roberson
Walter Roberson el 15 de En. de 2023
Interesting!
I take it that variable is only tested the first time that gpu would be relevant, and that there is no way to force the test to be reset?
Joss Knight
Joss Knight el 15 de En. de 2023
This is a variable recognised by the CUDA driver and only checked when the driver is initialized, which happens the first time you use or query the GPU. So correct, there is no way to reset this without restarting MATLAB. Alternatively, use a process pool which can be stopped and restarted at will.

Iniciar sesión para comentar.

Luca Ferro
Luca Ferro el 13 de En. de 2023

0 votos

the command:
gpuDevice([]);
should do the trick.
Mind that it requires that the Parallel Computing Toolbox is installed.
For more informations you can check here

1 comentario

Walter Roberson
Walter Roberson el 13 de En. de 2023
If you have code along the lines of
if gpu is detected
run deep learning on gpu
else
run deep learning on cpu
end
and you want to calculate the timings both ways without changing the detection test... then selecting the empty gpu is probably not going to be enough. But it would depend on how the gpu detection is coded.

Iniciar sesión para comentar.

Matt J
Matt J el 13 de En. de 2023
Editada: Matt J el 13 de En. de 2023

0 votos

Matlab will use the CPU by default unless you have in some way told it to use the GPU for a specific computation.
An exception might be the trainNetwork and predict commands, if you are doing DNN training or inference. Those commands have an option, however, called ExecutionEnvironment that you can use to specify CPU-only computation.

6 comentarios

Xiaohao Sun
Xiaohao Sun el 24 de Mzo. de 2023
Hey Matt, there is another predict function for dlnetwork objects (see https://www.mathworks.com/help/deeplearning/ref/dlnetwork.predict.html)
For this one, the documentation doesn't tell how to use CPU, and ExecutionEnvironment cannot be used for it. Do you have any ideas how to use CPU for this predict function? Thank you!
Catalytic
Catalytic el 24 de Mzo. de 2023
What about @Joss Knight's answer?
Matt J
Matt J el 24 de Mzo. de 2023
Joss Knight
Joss Knight el 24 de Mzo. de 2023
dlnetwork's execution environment is determined by the attributes of its input data and parameters. If you don't explicitly move anything to the GPU, it will run on the CPU. You can think of predict as a function with the input data and network parameters as inputs. As for all gpuArray behaviour, if any of those inputs are on the GPU then any operations with them will take place on the GPU and result in gpuArray outputs.
To move back and forth:
inputData = gpuArray(inputData); % Move data to GPU
net = dlupdate(@gpuArray, net); % Optional: move network learnables to GPU
net.State = dlupdate(@gpuArray, net.State); % Optional: for stateful networks
inputData = gather(inputData); % Move data back to CPU
net = dlupdate(@gather, net); % Move network learnables
net.State = dlupdate(@gather, net.State);
Moving the network back and forth isn't ever strictly necessary, but for example if you wish to do training on the GPU but inference on the CPU, you will need to gather the network because the network will naturally become moved to the GPU as its learnables and state are updated during training. Save/load will also move a network back to the CPU.
Matt J
Matt J el 24 de Mzo. de 2023
dlnetwork's execution environment is determined by the attributes of its input data and parameters.
If so, what is the acceleration property for?
Joss Knight
Joss Knight el 24 de Mzo. de 2023
That's a separate thing, although the kinds of accelerations we can do are affected by the environment.

Iniciar sesión para comentar.

Comentada:

el 24 de Mzo. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by