Skip to content

Commit 8ca3df7

Browse files
committed
docker: Add free-threaded base
1 parent 454a8d0 commit 8ca3df7

File tree

6 files changed

+122
-20
lines changed

6 files changed

+122
-20
lines changed

docker/Dockerfile.amd

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@
44
##############################################################
55

66
ARG ROCM_VERSION=6.3.2
7+
ARG FROM_IMAGE=ubuntu:22.04
78

9+
# FROM_IMAGE may be specified with the nogil base to provide a Python build
10+
FROM $FROM_IMAGE AS ubuntu-base
811
FROM rocm/dev-ubuntu-22.04:${ROCM_VERSION}-complete AS sdk-base
912

13+
COPY --from=ubuntu-base /opt /opt
14+
ENV PATH="/opt/python3/bin:${PATH}"
15+
1016
ARG UCX_BRANCH="v1.16.0"
1117
ARG OMPI_BRANCH="v5.0.x"
1218

1319
# Update and Install basic Linux development tools
1420
RUN rm /etc/apt/sources.list.d/* \
1521
&& apt-get update \
1622
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
17-
dh-autoreconf python3-venv python3-dev python3-pip git \
23+
dh-autoreconf git \
1824
ca-certificates ssh make libtinfo* initramfs-tools libelf-dev \
1925
wget build-essential autoconf automake libtool \
20-
pkg-config libnuma* gfortran flex hwloc cmake
26+
pkg-config libnuma* gfortran flex hwloc cmake && \
27+
if [ ! -d "/opt/python3" ]; then \
28+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
29+
python3-venv python3-dev python3-pip; \
30+
else \
31+
echo "Using free-threaded Python build"; \
32+
fi;
2133

2234
ENV ROCM_HOME=/opt/rocm\
2335
UCX_HOME=/opt/ucx \
@@ -84,8 +96,8 @@ RUN rm -rf /tmp/ucx && rm -rf /tmp/ompi
8496
# Adding OpenMPI and UCX to Environment
8597
ENV PATH=$OMPI_HOME/bin:$UCX_HOME/bin:$PATH \
8698
LD_LIBRARY_PATH=$OMPI_HOME/lib:$UCX_HOME/lib:$LD_LIBRARY_PATH \
87-
C_INCLUDE_PATH=$OMPI_HOME/include:$UCX_HOME/include:$C_INCLUDE_PATH \
88-
CPLUS_INCLUDE_PATH=$OMPI_HOME/include:$UCX_HOME/include:$CPLUS_INCLUDE_PATH \
99+
C_INCLUDE_PATH=$OMPI_HOME/include:$UCX_HOME/include:$C_INCLUDE_PATH \
100+
CPLUS_INCLUDE_PATH=$OMPI_HOME/include:$UCX_HOME/include:$CPLUS_INCLUDE_PATH \
89101
CPATH=$OMPI_HOME/include:$UCX_HOME/include:$CPATH \
90102
INCLUDE=$OMPI_HOME/include:$UCX_HOME/include:$INCLUDE \
91103
PKG_CONFIG_PATH=$OMPI_HOME/lib/pkgconfig:$UCX_HOME/lib/pkgconfig:$PKG_CONFIG_PATH

docker/Dockerfile.cpu

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
# architectures using GCC compilers and OpenMPI.
55
##############################################################
66

7-
# Base image
8-
FROM ubuntu:22.04 AS base
9-
7+
# Base image is either ubuntu or the nogil base
8+
ARG FROM_IMAGE=ubuntu:22.04
109
ARG gcc=""
1110

11+
FROM $FROM_IMAGE AS base
12+
1213
ENV DEBIAN_FRONTEND=noninteractive
1314

14-
# Install python
15+
# Install python, if not already present
1516
RUN apt-get update && \
16-
apt-get install -y software-properties-common dh-autoreconf python3-venv python3-dev python3-pip
17+
apt-get install -y software-properties-common dh-autoreconf && \
18+
if [ ! -d "/opt/python3" ]; then \
19+
apt-get install -y -q python3-venv python3-dev python3-pip; \
20+
else \
21+
echo "Using free-threaded Python build"; \
22+
fi;
1723

1824
# Install for basic base not containing it
1925
RUN apt-get install -y wget flex libnuma-dev hwloc curl cmake git \

docker/Dockerfile.devito

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,29 @@ FROM $base AS builder
1111
ARG USER_ID=1000
1212
ARG GROUP_ID=1000
1313

14+
1415
################## Install devito ############################################
1516

1617
ENV PIP_USE_PEP517=1
17-
# Install pip dependencies
18+
19+
# If we are using a free-threaded base image, need to install libffi-dev again
20+
ARG base
21+
RUN case "$base" in *nogil) \
22+
echo "Installing libffi-dev for free-threaded build"; \
23+
apt-get update && apt-get install -y libffi-dev;; \
24+
esac;
25+
26+
# Install pip dependencies
1827
RUN python3 -m venv /venv && \
19-
/venv/bin/pip install --no-cache-dir --upgrade pip wheel setuptools && \
20-
/venv/bin/pip install --no-cache-dir jupyter && \
21-
ln -fs /app/nvtop/build/src/nvtop /venv/bin/nvtop
28+
/venv/bin/pip install --no-cache-dir --upgrade pip wheel setuptools
29+
# Jupyter cannot yet be installed with a free-threaded Python build
30+
# See https://github.com/jupyterlab/jupyterlab/issues/16915#
31+
RUN case "$base" in *nogil) \
32+
echo "Skipping jupyter installation for free-threaded build";; \
33+
*) \
34+
/venv/bin/pip install --no-cache-dir jupyter;; \
35+
esac;
36+
RUN ln -fs /app/nvtop/build/src/nvtop /venv/bin/nvtop
2237

2338
# Copy Devito
2439
ADD . /app/devito

docker/Dockerfile.intel

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
##############################################################
55

66
# Base image
7-
FROM ubuntu:22.04 as base
7+
ARG FROM_IMAGE=ubuntu:22.04
8+
FROM $FROM_IMAGE as base
89

910
ENV DEBIAN_FRONTEND noninteractive
1011

11-
# Install python
12+
# Install python, if not already present
1213
RUN apt-get update && \
13-
apt-get install -y dh-autoreconf python3-venv python3-dev python3-pip
14+
apt-get install -y dh-autoreconf && \
15+
if [ ! -d "/opt/python3" ]; then \
16+
apt-get install -y -q python3-venv python3-dev python3-pip; \
17+
else \
18+
echo "Using free-threaded Python build"; \
19+
fi;
1420

1521
# Install for basic base not containing it
1622
RUN apt-get install -y wget flex libnuma-dev hwloc curl cmake \

docker/Dockerfile.nogil

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# syntax=docker/dockerfile:1
2+
##############################################################
3+
# This Dockerfile builds a base image with a free-threaded
4+
# build of Python 3.13.
5+
#
6+
# This is EXPERIMENTAL and intended for development and
7+
# testing purposes only.
8+
##############################################################
9+
10+
ARG FROM_IMAGE=ubuntu:22.04
11+
12+
# Builder stage: build Python 3.13 from source with the GIL disabled
13+
FROM $FROM_IMAGE AS builder
14+
15+
ARG DEBIAN_FRONTEND=noninteractive
16+
17+
# Install build dependencies for Python
18+
RUN apt-get update && apt-get install -y \
19+
build-essential \
20+
git \
21+
libffi-dev \
22+
libssl-dev \
23+
zlib1g-dev
24+
25+
# Clone CPython repository at the 3.13 branch
26+
RUN git clone --depth 1 --branch 3.13 https://github.com/python/cpython.git /usr/src/cpython
27+
28+
WORKDIR /usr/src/cpython
29+
30+
# Configure, compile, and install Python with the free-threaded build
31+
# --disable-gil: The key flag to enable the free-threaded build
32+
# --enable-optimizations: Apply profile-guided optimizations for better performance
33+
RUN ./configure --prefix=/opt/python3 --disable-gil --enable-optimizations
34+
RUN make -j$(nproc)
35+
RUN make install
36+
37+
# Base runtime stage
38+
FROM $FROM_IMAGE
39+
40+
ARG DEBIAN_FRONTEND=noninteractive
41+
42+
# Copy our Python build from the builder stage
43+
COPY --from=builder /opt/python3/ /opt/python3/
44+
45+
# Set the PATH to include our custom Python build
46+
ENV PATH="/opt/python3/bin:${PATH}"
47+
48+
# Install essential runtime dependencies.
49+
# Downstream images are responsible for installing Devito-specific
50+
# dependencies such as compilers/MPI.
51+
RUN apt-get update && apt-get install -y \
52+
libnuma-dev && \
53+
rm -rf /var/lib/apt/lists/*
54+
55+
RUN python3 -m pip install --upgrade pip && \
56+
python3 -m pip cache purge
57+

docker/Dockerfile.nvidia

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ ARG arch="nvc"
77
########################################################################
88
# Build base image with apt setup and common env
99
########################################################################
10-
FROM ubuntu:22.04 AS sdk-base
10+
ARG FROM_IMAGE=ubuntu:22.04
11+
FROM $FROM_IMAGE AS sdk-base
1112

1213
SHELL ["/bin/bash", "-c"]
1314

@@ -16,7 +17,12 @@ ENV DEBIAN_FRONTEND noninteractive
1617
# Install python
1718
RUN apt-get update && \
1819
apt-get install -y -q gpg apt-utils curl wget libnuma-dev cmake git \
19-
dh-autoreconf python3-venv python3-dev python3-pip
20+
dh-autoreconf && \
21+
if [ ! -d "/opt/python3" ]; then \
22+
apt-get install -y -q python3-venv python3-dev python3-pip; \
23+
else \
24+
echo "Using free-threaded Python build"; \
25+
fi;
2026

2127
# nodesource: nvdashboard requires nodejs>=10
2228
RUN curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | gpg --yes --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
@@ -97,8 +103,8 @@ RUN echo "$HPCSDK_HOME/cuda/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
97103
echo "$HPCSDK_HOME/compilers/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
98104
echo "$HPCSDK_HOME/comm_libs/mpi/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
99105
echo "$HPCSDK_CUPTI/lib64" >> /etc/ld.so.conf.d/nvidia.conf && \
100-
echo "$HPCSDK_HOME/math_libs/lib64" >> /etc/ld.so.conf.d/nvidia.conf
101-
106+
echo "$HPCSDK_HOME/math_libs/lib64" >> /etc/ld.so.conf.d/nvidia.conf
107+
102108
# Compiler, CUDA, and Library paths
103109
# CUDA_HOME has been deprecated but keep for now because of other dependencies (@mloubout).
104110
ENV CUDA_HOME $HPCSDK_HOME/cuda

0 commit comments

Comments
 (0)