Blender* and Intel® Iris® Xe MAX Graphics on Linux*

What is Blender? From blender.org:

Blender is the free and open source 3D creation suite. It supports the entirety of the 3D pipeline—modeling, rigging, animation, simulation, rendering, compositing and motion tracking, video editing and 2D animation pipeline.

At the end of this tutorial, you will have the version 2.90.1 of Blender built for your Linux system, fully enabled to leverage the latest Intel graphics processors.

The process of building Blender can be daunting to those not familiar, so we provide the exact steps to copy/paste to your console.

The general steps are:

  1. Use Docker to build Blender
  2. Transfer the generated Blender container to the systems you want to run Blender
  3. Run Blender

We refer to two systems in these intructions. The build system is where Blender will be built. The target system is the system where Blender will be run.

This tutorial is written for a dual-GPU system configured as documented in the Intel Iris Xe MAX Graphics page.

In that environment, the build system is the host system (using the Intel Iris Xe graphics adapter for the display.) The target system is the virtual machine (VM) with the Intel Iris Xe MAX graphics, accessed via ssh from the host. While you could build Blender on the target instead of the host, doing so may use more disk space than the 50G VM disk created in that guide.

Building Blender

On the build system, install Docker, download a Dockerfile that will contain all of the build tools needed to build Blender, and build Blender. Excluding the time to download the required packages, the total process for building Blender is about an hour.

Prior to running the instructions below, activate sudo in your session by running sudo -l. This will allow you to copy/paste the instructions which use sudo without being prompted for your password.

sudo -l

Install pre-requisites on the host

On the build system:

sudo apt install -y wget docker.io &&
sudo systemctl enable docker &&
sudo systemctl start docker

Add the active user to the ‘docker’ group so you can run docker without using sudo.

On the build system:

sudo usermod -aG docker $(whoami)

After adding your user to the docker group, you either need to log out and back in or run ‘newgrp docker’ to log in to the new group:

On the build system:

newgrp docker

The rest of the instructions assume the active user is a member of the group ‘docker’ and that docker is configured and functioning on the host system, including network access.

Download and build Blender in a Docker container

The following will download a Dockerfile.

On the build system:

mkdir $HOME/blender
cd $HOME/blender
wget https://dgpu-docs.intel.com/devices/iris-xe-max-graphics/guides/assets/Dockerfile.blender

At this point, you can build Blender inside the Docker container. This may take a while to download the Blender source code, various package dependencies, and then build them. You only need to perform this build once.

On the build system:

docker build -f Dockerfile.blender -t blender-custom .

By default, the above container will build Blender from the 2.90.1 tag. This was the latest commit at the time this guide was written, and the version tested. If you would like to build a specific tag or a different commit, you can specify build arguments when running docker build. For example, to build the latest commit on the master branch:

On the build system:

docker build -f Dockerfile.blender \
  --build-arg BLENDER_BRANCH=master --build-arg BLENDER_COMMIT=HEAD \
  -t blender-custom .

The Dockerfile.blender is a multi-stage container. The first stage builds blender, and can grow to several gigabytes. The second stage copies the built version of blender into a smaller runtime container, that doesn’t include all of the source code or generated binaries, and is around 550M.

Once the Docker image is created, you can create an archive of the image to transfer to different systems to run. The following will save the container a compressed tar archive file:

On the build system:

docker save blender-custom | gzip > blender-custom.tgz

You can then copy that container from the buidl system to the target system, which is the virtual machine (VM) configured while following the Intel Iris Xe MAX Graphics guide:

On the build system:

scp -P 10022 blender-custom.tgz localhost:.

To import the compressed container on that system, connect to the target system using ssh.

On the build system:

ssh -p 10022 localhost

Within that ssh session on the target system, install the blender-custom docker image:

gunzip -c blender-custom.tgz | docker load

At the end of the docker load, the target system will have the ‘blender-custom:latest’ image available. You can then run the image on that system as if it had been built there.

Running

Prior to running the Docker container, create the volume mount directories which will be used to store scenes, rendered output, and caching of compiled Computing Language (CL) kernels.

On the target system:

for dir in output cache blends; do
  mkdir ${HOME}/${dir}
  chmod a+rwX ${HOME}/${dir}
done

Render the BMW

In order to use the GPU to render via batch mode the OPENCL device needs to be activated. The Python script ‘set_device_gpu.py’ does that below. You need to run the Python script after you specify the scene to render for it to take effect.

The rendered output will be saved in ‘${HOME}/blends’ (which is mounted to /home/user/blends inside the container.)

The blender container will use only the GPU passed to it to render via the ‘set_device_gpu.py’ script. The output from the render will be placed into the ‘output’ directory.

On the target system:

wget https://download.blender.org/demo/test/BMW27_2.blend.zip
unzip -d blends BMW27_2.blend.zip
chmod -R a+rwX blends
docker run \
  --group-add=$(stat -c '%g' /dev/dri/renderD128) \
  --device=/dev/dri \
  -v ${HOME}/blends:/home/user/blends \
  -v ${HOME}/output:/home/user/output \
  -v ${HOME}/cache:/home/user/.cache \
  -it blender-custom \
  blender -b -E CYCLES \
    -noaudio \
    /home/user/blends/bmw27/bmw27_gpu.blend  \
    -P set_device_gpu.py \
    -o /home/user/output/bmw- -f 0

The above command will launch the container in interactive mode (so you can terminate it via CTRL-C if you want) and render the BMW scene, saving the output into the ‘${HOME}/blends/bmw-0000.png’ file’

The volume mounts for .cache will allow successive runs of the container to use cached CL kernels and intermediate files.

Access Blender through VNC

The following will launch the blender-custom container, providing GPU access and passing in port 5920, which you can then use to a VNC server running in the container. Once you connect to VNC, if you navigate to the Cycles Render Devices settings under Edit > Prefrences > System > OpenCL, you should see the Intel Iris Xe MAX graphics adapter listed as device 0x4905.

Blender in VNC

On the target system:

docker run \
  --group-add=$(stat -c '%g' /dev/dri/renderD128) \
  --device=/dev/dri \
  -p 5920:5920 \
  -v ${HOME}/blends:/home/user/blends \
  -v ${HOME}/output:/home/user/output \
  -v ${HOME}/cache:/home/user/.cache \
  -it blender-custom \
  vnc blender

Run your own command-line batch render

On the target system:

docker run \
  --group-add=$(stat -c '%g' /dev/dri/renderD128) \
  --device=/dev/dri \
  -p 5920:5920 \
  -v ${HOME}/blends:/home/user/blends \
  -v ${HOME}/output:/home/user/output \
  -v ${HOME}/cache:/home/user/.cache \
  -it blender-custom \
  /bin/bash

To explore the container

You can use /bin/bash to explore the container:

On the target system:

docker run \
  --group-add=$(stat -c '%g' /dev/dri/renderD128) \
  --device=/dev/dri \
  -v ${HOME}/blends:/home/user/blends \
  -v ${HOME}/output:/home/user/output \
  -v ${HOME}/cache:/home/user/.cache \
  -it blender-custom \
  /bin/bash

You can then run blender in batch mode, for example:

blender -b \
  -noaudio \
  -E CYCLES \
  -P set_device_gpu.py \
  -o ~/output/ -f 1

Troubleshooting

Is Blender dying while rendering? You might be running out of memory. This typically occurs while compiling the CL kernels, which can be very memory intensive.

To see if that’s what happened, check your kernel log:

dmesg | grep "Out of memory"

If you see entries about blender being killed, check the size of your swap file, and increase if it is less than 8G (or if you don’t have one.)

sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1G count=8 &&
sudo mkswap /swapfile &&
sudo swapon -a

Transfer blender from container to bare metal

The following will create the directory ‘blender-overlay’ in your home directory and setup your system to run blender from there:

Copy custom blender out of container

mkdir blender-overlay
cat << EOF | docker run -u $(id -u) -v ${HOME}/blender-overlay:/dst --rm -i blender-custom /bin/bash
mkdir /dst/opt
cp -a /opt/lib /dst/opt/lib
cp -a /home/user/blender /dst/bin
cp -a /home/user/*.py /dst/
mkdir -p /dst/etc/ld.so.conf.d
find /opt/lib -type d -name lib > /dst/etc/ld.so.conf.d/blender.conf
EOF

Copy the results into your root file system

sudo ln -s ${HOME}/blender-overlay/opt/lib /opt/lib
sudo cp ${HOME}/blender-overlay/etc/ld.so.conf.d/blender.conf \
  /etc/ld.so.conf.d/
sudo ldconfig

Install blender dependencies using package manager

sudo apt-get install -y blender libpotrace0

OPTIONAL: Remove blender itself apt-get remove blender

Point /usr/bin/blender at custom install

if [ -e /usr/bin/blender ]; then sudo mv /usr/bin/blender /usr/bin/blender.bk; fi
sudo ln -s ${HOME}/blender-overlay/bin/blender /usr/bin/blender

Enable CYCLES to use ALL OpenCL devices

echo "export CYCLES_OPENCL_TEST=all" >> ~/.bashrc
export CYCLES_OPENCL_TEST=all

Test

blender -v

Render a scene

blender -b -E CYCLES \
  ${HOME}/blends/bmw27/bmw27_gpu.blend  \
  -P ${HOME}/blender-overlay/set_device_gpu.py \
  -o ${HOME}/output/bmw- -f 0

Feedback on this page?

If you have feedback on this page, please visit the community documentation project project on GitHub and file an issue.