Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a GPU-accelerated GUI demo kernel using FreeCAD #124

Merged
merged 11 commits into from
Mar 17, 2020
15 changes: 11 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def print_header(s):
click.secho(s, fg='yellow', bold=True)


def build_kernel(name, tag, extra_opts='', *, squash=False):
def build_kernel(name, tag, extra_opts='', *, squash=False, testing=False):
assert Path(name).is_dir()

sq = '--squash' if squash else ''
Expand All @@ -44,11 +44,15 @@ def build_kernel(name, tag, extra_opts='', *, squash=False):
'the new kernelspec.',
fg='yellow', err=True)
return
if testing:
img_ref = f'beta.docker.backend.ai/testing/{short_name}:{tag}'
else:
img_ref = f'lablup/{short_name}:{tag}'
run('docker build '
f'-t lablup/{short_name}:{tag} {extra_opts} '
f'-t {img_ref} {extra_opts} '
f'-f {dockerfile} {sq} {name}')
if auto_push.get():
run(f'docker push lablup/{short_name}:{tag}')
run(f'docker push {img_ref}')


def build_common(name, tag, extra_opts=''):
Expand All @@ -74,7 +78,7 @@ def build_common(name, tag, extra_opts=''):
'tf-old', 'tf-current', 'tf-future',
'caffe', 'pytorch',
'cntk-builder','cntk',
'vendor-aws', 'vendor-ngc',
'vendor-aws', 'vendor-ngc', 'vendor-freecad',
]


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

if 'vendor-freecad' in build:
build_kernel('vendor/freecad', '0.18-glvnd1.1')

if 'vendor-ngc' in build:
build_kernel('vendor/ngc-caffe2', '18.08-py2')
build_kernel('vendor/ngc-caffe3', '18.08-py3')
Expand Down
6 changes: 6 additions & 0 deletions vendor/freecad/10_nvidia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"file_format_version" : "1.0.0",
"ICD" : {
"library_path" : "libEGL_nvidia.so.0"
}
}
109 changes: 109 additions & 0 deletions vendor/freecad/Dockerfile.0.18-glvnd1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# ------------- libglvnd build stage -------------
FROM ubuntu:16.04 as glvnd

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ca-certificates \
make \
automake \
autoconf \
libtool \
pkg-config \
python \
libxext-dev \
libx11-dev \
x11proto-gl-dev && \
rm -rf /var/lib/apt/lists/*

ARG LIBGLVND_VERSION=v1.1.0

WORKDIR /opt/libglvnd
RUN git clone --branch="${LIBGLVND_VERSION}" https://github.com/NVIDIA/libglvnd.git . && \
./autogen.sh && \
./configure --prefix=/usr/local --libdir=/usr/local/lib/x86_64-linux-gnu && \
make -j"$(nproc)" install-strip && \
find /usr/local/lib/x86_64-linux-gnu -type f -name 'lib*.la' -delete

RUN dpkg --add-architecture i386 && \
apt-get update && apt-get install -y --no-install-recommends \
gcc-multilib \
libxext-dev:i386 \
libx11-dev:i386 && \
rm -rf /var/lib/apt/lists/*

# 32-bit libraries
RUN make distclean && \
./autogen.sh && \
./configure --prefix=/usr/local --libdir=/usr/local/lib/i386-linux-gnu --host=i386-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32" && \
make -j"$(nproc)" install-strip && \
find /usr/local/lib/i386-linux-gnu -type f -name 'lib*.la' -delete


# ------------ FreeCAD main image ---------------
# Note: FreeCAD image is based on Ubuntu 16.04 (Xenial)
FROM izone/freecad:latest

ENV PYTHONUNBUFFERED=1 \
LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64" \
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" \
LANG=C.UTF-8

# Install noVNC
ENV NOVNC=/opt/noVNC
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
apt-utils \
libx11-6 \
libxext6 \
libxt6 \
libnss3 \
libglu1-mesa \
libosmesa6 \
net-tools \
git \
xterm \
vnc4server \
xfce4 \
ca-certificates \
sudo \
&& apt-get remove -y \
tumbler \
pulseaudio \
gvfs \
&& apt-get clean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*
RUN git clone --depth 1 --branch v1.0.0 https://github.com/novnc/noVNC.git "${NOVNC}" && \
git clone --depth 1 --branch v0.8.0 https://github.com/novnc/websockify.git "${NOVNC}/utils/websockify" && \
find "${NOVNC}" -name ".git*" | xargs rm -rf && \
ln -s "${NOVNC}/vnc.html" "${NOVNC}/index.html"

# Install OpenGL support
COPY --from=glvnd /usr/local/lib/x86_64-linux-gnu /usr/local/lib/x86_64-linux-gnu
COPY --from=glvnd /usr/local/lib/i386-linux-gnu /usr/local/lib/i386-linux-gnu
COPY 10_nvidia.json /usr/local/share/glvnd/egl_vendor.d/10_nvidia.json
RUN echo '/usr/local/lib/x86_64-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
echo '/usr/local/lib/i386-linux-gnu' >> /etc/ld.so.conf.d/glvnd.conf && \
ldconfig
ENV LD_LIBRARY_PATH /usr/local/lib/x86_64-linux-gnu:/usr/local/lib/i386-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# Backend.AI specifics
USER root
COPY policy.yml /etc/backend.ai/jail/policy.yml
COPY ./service-defs /etc/backend.ai/service-defs
LABEL ai.backend.kernelspec="1" \
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
ai.backend.features="uid-match" \
ai.backend.accelerators="cuda" \
ai.backend.resource.min.cpu="1" \
ai.backend.resource.min.mem="1g" \
ai.backend.resource.min.cuda.device=1 \
ai.backend.resource.min.cuda.shares=0.1 \
ai.backend.base-distro="ubuntu16.04" \
ai.backend.runtime-type="app" \
ai.backend.service-ports="vnc-web:http:6080"

COPY bootstrap.sh /opt/container/bootstrap.sh

WORKDIR /home/work
# vim: ft=dockerfile
65 changes: 65 additions & 0 deletions vendor/freecad/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /bin/bash

echo "DEBUG DATETIME: $(date)"
echo ">> Setting up FreeCAD environment"

rm -rf /tmp/.X*

mkdir -p /home/work/Desktop
cat >/home/work/Desktop/FreeCAD.desktop <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=FreeCAD 0.16
Comment=
Exec=/opt/FreeCAD/bin/FreeCAD
Icon=/opt/FreeCAD/data/freecad-icon-64.png
Path=/home/work
Terminal=true
StartupNotify=false
EOF
chmod +x /home/work/Desktop/FreeCAD.desktop

echo ">> Starting background VNC server"
printf "backendai\nbackendai\n\n" | /opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID vncpasswd >/dev/null 2>&1

mkdir -p /home/work/.vnc
cat >/home/work/.vnc/xstartup <<EOF
#!/bin/sh

xhost +

# SESSION_MANAGER is inherited from the environment and some window
# managers require that it be cleared.
# http://osdir.com/ml/gnome.ximian.snapshots/2002-09/msg00034.html
# For example, Xfce4 version 4.6.1 and Deb5-64 require the unsetenv.
# Goolging indicates that others also require the unsetenv.
unsetenv SESSION_MANAGER

# Startup scripts, e.g. /etc/xdg/xfce4/xinitrc require
# http://en.wikipedia.org/wiki/D-Bus to run correctly.
unsetenv DBUS_SESSION_BUS_ADDRESS


# Set VNCSESSION to tell /etc/xdg/xfce4/xinitrc to not run xscreensaver
# http://vstone.eu/2009/04/disabling-xscreensaver-when-using-xfce-vnc/
setenv VNCSESSION yes

startxfce4 &

# Make sure that copy / paste are correctly forwarded to the VNC viewer
vncconfig -nowin &
EOF
chmod +x /home/work/.vnc/xstartup

cat >/home/work/.xscreensaver <<EOF
mode: off
EOF

chown -R $LOCAL_USER_ID:$LOCAL_GROUP_ID /home/work
/opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID /usr/bin/vncserver -geometry 1600x1200

echo ">> VNC server is started."

# The next line is executed by the kernel runner's service port handler.
# "$SUEXEC" /opt/noVNC/utils/launch.sh --listen 6080 --vnc localhost:5901 > /dev/null 2>&1 &
27 changes: 27 additions & 0 deletions vendor/freecad/policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
whitelist_paths:
OP_OPEN: ["*"]
OP_ACCESS: ["*"]
OP_EXEC: ["*"]
OP_STAT: ["*"]
OP_CHMOD: ["/home/work/*", "/tmp/*"]
exec_allowance: -1
fork_allowance: -1
max_child_procs: 256
extra_envs: []
preserved_env_keys: [
"HOME", "PATH", "LANG",
"PYENV_ROOT", "PYTHONPATH",
"PYTHONUNBUFFERED",
"MPLCONFIGDIR",
"OPENBLAS_NUM_THREADS",
"OMP_NUM_THREADS",
"NPROC",
"LD_LIBRARY_PATH",
"LD_PRELOAD",
]

diff_to_default: true

# Following syscalls are blindly allowed.
# IMPORTANT: ptrace MUST NOT be included!
allowed_syscalls:
8 changes: 8 additions & 0 deletions vendor/freecad/service-defs/vnc-web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": [
"/opt/noVNC/utils/launch.sh",
"--vnc", "localhost:5901",
"--listen", "{ports[0]}"
],
"url_template": "{protocol}://{host}:{port}/vnc.html?host={host}&port={port}&password=backendai&autoconnect=true"
}
6 changes: 3 additions & 3 deletions vendor/ngc-matlab/Dockerfile.r2019b
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ ENV PYTHONUNBUFFERED=1 \
USER root

COPY policy.yml /etc/backend.ai/jail/policy.yml
COPY ./service-defs /etc/backend.ai/service-defs
LABEL ai.backend.kernelspec="1" \
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
ai.backend.features="batch uid-match" \
ai.backend.features="uid-match" \
ai.backend.accelerators="cuda" \
ai.backend.resource.min.cpu="1" \
ai.backend.resource.min.mem="1g" \
ai.backend.resource.preferred.shmem="512m" \
ai.backend.resource.min.cuda.device=1 \
ai.backend.resource.min.cuda.shares=0.1 \
ai.backend.base-distro="ubuntu16.04" \
ai.backend.runtime-type="vendor.ngc_matlab" \
ai.backend.runtime-path="/usr/bin/python" \
ai.backend.runtime-type="app" \
ai.backend.service-ports="vnc-web:http:6080"

COPY bootstrap.sh /opt/container/bootstrap.sh
Expand Down
8 changes: 8 additions & 0 deletions vendor/ngc-matlab/service-defs/vnc-web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": [
"/opt/noVNC/utils/launch.sh",
"--vnc", "localhost:5901",
"--listen", "{ports[0]}"
],
"url_template": "{protocol}://{host}:{port}/vnc.html?host={host}&port={port}&password=backendai&autoconnect=true"
}