Donating computing power to Science: How to run containerized BOINC with OpenCL and VirtualBox

Containerized, hardware accelerated, and virtualized!

Don’t you want to do something more useful with your silicon and electricity than producing low entropy outputs of hash functions?

There is a way. From Wikipedia:

The Berkeley Open Infrastructure for Network Computing (BOINC, pronounced /bɔɪŋk/ – rhymes with “oink”) is an open-source middleware system for volunteer computing and grid computing.

From the official BOINC website:

BOINC lets you help cutting-edge science research using your computer. The BOINC app, running on your computer, downloads scientific computing jobs and runs them invisibly in the background. It’s easy and safe.

Needless to say, the security conscientious among us will raise one or even two eyebrows when they read that some maybe non-Open Source binary blobs are automatically downloaded from somewhere in the internet and then executed on your machine. But not to worry! One of the purposes of containers was exactly to solve that; to isolate software. Again from Wikipedia:

OS-level virtualization is an operating system paradigm in which the kernel allows the existence of multiple isolated user space instances. Such instances, called containers […] may look like real computers from the point of view of programs running in them. A computer program running on an ordinary operating system can see all resources (connected devices, files and folders, network shares, CPU power, quantifiable hardware capabilities) of that computer. However, programs running inside of a container can only see the container’s contents and devices assigned to the container.

So I set out to develop a Docker Container image which allows running BOINC with full hardware power (GPU computing via OpenCL, virtualization via VirtualBox), but in complete isolation of the host system.

For AMD GPUs, this was a bit more straightforward than for NVIDIA GPUs.

For AMD GPUs, I just published this small but sweet Dockerfile project on Github which sets up a minimal image with software only from the official Debian repository. See https://github.com/michaelfranzl/container-boinc

For NVIDIA, the host system needs additional software from non-Debian repositories to be able to ‘forward’ the GPU into containers. This will be the topic of a future blog post.

Meanwhile, happy number crunching!

How to install FOSS OpenCL for AMD GPU on Debian 11 (Bullseye)

It is very easy to set up free-and-open-source OpenCL computing support if you have an AMD GPU and Debian 11:

apt install ocl-icd-libopencl1 mesa-opencl-icd

Then use clinfo (from the package clinfo) to display information about your platform.

You can now use /dev/dri and the files in /etc/OpenCL to run OpenCL applications.

(Many thanks to the author of this blog post.)

“Failed to suspend system. System resumed again: No space left on device”: How to increase swap by taking the space from a different logical volume

The automatic installer of my current Debian 11 installation chose to use only 1 GB of swap for some reason, which is far too little to receive the entire RAM contents for hibernation. Because of this, I got the error message “Failed to suspend system. System resumed again: No space left on device” in my syslog. But, because all space of the physical storage was already used up by several logical volumes, I needed to ‘steal’ some space from the home LV, which was 200GB.

Doing so is quite easy. The following example steps, ran in the ‘rescue mode’ of Debian, will give 50 GB from the home LV to swap space.

# Activate all logical volumes (makes them available in the /dev/VGname/LVname)
vgchange -a y

# Un-mount the /home directory. For this to succeed, all programs are not allowed to have open files there. This may require some kind of 'rescue' environment of your OS.
umount /home

# Check that the file system is in order, so that it is safe to shrink it in the next step.
e2fsck -fy /dev/vgname/home

# Shrink the file system to a size a bit smaller than the target size. There are only 20 GB of data. The partition is 200 GB.
resize2fs /dev/vgname/home 140G

# Reduce the logical volume to the target size of 150 GB. This is likely to lose data if the file system is larger than the target size. Please double check your numbers; lvreduce will ask you the same thing and then ask for a confirmation.
lvreduce -L 150G /dev/vgname/home

# Expand the file system to auto-fit exactly into the logical volume (grows from 140G to 150G)
resize2fs /dev/vgname/home

# Now there is some space left on the physical device. Next, expand the swap space to use the freshly made available space.
swapoff -a
lvextend -L 40G /dev/vgname/swap_1
mkswap /dev/vgname/swap_1
swapon -a

This blog post is based on https://www.rootusers.com/lvm-resize-how-to-decrease-an-lvm-partition/