Repository navigation
Add cupy.convolve - #3371
Add cupy.convolve#3371
cupy.convolve#3371Conversation
|
@asi1024 this is a primary version that still needs modifications. Could you please check the overall approach before resuming ? |
|
It was suggested in the discussion of #3184 that |
The biggest issue with that is probably that SciPy's NumPy instead determines appropriate dtypes based on both the input and filter and then performs the convolution using that dtype. Below are examples in how this leads to different behavior for the two. case 1: same result, but different dtype case 2: SciPy->floating point values truncated to the input dtype case 3: casting negative values to uint16 in SciPy causes unexpected result case 4: float16 not supported in SciPy |
|
@Dahlia-Chehata Does it work for non-contiguous input? |
Yes, but the input should be converted to contiguous form first |
|
The current implementation does not support complex dtype inputs. |
|
Now I doubt you need to use |
The thing is that I need to use dynamic parallelism. Each child kernel is invoked with different values of kernel's parameters ( nTPB, nBPG...) . These values depend on the parent's |
|
In my recognition, dynamic parallelism is often used to speed up recursive operations and does not so good for a simple loop. Actually, the algorithm of your implementation is essentially equivalent to the matrix dot, so the classic matrix multiplication algorithm seems better for the performance. |
|
The current implementation does not pass the following test. @testing.numpy_cupy_array_equal()
def test_large(self, xp):
a = testing.shaped_arange((4000,), xp, numpy.float64)
b = testing.shaped_arange((4000,), xp, numpy.float64)
return xp.correlate(a, b, mode=self.mode) |
Yes, I know. There are some issues I am still resolving as for example checking if It is still a draft 😉 |
So what is your suggestion ? |
|
Using |
I know it is early to check the performance (since I am still fixing some bugs and have not pushed the latest fix yet) but I wanted to check whether the performance will be really worse than numpy's
Edit: using 'full' mode |
|
@Dahlia-Chehata are those numbers times or speeds? Looks like maybe times. What units? Is that |
time in us ( didn't change a thing in |
|
Jenkins, test this please. |
|
Successfully created a job for commit 845e786: |
|
Jenkins CI test (for commit 845e786, target branch master) failed with status FAILURE. |
|
Could you remove this line? The test TestNotificationModes seems to assume that cupy.convolve is not implemented.
|
|
Jenkins, test this please. |
|
Successfully created a job for commit 8623128: |
|
Jenkins CI test (for commit 8623128, target branch master) succeeded! |
|
This looks nice but why only addresses 1d not Nd? I notice numpy.convolve focus on 1d but I believe that is because of numpy and scipy negotiation which let them focus separately implement |
|
@ke-zhang-rd CuPy aims to support NumPy compatible interface, so we won't support Nd array inputs in |
|
Jenkins, test this please. |
|
Successfully created a job for commit b4acd1d: |
|
Jenkins CI test (for commit b4acd1d, target branch master) succeeded! |
|
LGTM. |
@asi1024 Ok, is there anyone implementing that? If not, I could help. |
|
@ke-zhang-rd See #3526 which shows that this particular implementation of I do have plans on making |
|
@coderforlife CuPy aims to handle large inputs, so if you want to talk about performance, you should compare on large inputs. (It is better to have good performance even with small inputs of course! 😄) script: import numpy
import scipy.ndimage
import cupy
import cupyx
import cupyx.scipy.ndimage
a_shapes = [10, 2000000]
v_shapes = [2000000, 10]
for a_shape, v_shape in zip(a_shapes, v_shapes):
a = cupy.arange(a_shape, dtype=numpy.int32)
v = cupy.arange(v_shape, dtype=numpy.int32)
perf = cupyx.time.repeat(
cupy.convolve, (a, v, 'same'),
max_duration=1)
print(perf)
perf = cupyx.time.repeat(
cupyx.scipy.ndimage.convolve1d, (a, v), {'mode': 'constant'},
max_duration=1)
print(perf)Results:
|
|
@asi1024 The See the basic wrapper at #3414 (comment) and test against that. That wrapper does support |
|
@asi1024 And yes, I regular test on large arrays. A basic 4MP image is twice as large as the size you used. The only times when |
|
I don't speak for @asi1024, but the objection which I (and @ke-zhang-rd who is working on a FFT-based
Calling it "extremely slow" is very unfair to @Dahlia-Chehata's contribution. The point is CuPy focuses the performance for large inputs, and there requires some different, specialized considerations and approaches for small inputs. Often times, for the input sizes you tested in #3526 I'd just recommend to use SciPy directly, as GPUs won't win CPUs overwhelmingly and SciPy has been well-optimized. |
No description provided.