forked from mit-han-lab/torchsparse
-
-
Notifications
You must be signed in to change notification settings - Fork 5
571 lines (479 loc) · 19.7 KB
/
build-windows-wheels.yml
File metadata and controls
571 lines (479 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
name: Build Cross-Platform Wheels
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
python_versions:
description: 'Python versions to build (comma-separated)'
required: false
default: '3.8,3.9,3.10,3.11,3.12'
cuda_versions:
description: 'CUDA versions to build (comma-separated)'
required: false
default: '11.8,12.1,12.4,12.6,12.8'
pytorch_version:
description: 'PyTorch version to install (e.g., "2.1.0", "2.4.0", or "latest" for newest)'
required: false
default: 'latest'
platforms:
description: 'Platforms to build for (comma-separated: windows,linux)'
required: false
default: 'windows,linux'
build_latest_only:
description: 'Build only latest PyTorch version for each CUDA version'
required: false
default: 'true'
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Generate build matrix
id: set-matrix
run: |
# Get input parameters or use defaults
python_versions="${{ github.event.inputs.python_versions || '3.8,3.9,3.10,3.11,3.12' }}"
cuda_versions="${{ github.event.inputs.cuda_versions || '11.8,12.1,12.4,12.6,12.8' }}"
platforms="${{ github.event.inputs.platforms || 'windows,linux' }}"
# Convert comma-separated strings to arrays
IFS=',' read -ra PYTHON_ARRAY <<< "$python_versions"
IFS=',' read -ra CUDA_ARRAY <<< "$cuda_versions"
IFS=',' read -ra PLATFORM_ARRAY <<< "$platforms"
# Map platforms to OS
os_array=()
for platform in "${PLATFORM_ARRAY[@]}"; do
case "$platform" in
"windows") os_array+=("windows-2022") ;;
"linux") os_array+=("ubuntu-22.04") ;;
esac
done
# Build matrix JSON
matrix_json="{\"include\":["
first=true
for os in "${os_array[@]}"; do
for python in "${PYTHON_ARRAY[@]}"; do
for cuda in "${CUDA_ARRAY[@]}"; do
# Skip Python 3.12 with CUDA 11.8 for compatibility
if [[ "$python" == "3.12" && "$cuda" == "11.8" ]]; then
continue
fi
if [ "$first" = true ]; then
first=false
else
matrix_json+=","
fi
matrix_json+="{\"os\":\"$os\",\"python-version\":\"$python\",\"cuda-version\":\"$cuda\"}"
done
done
done
matrix_json+="]}"
echo "Generated matrix: $matrix_json"
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
build-wheels:
needs: generate-matrix
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libsparsehash-dev
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install CUDA Toolkit ${{ matrix.cuda-version }}
if: runner.os == 'Windows' # Only install CUDA Toolkit on Windows; Linux uses PyTorch wheels with CUDA runtime
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: Install sparsehash (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Download and extract sparsehash
Invoke-WebRequest -Uri "https://github.com/sparsehash/sparsehash/archive/refs/tags/sparsehash-2.0.4.zip" -OutFile "sparsehash.zip"
Expand-Archive -Path "sparsehash.zip" -DestinationPath "C:\"
Rename-Item "C:\sparsehash-sparsehash-2.0.4" "C:\sparsehash"
# Set environment variable for subsequent steps
echo "INCLUDE=$env:INCLUDE;C:\sparsehash\src" >> $env:GITHUB_ENV
- name: Setup Visual Studio environment (Windows)
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Install sparsehash (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Download and extract sparsehash
Invoke-WebRequest -Uri "https://github.com/sparsehash/sparsehash/archive/refs/tags/sparsehash-2.0.4.zip" -OutFile "sparsehash.zip"
Expand-Archive -Path "sparsehash.zip" -DestinationPath "C:\"
Rename-Item "C:\sparsehash-sparsehash-2.0.4" "C:\sparsehash"
# Set environment variable for subsequent steps
echo "INCLUDE=$env:INCLUDE;C:\sparsehash\src" >> $env:GITHUB_ENV
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libsparsehash-dev
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools ninja
- name: Install PyTorch (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$cuda_version = "${{ matrix.cuda-version }}"
$pytorch_version = "${{ github.event.inputs.pytorch_version || 'latest' }}"
# Determine CUDA short version for wheel index
$cuda_short = switch ($cuda_version) {
"11.8" { "cu118" }
"12.1" { "cu121" }
"12.4" { "cu124" }
"12.6" { "cu126" }
"12.8" { "cu128" }
default {
Write-Error "Unsupported CUDA version: $cuda_version"
exit 1
}
}
$index_url = "https://download.pytorch.org/whl/$cuda_short"
if ($pytorch_version -eq "latest") {
Write-Host "Installing latest PyTorch for CUDA $cuda_version"
pip install torch torchvision --index-url $index_url
} else {
Write-Host "Installing PyTorch $pytorch_version for CUDA $cuda_version"
# For specific versions, we need to determine compatible torchvision version
# This is a simplified mapping - in practice, you might want more sophisticated logic
$torchvision_version = switch ($pytorch_version) {
"2.0.1" { "0.15.2" }
"2.1.0" { "0.16.0" }
"2.4.0" { "0.19.0" }
"2.5.0" { "0.20.0" }
default {
Write-Host "Warning: Unknown torchvision version for PyTorch $pytorch_version, installing without version constraint"
$null
}
}
if ($torchvision_version) {
pip install "torch==$pytorch_version+$cuda_short" "torchvision==$torchvision_version+$cuda_short" --index-url $index_url
} else {
pip install "torch==$pytorch_version+$cuda_short" torchvision --index-url $index_url
}
}
- name: Install PyTorch (Linux)
if: runner.os == 'Linux'
run: |
cuda_version="${{ matrix.cuda-version }}"
pytorch_version="${{ github.event.inputs.pytorch_version || 'latest' }}"
# Determine CUDA short version for wheel index
case "$cuda_version" in
"11.8")
cuda_short="cu118"
;;
"12.1")
cuda_short="cu121"
;;
"12.4")
cuda_short="cu124"
;;
"12.6")
cuda_short="cu126"
;;
"12.8")
cuda_short="cu128"
;;
*)
echo "Error: Unsupported CUDA version: $cuda_version"
exit 1
;;
esac
index_url="https://download.pytorch.org/whl/$cuda_short"
if [ "$pytorch_version" = "latest" ]; then
echo "Installing latest PyTorch for CUDA $cuda_version"
pip install torch torchvision --index-url "$index_url"
else
echo "Installing PyTorch $pytorch_version for CUDA $cuda_version"
# Determine compatible torchvision version
case "$pytorch_version" in
"2.0.1")
torchvision_version="0.15.2"
;;
"2.1.0")
torchvision_version="0.16.0"
;;
"2.4.0")
torchvision_version="0.19.0"
;;
"2.5.0")
torchvision_version="0.20.0"
;;
*)
echo "Warning: Unknown torchvision version for PyTorch $pytorch_version, installing without version constraint"
torchvision_version=""
;;
esac
if [ -n "$torchvision_version" ]; then
pip install "torch==$pytorch_version+$cuda_short" "torchvision==$torchvision_version+$cuda_short" --index-url "$index_url"
else
pip install "torch==$pytorch_version+$cuda_short" torchvision --index-url "$index_url"
fi
fi
- name: Set build environment (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Set environment variables for optimized Windows build
echo "CL=/O1 /MP4" >> $env:GITHUB_ENV
echo "DISTUTILS_USE_SDK=1" >> $env:GITHUB_ENV
echo "MSSdk=1" >> $env:GITHUB_ENV
echo "FORCE_CUDA=1" >> $env:GITHUB_ENV
echo "TORCH_CUDA_ARCH_LIST=7.5;8.0;8.6;8.9" >> $env:GITHUB_ENV
- name: Set build environment (Linux)
if: runner.os == 'Linux'
run: |
# Set environment variables for optimized Linux build
echo "CXXFLAGS=-O2 -fopenmp" >> $GITHUB_ENV
echo "CFLAGS=-O2" >> $GITHUB_ENV
echo "FORCE_CUDA=1" >> $GITHUB_ENV
echo "TORCH_CUDA_ARCH_LIST=7.5;8.0;8.6;8.9" >> $GITHUB_ENV
echo "MAX_JOBS=4" >> $GITHUB_ENV
- name: Build wheel
run: |
python setup.py bdist_wheel
env:
INCLUDE: ${{ env.INCLUDE }}
- name: Test wheel installation (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Install the built wheel
$wheel = Get-ChildItem -Path "dist" -Filter "*.whl" | Select-Object -First 1
pip install $wheel.FullName
# Test basic functionality
python -c "import torchsparse; print(f'TorchSparse version: {torchsparse.__version__}')"
python -c "import torch; import torchsparse; print('Basic import test passed')"
- name: Test wheel installation (Linux)
if: runner.os == 'Linux'
run: |
# Install the built wheel
wheel=$(find dist -name "*.whl" | head -1)
pip install "$wheel"
# Test basic functionality
python -c "import torchsparse; print(f'TorchSparse version: {torchsparse.__version__}')"
python -c "import torch; import torchsparse; print('Basic import test passed')"
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ runner.os }}-python${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}
path: dist/*.whl
create-release:
needs: build-wheels
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all wheel artifacts
uses: actions/download-artifact@v4
with:
path: wheels
- name: Organize wheels
run: |
mkdir -p release
find wheels -name "*.whl" -exec cp {} release/ \;
ls -la release/
- name: Create release notes
run: |
cat > release_notes.md << 'EOF'
# TorchSparse v${{ github.ref_name }} - Cross-Platform Release
## 🎉 What's New
This release provides comprehensive cross-platform support for TorchSparse with extensive compatibility fixes and expanded version support.
### ✅ Platform Support
- **Windows**: Full native support with MSVC compatibility
- **Linux**: Enhanced build system with automatic dependency resolution
- **Cross-Platform**: Unified build system for both platforms
### 🔧 Compatibility Features
- **MSVC Compatibility**: Full support for Visual Studio 2019/2022
- **GCC Support**: Optimized builds for Linux environments
- **Type Safety**: Fixed all platform-specific type issues
- **Dependency Resolution**: Automated sparsehash handling
- **Memory Optimization**: Platform-specific build optimizations
### 📦 Available Packages
| Platform | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 | Python 3.12 |
|----------|-------------|-------------|--------------|-------------|-------------|
| **Windows** | | | | | |
| CUDA 11.8 | ✅ | ✅ | ✅ | ✅ | ❌ |
| CUDA 12.1 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.4 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.6 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.8 | ✅ | ✅ | ✅ | ✅ | ✅ |
| **Linux** | | | | | |
| CUDA 11.8 | ✅ | ✅ | ✅ | ✅ | ❌ |
| CUDA 12.1 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.4 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.6 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CUDA 12.8 | ✅ | ✅ | ✅ | ✅ | ✅ |
### 🚀 Quick Installation
```bash
# Windows - Download appropriate wheel
pip install [windows_wheel_name_from_assets_below]
# Linux - Download appropriate wheel
pip install [linux_wheel_name_from_assets_below]
# Or install directly from GitHub
pip install git+https://github.com/Deathdadev/torchsparse.git
```
### ⚙️ Build Configuration Options
The workflow supports flexible PyTorch version selection:
- **Latest PyTorch**: Use `pytorch_version: "latest"` (default) for newest compatible versions
- **Specific PyTorch**: Use `pytorch_version: "2.4.0"` for reproducible builds
- **CUDA Compatibility**: Automatic CUDA wheel index selection (cu118, cu121, cu124, cu126, cu128)
### 📋 System Requirements
**Windows:**
- OS: Windows 10/11 (x64)
- Python: 3.8-3.12
- PyTorch: 1.9.0+ to 2.5.0+
- CUDA: 11.8, 12.1, 12.4, 12.6, or 12.8
- Visual Studio: 2019 or 2022
**Linux:**
- OS: Ubuntu 20.04+, CentOS 8+, or equivalent
- Python: 3.8-3.12
- PyTorch: 1.9.0+ to 2.5.0+
- CUDA: 11.8, 12.1, 12.4, 12.6, or 12.8
- GCC: 9.0+
### 🎯 PyTorch & CUDA Version Support
| CUDA Version | Supported PyTorch Versions | Wheel Index |
|--------------|----------------------------|-------------|
| 11.8 | 2.0.0+ (latest recommended) | cu118 |
| 12.1 | 2.1.0+ (latest recommended) | cu121 |
| 12.4 | 2.4.0+ (latest recommended) | cu124 |
| 12.6 | 2.5.0+ (latest recommended) | cu126 |
| 12.8 | 2.5.0+ (latest recommended) | cu128 |
**Note**: The workflow supports both specific PyTorch versions and "latest" for maximum flexibility.
When using "latest", the newest compatible PyTorch version for each CUDA version is automatically installed.
### 📚 Documentation
- [Cross-Platform Setup Guide](CROSS_PLATFORM_SETUP_GUIDE.md)
- [Troubleshooting Guide](TROUBLESHOOTING.md)
- [Build Instructions](build_wheels.py)
- [Installation Verification](verify_installation.py)
### 🐛 Bug Fixes
- Fixed MSVC compilation errors on Windows
- Resolved memory exhaustion during builds
- Fixed sparsehash dependency issues across platforms
- Improved cross-platform environment detection
- Enhanced build system for multiple PyTorch versions
### 🔄 Build System Improvements
- Automated cross-platform wheel building
- Support for multiple PyTorch/CUDA combinations
- Intelligent dependency resolution
- Platform-specific optimizations
- Comprehensive testing pipeline
---
**Note**: These wheels support both Windows and Linux with comprehensive version coverage.
Choose the appropriate wheel for your platform, Python version, and CUDA version.
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: release/*.whl
body_path: release_notes.md
tag_name: ${{ github.ref_name }}
name: TorchSparse ${{ github.ref_name }} - Cross-Platform Release
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test-wheels:
needs: [build-wheels, generate-matrix]
strategy:
matrix:
os: [windows-2022, ubuntu-22.04]
python-version: ['3.10'] # Test with one version
cuda-version: ['12.1'] # Test with stable CUDA version
runs-on: ${{ matrix.os }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install CUDA Toolkit ${{ matrix.cuda-version }}
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-${{ runner.os }}-python${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}
path: wheels
- name: Install PyTorch (Windows)
if: runner.os == 'Windows'
run: |
pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 --index-url https://download.pytorch.org/whl/cu121
- name: Install PyTorch (Linux)
if: runner.os == 'Linux'
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 (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
# Install the wheel
$wheel = Get-ChildItem -Path "wheels" -Filter "*.whl" | Select-Object -First 1
pip install $wheel.FullName
# Run comprehensive tests
python -c "
import torch
import torchsparse
import numpy as np
print(f'TorchSparse version: {torchsparse.__version__}')
print(f'PyTorch version: {torch.__version__}')
print(f'CUDA available: {torch.cuda.is_available()}')
print(f'Platform: Windows')
# Test basic functionality
coords = torch.randint(0, 10, (100, 4))
feats = torch.randn(100, 16)
if torch.cuda.is_available():
coords = coords.cuda()
feats = feats.cuda()
sparse_tensor = torchsparse.SparseTensor(coords=coords, feats=feats)
print(f'Sparse tensor shape: {sparse_tensor.shape}')
print('✅ All tests passed!')
"
- name: Test wheel installation and functionality (Linux)
if: runner.os == 'Linux'
run: |
# Install the wheel
wheel=$(find wheels -name "*.whl" | head -1)
pip install "$wheel"
# Run comprehensive tests
python -c "
import torch
import torchsparse
import numpy as np
print(f'TorchSparse version: {torchsparse.__version__}')
print(f'PyTorch version: {torch.__version__}')
print(f'CUDA available: {torch.cuda.is_available()}')
print(f'Platform: Linux')
# Test basic functionality
coords = torch.randint(0, 10, (100, 4))
feats = torch.randn(100, 16)
if torch.cuda.is_available():
coords = coords.cuda()
feats = feats.cuda()
sparse_tensor = torchsparse.SparseTensor(coords=coords, feats=feats)
print(f'Sparse tensor shape: {sparse_tensor.shape}')
print('✅ All tests passed!')
'