Difference between revisions of "LXD/GPU Acceleration"

From Funtoo
< LXD
Jump to navigation Jump to search
(Created page with "Setting up GPU-accelerated containers under Funtoo Linux is quite easy. In this example, we will set up a multilib Gentoo container with the ability to access the host GPU. =...")
 
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
Setting up GPU-accelerated containers under Funtoo Linux is quite easy. In this example, we will set up a multilib Gentoo
{{Warning|Use [[LXD/GPU Acceleration (NVIDIA)]] to setup LXD with NVIDIA graphics. Soon, I will drop references to NVIDIA in these docs and these will be Open Source Graphics-specific instructions.}}
container with the ability to access the host GPU.
 
Setting up GPU-accelerated containers under Funtoo Linux is quite easy. In this example, we will set up a multilib Gentoo container with the ability to access the host GPU.
 
{{Important|Before starting, make sure you have followed [[LXD#Basic Setup on Funtoo|Basic Setup on Funtoo]] steps on the main [[LXD]] page.
 
Also be sure you are using ''at least Funtoo Linux 1.4''. Funtoo Linux 1.4 and above contain several ebuilds that have been significantly modified to make them container-friendly.}}


=== Container Launch ===
=== Container Launch ===
Line 16: Line 21:
{{console|body=
{{console|body=
# ##i##lxc exec gentoo-gpu-test -- su --login
# ##i##lxc exec gentoo-gpu-test -- su --login
gentoo-gpu-test ~ # ##i##emerge --sync
%gentoo-gpu-test% ##i##emerge --sync
gentoo-gpu-test ~ # echo 'VIDEO_CARDS="intel i915 i965"' >> /etc/portage/make.conf
%gentoo-gpu-test% ##i##echo 'VIDEO_CARDS="intel i915 i965"' >> /etc/portage/make.conf
gentoo-gpu-test ~ # emerge -auDN @world xorg-x11 --jobs
%gentoo-gpu-test% ##i##emerge -auDN @world xorg-x11 --jobs
}}
}}


Line 25: Line 30:
=== Host Setup ===
=== Host Setup ===


On your regular system (which we will refer to as your "host"), since it "hosts" the containers, you will want to inspect
On your regular system (which we will refer to as your "host", since it "hosts" the containers), you will want to inspect
the setting of your {{c|DISPLAY}} environment variable:
the setting of your {{c|DISPLAY}} environment variable:


Line 33: Line 38:
}}
}}


We will want to set the container to use this value. We will also want to add a GPU to our container configuration. Run the following command on the host to edit the container's configuration. You will want to add the {{c|environment.DISPLAY}} setting,
We will want to set the container to use this value. We will also want to add a GPU to our container configuration. Run the following command on the host to edit the container's configuration.  
as well as copy the {{c|devices:}} section in the container config below:


{{console|body=
{{console|body=
Line 40: Line 44:
}}
}}


You will be presented with a [[Wikipedia:YAML|YAML]] file which contains the configuration for the container. You will want to modify the container configuration to contain the  
You will be presented with a [[Wikipedia:YAML|YAML]] file which contains the configuration for the container. You will want to modify the container configuration to add the {{c|environment.DISPLAY}} setting,
as well as copy the {{c|devices:}} section in the container configuration snippet below. Note that you should keep all the existing configuration that is in your YAML, and ''do not'' wipe your config and paste what is below -- I'm including just the relevant parts to keep things easy-to-read:


{{file|name="gentoo-gpu-test configuration"|body=
{{file|name=gentoo-gpu-test configuration|body=
### This is a yaml representation of the configuration.
### Any line starting with a '# will be ignored.
###
### A sample configuration looks like:
### name: container1
### profiles:
### - default
### config:
###  volatile.eth0.hwaddr: 00:16:3e:e9:f8:7f
### devices:
###  homedir:
###    path: /extra
###    source: /home/user
###    type: disk
### ephemeral: false
###
### Note that the name is shown but cannot be changed


architecture: x86_64
architecture: x86_64
Line 67: Line 55:
   image.description: Gentoo current amd64 (20190717_17:39)
   image.description: Gentoo current amd64 (20190717_17:39)
   image.os: Gentoo
   image.os: Gentoo
  image.release: current
  image.serial: "20190717_17:39"
  volatile.base_image: 2c71e864b7bf2a3e3e5719b2857d68c7f7c3b2f1c364ae58bfe0fc3cbaffda21
  volatile.eth0.host_name: vethAHRHQJ
  volatile.eth0.hwaddr: 00:16:3e:2a:d2:ac
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":100000>
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":100000000>
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":100>
  volatile.last_state.power: RUNNING
devices:
devices:
   X11-unix:
   X11-unix:
Line 85: Line 63:
     type: gpu
     type: gpu
ephemeral: false
ephemeral: false
profiles:
- default
stateful: false
description: ""
}}
}}
Now your container is configured to use the host's GPU! All you need to do is run the following command as your regular user on your regular system to allow X connections from the container to your host:
{{console|body=
$ ##i##xhost +local:
}}
This {{c|xhost}} command will only be active until your system reboots, and will allow local connections to talk to your X server.
=== Testing OpenGL ===
You can now proceed to test use of OpenGL in the container:
{{console|body=
# ##i##lxc exec gentoo-gpu-test -- su --login
%gentoo-gpu-test% ##i##emerge -av --jobs mesa-progs
%gentoo-gpu-test% ##i##echo $DISPLAY
:1
%gentoo-gpu-test% ##i##glxgears
}}
You should be presented with a {{c|glxgears}} window, running within your container, but being displayed on your X server. Congratulations -- you now have accelerated OpenGL within a container!
[[Category:LXD]]
[[Category:Official Documentation]]

Latest revision as of 01:30, October 24, 2019

   Warning

Use LXD/GPU Acceleration (NVIDIA) to setup LXD with NVIDIA graphics. Soon, I will drop references to NVIDIA in these docs and these will be Open Source Graphics-specific instructions.

Setting up GPU-accelerated containers under Funtoo Linux is quite easy. In this example, we will set up a multilib Gentoo container with the ability to access the host GPU.

   Important

Before starting, make sure you have followed Basic Setup on Funtoo steps on the main LXD page.

Also be sure you are using at least Funtoo Linux 1.4. Funtoo Linux 1.4 and above contain several ebuilds that have been significantly modified to make them container-friendly.

Container Launch

First, let's launch a Gentoo container. By default, LXD configures the remote images: to point to https://images.linuxcontainers.org, and this site hosts Gentoo Linux images. Let's create one as follows:

root # lxc launch images:gentoo gentoo-gpu-test
Creating gentoo-gpu-test
Starting gentoo-gpu-test

Now, let's enter the container and perform an emerge --sync. We will then configure our container to use Intel GPU acceleration, which is what we are using on our host, and we will emerge xorg-x11:

root # lxc exec gentoo-gpu-test -- su --login
gentoo-gpu-test # emerge --sync
gentoo-gpu-test # echo 'VIDEO_CARDS="intel i915 i965"' >> /etc/portage/make.conf
gentoo-gpu-test # emerge -auDN @world xorg-x11 --jobs

Once this completes, we are close to having GPU acceleration but need to perform a few more steps.

Host Setup

On your regular system (which we will refer to as your "host", since it "hosts" the containers), you will want to inspect the setting of your DISPLAY environment variable:

user $ echo $DISPLAY
:1

We will want to set the container to use this value. We will also want to add a GPU to our container configuration. Run the following command on the host to edit the container's configuration.

root # lxc config edit gentoo-gpu-test

You will be presented with a YAML file which contains the configuration for the container. You will want to modify the container configuration to add the environment.DISPLAY setting, as well as copy the devices: section in the container configuration snippet below. Note that you should keep all the existing configuration that is in your YAML, and do not wipe your config and paste what is below -- I'm including just the relevant parts to keep things easy-to-read:

   gentoo-gpu-test configuration
architecture: x86_64
config:
  environment.DISPLAY: :1
  image.architecture: amd64
  image.description: Gentoo current amd64 (20190717_17:39)
  image.os: Gentoo
devices:
  X11-unix:
    path: /tmp/.X11-unix
    source: /tmp/.X11-unix
    type: disk
  mygpu:
    type: gpu
ephemeral: false

Now your container is configured to use the host's GPU! All you need to do is run the following command as your regular user on your regular system to allow X connections from the container to your host:

user $ xhost +local:

This xhost command will only be active until your system reboots, and will allow local connections to talk to your X server.

Testing OpenGL

You can now proceed to test use of OpenGL in the container:

root # lxc exec gentoo-gpu-test -- su --login
gentoo-gpu-test # emerge -av --jobs mesa-progs
gentoo-gpu-test # echo $DISPLAY
:1
gentoo-gpu-test # glxgears

You should be presented with a glxgears window, running within your container, but being displayed on your X server. Congratulations -- you now have accelerated OpenGL within a container!