diff --git a/cann/8.0.RC1/24.03-lts/Dockerfile b/cann/8.0.RC1/24.03-lts/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..1798f8ef96e3db78f1ce8d1db1b18b954ad5811e --- /dev/null +++ b/cann/8.0.RC1/24.03-lts/Dockerfile @@ -0,0 +1,138 @@ +# Arguments +ARG TARGETPLATFORM +ARG PY_VERSION=3.8 +ARG CANN_CHIP=910b +ARG VERSION=8.0.RC1 +ARG BASE=openeuler/openeuler:24.03-lts + +# Phase 1: Install Python +FROM ${BASE} as py-installer + +# Arguments +ARG PY_VERSION + +# Environment variables +ENV PATH=/usr/local/python${PY_VERSION}/bin:${PATH} + +# Install dependencies +RUN yum update -y && \ + yum install -y \ + gcc \ + gcc-c++ \ + make \ + cmake \ + curl \ + zlib-devel \ + bzip2-devel \ + openssl-devel \ + ncurses-devel \ + sqlite-devel \ + readline-devel \ + tk-devel \ + gdbm-devel \ + libpcap-devel \ + xz-devel \ + libev-devel \ + expat-devel \ + libffi-devel \ + systemtap-sdt-devel \ + && yum clean all \ + && rm -rf /var/cache/yum \ + && rm -rf /tmp/* + +# Copy files +COPY scripts/python.sh /tmp/python.sh + +# Download Python +RUN bash /tmp/python.sh --download + +# Install Python +RUN bash /tmp/python.sh --install && \ + rm /tmp/python.sh + +# Phase 2: Install CANN +FROM py-installer as cann-installer + +# Arguments +ARG TARGETPLATFORM +ARG CANN_CHIP +ARG VERSION + +# Install dependencies +RUN yum update -y && \ + yum install -y \ + gcc \ + gcc-c++ \ + make \ + cmake \ + unzip \ + zlib-devel \ + libffi-devel \ + openssl-devel \ + pciutils \ + net-tools \ + sqlite-devel \ + lapack-devel \ + gcc-gfortran \ + util-linux \ + findutils \ + && yum clean all \ + && rm -rf /var/cache/yum \ + && rm -rf /tmp/* + +# Copy files +COPY scripts/cann.sh /tmp/cann.sh + +# Download CANN +RUN bash /tmp/cann.sh --download + +# Install CANN +RUN bash /tmp/cann.sh --install && \ + rm /tmp/cann.sh + +# Phase 3: Copy results from previous phases +FROM ${BASE} as official + +# Arguments +ARG TARGETPLATFORM +ARG PY_VERSION +ARG CANN_CHIP +ARG VERSION + +# Environment variables +ENV PATH=/usr/local/python${PY_VERSION}/bin:${PATH} +ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:${LD_LIBRARY_PATH} + +# Change the default shell +SHELL [ "/bin/bash", "-c" ] + +# Install dependencies +RUN yum update -y && \ + yum install -y \ + ca-certificates \ + bash \ + glibc \ + sqlite-devel \ + && yum clean all \ + && rm -rf /var/cache/yum \ + && rm -rf /tmp/* + +# Copy files +COPY --from=cann-installer /usr/local/python${PY_VERSION} /usr/local/python${PY_VERSION} +COPY --from=cann-installer /usr/local/Ascend /usr/local/Ascend +COPY --from=cann-installer /etc/Ascend /etc/Ascend + +# Set environment variables for Python +RUN PY_PATH="PATH=/usr/local/python${PY_VERSION}/bin:\${PATH}" && \ + echo "export ${PY_PATH}" >> /etc/profile && \ + echo "export ${PY_PATH}" >> ~/.bashrc + +# Set environment variables for CANN +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 [ "/bin/bash", "-c", "source /usr/local/Ascend/ascend-toolkit/set_env.sh && exec \"$@\"", "--" ] \ No newline at end of file diff --git a/cann/8.0.RC1/24.03-lts/scripts/cann.sh b/cann/8.0.RC1/24.03-lts/scripts/cann.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee5dcea6fe40c4da1a54639d6df772626cf782b9 --- /dev/null +++ b/cann/8.0.RC1/24.03-lts/scripts/cann.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +set -e + +get_architecture() { + # not case sensitive + shopt -s nocasematch + + case "${PLATFORM}" in + "linux/x86_64"|"linux/amd64") + ARCH="x86_64" + ;; + "linux/aarch64"|"linux/arm64") + ARCH="aarch64" + ;; + *) + echo "Error: Unsupported architecture ${PLATFORM}." + exit 1 + ;; + esac + + echo "${ARCH}" +} + +download_file() { + set +e + + local max_retries=10 + local retry_delay=10 + local url="$1" + local path="$2" + + for ((i=1; i<=max_retries; i++)); do + echo "Attempt $i of $max_retries..." + curl -fsSL -o "${path}" "${url}" + if [[ $? -eq 0 ]]; then + return 0 + else + echo "Download failed with error code $?. Retrying in ${retry_delay} seconds..." + sleep ${retry_delay} + fi + done + + echo "All attempts failed. Exiting." + return 1 +} + +download_cann() { + if [[ ${CANN_VERSION} == "8.0.RC2.alpha001" ]]; then + local url_prefix="https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C18B800TP015" + elif [[ ${CANN_VERSION} == "8.0.RC2.alpha002" ]]; then + local url_prefix="https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C18SPC805" + elif [[ ${CANN_VERSION} == "8.0.RC2.alpha003" ]]; then + local url_prefix="https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C18SPC703" + else + local url_prefix="https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%20${CANN_VERSION}" + fi + local url_suffix="response-content-type=application/octet-stream" + local toolkit_url="${url_prefix}/${TOOLKIT_FILE}?${url_suffix}" + local kernels_url="${url_prefix}/${KERNELS_FILE}?${url_suffix}" + + if [ ! -f "${TOOLKIT_PATH}" ]; then + echo "Downloading ${TOOLKIT_FILE} from ${toolkit_url}" + download_file "${toolkit_url}" "${TOOLKIT_PATH}" + fi + + if [ ! -f "${KERNELS_PATH}" ]; then + echo "Downloading ${KERNELS_FILE} from ${kernels_url}" + download_file "${kernels_url}" "${KERNELS_PATH}" + fi + + echo "CANN ${CANN_VERSION} download successful." +} + +set_env() { + local cann_toolkit_env_file="${CANN_HOME}/ascend-toolkit/set_env.sh" + if [ ! -f "${cann_toolkit_env_file}" ]; then + echo "CANN Toolkit ${CANN_VERSION} installation failed." + exit 1 + else + local driver_path_env="LD_LIBRARY_PATH=${CANN_HOME}/driver/lib64/common/:${CANN_HOME}/driver/lib64/driver/:\${LD_LIBRARY_PATH}" && \ + echo "export ${driver_path_env}" >> /etc/profile + echo "export ${driver_path_env}" >> ~/.bashrc + echo "source ${cann_toolkit_env_file}" >> /etc/profile + echo "source ${cann_toolkit_env_file}" >> ~/.bashrc + source ${cann_toolkit_env_file} + fi +} + +install_cann() { + # Download installers + if [ ! -f "${TOOLKIT_PATH}" ] || [ ! -f "${KERNELS_PATH}" ]; then + echo "[WARNING] Installers do not exist, re-download them." + download_cann + fi + + # Install dependencies + pip install --no-cache-dir --upgrade pip + pip install --no-cache-dir \ + attrs cython numpy decorator sympy cffi pyyaml pathlib2 psutil protobuf scipy requests absl-py + + # Install CANN Toolkit + echo "Installing ${TOOLKIT_FILE}" + chmod +x "${TOOLKIT_PATH}" + bash "${TOOLKIT_PATH}" --quiet --install --install-for-all --install-path="${CANN_HOME}" + rm -f "${TOOLKIT_PATH}" + + # Set environment variables + set_env + + # Install CANN Kernels + echo "Installing ${KERNELS_FILE}" + chmod +x "${KERNELS_PATH}" + bash "${KERNELS_PATH}" --quiet --install --install-for-all --install-path="${CANN_HOME}" + rm -f "${KERNELS_PATH}" + + echo "CANN ${CANN_VERSION} installation successful." +} + +PLATFORM=${PLATFORM:=$(uname -s)/$(uname -m)} +ARCH=$(get_architecture) +CANN_HOME=${CANN_HOME:="/usr/local/Ascend"} +CANN_CHIP=${CANN_CHIP:="910b"} +CANN_VERSION=${CANN_VERSION:="8.0.RC1"} + +TOOLKIT_FILE="Ascend-cann-toolkit_${CANN_VERSION}_linux-${ARCH}.run" +KERNELS_FILE="Ascend-cann-kernels-${CANN_CHIP}_${CANN_VERSION}_linux.run" +TOOLKIT_PATH="/tmp/${TOOLKIT_FILE}" +KERNELS_PATH="/tmp/${KERNELS_FILE}" + +# Parse arguments +if [ "$1" == "--download" ]; then + download_cann +elif [ "$1" == "--install" ]; then + install_cann +elif [ "$1" == "--set_env" ]; then + set_env +else + echo "Unexpected arguments, use '--download', '--install' or '--set_env' instead" + exit 1 +fi \ No newline at end of file diff --git a/cann/8.0.RC1/24.03-lts/scripts/python.sh b/cann/8.0.RC1/24.03-lts/scripts/python.sh new file mode 100644 index 0000000000000000000000000000000000000000..077ffa178914255d314e1557fd03f99848d8e6d9 --- /dev/null +++ b/cann/8.0.RC1/24.03-lts/scripts/python.sh @@ -0,0 +1,81 @@ + +#!/bin/bash + +set -e + +PY_VERSION=${PY_VERSION:-"3.8"} +PY_MAJOR_VERSION=$(echo $PY_VERSION | cut -d'.' -f1) + +# Find the latest version +PY_LATEST_VERSION=$(curl -s https://www.python.org/ftp/python/ | grep -oE "${PY_VERSION}\.[0-9]+" | sort -V | tail -n 1) +if [ -z "${PY_LATEST_VERSION}" ]; then + echo "[WARNING] Could not find the latest version for Python ${PY_VERSION}" + exit 1 +else + echo "Latest Python version found: ${PY_LATEST_VERSION}" +fi + +PY_HOME="/usr/local/python${PY_VERSION}" +PY_INSTALLER_TGZ="Python-${PY_LATEST_VERSION}.tgz" +PY_INSTALLER_DIR="Python-${PY_LATEST_VERSION}" +PY_INSTALLER_URL="https://repo.huaweicloud.com/python/${PY_LATEST_VERSION}/${PY_INSTALLER_TGZ}" + +download_python() { + # Download python + echo "Downloading ${PY_INSTALLER_TGZ} from ${PY_INSTALLER_URL}" + curl -fsSL -o "/tmp/${PY_INSTALLER_TGZ}" "${PY_INSTALLER_URL}" + if [ $? -ne 0 ]; then + echo "Python ${PY_LATEST_VERSION} download failed." + exit 1 + fi +} + +install_python() { + # Download python + if [ ! -f "/tmp/${PY_INSTALLER_TGZ}" ]; then + echo "[WARNING] Installer do not exist, re-download it." + download_python + fi + + # Install python + echo "Installing ${PY_INSTALLER_DIR}" + tar -xf /tmp/${PY_INSTALLER_TGZ} -C /tmp + cd /tmp/${PY_INSTALLER_DIR} + mkdir -p /${PY_HOME}/lib + ./configure --prefix=${PY_HOME} --enable-shared LDFLAGS="-Wl,-rpath ${PY_HOME}/lib" + make -j $(nproc) + make altinstall + + # Create symbolic links at PY_HOME + ln -sf ${PY_HOME}/bin/python${PY_VERSION} ${PY_HOME}/bin/python${PY_MAJOR_VERSION} + ln -sf ${PY_HOME}/bin/pip${PY_VERSION} ${PY_HOME}/bin/pip${PY_MAJOR_VERSION} + ln -sf ${PY_HOME}/bin/python${PY_MAJOR_VERSION} ${PY_HOME}/bin/python + ln -sf ${PY_HOME}/bin/pip${PY_MAJOR_VERSION} ${PY_HOME}/bin/pip + + # Clean up + rm -rf /tmp/${PY_INSTALLER_TGZ} /tmp/${PY_INSTALLER_DIR} + echo "Python ${PY_LATEST_VERSION} installation successful." + ${PY_HOME}/bin/python -c "import sys; print(sys.version)" +} + +# Create symbolic links +create_links() { + ln -sf ${PY_HOME}/bin/python${PY_VERSION} /usr/bin/python${PY_VERSION} + ln -sf ${PY_HOME}/bin/pip${PY_VERSION} /usr/bin/pip${PY_VERSION} + ln -sf /usr/bin/python${PY_VERSION} /usr/bin/python${PY_MAJOR_VERSION} + ln -sf /usr/bin/pip${PY_VERSION} /usr/bin/pip${PY_MAJOR_VERSION} + ln -sf /usr/bin/python${PY_MAJOR_VERSION} /usr/bin/python + ln -sf /usr/bin/pip${PY_MAJOR_VERSION} /usr/bin/pip +} + +# Parse arguments +if [ "$1" == "--download" ]; then + download_python +elif [ "$1" == "--install" ]; then + install_python +elif [ "$1" == "--create_links" ]; then + create_links +else + echo "Unexpected arguments, use '--download', '--install' or '--create_links' instead" + exit 1 +fi