Skip to content

Commit

Permalink
Merge pull request #2618 from ROCm/develop-upstream-add-ub24
Browse files Browse the repository at this point in the history
Add Ubuntu24 image; rework python installations
  • Loading branch information
jayfurmanek authored Aug 9, 2024
2 parents 642aed3 + 54e1f81 commit d8198de
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG DISTRO_IMG
FROM ${DISTRO_IMG:-'ubuntu:22.04'} as runtime
################################################################################

# Note: Ubuntu jammy has Python 3.10 installed by default
#
# Install dependencies
COPY setup.packages.sh /setup.packages.sh
COPY runtime.packages.txt /runtime.packages.txt
Expand All @@ -29,12 +31,6 @@ RUN /setup.rocm.sh $ROCM_VERSION jammy
ARG CACHEBUSTER=0
RUN echo $CACHEBUSTER

# Setup Python environment. PYTHON_VERSION is e.g. "python3.8"
ARG PYTHON_VERSION
COPY setup.python.sh /setup.python.sh
COPY devel.requirements.txt /devel.requirements.txt
RUN /setup.python.sh $PYTHON_VERSION devel.requirements.txt true

# Setup ENV variables for tensorflow pip build
ENV TF_NEED_ROCM=1
ENV TF_ROCM_GCC=1
Expand Down
51 changes: 51 additions & 0 deletions tensorflow/tools/tf_sig_build_dockerfiles/Dockerfile.rocm.rt.ub24
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
################################################################################
ARG DISTRO_IMG
FROM ${DISTRO_IMG:-'ubuntu:24.04'} as runtime
################################################################################

# Note: Ubuntu Noble as Python 3.12 installed by default
#
# Install dependencies
COPY setup.packages.sh /setup.packages.sh
COPY runtime.packages.txt /runtime.packages.txt
COPY sles.runtime.packages.txt /sles.runtime.packages.txt
RUN /setup.packages.sh /runtime.packages.txt

# Install ROCM
ARG TF_PKGS_DIR=tmp/packages
ARG TENSORFLOW_PACKAGE=tf_nightly_rocm
ARG ROCM_VERSION=6.1.2
ARG CUSTOM_INSTALL
ARG ROCM_PATH=/opt/rocm-${ROCM_VERSION}
ENV ROCM_PATH=${ROCM_PATH}
COPY ${TF_PKGS_DIR}/${TENSORFLOW_PACKAGE} /${TF_PKGS_DIR}/${TENSORFLOW_PACKAGE}
COPY ${CUSTOM_INSTALL} /${CUSTOM_INSTALL}
COPY setup.rocm.sh /setup.rocm.sh
COPY devel.packages.rocm.txt /devel.packages.rocm.txt
COPY sles.devel.packages.rocm.txt /sles.devel.packages.rocm.txt
RUN /setup.rocm.sh $ROCM_VERSION jammy

# All lines past this point are reset when $CACHEBUSTER is set. We need this
# for Python specifically because we install some nightly packages which are
# likely to change daily.
ARG CACHEBUSTER=0
RUN echo $CACHEBUSTER

# Setup ENV variables for tensorflow pip build
ENV TF_NEED_ROCM=1
ENV TF_ROCM_GCC=1
ENV ROCM_TOOLKIT_PATH=${ROCM_PATH}

RUN pip install --no-cache-dir /${TF_PKGS_DIR}/${TENSORFLOW_PACKAGE}
RUN echo 'ALL ALL=NOPASSWD:ALL' | tee /etc/sudoers.d/sudo-nopasswd

ARG TF_TESTING_FL
ENV TF_TESTING_FL=${TF_TESTING_FL}
ARG DWLD_TF_SRC_CMD
RUN if [ -n "${DWLD_TF_SRC_CMD}" ]; then eval "${DWLD_TF_SRC_CMD}"; fi
RUN wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /usr/local/bin/bazel && \
chmod +x /usr/local/bin/bazel
RUN git clone https://github.com/tensorflow/models.git
RUN git clone https://github.com/tensorflow/examples.git
RUN git clone https://github.com/tensorflow/autograph.git
RUN git clone https://github.com/tensorflow/benchmarks.git
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ RUN echo $CACHEBUSTER

# Setup Python environment. PYTHON_VERSION is e.g. "python3.8"
ARG PYTHON_VERSION
COPY setup.python.sh /setup.python.sh
COPY setup.build-python_ubuntu.sh /setup.build-python_ubuntu.sh
COPY devel.requirements.txt /devel.requirements.txt
RUN /setup.python.sh $PYTHON_VERSION devel.requirements.txt
RUN /setup.build-python_ubuntu.sh $PYTHON_VERSION devel.requirements.txt

ARG TF_WHEEL_URL
RUN if [ -n "${TF_WHEEL_URL}" ]; then pip install "${TF_WHEEL_URL}"; fi
Expand Down
72 changes: 72 additions & 0 deletions tensorflow/tools/tf_sig_build_dockerfiles/Dockerfile.rocm.ub24
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
################################################################################
FROM ubuntu:24.04
################################################################################

ARG GPU_DEVICE_TARGETS="gfx908 gfx90a gfx940 gfx941 gfx942 gfx1030 gfx1100"
ENV GPU_DEVICE_TARGETS=${GPU_DEVICE_TARGETS}

# Install build dependencies
COPY setup.packages.sh setup.packages.sh
COPY builder.packages.txt builder.packages.txt
RUN /setup.packages.sh /builder.packages.txt

# Install ROCM
ARG ROCM_VERSION=6.1.2
ARG CUSTOM_INSTALL
ARG ROCM_PATH=/opt/rocm-${ROCM_VERSION}
ENV ROCM_PATH=${ROCM_PATH}
COPY ${CUSTOM_INSTALL} /${CUSTOM_INSTALL}
COPY setup.rocm.sh /setup.rocm.sh
COPY devel.packages.rocm.txt /devel.packages.rocm.txt
RUN /setup.rocm.sh $ROCM_VERSION noble

# Install various tools.
# - bats: bash unit testing framework
# - bazelisk: always use the correct bazel version
# - buildifier: clean bazel build deps
# - buildozer: clean bazel build deps
# - gcloud SDK: communicate with Google Cloud Platform (GCP) for RBE, CI
RUN git clone --branch v1.7.0 https://github.com/bats-core/bats-core.git && bats-core/install.sh /usr/local && rm -rf bats-core
RUN wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /usr/local/bin/bazel && chmod +x /usr/local/bin/bazel
RUN wget https://github.com/bazelbuild/buildtools/releases/download/3.5.0/buildifier -O /usr/local/bin/buildifier && chmod +x /usr/local/bin/buildifier
RUN wget https://github.com/bazelbuild/buildtools/releases/download/3.5.0/buildozer -O /usr/local/bin/buildozer && chmod +x /usr/local/bin/buildozer
RUN curl -sSL https://sdk.cloud.google.com > /tmp/gcloud && bash /tmp/gcloud --install-dir=~/usr/local/bin --disable-prompts


# All lines past this point are reset when $CACHEBUSTER is set. We need this
# for Python specifically because we install some nightly packages which are
# likely to change daily.
ARG CACHEBUSTER=0
RUN echo $CACHEBUSTER

# Setup Python environment. PYTHON_VERSION is e.g. "python3.8"
ARG PYTHON_VERSION
COPY setup.build-python_ubuntu.sh /setup.build-python_ubuntu.sh
COPY devel.requirements.txt /devel.requirements.txt
RUN /setup.build-python_ubuntu.sh $PYTHON_VERSION devel.requirements.txt

ARG TF_WHEEL_URL
RUN if [ -n "${TF_WHEEL_URL}" ]; then pip install "${TF_WHEEL_URL}"; fi
ARG DWLD_TF_SRC_CMD
RUN if [ -n "${DWLD_TF_SRC_CMD}" ]; then eval "${DWLD_TF_SRC_CMD}"; fi

# Setup build and environment
COPY devel.usertools /usertools
COPY devel.bashrc /root/.bashrc

# Setup ENV variables for tensorflow pip build
ENV TF_NEED_ROCM=1
ENV TF_ROCM_GCC=1
ENV ROCM_TOOLKIT_PATH=${ROCM_PATH}

# Don't use the bazel cache when a new docker image is created.
RUN echo build --action_env=DOCKER_CACHEBUSTER=$(date +%s%N)$RANDOM >> /etc/bazel.bazelrc
RUN echo build --host_action_env=DOCKER_HOST_CACHEBUSTER=$(date +%s%N)$RANDOM >> /etc/bazel.bazelrc

ARG TF_TESTING_FL
ENV TF_TESTING_FL=${TF_TESTING_FL}
ARG DWLD_TF_SRC_CMD
RUN if [ -n "${DWLD_TF_SRC_CMD}" ]; then eval "${DWLD_TF_SRC_CMD}"; fi
ARG CLONE_TEST_REPO
COPY ${CLONE_TEST_REPO} /${CLONE_TEST_REPO}
RUN if [ -n "${CLONE_TEST_REPO}" ]; then bash /${CLONE_TEST_REPO}; fi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ libssl-dev
libtool
libzmq3-dev
lld-17
mlocate
moreutils
openjdk-11-jdk
openjdk-11-jre-headless
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
#
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# setup.build-python_ubuntu.sh: Build python from src for SLES/Ubuntu
# and install some TF dependencies
# Usage: setup.build-python_ubuntu.sh <pyversion> <requirements.txt>
set -xe

function build_python_from_src() {
VERSION=$1
REQUIREMENTS=$2
_pyver="python${VERSION}"
local python_map
declare -A python_map=(
[python3.8]='3.8.12'
[python3.9]='3.9.12'
[python3.10]='3.10.9'
[python3.11]='3.11.2'
[python3.12]='3.12.4'
)
local _ver=${python_map[$_pyver]}
wget https://www.python.org/ftp/python/${_ver}/Python-${_ver}.tgz
tar xvf "Python-${_ver}.tgz" && rm -rf "Python-${_ver}.tgz"
cd Python-${_ver}/
./configure --enable-optimizations
make -j4
make altinstall

ln -sf "/usr/local/bin/python${_ver%.*}" /usr/bin/python3
ln -sf "/usr/local/bin/python${_ver%.*}" /usr/bin/python
ln -sf "/usr/local/bin/pip${_ver%.*}" /usr/bin/pip3
ln -sf "/usr/local/lib/python${_ver%.*}" /usr/lib/tf_python
cd -
}

if (source /etc/os-release && [[ ${NAME} == SLES ]]); then
## Build Python for SLES
build_python_from_src $1 $2
else
## Build Python for Ubuntu
source ~/.bashrc
VERSION=$1
REQUIREMENTS=$2
PY_VERSION="python${VERSION}"

# Install Python build from src dependencies
# See: https://github.com/pyenv/pyenv/wiki#suggested-build-environment
DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated update
DEBIAN_FRONTEND=noninteractive apt install -y wget software-properties-common
DEBIAN_FRONTEND=noninteractive apt-get install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git \
libncursesw5-dev xz-utils tk-dev libxml2-dev \
libxmlsec1-dev libffi-dev liblzma-dev
DEBIAN_FRONTEND=noninteractive apt-get clean all

build_python_from_src $1 $2

# Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
ln -sf "/usr/local/bin/pip${_ver%.*}" /usr/bin/pip3
python3 -m pip install --no-cache-dir --upgrade pip
python3 -m pip install -U setuptools
fi # end of conditional check of various distros

which python3
python3 --version

echo "Install Requirements"
# Disable the cache dir to save image space, and install packages
python3 -m pip install --no-cache-dir -r $REQUIREMENTS -U
python3 -m pip install --no-cache-dir --no-deps tf-keras-nightly
6 changes: 3 additions & 3 deletions tensorflow/tools/tf_sig_build_dockerfiles/setup.rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ if [[ -n $1 ]]; then
ROCM_VERSION=$1
fi
if [[ -n $2 ]]; then
if [[ "$2" == "focal" ]] || [[ "$2" == "jammy" ]] || [[ "$2" == "el7" ]] || [[ "$2" == "el8" ]]; then
if [[ "$2" == "focal" ]] || [[ "$2" == "jammy" ]] || [[ "$2" == "noble" ]] || [[ "$2" == "el7" ]] || [[ "$2" == "el8" ]]; then
DISTRO=$2
else
echo "Distro not supported"
echo "Supported distros are:\n focal\n jammy\n el7\n el8"
echo "Supported distros are:\n focal\n jammy\n noble\n el7\n el8"
exit 1
fi
fi
Expand All @@ -49,7 +49,7 @@ else
ROCM_VERS=$ROCM_VERSION
fi

if [[ "$DISTRO" == "focal" ]] || [[ "$DISTRO" == "jammy" ]]; then
if [[ "$DISTRO" == "focal" ]] || [[ "$DISTRO" == "jammy" ]] || [[ "$DISTRO" == "noble" ]]; then
ROCM_DEB_REPO_HOME=https://repo.radeon.com/rocm/apt/
AMDGPU_DEB_REPO_HOME=https://repo.radeon.com/amdgpu/
ROCM_BUILD_NAME=${DISTRO}
Expand Down

0 comments on commit d8198de

Please sign in to comment.