Skip to content

Build Cross-Platform Wheels #17

Build Cross-Platform Wheels

Build Cross-Platform Wheels #17

name: Build Cross-Platform Wheels
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
cuda_versions:
description: 'CUDA versions to build for (comma-separated)'
required: false
default: '11.8,12.1'
pytorch_version:
description: 'PyTorch version to install (e.g., "2.1.0", "latest")'
required: false
default: 'latest'
platforms:
description: 'Platforms to build for (comma-separated: windows,linux)'
required: false
default: 'windows,linux'
jobs:
build_wheels:
name: Build wheels on ${{ matrix.platform.name }} for CUDA ${{ matrix.cuda_version }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- name: linux
os: ubuntu-22.04
- name: windows
os: windows-2022
cuda_version: ['11.8', '12.1', '12.4', '12.6', '12.8']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install CUDA Toolkit ${{ matrix.cuda_version }} (Windows)
if: matrix.platform.os == 'windows-2022'
uses: Jimver/cuda-toolkit@v0.2.23
with:
cuda: ${{ matrix.cuda_version }}.0
method: 'network'
sub-packages: '["nvcc", "cudart", "cublas", "curand", "cufft", "cusparse", "cusolver"]'
- name: Setup Visual Studio environment (Windows)
if: matrix.platform.os == 'windows-2022'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Build wheels
uses: pypa/cibuildwheel@v3.0.0
env:
# Pass matrix and input variables to cibuildwheel's environment
PYTORCH_VERSION: ${{ github.event.inputs.pytorch_version || 'latest' }}
CUDA_VERSION: ${{ matrix.cuda_version }}
# Configure cibuildwheel
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
CIBW_SKIP: ${{ matrix.cuda_version == '11.8' && 'cp312-*' || '' }}
CIBW_BEFORE_BUILD_LINUX: |
set -euxo pipefail
dnf install -y gcc-c++ sparsehash-devel
bash .github/tools/install_pytorch.sh
CIBW_BEFORE_BUILD_WINDOWS: |
powershell -Command "Invoke-WebRequest -Uri https://github.com/sparsehash/sparsehash/archive/refs/tags/sparsehash-2.0.4.zip -OutFile sparsehash.zip"
powershell -Command "Expand-Archive -Path sparsehash.zip -DestinationPath C:\"
powershell -Command "Rename-Item C:\sparsehash-sparsehash-2.0.4 C:\sparsehash"
powershell -ExecutionPolicy Bypass -File .github/tools/install_pytorch.ps1
CIBW_ENVIRONMENT_LINUX: >
CXXFLAGS="-O2 -fopenmp"
CFLAGS="-O2"
FORCE_CUDA=1
TORCH_CUDA_ARCH_LIST="7.5;8.0;8.6;8.9"
MAX_JOBS=4
CIBW_ENVIRONMENT_WINDOWS: >
CL="/O1 /MP4"
DISTUTILS_USE_SDK=1
MSSdk=1
FORCE_CUDA=1
TORCH_CUDA_ARCH_LIST="7.5;8.0;8.6;8.9"
INCLUDE="$INCLUDE;C:\sparsehash\src"
CIBW_BEFORE_TEST_LINUX: |
bash .github/tools/install_pytorch.sh
CIBW_BEFORE_TEST_WINDOWS: |
powershell -ExecutionPolicy Bypass -File .github/tools/install_pytorch.ps1
CIBW_TEST_COMMAND_WINDOWS: "python -c \"import torch; import torchsparse; print(f'TorchSparse version: {torchsparse.__version__}')\""
CIBW_TEST_COMMAND_LINUX: "python -c 'import torch; import torchsparse; print(f\"TorchSparse version: {torchsparse.__version__}\")'"
CIBW_BUILD_VERBOSITY: 1
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.name }}-cuda${{ matrix.cuda_version }}
path: ./wheelhouse/*.whl
create-release:
needs: build_wheels
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download all wheel artifacts
uses: actions/download-artifact@v4
with:
path: wheels
pattern: wheels-*
merge-multiple: true
- name: Organize wheels and create release
run: |
mkdir -p release
find wheels -name "*.whl" -exec cp {} release/ \;
ls -la release/
gh release create ${{ github.ref_name }} --generate-notes --title "TorchSparse ${{ github.ref_name }} - Cross-Platform Release" release/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test-wheels:
needs: build_wheels
strategy:
fail-fast: false
matrix:
platform:
- name: linux
os: ubuntu-22.04
- name: windows
os: windows-2022
python-version: ['3.10']
cuda-version: ['12.1']
runs-on: ${{ matrix.platform.os }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up python-version-nodot
id: py-ver
run: echo "nodot=$(echo ${{ matrix.python-version }} | tr -d .)" >> $GITHUB_ENV
- name: Install CUDA Toolkit (if needed for testing runtime)
if: matrix.platform.os == 'windows-2022'
uses: Jimver/cuda-toolkit@v0.2.23
with:
cuda: ${{ matrix.cuda_version }}.0
method: 'network'
- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
name: wheels-${{ matrix.platform.name }}-cuda${{ matrix.cuda_version }}
path: wheels
- name: Install PyTorch (for testing)
run: pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 --index-url https://download.pytorch.org/whl/cu121
- name: Test wheel installation and functionality
shell: bash
run: |
wheel_file=$(find wheels -name "*cp${{ env.nodot }}*.whl" | head -1)
pip install "$wheel_file"
python -c "import torch; import torchsparse; print('TorchSparse version:', torchsparse.__version__); print('PyTorch version:', torch.__version__); print('CUDA available:', torch.cuda.is_available())"