Use GPUs in Containers
To take advantage of the performance benefits offered by graphics processing units (GPUs), you can use the GPUs of the host system in a container. By default, a container does not have access to hardware resources of its host. To enable the container to access the NVIDIA® GPUs of the host system, you need to:
Run the container on a host system with the appropriate NVIDIA GPU drivers and NVIDIA Container Toolkit installed. For setup instructions, see GPU access in the Docker® documentation.
Make the GPUs of the host visible to the container by using the
--gpusflag when you execute thedocker runcommand. Set this flag toallif you want the container to have access to all the GPUs of the host machine. For example, run a MATLAB® Deep Learning container and give it access to the GPUs of the host by executing a command like the one belowdocker run --gpus all mathworks/matlab-deep-learning:latest
Check Container Access to GPUs
To check if your container has access to the GPUs of the host, open MATLAB in the container and run this command.
tbl = gpuDeviceTable
tbl=
2×5 table
Index Name ComputeCapability DeviceAvailable DeviceSelected
_____ __________________ _________________ _______________ ______________
1 "NVIDIA RTX A5000" "8.6" true true
2 "NVIDIA RTX A5000" "8.6" true false
Use GPUs to Speed Up MATLAB Code
After giving the container access to the GPUs, you can speed up your MATLAB code, such as a training neural networks in parallel, by taking advantage of their computational power. To get started, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox). To learn more about using multiple GPUs to train a single neural network in parallel, see Deep Learning with MATLAB on Multiple GPUs (Deep Learning Toolbox).
See Also
gpuDeviceTable (Parallel Computing Toolbox)