Repository navigation
[REVIEW] Implementation of Raw CuPy Module for upfirdn - #25
Conversation
|
I think compiling the CuPy kernel for |
|
Looks great, @gmarkall! Both @mnicely and I didn't realize CuPy wasn't caching the compiled kernel after the first run. Your experiment looks straight forward, and I'm good with rolling it into the baseline code. Can you commit to this PR, or do you need to create a separate one that merges after this? |
|
I can't commit to the PR branch as I don't have write access to github.com/awthomp/cusignal-dev repo - I'll create a separate PR that merges after this one. |
|
PR #26 created for the merge afterwards. |
|
It's also worth considering that at the moment the notebook example is comparing a raw kernel operating on 32-bit types with a Numba kernel operating on 64-bit types - for example, diff --git a/python/cusignal/_upfirdn.py b/python/cusignal/_upfirdn.py
index 54f887c..aacab2f 100644
--- a/python/cusignal/_upfirdn.py
+++ b/python/cusignal/_upfirdn.py
@@ -12,7 +12,7 @@
# limitations under the License.
import cupy as cp
-from numba import cuda
+from numba import cuda, float32, int32, void
import math
@@ -94,7 +94,7 @@ def _apply(x, h_trans_flip, out, up, down, axis=-1):
h_idx += 1
-@cuda.jit(fastmath=True)
+@cuda.jit(void(float32[:], float32[:], float32[:], int32, int32, int32), fastmath=True)
def _apply_1d(x, h_trans_flip, out, up, down, axis=-1):
X = cuda.grid(1)and then changing the declaration of gx = cp.linspace(start, stop, num, endpoint=False, dtype=np.float32)
gy = cp.cos(-gx**2/6.0)results in the following times: which closes the gap to 2x performance from CuPy - still some more improvement to do on the Numba side :-) |
|
Since this PR gives the user the option to roll back to the default Numba CUDA kernel (in fact, it's enabled by default), I'm going to recommend merging this PR. |
|
@mnicely -- this PR contains the |
|
@awthomp If it's not too late, I suggest we remove the int kernel from the Raw Module. It is technically dead code, because it will never be reached as all int inputs are promoted to float. |
This PR closes #16
CC: @mnicely
WIP implementation comparing the performance of a raw CuPy CUDA kernel via
RawModuleversus the legacy Numba CUDA kernel. This currently only addresses the 1D case forupfirdnand adds an additional parameter forapply_filterwhere:use_numba=Trueuses the legacyupfirdnCUDA kernel anduse_numba=Falseuses the CuPy RawModuleThis is also exposed in
resample_poly. As an example:Matt has a separate test script that has been profiled via NSIGHT; it's getting about a 4x perf increase. When timed Python, however, I'm getting a ~2x speed decrease in
resample_poly.There are also Python formatting fixes in this PR and an update to the relevant Jupyter notebook showing the option to use the Numba/Raw CuPy kernel.