Repository navigation
Improve ndimage convolve/correlate - #3179
Conversation
|
That is a very nice speedup for such a small change! Not directly related to this PR, but for cases when the kernel is small enough to fit, do you think it would help to copy it to shared memory? I suppose with a |
|
This is a very good catch, @anaruse! Do you think the |
|
Note that I currently have a similar solution but then also generalizes to all of ndimage.filters. I too did notice the slow CArray lookups and then when using custom handling of indices it was way faster. |
|
Your current version does always force the input array to be C contiguous and if it isn't copies the entire array. With a little extra work as done in mine (which I am going to submit a PR for in just a bit) it doesn't require non-contiguous arrays to be copied first. |
| out_params = 'Y y' | ||
|
|
||
| ops = [] | ||
| ops.append('X* _x = (X*)&(x[0]);') |
There was a problem hiding this comment.
Can you change the variable prefix?
We are working on some coding guidelines for CuPy and one of them will be not allowing '_' to prefix local variables.
Thanks!
There was a problem hiding this comment.
Got it!
BTW, is it OK to use '_' as suffix (^^).
I agree that this is a limitation, but it could potentially be worth always enforcing contiguity for performance? We would have to benchmark on various contiguous and non-contiguous inputs to be sure. In memory-limited scenarios, avoiding the copy would obviously be preferable, though. In any case, contiguity was already being enforced prior to this PR, so at least it is not a new requirement: cupy/cupyx/scipy/ndimage/filters.py Lines 106 to 107 in 05c8194 |
|
@grlee77 I did some very basic timing tests on my machine and having the non-contiguous helping of the input image (but not the weights, I still always make that contiguous since it should be relatively small) did not make a time difference with my code as in the other PR. I didn't actually test with any non-contiguous array, but the lack of speed difference isn't surprising since the current code essentially multiples by the stride right now anyways: cupy/cupyx/scipy/ndimage/filters.py Line 175 in 05c8194 It just computes the Here are the times for some convolutions, first line is not assuming contiguous arrays and second assumes contiguous (but doesn't actually do the check). Sometimes assuming contiguous is slower. (4000, 4000) ⊗ (3, 3) (4000, 4000) ⊗ (5, 5) (4000, 4000) ⊗ (7, 7) (300, 300, 300) ⊗ (3, 3, 3) |
|
@leofang The problem with I understand why it is doing this - it is to protect
I can't remember if the tuple-index lookup has the same division problem, but I suspect not since I think it should only need the multiplications. |
This should be fairly easy to do |
|
I will allow this PR to go to the master branch while I review #3184. This will allow having some performance benefits right now. Jenkins, test this please |
|
Successfully created a job for commit f151fc7: |
|
Jenkins CI test (for commit f151fc7, target branch master) succeeded! |
This PR improves performance of
convolveandcorrelateincupyx.scipy.ndimage.filter.py.I was investing why the performance of
convolveandcorrelatewas slower than expected, and it seems one of the causes is that raw array access viaCArrayis slow.. The issue will be addressed with this PR.Performance (convolution, fp32)