xref: /aosp_15_r20/external/tensorflow/tensorflow/tools/ci_build/Dockerfile.rocm (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1# This Dockerfile provides a starting point for a ROCm installation of
2# MIOpen and tensorflow.
3FROM ubuntu:bionic
4MAINTAINER Jeff Poznanovic <[email protected]>
5
6ARG ROCM_DEB_REPO=https://repo.radeon.com/rocm/apt/5.1/
7ARG ROCM_BUILD_NAME=ubuntu
8ARG ROCM_BUILD_NUM=main
9ARG ROCM_PATH=/opt/rocm-5.1.0
10
11ENV DEBIAN_FRONTEND noninteractive
12ENV TF_NEED_ROCM 1
13ENV HOME /root/
14RUN apt-get --allow-unauthenticated update && apt install -y wget software-properties-common
15
16# Add rocm repository
17RUN apt-get clean all
18RUN wget -qO - https://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -;
19RUN bin/bash -c 'if [[ $ROCM_DEB_REPO == https://repo.radeon.com/rocm/*  ]] ; then \
20      echo "deb [arch=amd64] $ROCM_DEB_REPO $ROCM_BUILD_NAME $ROCM_BUILD_NUM" > /etc/apt/sources.list.d/rocm.list; \
21    else \
22      echo "deb [arch=amd64 trusted=yes] $ROCM_DEB_REPO $ROCM_BUILD_NAME $ROCM_BUILD_NUM" > /etc/apt/sources.list.d/rocm.list ; \
23    fi'
24
25# Install misc pkgs
26RUN apt-get update --allow-insecure-repositories && DEBIAN_FRONTEND=noninteractive apt-get install -y \
27  build-essential \
28  bsdmainutils \
29  clang-6.0 \
30  clang-format-6.0 \
31  clang-tidy-6.0 \
32  cmake \
33  cmake-qt-gui \
34  ssh \
35  curl \
36  apt-utils \
37  pkg-config \
38  g++-multilib \
39  git \
40  kmod \
41  libunwind-dev \
42  libfftw3-dev \
43  libelf-dev \
44  libncurses5-dev \
45  libpthread-stubs0-dev \
46  vim \
47  gfortran \
48  libboost-program-options-dev \
49  libssl-dev \
50  libboost-dev \
51  libboost-system-dev \
52  libboost-filesystem-dev \
53  rpm \
54  libnuma-dev \
55  pciutils \
56  virtualenv \
57  python-pip \
58  libxml2 \
59  libxml2-dev \
60  wget && \
61  apt-get clean && \
62  rm -rf /var/lib/apt/lists/*
63
64# Add to get ppa
65RUN apt-get update
66RUN apt-get install -y software-properties-common
67# Install rocm pkgs
68RUN apt-get update --allow-insecure-repositories && \
69    DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \
70    rocm-dev rocm-libs rccl && \
71    apt-get clean && \
72    rm -rf /var/lib/apt/lists/*
73
74# Set up paths
75ENV HCC_HOME=$ROCM_PATH/hcc
76ENV HIP_PATH=$ROCM_PATH/hip
77ENV OPENCL_ROOT=$ROCM_PATH/opencl
78ENV PATH="$HCC_HOME/bin:$HIP_PATH/bin:${PATH}"
79ENV PATH="$ROCM_PATH/bin:${PATH}"
80ENV PATH="$OPENCL_ROOT/bin:${PATH}"
81
82# Add target file to help determine which device(s) to build for
83RUN bash -c 'echo -e "gfx900\ngfx906\ngfx908" >> ${ROCM_PATH}/bin/target.lst'
84
85# Need to explicitly create the $ROCM_PATH/.info/version file to workaround what seems to be a bazel bug
86# The env vars being set via --action_env in .bazelrc and .tf_configure.bazelrc files are sometimes
87# not getting set in the build command being spawned by bazel (in theory this should not happen)
88# As a consequence ROCM_PATH is sometimes not set for the hipcc commands.
89# When hipcc incokes hcc, it specifies $ROCM_PATH/.../include dirs via the `-isystem` options
90# If ROCM_PATH is not set, it defaults to /opt/rocm, and as a consequence a dependency is generated on the
91# header files included within `/opt/rocm`, which then leads to bazel dependency errors
92# Explicitly creating the $ROCM_PATH/.info/version allows ROCM path to be set correrctly, even when ROCM_PATH
93# is not explicitly set, and thus avoids the eventual bazel dependency error.
94# The bazel bug needs to be root-caused and addressed, but that is out of our control and may take a long time
95# to come to fruition, so implementing the workaround to make do till then
96# Filed https://github.com/bazelbuild/bazel/issues/11163 for tracking this
97RUN touch ${ROCM_PATH}/.info/version
98
99ENV PATH="/root//bin:/root/.local/bin:$PATH"
100# Copy and run the install scripts.
101COPY install/*.sh /install/
102COPY release/common.sh /install/common.sh
103COPY release/* tensorflow/tools/ci_build/release/
104ARG DEBIAN_FRONTEND=noninteractive
105RUN /install/install_deb_packages.sh
106RUN /install/install_pi_python3.9_toolchain.sh
107
108SHELL ["/bin/bash", "-c"]
109RUN /install/install_bazel.sh
110# Set up the master bazelrc configuration file.
111COPY install/.bazelrc /etc/bazel.bazelrc
112# Configure the build for our ROCm configuration.
113ENV TF_NEED_ROCM 1
114
115# This is a temporary workaround to fix Out-Of-Memory errors we are running into with XLA perf tests
116# By default, HIP runtime "hides" 256MB from the TF Runtime, but with recent changes (update to ROCm2.3, dynamic loading of roc* libs, et al)
117# it seems that we need to up the threshold slightly to 320MB
118ENV HIP_HIDDEN_FREE_MEM=320
119