メインコンテンツ

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 --gpus flag when you execute the docker run command. Set this flag to all if 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 below

    docker 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       

This command returns a table of properties of all GPU devices detected in your system. Both devices are available for use in this MATLAB session. The selected GPU device, with index 1, has a higher compute capability than the device with index 2. For more information, on this command and on how to select a specific GPU, see Identify and Select a GPU Device (Parallel Computing Toolbox).

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

(Parallel Computing Toolbox)

Topics