Repository navigation
rewrite cupyx.scipy.ndimage.interpolation using ElementwiseKernel - #3166
Conversation
Memory overhead in affine_transform is greatly reduced by not explicitly generating nd coordinate arrays. The performance of all functions are also improved.
|
The following timings were measured for this PR vs. current master (8.0.0a1) for various operations applied to a 2D float32 image of shape (4096, 4096). The case labeled The next-to-last column gives the acceleration factor for the PR vs. current master, showing from between 4x and 26x improvement!
|
|
Really great! |
|
I suppose the same type of indexing changes made in #3179 should also help here. I can take a look at that when I get a chance. |
leofang
left a comment
There was a problem hiding this comment.
I know very little about the ndimage module, so can't comment much, but I noticed that we almost always need to do memoize() for each device.
Co-authored-by: Leo Fang <[email protected]>
|
#3184 managed to remove I did try making indexing changes as in #3179 and most functions stayed about the same, although |
Update cupyx/scipy/ndimage/_interp_kernels.py
607cdf9 to
3dc0824
Compare
| import cupy | ||
| import cupy.core.internal | ||
|
|
||
| from .filters import _generate_boundary_condition_ops |
There was a problem hiding this comment.
Relative imports are prohibited.
| """ | ||
| W c_{j} = zoom[{j}] * ((W)in_coord[{j}] - shift[{j}]); | ||
| """.format(j=j)) |
There was a problem hiding this comment.
This string includes 2 newline characters.
| import cupy | ||
| import numpy | ||
|
|
||
| from ._interp_kernels import ( |
There was a problem hiding this comment.
Importing non-module symbols is prohibited.
| offset = matrix[:-1, -1] | ||
| matrix = matrix[:-1, :-1] | ||
| if matrix.ndim not in [1, 2]: | ||
| raise RuntimeError('no proper affine matrix provided') |
There was a problem hiding this comment.
Could you add a test for this exception?
| ret[:] = map_coordinates(input, coordinates, ret.dtype, order, mode, cval, | ||
| prefilter).reshape(output_shape) | ||
| return ret | ||
| matrix = matrix.astype(float, copy=False) |
There was a problem hiding this comment.
Please use cupy.float64 for the readability.
| matrix = matrix.astype(float, copy=False) | |
| matrix = matrix.astype(cupy.float64, copy=False) |
There was a problem hiding this comment.
BTW, Is this typecast needed? A float64 array looks to be returned without this typecast.
|
@grlee77 Could you check the travis failure? |
3ac86d1 to
aabf746
Compare
|
Okay, Travis is happy now. |
|
Jenkins, test this please. |
|
Successfully created a job for commit aabf746: |
|
Jenkins CI test (for commit aabf746, target branch master) failed with status FAILURE. |
|
@grlee77 Could you check Jenkins failure? |
Please try again now. (It looks like SciPy prior to 1.3 raised |
|
Jenkins, test this please. |
|
Successfully created a job for commit 048d0c0: |
|
Jenkins CI test (for commit 048d0c0, target branch master) succeeded! |
|
LGTM. Thanks for your PR! |
This was inadvertently removed in cupygh-3166
This was inadvertently removed in cupygh-3166 fix mode opencv for rotate and shift as well
This PR improves the performance and reduces memory usage for the
cupyx.scipy.ndimage.interpolationmodule. There should be no change in behavior from the prior implementation.Memory overhead in various functions like
affine_transformis greatly reduced by not explicitly generating dense n-dimensional coordinate arrays.closes #2607
also resolves some issues with performance that were previously reported in: #1168, #2345, #2844
Will post the benchmarks in a follow-up comment, but performance is greatly improved on all cases I tested.
The main downside to this PR is that such template-based code generation is a bit harder to read than the previous implementations, but I tried to add some comments describing what is going on.