Skip to content

Commit

Permalink
Merge pull request #42 from flatironinstitute/fix_setpts_dtype_check
Browse files Browse the repository at this point in the history
Misc Patches
  • Loading branch information
garrettwrong authored Jul 29, 2020
2 parents df89eea + 6d3f1e8 commit 7532253
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ bin
lib
lib-static

cufinufftpy/docs/_build
cufinufftpy/docs/_static
cufinufftpy/docs/_templates
python/cufinufft/docs/_build
python/cufinufft/docs/_static
python/cufinufft/docs/_templates
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ CUFINUFFTOBJS_64=src/2d/spreadinterp2d.o src/2d/cufinufft2d.o \
src/3d/interp3d_wrapper.o src/3d/cufinufft3d.o \
$(CONTRIBOBJS)
CUFINUFFTOBJS_32=$(CUFINUFFTOBJS_64:%.o=%_32.o)
$(info $$CUFINUFFTOBJS_32 is [${CUFINUFFTOBJS_32}])


%_32.o: %.cpp $(HEADERS)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ If not, please ask, we might be able to help.

### Python Wrapper

For those installing from source, this code comes with a Python wrapper module `cufinufftpy`.
For those installing from source, this code comes with a Python wrapper module `cufinufft`.
Once you have successfully installed and tested the CUDA library
you may run `make python` to manually install the additional Python package.

### Python Package

General Python users, or Python software packages which would like to automatically
depend on cufinufftpy using `setuptools` may use a precompiled binary distribution.
depend on cufinufft using `setuptools` may use a precompiled binary distribution.
This totally avoids installing from source and managing libraries for supported systems.

Because binary distributions are specific to both hardware and software,
we currently only support systems covered by `manylinux2010` that are using
CUDA 10.1, 10.2, or 11.0-rc with a compatible GPU. This is currently the most
common arrangement. If you have such a system, you may run:

`pip install cufinufftpy`
`pip install cufinufft`

For other cases, the Python wrapper should be able to be built from source.
We hope to extend this in the future, and have begun work for `manylinux2014`.
Expand Down
37 changes: 37 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Building Wheels

Noting how I built the wheels for myself in the future,
and in case it is helpful for when this is automated into the FI CI systems.
Typically these steps would be stages in CICD, and fully automated (up to the review).

```
# build the wheel
docker build -f ci/docker/cuda10.1/Dockerfile-x86_64 -t garrettwrong/cufinufft-1.0-manylinux2010 .
# optionally push it (might take a long time, because I didn't strip/clean the containers, tsk tsk)
docker push garrettwrong/cufinufft-1.0-manylinux2010
# Run the container, invoking the build-wheels script to generate the wheels
docker run --gpus all -it -v `pwd`/wheelhouse:/io/wheelhouse -e PLAT=manylinux2010_x86_64 garrettwrong/cufinufft-1.0-manylinux2010 /io/ci/build-wheels.sh
# Create a source distribution (requires you've built or have lib available)
python setup.py sdist
# Copy the wheels we care about to the dist folder
cp -v wheelhouse/cufinufft-1.0-cp3*manylinux2010* dist
# Push to Test PyPI for review/testing
twine upload -r testpypi dist/*
# Tag release.
## Can do in a repo and push or on manually on GH gui.
# Review wheels from test index
pip install -i https://test.pypi.org/simple/ --no-deps cufinufft
# Push to live index
## twine upload dist/*
```

Note that because the large size of the library, initially I expect this package will be over the 100MB limit imposed by PyPI.
Generally this just requires pushing a trivial source release, and then requesting an increase.
9 changes: 5 additions & 4 deletions ci/build-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function repair_wheel {


# Compile wheels
for PYBIN in /opt/python/*/bin; do
for PYBIN in /opt/python/cp3*/bin; do
"${PYBIN}/pip" install -r /io/python/cufinufft/requirements.txt
"${PYBIN}/pip" install auditwheel pytest
"${PYBIN}/pip" wheel /io/ --no-deps -w wheelhouse/
done
Expand All @@ -25,7 +26,7 @@ done


# Install packages and test
for PYBIN in /opt/python/*/bin/; do
"${PYBIN}/pip" install cufinufftpy -f /io/wheelhouse
pytest /io/
for PYBIN in /opt/python/cp3*/bin/; do
"${PYBIN}/pip" install cufinufft -f /io/wheelhouse
"${PYBIN}/python" -m pytest /io/python/cufinufft/tests
done
3 changes: 0 additions & 3 deletions cufinufftpy/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions python/cufinufft/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cufinufft.cufinufft import cufinufft

__all__ = ['cufinufft']
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
try:
if lib is None:
# Find the library.
fh = imp.find_module('cufinufft')[0]
fh = imp.find_module('cufinufftc')[0]
# Get the full path for the ctypes loader.
full_lib_path = os.path.realpath(fh.name)
fh.close() # Be nice and close the open file handle.
Expand Down
34 changes: 21 additions & 13 deletions cufinufftpy/cufinufft.py → python/cufinufft/cufinufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
from ctypes import c_int
from ctypes import c_void_p

from cufinufftpy._cufinufft import NufftOpts
from cufinufftpy._cufinufft import _default_opts
from cufinufftpy._cufinufft import _make_plan
from cufinufftpy._cufinufft import _make_planf
from cufinufftpy._cufinufft import _set_pts
from cufinufftpy._cufinufft import _set_ptsf
from cufinufftpy._cufinufft import _exec_plan
from cufinufftpy._cufinufft import _exec_planf
from cufinufftpy._cufinufft import _destroy_plan
from cufinufftpy._cufinufft import _destroy_planf
from cufinufft._cufinufft import NufftOpts
from cufinufft._cufinufft import _default_opts
from cufinufft._cufinufft import _make_plan
from cufinufft._cufinufft import _make_planf
from cufinufft._cufinufft import _set_pts
from cufinufft._cufinufft import _set_ptsf
from cufinufft._cufinufft import _exec_plan
from cufinufft._cufinufft import _exec_planf
from cufinufft._cufinufft import _destroy_plan
from cufinufft._cufinufft import _destroy_planf


class cufinufft:
Expand Down Expand Up @@ -144,9 +144,17 @@ def set_pts(self, M, kx, ky=None, kz=None):
:param kz: Array of z points.
"""

if not (kx.dtype == ky.dtype == kz.dtype == self.dtype):
raise TypeError("cifinufft plan.dtype and "
"kx, ky, kz dtypes do not match.")
if kx.dtype != self.dtype:
raise TypeError("cufinufft plan.dtype and "
"kx dtypes do not match.")

if ky and ky.dtype != self.dtype:
raise TypeError("cufinufft plan.dtype and "
"ky dtypes do not match.")

if kz and kz.dtype != self.dtype:
raise TypeError("cufinufft plan.dtype and "
"kz dtypes do not match.")

kx = kx.ptr

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cufinufftpy/docs/conf.py → python/cufinufft/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# -- Project information -----------------------------------------------------

project = 'cufinufftpy'
project = 'cufinufft'
copyright = ('2020 The Simons Foundation, '
'Melody Shih, Joakim Anden, Garrett Wright.')
author = 'Melody Shih, Joakim Anden, Garrett Wright'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to cufinufftpy's documentation!
=======================================
Welcome to cufinufft's Python documentation!
==============================================

.. automodule:: cufinufft
:members:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pycuda.autoinit # NOQA:401
import pycuda.gpuarray as gpuarray

from cufinufftpy import cufinufft
from cufinufft import cufinufft

import utils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pycuda.autoinit # NOQA:401
import pycuda.gpuarray as gpuarray

from cufinufftpy import cufinufft
from cufinufft import cufinufft

import utils

Expand Down Expand Up @@ -39,9 +39,6 @@ def test_set_nu_raises_on_dtype():
plan.set_pts(M, kxyz_gpu_wrong_type[0],
kxyz_gpu_wrong_type[1], kxyz_gpu_wrong_type[2])

plan.set_pts(M, kxyz_gpu[0],
kxyz_gpu[1], kxyz_gpu[2])


def test_exec_raises_on_dtype():
dtype = np.float32
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import setup, Extension

# Parse the requirements
with open(os.path.join('cufinufftpy', 'requirements.txt'), 'r') as fh:
with open(os.path.join('python/cufinufft', 'requirements.txt'), 'r') as fh:
requirements = [item.strip() for item in fh.readlines()]

# Sanity check that we can find the CUDA cufinufft libraries before we get too far.
Expand All @@ -22,15 +22,16 @@

# Python Package Setup
setup(
name='cufinufftpy',
name='cufinufft',
version='1.0',
author='Python interfaces by: Melody Shih, Joakim Anden, Garrett Wright',
author_email='[email protected]',
url='http://github.com/flatironinstitute/cufinufft',
description='Python interface to cufinufft',
long_description='Python interface to cufinufft (CUDA Flatiron Institute Nonuniform Fast Fourier Transform) library.',
license="Apache 2",
packages=['cufinufftpy'],
packages=['cufinufft'],
package_dir={'': 'python'},
install_requires=requirements,
# If you'd like to build or alter the docs you may additionally require these.
extras_require={
Expand All @@ -42,9 +43,9 @@
# that is rpath linked to CUDA library, also decorated (by auditwheel).
# Most importantly, pip will manage to install all this stuff in
# in places Python can find it (with a little help).
py_modules=['cufinufft'],
py_modules=['cufinufftc'],
ext_modules=[
Extension(name='cufinufft',
Extension(name='cufinufftc',
sources=[],
libraries=['cufinufft'],
library_dirs=['lib'])
Expand Down
2 changes: 2 additions & 0 deletions src/cufinufft.cu
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ int CUFINUFFT_MAKEPLAN(int type, int dim, int *nmodes, int iflag,
/* allocate the plan structure, assign address to user pointer. */
CUFINUFFT_PLAN d_plan = new CUFINUFFT_PLAN_S;
*d_plan_ptr = d_plan;
// Zero out your struct, (sets all pointers to NULL)
memset(d_plan, 0, sizeof(*d_plan));


/* If a user has not supplied their own options, assign defaults for them. */
Expand Down

0 comments on commit 7532253

Please sign in to comment.