Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shink committed Jul 2, 2024
1 parent 3c35556 commit 6edcd88
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 352 deletions.
120 changes: 85 additions & 35 deletions cann/openeuler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
# Arguments
ARG BASE_VERSION=latest
ARG PLATFORM=${TARGETPLATFORM}
ARG PY_VERSION=3.8
ARG CANN_CHIP=910b
ARG CANN_VERSION=8.0.RC2.alpha002

# Phase 1: download CANN installers
FROM alpine as downloader
# Phase 1: Install Miniconda
FROM openeuler/openeuler:${BASE_VERSION} as conda-installer

# Arguments
ARG PLATFORM
ARG CANN_CHIP
ARG CANN_VERSION
ARG PY_VERSION

RUN apk add --no-cache \
bash \
curl \
&& rm -rf /var/cache/apk/* \
# Environment variables
ENV PATH=/opt/miniconda/bin:${PATH}

# Install dependencies
RUN yum update -y && \
yum install -y \
gcc \
gcc-c++ \
make \
cmake \
zlib-devel \
bzip2-devel \
openssl-devel \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& rm -rf /tmp/*

# Copy files
COPY ../scripts/cann.sh /tmp/cann.sh
COPY ../scripts/install-py.sh /tmp/install-py.sh
# Download Miniconda
RUN case ${PLATFORM} in \
"linux/amd64") MINICONDA_ARCH=x86_64 ;; \
*) MINICONDA_ARCH=aarch64 ;; \
esac && \
MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-${MINICONDA_ARCH}.sh" && \
# download \
echo "Downloading Miniconda from ${MINICONDA_URL}" && \
curl -fsSL -o /tmp/miniconda.sh "${MINICONDA_URL}"

# Download CANN
RUN chmod +x /tmp/cann.sh && \
bash /tmp/cann.sh --download
# Install Miniconda to /opt/miniconda
RUN chmod +x /tmp/miniconda.sh && \
bash /tmp/miniconda.sh -b -u -p /opt/miniconda && \
rm -rf /tmp/miniconda.sh && \
/opt/miniconda/bin/conda install -y python=${PY_VERSION} && \
/opt/miniconda/bin/conda clean -ya

# Phase 2: install CANN toolkit and kernels
FROM openeuler/openeuler:${BASE_VERSION} as builder
# Phase 2: Install CANN
FROM conda-installer as cann-installer

# Arguments
ARG PLATFORM
ARG CANN_CHIP
ARG CANN_VERSION

# Change the default shell
SHELL [ "/bin/bash", "-c" ]

RUN yum install -y \
# Install dependencies
RUN yum update -y && \
yum install -y \
gcc \
gcc-c++ \
make \
Expand Down Expand Up @@ -61,25 +84,52 @@ RUN yum install -y \
&& rm -rf /var/cache/yum \
&& rm -rf /tmp/*

# Install Python
RUN --mount=type=cache,from=downloader,target=/tmp,source=/tmp \
umask 0022 && \
chmod +x /tmp/install-py.sh && \
bash /tmp/install-py.sh
# Copy files
COPY ../scripts/cann.sh /tmp/cann.sh

# Install CANN
RUN --mount=type=cache,from=downloader,target=/tmp,source=/tmp \
umask 0022 && \
chmod +x /tmp/cann.sh && \
bash /tmp/cann.sh --install
RUN bash /tmp/cann.sh --install && \
rm /tmp/cann.sh

# Phase 3: Copy results from previous phases
FROM openeuler/openeuler:${BASE_VERSION} as official

# Arguments
ARG PLATFORM
ARG PY_VERSION
ARG CANN_CHIP
ARG CANN_VERSION

# Environment variables
ENV PATH=/opt/miniconda/bin:${PATH}
ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:${LD_LIBRARY_PATH}

# Install dependencies
RUN yum update -y && \
yum install -y \
ca-certificates \
bash \
glibc \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& rm -rf /tmp/*

# Copy files
COPY ../scripts/docker-entrypoint.sh /root/docker-entrypoint.sh
COPY --from=cann-installer /opt/miniconda /opt/miniconda
COPY --from=cann-installer /usr/local/Ascend /usr/local/Ascend
COPY --from=cann-installer /etc/Ascend /etc/Ascend

# Driver path
ENV DRIVER_PATH=/usr/local/Ascend/driver
# Init conda environment
RUN /opt/miniconda/bin/conda init --all --system && \
chmod 644 /etc/profile.d/conda.sh && \
chmod -R 755 /opt/miniconda

# Add the driver path to the library path
ENV LD_LIBRARY_PATH=${DRIVER_PATH}/lib64/common/:${DRIVER_PATH}/lib64/driver/:${LD_LIBRARY_PATH}
# Set environment variables
RUN CANN_TOOLKIT_ENV_FILE="/usr/local/Ascend/ascend-toolkit/set_env.sh" && \
DRIVER_LIBRARY_PATH="LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:\${LD_LIBRARY_PATH}" && \
echo "export ${DRIVER_LIBRARY_PATH}" >> /etc/profile && \
echo "export ${DRIVER_LIBRARY_PATH}" >> ~/.bashrc && \
echo "source ${CANN_TOOLKIT_ENV_FILE}" >> /etc/profile && \
echo "source ${CANN_TOOLKIT_ENV_FILE}" >> ~/.bashrc

ENTRYPOINT [ "/root/docker-entrypoint.sh" ]
ENTRYPOINT [ "/bin/bash", "-c", "source /usr/local/Ascend/ascend-toolkit/set_env.sh && exec \"$@\"", "--" ]
135 changes: 0 additions & 135 deletions cann/openeuler/test.Dockerfile

This file was deleted.

Loading

0 comments on commit 6edcd88

Please sign in to comment.