Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous integration #31

Merged
merged 49 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
bcd3aa8
Fix(setup): be a bit more robust with openmp
balbasty Dec 9, 2020
3eb5139
Merge branch 'master' into buildsystem
balbasty Dec 9, 2020
5df9b34
Merge branch 'master' into buildsystem
balbasty Dec 9, 2020
b144c2c
Merge branch 'master' into buildsystem
balbasty Dec 9, 2020
ad3e85b
Enhancement(setup): find arch list in libtorch
balbasty Dec 9, 2020
77de355
Merge branch 'master' into buildsystem
balbasty Dec 9, 2020
33116ac
Merge branch 'master' into buildsystem
balbasty Dec 9, 2020
a6e7aa6
Fix(setup): missing space
balbasty Dec 9, 2020
34d2354
Fix(setup): oops... started counting at 1
balbasty Dec 9, 2020
91cdb1f
Fix(setup): always add '/usr/include' to include_dirs
balbasty Dec 9, 2020
49de03d
Refactor(ci)
balbasty Dec 9, 2020
9b9230f
Fix(ci)
balbasty Dec 9, 2020
5530bf5
Fix(ci)
balbasty Dec 9, 2020
d64c043
CI: activate build/test
balbasty Dec 9, 2020
a1d94f9
CI: do not lint for now (needs advanced config)
balbasty Dec 9, 2020
9c317aa
CI(test
balbasty Dec 9, 2020
717423f
pytest needs test folders to be proper modules
balbasty Dec 9, 2020
44dacc5
Ci(test): build in devel
balbasty Dec 10, 2020
25d7df8
Fix: remove dependency to nibabel
balbasty Dec 10, 2020
dd43139
CI(test): install optional dependencies
balbasty Dec 10, 2020
450d386
Fix failing test (behaviour of neg2pos had changed
balbasty Dec 10, 2020
a867183
FixMe(grid_grad): disabled failing test -- backward pass of grid_grad…
balbasty Dec 10, 2020
637c81e
Fix(io.tests): test files must be prefixed 'test_'
balbasty Dec 10, 2020
afe33ea
Fix(ci)
balbasty Dec 10, 2020
de584ea
Fix(install_pytorch): bad cuda suffix
balbasty Dec 10, 2020
8ffa78c
Fix(install_pytorch): default cuda versions
balbasty Dec 10, 2020
1f1a6f3
Fix(ci.build): include/exclude
balbasty Dec 10, 2020
72396b5
Fix(ci.build): typo
balbasty Dec 10, 2020
8e4d860
Fix(ci.build): ecclude
balbasty Dec 10, 2020
001e5f3
Fix(ci)
balbasty Dec 10, 2020
89ca59f
Fix(ci): install full cuda toolkit
balbasty Dec 10, 2020
c0eecc0
Debug(ci): try to find cublas
balbasty Dec 10, 2020
22699e5
Debug(ci): try to find cublas
balbasty Dec 10, 2020
9bb74d5
Debug(ci): try to find cublas
balbasty Dec 10, 2020
5139456
Fix(ci): still trying to locate cublas
balbasty Dec 10, 2020
82d5175
Fix(ci): still trying to locate cublas
balbasty Dec 10, 2020
3e47c15
Fix(ci): still trying to locate cublas
balbasty Dec 10, 2020
da8eed9
Fix(ci): still trying to locate cublas
balbasty Dec 10, 2020
6e4da78
Fix(nn.mixture): is -> ==
balbasty Dec 10, 2020
7fad527
Enhancement(ic): only compile for one cuda arch
balbasty Dec 10, 2020
9013501
CI: compile only one arch
balbasty Dec 10, 2020
622e95a
CI: add option to (un)trigger fail-fast
balbasty Dec 10, 2020
5346f45
Fix(ci)
balbasty Dec 10, 2020
7e5254e
Fix(ci)
balbasty Dec 10, 2020
d0c5fe2
Fix(ci)
balbasty Dec 10, 2020
a99d556
Fix(install_pytorch): do not use repo if default cuda
balbasty Dec 10, 2020
5d91a23
Fix(ci+setup)
balbasty Dec 10, 2020
92cfc81
Fix(buildtools): more robust parsing of cuda version
balbasty Dec 10, 2020
66d5db4
Disable python 3.7 until I figure out the bug
balbasty Dec 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 125 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,146 @@
name: nitorch-build

on:
workflow_dispatch
# push:
# branches: [ ]
# pull_request:
# branches: [ ]
workflow_dispatch:
inputs:
fail-fast:
description: 'Fail fast mode'
required: false
default: 'true'
push:
paths:
# all c++/cuda source files
- "**.c"
- "**.cc"
- "**.cu"
- "**.cpp"
- "**.h"
- "**.cuh"
# github actions
- ".github/workflows/build.yml"
- "scripts/actions/**"
# all python files in the root directory
- "*.py"
branches: [ master ]
pull_request:
paths:
# all c++/cuda source files
- "**.c"
- "**.cc"
- "**.cu"
- "**.cpp"
- "**.h"
- "**.cuh"
# github actions
- ".github/workflows/build.yml"
- "scripts/actions/**"
# all python files in the root directory
- "*.py"
branches: [ master ]

jobs:

build:

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
# runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: ${{ github.event.inputs.fail-fast == 'true' }}
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [ 3.6, 3.7, 3.8 ]
pytorch-version: [ 1.3, 1.4, 1.5, 1.6, 1.7 ]
os: [ ubuntu-latest ]
# os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ '3.6', '3.8' ] # '3.7' fails for some weird reason
pytorch-version: [ '1.3', '1.4', '1.5', '1.6', '1.7' ]
cuda-version: [ 'cpu', '10.1', '10.2', '11.0' ]
exclude:
- pytorch-version: '1.3'
python-version: '3.8'
- pytorch-version: '1.3'
cuda-version: '10.2'
- pytorch-version: '1.4'
cuda-version: '10.2'
- pytorch-version: '1.3'
cuda-version: '11.0'
- pytorch-version: '1.4'
cuda-version: '11.0'
- pytorch-version: '1.5'
cuda-version: '11.0'
- pytorch-version: '1.6'
cuda-version: '11.0'

steps:

- uses: actions/checkout@v2

- if: matrix.cuda-version != 'cpu' && runner.os == 'Windows'
# Windows -> powershell
name: Install CUDA ${{ matrix.cuda-version }} (Windows)
env:
cuda: ${{ matrix.cuda-version }}
shell: powershell
run: |
# Install CUDA via a powershell script
.\scripts\actions\install_cuda_windows.ps1
if ($?) {
# Set paths for subsequent steps, using $env:CUDA_PATH
echo "Adding CUDA to CUDA_PATH, CUDA_PATH_X_Y and PATH"
echo "CUDA_PATH=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:CUDA_PATH_VX_Y=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:CUDA_PATH/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
}

- if: matrix.cuda-version != 'cpu' && runner.os != 'Windows'
# Unix -> bash
name: Install CUDA ${{ matrix.cuda-version }} (Unix)
env:
cuda: ${{ matrix.cuda-version }}
shell: bash
run: |
if [ ! -z ${{ matrix.cuda-version }} ]; then
os="$(cut -d'-' -f1 <<< ${{ matrix.os }})"
echo "$os"
if [ ! -f "./scripts/actions/install_cuda_${os}.sh" ]; then
echo "cuda not available on ${os}"
exit 1
fi
source "./scripts/actions/install_cuda_${os}.sh"
if [[ $? -eq 0 ]]; then
# Set paths for subsequent steps, using ${CUDA_PATH}
echo "Adding CUDA to CUDA_PATH, PATH and LD_LIBRARY_PATH"
echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV
echo "${CUDA_PATH}/bin" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${CUDA_PATH}/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
fi
fi

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install pip
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install PyTorch
run: pip install torch==${{ matrix.pytorch-version }}
- name: Build
run: python ./setup.py install

- name: Install PyTorch ${{ matrix.pytorch-version }}
env:
cuda: ${{ matrix.cuda-version }}
torch: ${{ matrix.pytorch-version }}
shell: bash
run: |
os="$(cut -d'-' -f1 <<< ${{ matrix.os }})"
echo "$os"
if [ ! -f "./scripts/actions/install_pytorch_${os}.sh" ]; then
echo "pytorch not available on ${os}"
exit 1
fi
source "./scripts/actions/install_pytorch_${os}.sh"

- name: Build nitorch
# Compiling for all architectures takes ages and this workflow is just
# here to test that we didn't break anything in the compilation chain
# so we only test one architecture (sm_35 -> the default)
# In the package distribution workflow, we'll need to compile for
# all architectures supported by (the pypi version of) pytorch.
run: TORCH_CUDA_ARCH_LIST="3.5" python setup.py install
48 changes: 38 additions & 10 deletions .github/workflows/manual-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,29 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install CUDA ${{ github.event.inputs.cuda-version }}
- if: runner.os == 'Windows'
# Windows -> powershell
name: Install CUDA ${{ github.event.inputs.cuda-version }} (Windows)
env:
cuda: ${{ github.event.inputs.cuda-version }}
shell: powershell
run: |
# Install CUDA via a powershell script
.\scripts\actions\install_cuda_windows.ps1
if ($?) {
# Set paths for subsequent steps, using $env:CUDA_PATH
echo "Adding CUDA to CUDA_PATH, CUDA_PATH_X_Y and PATH"
echo "CUDA_PATH=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:CUDA_PATH_VX_Y=$env:CUDA_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:CUDA_PATH/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
}

- if: runner.os != 'Windows'
# Unix -> bash
name: Install CUDA ${{ github.event.inputs.cuda-version }} (Unix)
env:
cuda: ${{ github.event.inputs.cuda-version }}
shell: bash
run: |
if [ ! -z ${{ github.event.inputs.cuda-version }} ]; then
os="$(cut -d'-' -f1 <<< ${{ github.event.inputs.os }})"
Expand All @@ -49,7 +69,6 @@ jobs:
echo "LD_LIBRARY_PATH=${CUDA_PATH}/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
fi
fi
shell: bash

- name: Set up Python ${{ github.event.inputs.python-version }} on ${{ github.event.inputs.os }}
uses: actions/setup-python@v2
Expand All @@ -62,14 +81,23 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Install PyTorch ${{ github.event.inputs.pytorch-version }}
env:
cuda: ${{ github.event.inputs.cuda-version }}
torch: ${{ github.event.inputs.pytorch-version }}
shell: bash
run: |
version=${{ github.event.inputs.pytorch-version }}
if [ ! -z ${{ github.event.inputs.cuda-version }} ]; then
cudaversion="$(sed 's/\.//' <<< ${{ github.event.inputs.cuda-version }})"
version+="+cu${cudaversion}"
else
version+="+cpu"
os="$(cut -d'-' -f1 <<< ${{ github.event.inputs.os }})"
echo "$os"
if [ ! -f "./scripts/actions/install_pytorch_${os}.sh" ]; then
echo "pytorch not available on ${os}"
exit 1
fi
pip install torch=="${version}" -f https://download.pytorch.org/whl/torch_stable.html
source "./scripts/actions/install_pytorch_${os}.sh"

- name: Build nitorch
run: python setup.py install
# Compiling for all architectures takes ages and this workflow is just
# here to test that we didn't break anything in the compilation chain
# so we only test one architecture (sm_35 -> the default)
# In the package distribution workflow, we'll need to compile for
# all architectures supported by (the pypi version of) pytorch.
run: TORCH_CUDA_ARCH_LIST="3.5" python setup.py install
71 changes: 51 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
name: nitorch-test

on:
workflow_dispatch
# push:
# branches: [ ]
# pull_request:
# branches: [ ]
workflow_dispatch:
inputs:
fail-fast:
description: 'Fail fast mode'
required: false
default: 'true'
push:
paths:
# all library files
- "nitorch/**"
branches: [ master ]
pull_request:
# always run tests on pull request
branches: [ master ]

jobs:

build:
test:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: ${{ github.event.inputs.fail-fast == 'true' }}
matrix:
os: [ubuntu-latest]
python-version: [ 3.6 ]
pytorch-version: [ 1.3, 1.6 ]
os: [ ubuntu-latest ] # we only run tests on ubuntu/cpu
python-version: [ '3.6' ] # smallest version supported
pytorch-version: [ '1.3', '1.7' ] # smallest and biggest versions

steps:

- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install pip
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install PyTorch
run: pip install torch==${{ matrix.pytorch-version }}
- name: Lint
pip install nibabel
pip install tifffile

- name: Install PyTorch ${{ matrix.pytorch-version }}
env:
cuda: cpu
torch: ${{ matrix.pytorch-version }}
shell: bash
run: |
pip install flake8
flake8 .
- name: Build
run: python ./setup.py install
- name: Test
os="$(cut -d'-' -f1 <<< ${{ matrix.os }})"
echo "$os"
if [ ! -f "./scripts/actions/install_pytorch_${os}.sh" ]; then
echo "pytorch not available on ${os}"
exit 1
fi
source "./scripts/actions/install_pytorch_${os}.sh"

# we must build in development mode for pytest to work in place
- name: Build nitorch
run: |
python setup.py develop
python -c "from nitorch._C import spatial"

# - name: Lint
# run: |
# pip install flake8
# flake8 .

- name: Tests
run: |
pip install pytest
pip install pytest-cov
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
pytest
8 changes: 7 additions & 1 deletion buildtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def cuda_version():
return None
with open(os.devnull, 'w') as devnull:
version = subprocess.check_output([nvcc, '--version'], stderr=devnull).decode()
match = re.search(r'V(?P<version>[0-9\.]+)$', version)
match = None
for line in version.split('\n'):
match = re.search(r'V(?P<version>[0-9\.]+)$', line)
if match:
break
if not match:
raise RuntimeError('Failed to parse cuda version')
version = match.group('version').split('.')
version = tuple(int(v) for v in version)
return version
Expand Down
9 changes: 6 additions & 3 deletions nitorch/io/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def neg2pos(index, shape):

# sanity checks
try:
shape = int(shape)
shape0 = shape
shape = int(shape0)
if shape != shape0:
raise TypeError('Shape should be an integer')
except TypeError:
raise TypeError('Shape should be an integer')
if shape < 0:
Expand All @@ -97,9 +100,9 @@ def neg2pos(index, shape):
if index is not None and index < 0:
index = shape + index
return index
else:
assert isinstance(index, (oob_slice, type(None), type(Ellipsis)))
elif isinstance(index, (oob_slice, type(None), type(Ellipsis))):
return index
raise TypeError('Index should be an int, slice, Ellipsis or None')


def is_fullslice(index, shape, do_neg2pos=True):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_neg2pos():
try: idx.neg2pos(0, -1)
except ValueError: pass
else: assert False, "raise on negative shape"
try: idx.neg2pos(0, 3.)
try: idx.neg2pos(0, 3.5)
except TypeError: pass
else: assert False, "raise on non integer shape"
try: idx.neg2pos(4., 3)
Expand Down
2 changes: 1 addition & 1 deletion nitorch/nn/generators/_mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def forward(self, index, **overload):

# check distribution shape
batches = [batch]
channels = [] if channels is 1 else [channels]
channels = [] if channels == 1 else [channels]
for dist in distributions:
sample_shape = dist.batch_shape + dist.event_shape
if len(sample_shape) > 0:
Expand Down
Empty file added nitorch/tests/__init__.py
Empty file.
Loading