Skip to content

Commit

Permalink
Merge pull request #549 from janden/cufinufft_wheel_building
Browse files Browse the repository at this point in the history
Update cufinufft wheel building scripts
  • Loading branch information
ahbarnett authored Sep 5, 2024
2 parents 0ac0721 + 2f93d8a commit 24cf795
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 74 deletions.
73 changes: 32 additions & 41 deletions tools/cufinufft/distribution_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,59 @@

# Helper Script For Building Wheels

cufinufft_version=2.2
manylinux_version=manylinux2014
cuda_version=11.0
cuda_version=11.2
dockerhub=janden

image_name=cufinufft-cuda${cuda_version}

echo "# Build the docker image"
docker build \
--file tools/cufinufft/docker/cuda${cuda_version}/Dockerfile-x86_64 \
--tag ${dockerhub}/cufinufft-${cufinufft_version}-${manylinux_version} .

--tag ${dockerhub}/cufinufft-cuda${cuda_version} \
.

echo "# Create the container and start it"
docker create \
--gpus all \
--interactive \
--tty \
--volume $(pwd)/wheelhouse:/io/wheelhouse \
--env PLAT=${manylinux_version}_x86_64 \
--env LIBRARY_PATH="/io/build" \
--env LD_LIBRARY_PATH="/io/build" \
--name cufinufft \
${dockerhub}/cufinufft-${cufinufft_version}-${manylinux_version}
--name ${image_name} \
${dockerhub}/${image_name}

docker start cufinufft
docker start ${image_name}

echo "# Copy the code and build the library"
docker cp . cufinufft:/io
docker exec cufinufft /io/tools/cufinufft/build-library.sh
echo "# Copy the code"
docker cp . ${image_name}:/io

echo "# Build the wheels"
docker exec cufinufft /io/tools/cufinufft/build-wheels.sh
docker exec ${image_name} \
python3 -m pip wheel \
--verbose \
/io/python/cufinufft \
--config-settings=cmake.define.FINUFFT_CUDA_ARCHITECTURES="50;60;70;80" \
--config-settings=cmake.define.CMAKE_CUDA_FLAGS="-Wno-deprecated-gpu-targets" \
--config-settings=cmake.define.FINUFFT_ARCH_FLAGS="" \
--config-settings=cmake.define.CMAKE_VERBOSE_MAKEFILE=ON \
--no-deps \
--wheel-dir /io/wheelhouse

wheel_name=$(docker exec ${image_name} bash -c 'ls /io/wheelhouse/cufinufft-*-linux_x86_64.whl')

echo "# Repair the wheels"
docker exec ${image_name} \
python3 -m auditwheel repair \
${wheel_name} \
--plat manylinux2014_x86_64 \
--wheel-dir /io/wheelhouse/

echo "# Shut down the container and remove it"
docker stop cufinufft
docker rm cufinufft
docker stop ${image_name}
docker rm ${image_name}

echo "# Copy the wheels we care about to the dist folder"
mkdir -p dist
cp -v wheelhouse/cufinufft-${cufinufft_version}-cp3*${manylinux_version}* dist

echo "The following steps should be performed manually for now.\n"

echo "# Push to Test PyPI for review/testing"
echo "#twine upload -r testpypi dist/*"
echo


echo "# Tag release."
## Can do in a repo and push or on manually on GH gui.
echo


echo "# Review wheels from test index"
echo "#pip install -i https://test.pypi.org/simple/ --no-deps cufinufft"
echo


echo "# Push to live index"
echo "## twine upload dist/*"
echo

cp -v wheelhouse/cufinufft-*${manylinux_version}* dist

echo "# optionally push it (might take a long time)."
echo "#docker push ${dockerhub}/cufinufft-${cufinufft_version}-${manylinux_version}"
# TODO: Test installing the wheels and running pytest.
5 changes: 5 additions & 0 deletions tools/cufinufft/docker/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
These configurations are based off of manylinux2014, which is itself based off
of centos8.

These images extend manylinux with a compatible CUDA toolkit and runtime
environment suitable for both building and running code inside docker.
9 changes: 9 additions & 0 deletions tools/cufinufft/docker/cuda11.2/Dockerfile-x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ ENV PATH /opt/rh/devtoolset-9/root/usr/bin:${PATH}
RUN yum install -y \
cmake && \
rm -rf /var/cache/yum/*

# pick py312 as default
RUN ln -s /opt/python/cp312-cp312/bin/python3 /usr/bin/python3

# upgrade pip, install auditwheel
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir --upgrade auditwheel

CMD ["/bin/bash"]
6 changes: 0 additions & 6 deletions tools/cufinufft/docker/cuda11.2/README

This file was deleted.

74 changes: 74 additions & 0 deletions tools/cufinufft/docker/cuda11.8/Dockerfile-x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM quay.io/pypa/manylinux2014_x86_64
LABEL maintainer "Joakim Andén"

ENV CUDA_MAJOR 11
ENV CUDA_MINOR 8
ENV CUDA_DASH_VERSION ${CUDA_MAJOR}-${CUDA_MINOR}
ENV CUDA_DOT_VERSION ${CUDA_MAJOR}.${CUDA_MINOR}

# ---- The following block adds layers for CUDA --- #
# base
RUN NVIDIA_GPGKEY_SUM=d0664fbbdb8c32356d45de36c5984617217b2d0bef41b93ccecd326ba3b80c87 && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/D42D0685.pub | sed '/^Version/d' > /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA && \
echo "$NVIDIA_GPGKEY_SUM /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA" | sha256sum -c --strict -

COPY tools/cufinufft/docker/cuda${CUDA_DOT_VERSION}/cuda.repo /etc/yum.repos.d/cuda.repo

# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a
RUN yum install -y \
cuda-cudart-${CUDA_DASH_VERSION} \
cuda-compat-${CUDA_DASH_VERSION} && \
ln -s cuda-${CUDA_DOT_VERSION} /usr/local/cuda && \
rm -rf /var/cache/yum/*

# nvidia-docker 1.0
RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf

ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib:/usr/local/nvidia/lib64

# nvidia-container-runtime
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
ENV NVIDIA_REQUIRE_CUDA "cuda>=${CUDA_DOT_VERSION} brand=tesla,driver>=418,driver<419 brand=tesla,driver>=440,driver<441"

# runtime
RUN yum install -y \
cuda-libraries-${CUDA_DASH_VERSION} \
cuda-nvtx-${CUDA_DASH_VERSION} && \
rm -rf /var/cache/yum/*

# devel
RUN yum install -y \
cuda-cudart-devel-${CUDA_DASH_VERSION} \
cuda-libraries-devel-${CUDA_DASH_VERSION} \
cuda-nvprof-${CUDA_DASH_VERSION} \
cuda-nvcc-${CUDA_DASH_VERSION} && \
rm -rf /var/cache/yum/*

ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs

# /CUDA #

# CUDA 11 doesn't work on gcc/g++ newer than v9
RUN yum install -y \
devtoolset-9-gcc \
devtoolset-9-gcc-c++ && \
rm -rf /var/cache/yum/*

ENV PATH /opt/rh/devtoolset-9/root/usr/bin:${PATH}

# finufft reqs
RUN yum install -y \
cmake && \
rm -rf /var/cache/yum/*

# pick py312 as default
RUN ln -s /opt/python/cp312-cp312/bin/python3 /usr/bin/python3

# upgrade pip, install auditwheel
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir --upgrade auditwheel

CMD ["/bin/bash"]
6 changes: 6 additions & 0 deletions tools/cufinufft/docker/cuda11.8/cuda.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[cuda]
name=cuda
baseurl=https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA
33 changes: 6 additions & 27 deletions tools/cufinufft/docker/cuda12.0/Dockerfile-x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,11 @@ RUN yum install -y \
cmake && \
rm -rf /var/cache/yum/*

# Okay, so now we can begin cufinufft

# Only copy the C++/CUDA code (this way the cache is not invalidated by changes
# to the Python code or to the docs).
COPY src /io/src
COPY fortran /io/fortran
COPY include /io/include
COPY test /io/test
COPY perftest /io/perftest
COPY examples /io/examples
COPY cmake /io/cmake
COPY contrib /io/contrib
COPY CMakeLists.txt /io/

# Set up cmake and build the code.
RUN mkdir -p /io/build
WORKDIR /io/build
RUN cmake -D FINUFFT_USE_CUDA=ON -D FINUFFT_USE_CPU=OFF -D CMAKE_CUDA_ARCHITECTURES="50;60;70;75;80;90" -DBUILD_TESTING=ON -DFINUFFT_BUILD_TESTS=ON ..
RUN make -j4

# Need to pack the compiled library into our path.
ENV LD_LIBRARY_PATH /io/build:${LD_LIBRARY_PATH}

# Now copy the rest of the repository in.
COPY python /io/python
COPY docs /io/docs
COPY tools /io/tools
# pick py312 as default
RUN ln -s /opt/python/cp312-cp312/bin/python3 /usr/bin/python3

# upgrade pip, install auditwheel
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir --upgrade auditwheel

CMD ["/bin/bash"]

0 comments on commit 24cf795

Please sign in to comment.