Skip to content

Commit 18efaa7

Browse files
committed
[ci]: Refactor CI workflows to use Miniconda for CUDA setup, enhancing environment management and installation verification
1 parent 5b56372 commit 18efaa7

3 files changed

Lines changed: 82 additions & 47 deletions

File tree

.github/workflows/build_wheels.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,38 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424

25-
# Install CUDA on the runner
26-
- name: Install CUDA
27-
uses: Jimver/cuda-toolkit@v0.2.16
28-
id: cuda-toolkit
25+
# Set up conda with CUDA environment
26+
- name: Setup Miniconda
27+
uses: conda-incubator/setup-miniconda@v3
2928
with:
30-
cuda: ${{ matrix.cuda-version }}
31-
method: 'network'
32-
sub-packages: '["nvcc", "cudart", "cufft", "cublas", "cusparse", "cusolver", "curand", "npp", "nvrtc"]'
33-
34-
- name: Set up Python
35-
uses: actions/setup-python@v5
36-
with:
37-
python-version: '3.11' # Version for running cibuildwheel
29+
environment-file: environment/environment-gpu.yml
30+
activate-environment: ccc-gpu
31+
auto-activate-base: false
32+
miniforge-variant: Mambaforge
33+
miniforge-version: latest
34+
use-mamba: true
35+
36+
- name: Verify CUDA installation
37+
shell: bash -l {0}
38+
run: |
39+
conda info
40+
conda list cuda
41+
nvcc --version
42+
echo "CUDA_HOME: $CONDA_PREFIX"
3843
3944
- name: Install cibuildwheel
45+
shell: bash -l {0}
4046
run: python -m pip install cibuildwheel==2.21.3
4147

4248
- name: Build wheels
49+
shell: bash -l {0}
4350
env:
4451
CIBW_BUILD: "cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64 cp314-manylinux_x86_64"
4552
# Skip PyPy, musllinux, and other architectures
4653
CIBW_SKIP: "pp* *-musllinux* *-manylinux_i686 *-manylinux_aarch64"
4754
# Install CUDA and other dependencies inside the container
4855
CIBW_BEFORE_ALL_LINUX: |
49-
# Install CUDA repository and toolkit
56+
# Install CUDA repository and toolkit - using same version as conda env
5057
yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
5158
yum clean all
5259
yum install -y cuda-toolkit-12-5 ninja-build
@@ -118,16 +125,16 @@ jobs:
118125
steps:
119126
- uses: actions/checkout@v4
120127

121-
# Install CUDA for testing
122-
- name: Install CUDA
123-
uses: Jimver/cuda-toolkit@v0.2.16
124-
with:
125-
cuda: ${{ matrix.cuda-version }}
126-
method: 'network'
127-
128-
- name: Set up Python ${{ matrix.python-version }}
129-
uses: actions/setup-python@v5
128+
# Set up conda with CUDA environment for testing
129+
- name: Setup Miniconda
130+
uses: conda-incubator/setup-miniconda@v3
130131
with:
132+
environment-file: environment/environment-gpu.yml
133+
activate-environment: ccc-gpu
134+
auto-activate-base: false
135+
miniforge-variant: Mambaforge
136+
miniforge-version: latest
137+
use-mamba: true
131138
python-version: ${{ matrix.python-version }}
132139

133140
- name: Download wheels
@@ -137,17 +144,19 @@ jobs:
137144
path: ./wheelhouse
138145

139146
- name: Install wheel and test dependencies
147+
shell: bash -l {0}
140148
run: |
141149
python -m pip install --upgrade pip
142-
python -m pip install numpy scipy numba pandas scikit-learn pytest
143150
python -m pip install --find-links ./wheelhouse cccgpu
144151
145152
- name: Run basic import test
153+
shell: bash -l {0}
146154
run: |
147155
python -c "import ccc; import ccc_cuda_ext; print('All imports successful')"
148156
python -c "from ccc import compute; print('CCC compute module loaded')"
149157
150158
- name: Run pytest
159+
shell: bash -l {0}
151160
run: |
152161
pytest tests/test_coef.py -v
153162

.github/workflows/build_wheels_simple.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v4
2525

26-
- name: Install CUDA
27-
uses: Jimver/cuda-toolkit@v0.2.16
28-
id: cuda-toolkit
26+
- name: Setup Miniconda
27+
uses: conda-incubator/setup-miniconda@v3
2928
with:
30-
cuda: '12.5.0'
31-
method: 'network'
29+
environment-file: environment/environment-gpu.yml
30+
activate-environment: ccc-gpu
31+
auto-activate-base: false
32+
miniforge-variant: Mambaforge
33+
miniforge-version: latest
34+
use-mamba: true
3235

33-
- name: Set up Python
34-
uses: actions/setup-python@v5
35-
with:
36-
python-version: '3.11'
36+
- name: Verify CUDA installation
37+
shell: bash -l {0}
38+
run: |
39+
conda info
40+
nvcc --version
3741
3842
- name: Install cibuildwheel
43+
shell: bash -l {0}
3944
run: python -m pip install cibuildwheel==2.21.3
4045

4146
- name: Build wheel
47+
shell: bash -l {0}
4248
env:
4349
CIBW_BUILD: "${{ inputs.python_version }}-*"
4450
CIBW_SKIP: "pp* *-musllinux* *-manylinux_i686 *-manylinux_aarch64 *-win32"

docs/WHEEL_BUILDING.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ This is the primary workflow that builds wheels for all supported configurations
1818
- **CUDA version**: 12.5 (for stable GPU support and features)
1919

2020
#### Key Features:
21-
1. Builds wheels for all Python versions in parallel on Linux
22-
2. Automatically installs CUDA toolkit in manylinux container
23-
3. Bundles CUDA libraries with wheels for standalone distribution
24-
4. Runs basic import tests after building
25-
5. Uploads wheels as GitHub Actions artifacts
26-
6. Optionally publishes to PyPI on version tags
21+
1. Uses conda to manage CUDA 12.5 environment for reliable installation
22+
2. Builds wheels for all Python versions in parallel on Linux
23+
3. Automatically installs CUDA toolkit in manylinux container
24+
4. Bundles CUDA libraries with wheels for standalone distribution
25+
5. Runs basic import tests after building
26+
6. Uploads wheels as GitHub Actions artifacts
27+
7. Optionally publishes to PyPI on version tags
2728

2829
### Simplified Workflow: `build_wheels_simple.yml`
2930

@@ -54,12 +55,23 @@ Helper script for Windows wheels:
5455

5556
### Prerequisites
5657

57-
1. Install cibuildwheel:
58+
1. Install conda/mamba:
5859
```bash
59-
pip install cibuildwheel
60+
# Install miniforge (includes mamba)
61+
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
62+
bash Miniforge3-$(uname)-$(uname -m).sh
63+
```
64+
65+
2. Create CUDA environment:
66+
```bash
67+
mamba env create -f environment/environment-gpu.yml
68+
conda activate ccc-gpu
6069
```
6170

62-
2. Install CUDA Toolkit 12.5 (or compatible version)
71+
3. Install cibuildwheel:
72+
```bash
73+
pip install cibuildwheel
74+
```
6375

6476
### Build Commands
6577

@@ -73,21 +85,25 @@ Build specific Python version:
7385
CIBW_BUILD="cp311-*" cibuildwheel --output-dir wheelhouse
7486
```
7587

76-
Build with custom CUDA path (Linux):
88+
Build with conda CUDA environment:
7789
```bash
78-
export CUDA_HOME=/usr/local/cuda-12.5
90+
# Activate the conda environment with CUDA
91+
conda activate ccc-gpu
92+
# CUDA paths are automatically set by conda
7993
cibuildwheel --output-dir wheelhouse
8094
```
8195

8296
## Platform-Specific Notes
8397

8498
### Linux (manylinux)
8599

86-
- Uses manylinux2014 base image for broad Linux distribution compatibility
87-
- CUDA 12.5 is installed inside the container via yum package manager
100+
- Uses conda to install CUDA 12.5 on the host system for reliable setup
101+
- Uses manylinux2014 base image for broad Linux distribution compatibility
102+
- CUDA 12.5 is also installed inside the container via yum package manager
88103
- Wheels are repaired with `auditwheel` to bundle CUDA shared libraries
89104
- Resulting wheels are compatible with most Linux distributions (CentOS 7+, Ubuntu 16.04+, etc.)
90105
- Supports x86_64 architecture only
106+
- Conda environment ensures consistent CUDA version across local and CI builds
91107

92108
## CUDA Architecture Support
93109

@@ -119,8 +135,9 @@ To support additional architectures, modify the `CMAKE_CUDA_ARCHITECTURES` setti
119135
### Common Issues
120136

121137
1. **CUDA not found during build**
122-
- Ensure CUDA_HOME/CUDA_PATH environment variable is set
123-
- Verify CUDA toolkit version compatibility
138+
- Ensure conda environment is activated: `conda activate ccc-gpu`
139+
- Verify CUDA installation: `nvcc --version`
140+
- Check conda CUDA package: `conda list cuda`
124141

125142
2. **Wheel import fails with missing shared library**
126143
- Check auditwheel output for excluded libraries
@@ -134,6 +151,9 @@ To support additional architectures, modify the `CMAKE_CUDA_ARCHITECTURES` setti
134151

135152
Enable verbose output:
136153
```bash
154+
# Ensure conda environment is active
155+
conda activate ccc-gpu
156+
# Enable verbose cibuildwheel output
137157
CIBW_BUILD_VERBOSITY=3 cibuildwheel --output-dir wheelhouse
138158
```
139159

0 commit comments

Comments
 (0)