Skip to content

Commit 16604c5

Browse files
committed
Added initial code
1 parent e598e43 commit 16604c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+10246
-201
lines changed

.github/workflows/build-wheels.yml

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
name: Build Wheels
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build_wheels:
12+
name: Build wheel for ${{ matrix.os }}
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-22.04, windows-2022]
18+
python-version: ["3.12"]
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Install CUDA Toolkit 13.0.2
25+
uses: Jimver/[email protected]
26+
id: cuda-toolkit
27+
with:
28+
cuda: '13.0.2'
29+
method: 'network'
30+
use-github-cache: 'true'
31+
log-file-suffix: '${{ matrix.os }}.txt'
32+
33+
- name: Set additional CUDA environment variables (Linux)
34+
if: runner.os == 'Linux'
35+
shell: bash
36+
run: |
37+
echo "LD_LIBRARY_PATH=$CUDA_PATH/lib64:$CUDA_PATH/lib64/stubs:$LD_LIBRARY_PATH" >> $GITHUB_ENV
38+
echo "LIBRARY_PATH=$CUDA_PATH/lib64:$CUDA_PATH/lib64/stubs:$LIBRARY_PATH" >> $GITHUB_ENV
39+
40+
- name: Set additional CUDA environment variables (Windows)
41+
if: runner.os == 'Windows'
42+
shell: pwsh
43+
run: |
44+
echo "CUDA_PATH_V13_0=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
45+
46+
- name: Verify CUDA installation
47+
shell: bash
48+
run: |
49+
echo "CUDA_HOME: $CUDA_HOME"
50+
echo "CUDA_PATH: $CUDA_PATH"
51+
nvcc --version
52+
53+
- name: Setup MSVC (Windows)
54+
if: runner.os == 'Windows'
55+
uses: ilammy/msvc-dev-cmd@v1
56+
57+
- name: Setup CUDA MSBuild integration (Windows)
58+
if: runner.os == 'Windows'
59+
shell: pwsh
60+
run: |
61+
# Copy CUDA MSBuild integration files to Visual Studio directory
62+
$cudaPath = $env:CUDA_PATH
63+
$cudaMSBuildSource = Join-Path $cudaPath "extras\visual_studio_integration\MSBuildExtensions"
64+
65+
if (-not (Test-Path $cudaMSBuildSource)) {
66+
Write-Error "CUDA MSBuild extensions not found at $cudaMSBuildSource"
67+
exit 1
68+
}
69+
70+
# Find Visual Studio installation
71+
$vsBasePaths = @(
72+
"C:\Program Files (x86)\Microsoft Visual Studio",
73+
"C:\Program Files\Microsoft Visual Studio"
74+
)
75+
76+
$vsVersions = @("2022", "2019")
77+
$vsEditions = @("BuildTools", "Enterprise", "Professional", "Community")
78+
$toolsets = @("v170", "v160")
79+
80+
$destinations = @()
81+
82+
foreach ($basePath in $vsBasePaths) {
83+
if (Test-Path $basePath) {
84+
foreach ($version in $vsVersions) {
85+
foreach ($edition in $vsEditions) {
86+
foreach ($toolset in $toolsets) {
87+
$vsPath = Join-Path $basePath "$version\$edition\MSBuild\Microsoft\VC\$toolset\BuildCustomizations"
88+
if (Test-Path $vsPath) {
89+
$destinations += $vsPath
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
96+
97+
if ($destinations.Count -eq 0) {
98+
Write-Error "Could not find Visual Studio MSBuild directory"
99+
exit 1
100+
}
101+
102+
# CUDA 13.0 uses versioned filenames that need to be copied as both versioned and standard names
103+
$fileMapping = @{
104+
"CUDA 13.0.props" = @("CUDA 13.0.props", "CUDA.props")
105+
"CUDA 13.0.targets" = @("CUDA 13.0.targets", "CUDA.targets")
106+
"CUDA 13.0.xml" = @("CUDA 13.0.xml", "CUDA.xml")
107+
"Nvda.Build.CudaTasks.v13.0.dll" = @("Nvda.Build.CudaTasks.v13.0.dll")
108+
}
109+
110+
$copySuccess = $false
111+
112+
foreach ($destDir in $destinations) {
113+
try {
114+
foreach ($srcFileName in $fileMapping.Keys) {
115+
$srcFile = Join-Path $cudaMSBuildSource $srcFileName
116+
117+
if (Test-Path $srcFile) {
118+
foreach ($destFileName in $fileMapping[$srcFileName]) {
119+
$destFile = Join-Path $destDir $destFileName
120+
Copy-Item -Path $srcFile -Destination $destFile -Force
121+
}
122+
}
123+
}
124+
$copySuccess = $true
125+
} catch {
126+
Write-Warning "Failed to copy to $destDir : $_"
127+
}
128+
}
129+
130+
if (-not $copySuccess) {
131+
Write-Error "Failed to copy CUDA MSBuild files to any destination"
132+
exit 1
133+
}
134+
135+
Write-Host "CUDA MSBuild integration configured successfully"
136+
137+
- name: Set up Python ${{ matrix.python-version }}
138+
uses: actions/setup-python@v5
139+
with:
140+
python-version: ${{ matrix.python-version }}
141+
142+
- name: Create python3.lib for stable ABI (Windows)
143+
if: runner.os == 'Windows'
144+
shell: pwsh
145+
run: |
146+
# Create python3.lib for stable ABI support
147+
$pythonDir = Split-Path -Parent (Get-Command python).Source
148+
$libsDir = Join-Path $pythonDir "libs"
149+
$pythonLib = Get-ChildItem -Path $libsDir -Filter "python3*.lib" | Where-Object { $_.Name -match "python3\d+\.lib" } | Select-Object -First 1
150+
151+
if ($pythonLib) {
152+
$python3Lib = Join-Path $libsDir "python3.lib"
153+
if (-not (Test-Path $python3Lib)) {
154+
Copy-Item -Path $pythonLib.FullName -Destination $python3Lib
155+
Write-Host "Created python3.lib for stable ABI"
156+
}
157+
} else {
158+
Write-Error "Could not find python3XX.lib"
159+
exit 1
160+
}
161+
162+
- name: Install CMake
163+
uses: lukka/get-cmake@latest
164+
with:
165+
cmakeVersion: "~3.27.0"
166+
167+
- name: Install build dependencies
168+
shell: bash
169+
run: |
170+
python -m pip install --upgrade pip
171+
pip install build setuptools wheel nanobind
172+
173+
- name: Build CUDA wheel (Stable ABI - cp312-abi3)
174+
shell: bash
175+
run: |
176+
# Build with default platform-specific CUDA architectures from setup.py
177+
python setup.py bdist_wheel
178+
179+
- name: Build CPU-only wheel (Linux only - py3-none-any)
180+
if: runner.os == 'Linux'
181+
shell: bash
182+
run: |
183+
# Clean build artifacts to avoid conflicts
184+
rm -rf build *.egg-info
185+
# Build CPU-only variant (pure Python, no CUDA)
186+
# This produces a universal wheel that works on any platform
187+
python setup.py bdist_wheel --no-cuda
188+
189+
- name: List built wheels
190+
shell: bash
191+
run: |
192+
ls -lh dist/
193+
echo "Built wheels:"
194+
ls -1 dist/*.whl
195+
196+
- name: Upload wheels
197+
uses: actions/upload-artifact@v4
198+
with:
199+
name: wheels-${{ matrix.os }}-py${{ matrix.python-version }}
200+
path: dist/*.whl
201+
if-no-files-found: error
202+
203+
test:
204+
name: Test on ${{ matrix.os }}
205+
needs: build_wheels
206+
runs-on: ${{ matrix.os }}
207+
strategy:
208+
fail-fast: false
209+
matrix:
210+
os: [ubuntu-22.04, windows-2022]
211+
python-version: ["3.12"]
212+
213+
steps:
214+
- name: Checkout code
215+
uses: actions/checkout@v4
216+
217+
- name: Set up Python ${{ matrix.python-version }}
218+
uses: actions/setup-python@v5
219+
with:
220+
python-version: ${{ matrix.python-version }}
221+
222+
- name: Download wheels
223+
uses: actions/download-artifact@v4
224+
with:
225+
name: wheels-${{ matrix.os }}-py${{ matrix.python-version }}
226+
path: dist/
227+
228+
- name: Install wheel and test dependencies
229+
shell: bash
230+
run: |
231+
python -m pip install --upgrade pip
232+
# Install CPU-only PyTorch first (smaller download, no CUDA needed for CI)
233+
pip install torch --index-url https://download.pytorch.org/whl/cpu
234+
# Install the CPU-only wheel on Linux, CUDA wheel on Windows
235+
# (CPU wheel is py3-none-any, works everywhere without CUDA runtime)
236+
if [ "$RUNNER_OS" == "Linux" ]; then
237+
pip install dist/*py3-none-any.whl
238+
else
239+
# Windows: install the CUDA wheel (will work in CPU-only mode)
240+
pip install dist/*.whl
241+
fi
242+
pip install pytest ruff
243+
244+
- name: Ruff check
245+
shell: bash
246+
run: |
247+
ruff check .
248+
249+
- name: Run tests
250+
shell: bash
251+
run: |
252+
# Run all tests - conftest handles backend availability
253+
# Tests requiring CUDA will be skipped on CPU-only runners
254+
python -m pytest tests/ -v --tb=short
255+

0 commit comments

Comments
 (0)