Skip to content

Commit 26cec7e

Browse files
authored
Add a GPU-accelerated GUI demo kernel using FreeCAD (#124)
* vendor/freecad: Add the FreeCAD image recipe (0.18, based on libglvnd by NVIDIA) * builder: Make it easier to use our beta docker registry * Use latest app-only base krunner (applied since Backend.AI Agent v20.03+) * ngc-matlab: Migrate to use "app" krunner and the service-port template
1 parent d15ab3b commit 26cec7e

File tree

8 files changed

+237
-7
lines changed

8 files changed

+237
-7
lines changed

build.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def print_header(s):
2222
click.secho(s, fg='yellow', bold=True)
2323

2424

25-
def build_kernel(name, tag, extra_opts='', *, squash=False):
25+
def build_kernel(name, tag, extra_opts='', *, squash=False, testing=False):
2626
assert Path(name).is_dir()
2727

2828
sq = '--squash' if squash else ''
@@ -44,11 +44,15 @@ def build_kernel(name, tag, extra_opts='', *, squash=False):
4444
'the new kernelspec.',
4545
fg='yellow', err=True)
4646
return
47+
if testing:
48+
img_ref = f'beta.docker.backend.ai/testing/{short_name}:{tag}'
49+
else:
50+
img_ref = f'lablup/{short_name}:{tag}'
4751
run('docker build '
48-
f'-t lablup/{short_name}:{tag} {extra_opts} '
52+
f'-t {img_ref} {extra_opts} '
4953
f'-f {dockerfile} {sq} {name}')
5054
if auto_push.get():
51-
run(f'docker push lablup/{short_name}:{tag}')
55+
run(f'docker push {img_ref}')
5256

5357

5458
def build_common(name, tag, extra_opts=''):
@@ -74,7 +78,7 @@ def build_common(name, tag, extra_opts=''):
7478
'tf-old', 'tf-current', 'tf-future',
7579
'caffe', 'pytorch',
7680
'cntk-builder','cntk',
77-
'vendor-aws', 'vendor-ngc',
81+
'vendor-aws', 'vendor-ngc', 'vendor-freecad',
7882
]
7983

8084

@@ -338,6 +342,9 @@ def main(build, list_builds, _auto_push):
338342
if 'vendor-aws' in build:
339343
build_kernel('vendor/aws_polly', '0.1-alpine3.8')
340344

345+
if 'vendor-freecad' in build:
346+
build_kernel('vendor/freecad', '0.18-glvnd1.1')
347+
341348
if 'vendor-ngc' in build:
342349
build_kernel('vendor/ngc-caffe2', '18.08-py2')
343350
build_kernel('vendor/ngc-caffe3', '18.08-py3')

vendor/freecad/10_nvidia.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"file_format_version" : "1.0.0",
3+
"ICD" : {
4+
"library_path" : "libEGL_nvidia.so.0"
5+
}
6+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# ------------- libglvnd build stage -------------
2+
FROM ubuntu:16.04 as glvnd
3+
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
git \
6+
ca-certificates \
7+
make \
8+
automake \
9+
autoconf \
10+
libtool \
11+
pkg-config \
12+
python \
13+
libxext-dev \
14+
libx11-dev \
15+
x11proto-gl-dev && \
16+
rm -rf /var/lib/apt/lists/*
17+
18+
ARG LIBGLVND_VERSION=v1.1.0
19+
20+
WORKDIR /opt/libglvnd
21+
RUN git clone --branch="${LIBGLVND_VERSION}" https://github.com/NVIDIA/libglvnd.git . && \
22+
./autogen.sh && \
23+
./configure --prefix=/usr/local --libdir=/usr/local/lib/x86_64-linux-gnu && \
24+
make -j"$(nproc)" install-strip && \
25+
find /usr/local/lib/x86_64-linux-gnu -type f -name 'lib*.la' -delete
26+
27+
RUN dpkg --add-architecture i386 && \
28+
apt-get update && apt-get install -y --no-install-recommends \
29+
gcc-multilib \
30+
libxext-dev:i386 \
31+
libx11-dev:i386 && \
32+
rm -rf /var/lib/apt/lists/*
33+
34+
# 32-bit libraries
35+
RUN make distclean && \
36+
./autogen.sh && \
37+
./configure --prefix=/usr/local --libdir=/usr/local/lib/i386-linux-gnu --host=i386-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32" && \
38+
make -j"$(nproc)" install-strip && \
39+
find /usr/local/lib/i386-linux-gnu -type f -name 'lib*.la' -delete
40+
41+
42+
# ------------ FreeCAD main image ---------------
43+
# Note: FreeCAD image is based on Ubuntu 16.04 (Xenial)
44+
FROM izone/freecad:latest
45+
46+
ENV PYTHONUNBUFFERED=1 \
47+
LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64" \
48+
PATH="/home/work/.local/bin:/opt/FreeCAD/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
49+
LANG=C.UTF-8
50+
51+
# Install noVNC
52+
ENV NOVNC=/opt/noVNC
53+
RUN apt-get update && \
54+
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
55+
apt-utils \
56+
libx11-6 \
57+
libxext6 \
58+
libxt6 \
59+
libnss3 \
60+
libglu1-mesa \
61+
libosmesa6 \
62+
net-tools \
63+
git \
64+
xterm \
65+
vnc4server \
66+
xfce4 \
67+
ca-certificates \
68+
sudo \
69+
&& apt-get remove -y \
70+
tumbler \
71+
pulseaudio \
72+
gvfs \
73+
&& apt-get clean \
74+
&& apt-get -y autoremove \
75+
&& rm -rf /var/lib/apt/lists/*
76+
RUN git clone --depth 1 --branch v1.0.0 https://github.com/novnc/noVNC.git "${NOVNC}" && \
77+
git clone --depth 1 --branch v0.8.0 https://github.com/novnc/websockify.git "${NOVNC}/utils/websockify" && \
78+
find "${NOVNC}" -name ".git*" | xargs rm -rf && \
79+
ln -s "${NOVNC}/vnc.html" "${NOVNC}/index.html"
80+
81+
# Install OpenGL support
82+
COPY --from=glvnd /usr/local/lib/x86_64-linux-gnu /usr/local/lib/x86_64-linux-gnu
83+
COPY --from=glvnd /usr/local/lib/i386-linux-gnu /usr/local/lib/i386-linux-gnu
84+
COPY 10_nvidia.json /usr/local/share/glvnd/egl_vendor.d/10_nvidia.json
85+
RUN echo '/usr/local/lib/x86_64-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
86+
echo '/usr/local/lib/i386-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
87+
ldconfig
88+
ENV LD_LIBRARY_PATH /usr/local/lib/x86_64-linux-gnu:/usr/local/lib/i386-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
89+
90+
# Backend.AI specifics
91+
USER root
92+
COPY policy.yml /etc/backend.ai/jail/policy.yml
93+
COPY ./service-defs /etc/backend.ai/service-defs
94+
LABEL ai.backend.kernelspec="1" \
95+
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
96+
ai.backend.features="uid-match" \
97+
ai.backend.accelerators="cuda" \
98+
ai.backend.resource.min.cpu="1" \
99+
ai.backend.resource.min.mem="1g" \
100+
ai.backend.resource.min.cuda.device=1 \
101+
ai.backend.resource.min.cuda.shares=0.1 \
102+
ai.backend.base-distro="ubuntu16.04" \
103+
ai.backend.runtime-type="app" \
104+
ai.backend.service-ports="vnc-web:http:6080"
105+
106+
COPY bootstrap.sh /opt/container/bootstrap.sh
107+
108+
WORKDIR /home/work
109+
# vim: ft=dockerfile

vendor/freecad/bootstrap.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#! /bin/bash
2+
3+
echo "DEBUG DATETIME: $(date)"
4+
echo ">> Setting up FreeCAD environment"
5+
6+
rm -rf /tmp/.X*
7+
8+
mkdir -p /home/work/Desktop
9+
cat >/home/work/Desktop/FreeCAD.desktop <<EOF
10+
[Desktop Entry]
11+
Version=1.0
12+
Type=Application
13+
Name=FreeCAD 0.16
14+
Comment=
15+
Exec=/opt/FreeCAD/bin/FreeCAD
16+
Icon=/opt/FreeCAD/data/freecad-icon-64.png
17+
Path=/home/work
18+
Terminal=true
19+
StartupNotify=false
20+
EOF
21+
chmod +x /home/work/Desktop/FreeCAD.desktop
22+
23+
echo ">> Starting background VNC server"
24+
printf "backendai\nbackendai\n\n" | /opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID vncpasswd >/dev/null 2>&1
25+
26+
mkdir -p /home/work/.vnc
27+
cat >/home/work/.vnc/xstartup <<EOF
28+
#!/bin/sh
29+
30+
xhost +
31+
32+
# SESSION_MANAGER is inherited from the environment and some window
33+
# managers require that it be cleared.
34+
# http://osdir.com/ml/gnome.ximian.snapshots/2002-09/msg00034.html
35+
# For example, Xfce4 version 4.6.1 and Deb5-64 require the unsetenv.
36+
# Goolging indicates that others also require the unsetenv.
37+
unsetenv SESSION_MANAGER
38+
39+
# Startup scripts, e.g. /etc/xdg/xfce4/xinitrc require
40+
# http://en.wikipedia.org/wiki/D-Bus to run correctly.
41+
unsetenv DBUS_SESSION_BUS_ADDRESS
42+
43+
44+
# Set VNCSESSION to tell /etc/xdg/xfce4/xinitrc to not run xscreensaver
45+
# http://vstone.eu/2009/04/disabling-xscreensaver-when-using-xfce-vnc/
46+
setenv VNCSESSION yes
47+
48+
startxfce4 &
49+
50+
# Make sure that copy / paste are correctly forwarded to the VNC viewer
51+
vncconfig -nowin &
52+
EOF
53+
chmod +x /home/work/.vnc/xstartup
54+
55+
cat >/home/work/.xscreensaver <<EOF
56+
mode: off
57+
EOF
58+
59+
chown -R $LOCAL_USER_ID:$LOCAL_GROUP_ID /home/work
60+
/opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID /usr/bin/vncserver -geometry 1600x1200
61+
62+
echo ">> VNC server is started."
63+
64+
# The next line is executed by the kernel runner's service port handler.
65+
# "$SUEXEC" /opt/noVNC/utils/launch.sh --listen 6080 --vnc localhost:5901 > /dev/null 2>&1 &

vendor/freecad/policy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
whitelist_paths:
2+
OP_OPEN: ["*"]
3+
OP_ACCESS: ["*"]
4+
OP_EXEC: ["*"]
5+
OP_STAT: ["*"]
6+
OP_CHMOD: ["/home/work/*", "/tmp/*"]
7+
exec_allowance: -1
8+
fork_allowance: -1
9+
max_child_procs: 256
10+
extra_envs: []
11+
preserved_env_keys: [
12+
"HOME", "PATH", "LANG",
13+
"PYENV_ROOT", "PYTHONPATH",
14+
"PYTHONUNBUFFERED",
15+
"MPLCONFIGDIR",
16+
"OPENBLAS_NUM_THREADS",
17+
"OMP_NUM_THREADS",
18+
"NPROC",
19+
"LD_LIBRARY_PATH",
20+
"LD_PRELOAD",
21+
]
22+
23+
diff_to_default: true
24+
25+
# Following syscalls are blindly allowed.
26+
# IMPORTANT: ptrace MUST NOT be included!
27+
allowed_syscalls:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"command": [
3+
"/opt/noVNC/utils/launch.sh",
4+
"--vnc", "localhost:5901",
5+
"--listen", "{ports[0]}"
6+
],
7+
"url_template": "{protocol}://{host}:{port}/vnc.html?host={host}&port={port}&password=backendai&autoconnect=true"
8+
}

vendor/ngc-matlab/Dockerfile.r2019b

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ ENV PYTHONUNBUFFERED=1 \
99
USER root
1010

1111
COPY policy.yml /etc/backend.ai/jail/policy.yml
12+
COPY ./service-defs /etc/backend.ai/service-defs
1213
LABEL ai.backend.kernelspec="1" \
1314
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
14-
ai.backend.features="batch uid-match" \
15+
ai.backend.features="uid-match" \
1516
ai.backend.accelerators="cuda" \
1617
ai.backend.resource.min.cpu="1" \
1718
ai.backend.resource.min.mem="1g" \
1819
ai.backend.resource.preferred.shmem="512m" \
1920
ai.backend.resource.min.cuda.device=1 \
2021
ai.backend.resource.min.cuda.shares=0.1 \
2122
ai.backend.base-distro="ubuntu16.04" \
22-
ai.backend.runtime-type="vendor.ngc_matlab" \
23-
ai.backend.runtime-path="/usr/bin/python" \
23+
ai.backend.runtime-type="app" \
2424
ai.backend.service-ports="vnc-web:http:6080"
2525

2626
COPY bootstrap.sh /opt/container/bootstrap.sh
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"command": [
3+
"/opt/noVNC/utils/launch.sh",
4+
"--vnc", "localhost:5901",
5+
"--listen", "{ports[0]}"
6+
],
7+
"url_template": "{protocol}://{host}:{port}/vnc.html?host={host}&port={port}&password=backendai&autoconnect=true"
8+
}

0 commit comments

Comments
 (0)