22set -eoux pipefail
33
44# ####################################################################################################
5- # This script is expected to be run on ppc64le hosts as `root` #
5+ # This script is expected to be run on ppc64le and s390x hosts as `root` #
66# It installs the required build-time dependencies for python wheels #
77# OpenBlas is built from source (instead of distro provided) with recommended flags for performance #
88# ####################################################################################################
9+
10+ # Initialize environment variables with default values
11+ if [[ $( uname -m) == " s390x" ]]; then
12+ export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
13+ export CFLAGS=" -O3"
14+ export CXXFLAGS=" -O3"
15+ else
16+ # For other architectures, set custom library paths
17+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/ usr/ local/ lib64:/ usr/ local/ lib}
18+ export PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-/ usr/ local/ lib64/ pkgconfig:/ usr/ local/ lib/ pkgconfig}
19+ fi
20+
921WHEELS_DIR=/wheelsdir
1022mkdir -p ${WHEELS_DIR}
11- if [[ $( uname -m) == " ppc64le" ]]; then
23+ if [[ $( uname -m) == " ppc64le" ]] || [[ $( uname -m ) == " s390x " ]] ; then
1224 CURDIR=$( pwd)
1325
1426 # install development packages
@@ -17,31 +29,64 @@ if [[ $(uname -m) == "ppc64le" ]]; then
1729 dnf install -y fribidi-devel gcc-toolset-13 lcms2-devel libimagequant-devel patchelf \
1830 libraqm-devel openjpeg2-devel tcl-devel tk-devel unixODBC-devel
1931
20- curl --proto ' =https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
32+ # Install build tools and libraries needed for compiling PyTorch/PyArrow
33+ if [[ $( uname -m) == " s390x" ]]; then
34+ dnf install -y gcc gcc-gfortran gcc-c++ make cmake ninja-build \
35+ autoconf automake libtool pkg-config \
36+ python3.12-devel python3-devel pybind11-devel \
37+ openssl-devel openblas-devel \
38+ libjpeg-devel zlib-devel libtiff-devel freetype-devel \
39+ lcms2-devel libwebp-devel \
40+ fribidi-devel openjpeg2-devel libraqm-devel libimagequant-devel \
41+ tcl-devel tk-devel unixODBC-devel \
42+ git tar wget unzip
43+ else
44+ # ppc64le packages
45+ dnf install -y fribidi-devel lcms2-devel libimagequant-devel \
46+ libraqm-devel openjpeg2-devel tcl-devel tk-devel unixODBC-devel
47+ fi
48+
49+ # Install Rust for both ppc64le and s390x
50+ curl --proto ' =https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
51+ source $HOME /.cargo/env
2152
22- source /opt/rh/gcc-toolset-13/enable
23- source $HOME /.cargo/env
24-
25- uv pip install cmake
53+ # Install cmake via pip (already available via dnf for s390x, but this ensures it's in PATH)
54+ uv pip install cmake
55+
56+ # Set python alternatives for s390x
57+ if [[ $( uname -m) == " s390x" ]]; then
58+ alternatives --install /usr/bin/python python /usr/bin/python3.12 1
59+ alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
60+ alternatives --install /usr/bin/python3-config python3-config /usr/bin/python3.12-config 1
61+ alternatives --install /usr/bin/python3-devel python3-devel /usr/bin/python3.12-devel 1
62+ python --version && python3 --version
63+ fi
2664
2765 export MAX_JOBS=${MAX_JOBS:- $(nproc)}
28- export OPENBLAS_VERSION=${OPENBLAS_VERSION:- 0.3.30}
29-
30- # Install OpenBlas
31- # IMPORTANT: Ensure Openblas is installed in the final image
32- cd /root
33- curl -L https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION} /OpenBLAS-${OPENBLAS_VERSION} .tar.gz | tar xz
34- # rename directory for mounting (without knowing version numbers) in multistage builds
35- mv OpenBLAS-${OPENBLAS_VERSION} / OpenBLAS/
36- cd OpenBLAS/
37- make -j${MAX_JOBS} TARGET=POWER9 BINARY=64 USE_OPENMP=1 USE_THREAD=1 NUM_THREADS=120 DYNAMIC_ARCH=1 INTERFACE64=0
38- make install
39- cd ..
40-
41- # set path for openblas
42- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH :/opt/OpenBLAS/lib/:/usr/local/lib64:/usr/local/lib
43- export PKG_CONFIG_PATH=$( find / -type d -name " pkgconfig" 2> /dev/null | tr ' \n' ' :' )
44- export CMAKE_ARGS=" -DPython3_EXECUTABLE=python"
66+
67+ # For s390x, we use the system openblas-devel package
68+ # Only build OpenBLAS from source for ppc64le
69+ if [[ $( uname -m) == " ppc64le" ]]; then
70+ export OPENBLAS_VERSION=${OPENBLAS_VERSION:- 0.3.30}
71+ cd /root
72+ curl -L https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION} /OpenBLAS-${OPENBLAS_VERSION} .tar.gz | tar xz
73+ mv OpenBLAS-${OPENBLAS_VERSION} / OpenBLAS/
74+ cd OpenBLAS/
75+ make -j${MAX_JOBS} TARGET=POWER9 BINARY=64 USE_OPENMP=1 USE_THREAD=1 NUM_THREADS=120 DYNAMIC_ARCH=1 INTERFACE64=0
76+ make PREFIX=/usr/local install NO_STATIC=1
77+ cd ..
78+ else
79+ # Create empty OpenBLAS directory for s390x (for Docker mount compatibility)
80+ mkdir -p /root/OpenBLAS/
81+ fi
82+
83+ # Verify OpenBLAS is found by pkg-config for s390x
84+ if [[ $( uname -m) == " s390x" ]]; then
85+ echo " Checking OpenBLAS pkg-config..."
86+ pkg-config --exists openblas || echo " Warning: openblas.pc not found"
87+ fi
88+
89+ export CMAKE_ARGS=" -DPython3_EXECUTABLE=python -DCMAKE_PREFIX_PATH=/usr/local"
4590 export CMAKE_POLICY_VERSION_MINIMUM=3.5
4691
4792 TMP=$( mktemp -d)
@@ -50,36 +95,82 @@ if [[ $(uname -m) == "ppc64le" ]]; then
5095 cd ${CURDIR}
5196 TORCH_VERSION=$( grep -A1 ' "torch"' pylock.toml | grep -Eo ' \b[0-9\.]+\b' )
5297 cd ${TMP}
53- git clone --recursive https://github.com/pytorch/pytorch.git -b v${TORCH_VERSION}
54- cd pytorch
55- uv pip install -r requirements.txt
56- python setup.py develop
57- rm -f dist/torch* +git* whl
58- MAX_JOBS=${MAX_JOBS:- $(nproc)} \
59- PYTORCH_BUILD_VERSION=${TORCH_VERSION} PYTORCH_BUILD_NUMBER=1 uv build --wheel --out-dir ${WHEELS_DIR}
98+ if [[ $( uname -m) == " s390x" ]]; then
99+ echo " Building PyTorch for s390x"
100+ export CMAKE_C_FLAGS=" -fPIC -O2"
101+ export CMAKE_CXX_FLAGS=" -fPIC -O2"
102+ export CFLAGS=" -O2 -pipe"
103+ export CXXFLAGS=" -O2 -pipe"
104+ git clone --depth 1 --branch " v${TORCH_VERSION} " --recurse-submodules --shallow-submodules https://github.com/pytorch/pytorch.git
105+ cd pytorch
106+ pip install --no-cache-dir -r requirements.txt
107+ python setup.py develop
108+ rm -f dist/torch* +git* whl
109+ MAX_JOBS=${MAX_JOBS} PYTORCH_BUILD_VERSION=${TORCH_VERSION} PYTORCH_BUILD_NUMBER=1 uv build --wheel --out-dir ${WHEELS_DIR}
110+ echo " PyTorch build completed successfully"
111+ else
112+ git clone --depth 1 --branch " v${TORCH_VERSION} " --recurse-submodules --shallow-submodules https://github.com/pytorch/pytorch.git
113+ cd pytorch
114+ uv pip install -r requirements.txt
115+ python setup.py develop
116+ rm -f dist/torch* +git* whl
117+ MAX_JOBS=${MAX_JOBS:- $(nproc)} \
118+ PYTORCH_BUILD_VERSION=${TORCH_VERSION} PYTORCH_BUILD_NUMBER=1 uv build --wheel --out-dir ${WHEELS_DIR}
119+ fi
60120
61121 cd ${CURDIR}
62122 # Pyarrow
63123 PYARROW_VERSION=$( grep -A1 ' "pyarrow"' pylock.toml | grep -Eo ' \b[0-9\.]+\b' )
64124 cd ${TMP}
65- git clone --recursive https://github.com/apache/arrow.git -b apache-arrow- ${PYARROW_VERSION}
125+ git clone --depth 1 --branch " apache-arrow- ${PYARROW_VERSION} " --recurse-submodules --shallow-submodules https://github.com/apache/arrow.git
66126 cd arrow/cpp
67127 mkdir build && cd build && \
68- cmake -DCMAKE_BUILD_TYPE=release \
69- -DCMAKE_INSTALL_PREFIX=/usr/local \
70- -DARROW_PYTHON=ON \
71- -DARROW_BUILD_TESTS=OFF \
72- -DARROW_JEMALLOC=ON \
73- -DARROW_BUILD_STATIC=" OFF" \
74- -DARROW_PARQUET=ON \
75- .. && \
76- make install -j ${MAX_JOBS:- $(nproc)} && \
128+ # Set architecture-specific CMake flags
129+ if [[ $( uname -m) == " s390x" ]]; then
130+ ARROW_CMAKE_FLAGS=" -DCMAKE_BUILD_TYPE=Release \
131+ -DCMAKE_INSTALL_PREFIX=/usr/local \
132+ -DARROW_PYTHON=ON \
133+ -DARROW_PARQUET=ON \
134+ -DARROW_ORC=ON \
135+ -DARROW_FILESYSTEM=ON \
136+ -DARROW_JSON=ON \
137+ -DARROW_CSV=ON \
138+ -DARROW_DATASET=ON \
139+ -DARROW_DEPENDENCY_SOURCE=BUNDLED \
140+ -DARROW_WITH_LZ4=OFF \
141+ -DARROW_WITH_ZSTD=OFF \
142+ -DARROW_WITH_SNAPPY=OFF \
143+ -DARROW_BUILD_TESTS=OFF \
144+ -DARROW_BUILD_BENCHMARKS=OFF"
145+ else
146+ ARROW_CMAKE_FLAGS=" -DCMAKE_BUILD_TYPE=release \
147+ -DCMAKE_INSTALL_PREFIX=/usr/local \
148+ -DARROW_PYTHON=ON \
149+ -DARROW_BUILD_TESTS=OFF \
150+ -DARROW_JEMALLOC=ON \
151+ -DARROW_BUILD_STATIC=OFF \
152+ -DARROW_PARQUET=ON"
153+ fi && \
154+ cmake ${ARROW_CMAKE_FLAGS} .. && \
155+ make -j${MAX_JOBS} VERBOSE=1 && \
156+ make install -j${MAX_JOBS} && \
77157 cd ../../python/ && \
78- uv pip install -v -r requirements-wheel-build.txt && \
79- PYARROW_PARALLEL=${PYARROW_PARALLEL:- $(nproc)} \
80- python setup.py build_ext \
81- --build-type=release --bundle-arrow-cpp \
82- bdist_wheel --dist-dir ${WHEELS_DIR}
158+ uv pip install -v -r requirements-build.txt && \
159+ if [[ $( uname -m) == " s390x" ]]; then
160+ PYARROW_WITH_PARQUET=1 \
161+ PYARROW_WITH_DATASET=1 \
162+ PYARROW_WITH_FILESYSTEM=1 \
163+ PYARROW_WITH_JSON=1 \
164+ PYARROW_WITH_CSV=1 \
165+ PYARROW_PARALLEL=${MAX_JOBS} \
166+ python setup.py build_ext --build-type=release --bundle-arrow-cpp bdist_wheel
167+ else
168+ PYARROW_PARALLEL=${PYARROW_PARALLEL:- $(nproc)} \
169+ python setup.py build_ext \
170+ --build-type=release --bundle-arrow-cpp \
171+ bdist_wheel
172+ fi && \
173+ mkdir -p /wheelsdir && cp dist/pyarrow-* .whl /wheelsdir/ && cp dist/pyarrow-* .whl ${WHEELS_DIR} /
83174
84175 # Pillow (use auditwheel repaired wheel to avoid pulling runtime libs from EPEL)
85176 cd ${CURDIR}
@@ -97,11 +188,15 @@ if [[ $(uname -m) == "ppc64le" ]]; then
97188 ls -ltr ${WHEELS_DIR}
98189
99190 cd ${CURDIR}
100- uv pip install --refresh ${WHEELS_DIR} /* .whl accelerate==$( grep -A1 ' "accelerate"' pylock.toml | grep -Eo ' \b[0-9\.]+\b' )
191+ # Install wheels for s390x and ppc64le
192+ if [[ $( uname -m) == " ppc64le" ]] || [[ $( uname -m) == " s390x" ]]; then
193+ pip install --no-cache-dir " ${WHEELS_DIR} " /* .whl
194+ uv pip install --refresh ${WHEELS_DIR} /* .whl accelerate==$( grep -A1 ' "accelerate"' pylock.toml | grep -Eo ' \b[0-9\.]+\b' )
195+ fi
101196
102197 uv pip list
103198 cd ${CURDIR}
104199else
105- # only for mounting on non-ppc64le
200+ # only for mounting on non-ppc64le and non-s390x
106201 mkdir -p /root/OpenBLAS/
107202fi
0 commit comments