Skip to content

Commit 106632e

Browse files
MatX Containers (#892)
* initial commit with a standalone docker for production and a devcontainer
1 parent a0fc788 commit 106632e

File tree

10 files changed

+517
-1
lines changed

10 files changed

+517
-1
lines changed

.devcontainer/dev.Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use the base image
2+
FROM ghcr.io/nvidia/matx/production:latest
3+
4+
ARG REMOTE_USER
5+
ARG REMOTE_UID
6+
ARG REMOTE_GID
7+
8+
# Create the user
9+
RUN groupadd --gid $REMOTE_GID $REMOTE_USER \
10+
&& useradd --uid $REMOTE_UID --gid $REMOTE_GID -m $REMOTE_USER \
11+
#
12+
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
13+
&& apt-get update \
14+
&& apt-get install -y sudo \
15+
&& echo $REMOTE_USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$REMOTE_USER \
16+
&& chmod 0440 /etc/sudoers.d/$REMOTE_USER
17+
18+
# Set user
19+
USER $REMOTE_USER
20+
21+
# Copy all files in the current folder to the container
22+
COPY --chown=$REMOTE_USER:$REMOTE_USER . /workspaces/MatX
23+
24+
# Set the working directory
25+
WORKDIR /workspaces/MatX

.devcontainer/devcontainer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
3+
{
4+
"name": "MatX Development Container",
5+
"build": {
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
// Update the 'dockerFile' property to correct location of production Dockerfile
9+
"dockerfile": "./dev.Dockerfile",
10+
"args": {
11+
"REMOTE_USER": "${localEnv:USER}",
12+
"REMOTE_UID": "${localEnv:REMOTE_UID:1000}",
13+
"REMOTE_GID": "${localEnv:REMOTE_GID:1000}"
14+
}
15+
},
16+
"privileged": true,
17+
"capAdd": [
18+
"SYS_NICE",
19+
"SYS_PTRACE"
20+
],
21+
"hostRequirements": {
22+
"gpu": "optional"
23+
},
24+
"securityOpt": [
25+
"seccomp=unconfined"
26+
],
27+
// Features to add to the dev container. More info: https://containers.dev/features.
28+
// "features": {},
29+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
30+
"forwardPorts": [
31+
3000,
32+
8888,
33+
6006
34+
],
35+
// Uncomment the next line to run commands after the container is created.
36+
// "postCreateCommand": "cat /etc/os-release",
37+
"runArgs": [
38+
"--ipc=host",
39+
"--gpus=all",
40+
"--entrypoint",
41+
"fixuid"
42+
],
43+
// Configure tool-specific properties.
44+
"customizations": {
45+
"vscode": {
46+
"extensions": [
47+
"ms-python.python",
48+
"ms-toolsai.jupyter",
49+
"eamodio.gitlens",
50+
"ms-vscode.cpptools",
51+
"ms-vscode.cmake-tools"
52+
]
53+
}
54+
}
55+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
56+
// "remoteUser": "${localEnv:USER}"
57+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.vscode
22
.cache
3-
build*
3+
build
44
*.pyc

docker/dli_lab/build_lab.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cp ../../docs_input/notebooks/gtc_lab/run_matx.py ./
2+
docker build -f lab.Dockerfile -t ghcr.io/nvidia/matx/lab:latest .
3+
rm run_matx.py

docker/dli_lab/lab.Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM ghcr.io/nvidia/matx/production:latest AS devel
2+
3+
4+
5+
# Prevent interactive prompts during package installation
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
8+
# Install system dependencies
9+
RUN apt-get update && apt-get install -y \
10+
build-essential \
11+
cmake \
12+
git \
13+
python3 \
14+
python3-pip \
15+
python3-dev \
16+
python3-venv \
17+
nodejs \
18+
npm \
19+
libpugixml-dev \
20+
lsb-release \
21+
wget \
22+
software-properties-common \
23+
gnupg \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Create and activate virtual environment
27+
RUN python3 -m venv /opt/venv
28+
ENV PATH="/opt/venv/bin:$PATH"
29+
30+
RUN mkdir /root/.ipython/profile_default
31+
RUN mkdir /root/.ipython/extensions
32+
RUN echo c.InteractiveShellApp.extensions = ['run_matx'] >> /root/.ipython/profile_default/ipython_config.py
33+
RUN cp ./run_matx.py /root/.ipython/extensions/
34+
35+
# Install Python packages
36+
RUN pip3 install --no-cache-dir \
37+
jupyter \
38+
jupyterlab \
39+
cmake \
40+
nlohmann-json==3.11.2 \
41+
xtl \
42+
pugixml
43+
44+
RUN pip install bash_kernel
45+
RUN python -m bash_kernel.install
46+
47+
# Create jupyter config directory
48+
RUN mkdir -p ~/.jupyter
49+
50+
# Expose Jupyter port
51+
EXPOSE 8888
52+
53+
# Set working directory for Jupyter
54+
WORKDIR /notebooks
55+
56+
# Start Jupyter Lab
57+
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]

docker/production/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# MatX Container Generation and Usage scripts
2+
3+
## Steps for running a Matx container
4+
5+
1. Run the run_matx.sh script, optionally specifying a version tag
6+
7+
`./run_matx.sh # defaults to latest tag in setup.sh`
8+
9+
or
10+
11+
`MATX_VERSION_TAG="12.6.314_ubuntu22.04" ./run_matx.sh`
12+
13+
Note: architecture (`-amd64` or `-arm64`) is automatically added to the tag by the scripts
14+
15+
16+
## Steps for building a new 'build' container
17+
18+
1. Make your changes to the container recipe
19+
20+
2. Build the container
21+
22+
`MATX_VERSION_TAG="someNewTag" create_build_container.sh`
23+
24+
The MATX_VERSION_TAG must be different than the current value in setup.sh, to avoid accidentally overwriting the working container.
25+
Example: MATX_VERSION_TAG="12.6.314_ubuntu22.04"
26+
27+
Note: architecture (`-amd64` or `-arm64`) is automatically added to the tag by the scripts
28+
29+
3. Test the container
30+
31+
4. Retag the container as latest and push it
32+
33+
Exercise left to the reader, to prevent accidentally pushing the latest tag.
34+
We should have a CICD step that does this...
35+
36+
5. Modify setup.sh to update the MATX_VERSION_TAG and commit your updates to setup.sh and recipe.py
37+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Switch to SCRIPT_DIR directory
3+
SCRIPT=$(readlink -f $0)
4+
SCRIPT_DIR=$(dirname $SCRIPT)
5+
echo $SCRIPT starting...
6+
cd $SCRIPT_DIR
7+
8+
9+
if [ ! -v MATX_VERSION_TAG ]; then
10+
MATX_VERSION=$(git describe --tags "$(git rev-list --tags --max-count=1)")
11+
MATX_VERSION_TAG="${MATX_VERSION}_ubuntu22.04"
12+
fi
13+
14+
if [ ! -v MATX_REPO ]; then
15+
MATX_REPO=" ghcr.io/nvidia/matx/"
16+
fi
17+
18+
if [ ! -v MATX_IMAGE_NAME ]; then
19+
MATX_IMAGE_NAME="production"
20+
fi
21+
22+
if [ -z "$MATX_PLATFORM" ]; then
23+
case "$(arch)" in
24+
"x86_64")
25+
MATX_PLATFORM="linux/amd64"
26+
;;
27+
"aarch64")
28+
MATX_PLATFORM="linux/arm64"
29+
;;
30+
*)
31+
echo "Unsupported arch type"
32+
exit 1
33+
;;
34+
esac
35+
fi
36+
37+
# add the architecture name to the tag
38+
TARGETARCH=$(basename $MATX_PLATFORM)
39+
case "$TARGETARCH" in
40+
"amd64")
41+
CPU_TARGET=x86_64
42+
;;
43+
"arm64")
44+
CPU_TARGET=aarch64
45+
;;
46+
*)
47+
echo "Unsupported target architecture"
48+
exit 1
49+
;;
50+
esac
51+
# create the Dockerfile
52+
hpccm --recipe matx-production.py --cpu-target $CPU_TARGET --format docker > production.Dockerfile
53+
54+
# build the container
55+
DOCKER_BUILDKIT=1 docker build -f production.Dockerfile --platform $MATX_PLATFORM -t $MATX_REPO$MATX_IMAGE_NAME:$MATX_VERSION_TAG-$TARGETARCH .
56+
57+
58+
docker tag $MATX_REPO$MATX_IMAGE_NAME:$MATX_VERSION_TAG-$TARGETARCH ghcr.io/nvidia/matx/production:latest
59+
60+
# push the container to the repository
61+
# docker push $MATX_REPO$MATX_IMAGE_NAME:$MATX_VERSION_TAG-$TARGETARCH
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
3+
import hpccm
4+
from hpccm.building_blocks import gnu, mlnx_ofed, nvshmem, cmake
5+
from hpccm.primitives import baseimage
6+
7+
DOXYGEN_VER = "1.9.6"
8+
GDRCOPY_HOME = "/usr/local/gdrcopy"
9+
PYBIND11_VER = "2.7.1"
10+
FFTW_VER="3.3.10"
11+
OPENBLAS_VER="0.3.27"
12+
BLIS_VER="1.0"
13+
14+
if cpu_target == 'x86_64':
15+
TARGETARCH='amd64'
16+
elif cpu_target == 'aarch64':
17+
TARGETARCH='arm64'
18+
else:
19+
raise RuntimeError("Unsupported platform")
20+
21+
Stage0 = hpccm.Stage()
22+
Stage0 += baseimage(image='nvidia/cuda:12.6.2-devel-ubuntu22.04', _as='devel', _distro="ubuntu22")
23+
24+
Stage0 += packages(ospackages=[
25+
'bison',
26+
'clang-tidy',
27+
'curl',
28+
'flex',
29+
'ghostscript',
30+
'git',
31+
'libjs-mathjax',
32+
'liblapacke-dev',
33+
'libopenblas64-openmp-dev',
34+
'lcov',
35+
'ninja-build',
36+
'numactl',
37+
'python3-pip',
38+
'python3-dev',
39+
'sudo',
40+
'texlive-font-utils',
41+
'valgrind',
42+
'vim',
43+
])
44+
45+
#Stage0 += shell(commands=["mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.old"])
46+
Stage0 += pip(pip="pip3", upgrade=True, packages=[
47+
'breathe',
48+
'cupy-cuda12x',
49+
'hpccm',
50+
'numpy',
51+
'pandas',
52+
'plotly==5.2.1',
53+
'pybind11',
54+
'scipy',
55+
'sphinx',
56+
'sphinx_book_theme',
57+
'sphinx-rtd-theme',
58+
])
59+
60+
Stage0 += gnu()
61+
Stage0 += cmake(eula=True, version="3.26.4")
62+
Stage0 += nsight_compute(eula=True)
63+
Stage0 += nsight_systems()
64+
65+
Stage0 += shell(commands=["wget https://doxygen.nl/files/doxygen-{}.src.tar.gz".format(DOXYGEN_VER),
66+
"tar -zxf doxygen-{}.src.tar.gz".format(DOXYGEN_VER),
67+
"cd doxygen-{} && mkdir build && cd build && cmake .. && make -j && make install".format(DOXYGEN_VER)])
68+
Stage0 += shell(commands=["python3 --version"])
69+
70+
Stage0 += shell(commands=[f"wget https://www.fftw.org/fftw-{FFTW_VER}.tar.gz && tar -xzf fftw-{FFTW_VER}.tar.gz",
71+
f"cd fftw-{FFTW_VER} && ./configure --enable-sse2 --enable-avx2 --enable-shared --enable-avx512 --enable-openmp --enable-float && make && make install",
72+
"./configure --enable-sse2 --enable-avx2 --enable-avx512 --enable-openmp && make && sudo make install"])
73+
74+
# Stage0 += shell(commands=[f"cd /tmp && wget https://github.com/OpenMathLib/OpenBLAS/releases/download/v{OPENBLAS_VER}/OpenBLAS-{OPENBLAS_VER}.tar.gz && tar -zxvf OpenBLAS-{OPENBLAS_VER}.tar.gz && cd OpenBLAS-{OPENBLAS_VER}",
75+
# "make -j && sudo make USE_OPENMP=1 INTERFACE64=1 install"])
76+
77+
Stage0 += shell(commands=["curl -L https://coveralls.io/coveralls-linux.tar.gz | tar -xz -C /usr/local/bin"])
78+
79+
Stage0 += shell(commands=[f"cd /tmp && wget https://github.com/flame/blis/archive/refs/tags/{BLIS_VER}.tar.gz && tar -zxvf {BLIS_VER}.tar.gz && cd blis-{BLIS_VER}",
80+
"./configure --enable-threading=openmp --enable-cblas -b 64 auto && sudo make -j install"])
81+
82+
83+
# # Install fixuid
84+
# Stage0 += shell(commands=[
85+
# 'addgroup --gid 1000 matx',
86+
# 'adduser --uid 1000 --ingroup matx --home /home/matx --shell /bin/sh --disabled-password --gecos "" matx',
87+
# 'USER=matx',
88+
# 'GROUP=matx',
89+
# f'curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.5/fixuid-0.5-linux-{TARGETARCH}.tar.gz | tar -C /usr/local/bin -xzf -',
90+
# 'chown root:root /usr/local/bin/fixuid',
91+
# 'chmod 4755 /usr/local/bin/fixuid',
92+
# 'mkdir -p /etc/fixuid',
93+
# 'printf "user: $USER\\ngroup: $GROUP\\n" > /etc/fixuid/config.yml',
94+
# '/bin/echo "matx ALL = (root) NOPASSWD: ALL" >> /etc/sudoers',
95+
# ])
96+
97+
print(Stage0)

0 commit comments

Comments
 (0)