Skip to content

Commit de7815d

Browse files
committed
conda: add _GLIBCXX_USE_CXX11_ABI=1 support for linux cpu wheel
The target of this commit is to add the support for a new linux cpu conda wheel file built with _GLIBCXX_USE_CXX11_ABI=1. we add a Dockerfile (conda/Dockerfile_cxx11-abi) with CentOS8 as base image to support CXX11_ABI=1. To build the new docker image with CXX11_ABI support, run: CUDA_VERSION=cpu-cxx11-abi conda/build_docker.sh or conda/build_all_docker.sh To build a linux cpu conda wheel with CXX11_ABI within this image, run: // the below settings are special for this image export DESIRED_CUDA=cpu-cxx11-abi # change from cpu for wheel name export GPU_ARCH_TYPE=cpu-cxx11-abi # change from cpu for build.sh export DOCKER_IMAGE=pytorch/conda-builder:cpu-cxx11-abi export DESIRED_DEVTOOLSET=cxx11-abi // the below settings are as usual export BINARY_ENV_FILE=/tmp/env export BUILDER_ROOT=/builder export DESIRED_PYTHON=3.7 # or 3.8, 3.9, etc. export IS_GHA=1 export PACKAGE_TYPE=conda export PYTORCH_FINAL_PACKAGE_DIR=/artifacts export PYTORCH_ROOT=/pytorch export GITHUB_WORKSPACE=/your_path_to_workspace // the '-e DESIRED_DEVTOOLSET' below is newly added for this container, // others are as usual set -x mkdir -p artifacts/ container_name=$(docker run -e BINARY_ENV_FILE -e BUILDER_ROOT -e DESIRED_CUDA -e DESIRED_PYTHON -e GPU_ARCH_TYPE -e IS_GHA -e PACKAGE_TYPE -e PYTORCH_FINAL_PACKAGE_DIR -e PYTORCH_ROOT -e DOCKER_IMAGE -e DESIRED_DEVTOOLSET --tty --detach -v "${GITHUB_WORKSPACE}/pytorch:/pytorch" -v "${GITHUB_WORKSPACE}/builder:/builder" -v "${RUNNER_TEMP}/artifacts:/artifacts" -w / "${DOCKER_IMAGE}" ) // build conda wheel as usual, // and the built wheel file name looks like: pytorch-1.13.0.dev20220616-py3.7_cpu_0.tar.bz2 docker exec -t -w "${PYTORCH_ROOT}" "${container_name}" bash -c "bash .circleci/scripts/binary_populate_env.sh" docker exec -t "${container_name}" bash -c "source ${BINARY_ENV_FILE} && bash /builder/conda/build.sh" // to verify the built wheel file, we'll see 'True' $ conda install pytorch-1.13.0.dev20220616-py3.7_cpu_0.tar.bz2 $ python -c 'import torch; print(torch._C._GLIBCXX_USE_CXX11_ABI)' True Co-authored-by: Zhu Hong [email protected] Co-authored-by: Guo Yejun [email protected]
1 parent 6649435 commit de7815d

File tree

6 files changed

+78
-8
lines changed

6 files changed

+78
-8
lines changed

conda/Dockerfile_cxx11-abi

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM centos:8 as base
2+
3+
ENV LC_ALL en_US.UTF-8
4+
ENV LANG en_US.UTF-8
5+
ENV LANGUAGE en_US.UTF-8
6+
7+
# change to a valid repo
8+
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*.repo
9+
# enable to install ninja-build
10+
RUN sed -i 's|enabled=0|enabled=1|g' /etc/yum.repos.d/CentOS-Linux-PowerTools.repo
11+
12+
RUN yum -y update
13+
RUN yum install -y wget curl perl util-linux xz bzip2 git patch which unzip
14+
RUN yum install -y autoconf automake make cmake gdb gcc gcc-c++
15+
16+
FROM base as patchelf
17+
# Install patchelf
18+
ADD ./common/install_patchelf.sh install_patchelf.sh
19+
RUN bash ./install_patchelf.sh && rm install_patchelf.sh && cp $(which patchelf) /patchelf
20+
21+
FROM base as openssl
22+
# Install openssl
23+
ADD ./common/install_openssl.sh install_openssl.sh
24+
RUN bash ./install_openssl.sh && rm install_openssl.sh
25+
26+
FROM base as conda
27+
# Install Anaconda
28+
ADD ./common/install_conda.sh install_conda.sh
29+
RUN bash ./install_conda.sh && rm install_conda.sh
30+
31+
# Install MNIST test data
32+
FROM base as mnist
33+
ADD ./common/install_mnist.sh install_mnist.sh
34+
RUN bash ./install_mnist.sh
35+
36+
FROM base as final
37+
# Install LLVM
38+
COPY --from=pytorch/llvm:9.0.1 /opt/llvm /opt/llvm
39+
COPY --from=pytorch/llvm:9.0.1 /opt/llvm_no_cxx11_abi /opt/llvm_no_cxx11_abi
40+
COPY --from=openssl /opt/openssl /opt/openssl
41+
COPY --from=patchelf /patchelf /usr/local/bin/patchelf
42+
COPY --from=conda /opt/conda /opt/conda
43+
ADD ./java/jni.h /usr/local/include/jni.h
44+
ENV PATH /opt/conda/bin:$PATH
45+
COPY --from=mnist /usr/local/mnist /usr/local/mnist
46+
RUN rm -rf /usr/local/cuda
47+
RUN chmod o+rw /usr/local
48+
RUN touch /.condarc && \
49+
chmod o+rw /.condarc && \
50+
chmod -R o+rw /opt/conda

conda/build_all_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/usr/bin/env bash
1+
v#!/usr/bin/env bash
22

33
set -eou pipefail
44

55
TOPDIR=$(git rev-parse --show-toplevel)
66

7-
for CUDA_VERSION in 11.8 11.7 11.6 cpu; do
7+
for CUDA_VERSION in 11.7 11.6 11.5 11.3 10.2 cpu cpu-cxx11-abi; do
88
CUDA_VERSION="${CUDA_VERSION}" conda/build_docker.sh
99
done

conda/build_docker.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ DEVTOOLSET_VERSION="9"
1010
if [[ ${CUDA_VERSION:0:2} == "10" ]]; then
1111
DEVTOOLSET_VERSION="7"
1212
fi
13+
CONDA_LINUX_VERSION=${CONDA_LINUX_VERSION:-}
1314

15+
# add a empty line
1416
case ${CUDA_VERSION} in
1517
cpu)
1618
BASE_TARGET=base
1719
DOCKER_TAG=cpu
1820
;;
21+
cpu-cxx11-abi)
22+
BASE_TARGET=base
23+
DOCKER_TAG=cpu-cxx11-abi
24+
CONDA_LINUX_VERSION="cxx11-abi"
25+
;;
1926
all)
2027
BASE_TARGET=all_cuda
2128
DOCKER_TAG=latest
@@ -26,6 +33,12 @@ case ${CUDA_VERSION} in
2633
;;
2734
esac
2835

36+
if [[ -n ${CONDA_LINUX_VERSION} ]]; then
37+
DOCKERFILE_SUFFIX=_${CONDA_LINUX_VERSION}
38+
else
39+
DOCKERFILE_SUFFIX=''
40+
fi
41+
2942
(
3043
set -x
3144
docker build \
@@ -34,7 +47,7 @@ esac
3447
--build-arg "CUDA_VERSION=${CUDA_VERSION}" \
3548
--build-arg "DEVTOOLSET_VERSION=${DEVTOOLSET_VERSION}" \
3649
-t "pytorch/conda-builder:${DOCKER_TAG}" \
37-
-f "${TOPDIR}/conda/Dockerfile" \
50+
-f "${TOPDIR}/conda/Dockerfile${DOCKERFILE_SUFFIX}" \
3851
${TOPDIR}
3952
)
4053

conda/build_pytorch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ else
4949
build_version="$2"
5050
build_number="$3"
5151
fi
52-
if [[ "$desired_cuda" != cpu ]]; then
52+
if [[ "$desired_cuda" != cpu ]] && [[ "$desired_cuda" != cpu-cxx11-abi ]]; then
5353
desired_cuda="$(echo $desired_cuda | tr -d cuda. )"
5454
fi
5555
echo "Building cuda version $desired_cuda and pytorch version: $build_version build_number: $build_number"
@@ -108,7 +108,7 @@ fi
108108
if [[ "$OSTYPE" == "darwin"* ]]; then
109109
DEVELOPER_DIR=/Applications/Xcode_13.3.1.app/Contents/Developer
110110
fi
111-
if [[ "$desired_cuda" == 'cpu' ]]; then
111+
if [[ "$desired_cuda" == 'cpu' ]] || [[ "$desired_cuda" == 'cpu-cxx11-abi' ]]; then
112112
cpu_only=1
113113
else
114114
# Switch desired_cuda to be M.m to be consistent with other scripts in

conda/pytorch-nightly/build.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ export CMAKE_PREFIX_PATH=$PREFIX
66
export TH_BINARY_BUILD=1 # links CPU BLAS libraries thrice in a row (was needed for some MKL static linkage)
77
export PYTORCH_BUILD_VERSION=$PKG_VERSION
88
export PYTORCH_BUILD_NUMBER=$PKG_BUILDNUM
9-
export USE_LLVM="/opt/llvm_no_cxx11_abi"
10-
export LLVM_DIR="$USE_LLVM/lib/cmake/llvm"
9+
if [[ "$DESIRED_DEVTOOLSET" == *"cxx11-abi"* ]]; then
10+
export _GLIBCXX_USE_CXX11_ABI=1
11+
export USE_LLVM="/opt/llvm"
12+
export LLVM_DIR="$USE_LLVM/lib/cmake/llvm"
13+
else
14+
export _GLIBCXX_USE_CXX11_ABI=0
15+
export USE_LLVM="/opt/llvm_no_cxx11_abi"
16+
export LLVM_DIR="$USE_LLVM/lib/cmake/llvm"
17+
fi
1118
export PACKAGE_TYPE="conda"
12-
1319
# set OPENSSL_ROOT_DIR=/opt/openssl if it exists
1420
if [[ -e /opt/openssl ]]; then
1521
export OPENSSL_ROOT_DIR=/opt/openssl

conda/pytorch-nightly/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ build:
7070
- DEVELOPER_DIR
7171
- DEBUG
7272
- USE_FBGEMM
73+
- DESIRED_DEVTOOLSET
7374
- USE_GLOO_WITH_OPENSSL # [unix]
7475
- USE_SCCACHE # [win]
7576
- USE_DISTRIBUTED # [unix]

0 commit comments

Comments
 (0)