Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use my GPU from a docker container on a MacBook Pro ? (AMD Radeon GPU)

I would like to run a GPU enabled app (Gazebo) inside a docker container on my MacBook Pro.

I seemed to me, through my research, that about a year ago, Docker released a native Docker app for MacOS.

Before that, Docker used to spawn an entire Linux VM and run the container on top of it.

Now, it apparently uses some native hypervisor framework, making it more optimized and closer to the hardware, changing entirely Docker's approach to containerization on a Mac.

All this is not very clear to me and I am not sure of everything I stated.

Is it now possible to use my macbook pro's GPU from a docker container, and, if yes, how ?

The command line I'm using right now, which works for regular X11 apps but not GPU-enabled apps like Gazebo is:

xhost +
docker run -it -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix image_name bash
like image 634
deb0ch Avatar asked Sep 22 '17 14:09

deb0ch


People also ask

Can Docker containers use GPU?

In order to do so, you need to install the nvidia-docker2 package and then use the –gpu flag when running your containers. Docker is a powerful tool that … Yes, docker can run on a GPU. In order to do so, you need to install the nvidia-docker2 package and then use the –gpu flag when running your containers.

Can I run a Docker container on Mac?

Docker Desktop currently supports macOS Catalina, macOS Big Sur, and macOS Monterey. At least 4 GB of RAM. VirtualBox prior to version 4.3.30 must not be installed as it is not compatible with Docker Desktop.

Does Docker need GPU?

Running CUDA container requires Nvidia drivers for Linux and access to Linux devices representing GPU, e.g. /dev/nvidia0. These devices and drivers are not available when Docker is installed on Windows and running inside VirtualBox virtual machine.

Will Docker ever run natively on Mac?

Docker can now be installed as a native Windows or native Mac app, launched and utilized from a system toolbar just like any other packaged application.


1 Answers

There's still a virtual machine involved.

Docker for Mac uses a virtualization layer called XHyve. It's a lot thinner and more lightweight than VirtualBox or such (emulates fewer peripherals), but it's still virtualization.


PCI passthrough is (theoretically) possible, but you can't pass through your laptop's main GPU and still use it.

Hardware with an IOMMU (and yes, your MacBook Pro has an Intel chipset with such support) can allow a virtualized environment direct access to PCI hardware.

However, you can't cede control of a piece of hardware to a VM and still use that hardware from the host. (Some high-end server network cards work around this by having multiple PCI endpoints, so the host and each guest gets a different endpoint to talk to).


So -- you could get an external Thunderbolt-attached GPU, and it might work... in the future.

The underlying support in Xhyve isn't there yet (as of this mid-2017 writing), and even on KVM (used by a lot of folks doing pioneering work here), there are only limited reports of success (with a specific video card -- the Radeon HD 5850).

like image 63
Charles Duffy Avatar answered Oct 20 '22 13:10

Charles Duffy