-
Notifications
You must be signed in to change notification settings - Fork 88
Python simple cuda #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Python simple cuda #685
Conversation
This looks great. I would ask @janden to review. My suggestion it to extend https://github.com/flatironinstitute/finufft/blob/master/python/cufinufft/tests/test_simple.py with type3 |
…e3 with CPU version gen_coef_ind
Hi @MaximEremenko, I noticed the tests failing do you need help with it? |
…789 * n_target_pts),) keep in mind n_tr
Hi @DiamonDinoia , ind = (int(0.1789 * n_target_pts),) and assert type3_rel_err < 100 * tol Original CPU code looks a little different. I made verify_type3 to ind = tuple(n-1 for n in n_tr + (int(0.1789 *n_pts),)) and it works but it looks like GPU version gives bigger error compare to CPU and general test case tuple(np.random.randint(0, n) for n in n_tr + (n_pts,)) does not work correctly. |
Really the python tests should not rely on the error of a single output
(ind),
since this can fluctuate too much.
In the C++ and matlab/octave tests I updated this (eg for the latter see
https://github.com/flatironinstitute/finufft/blob/master/matlab/test/fullmathtest.m
).
They use small tests where computing the answer directly is cheap, then
using relative l2-norm of difference.
…On Wed, May 28, 2025 at 11:01 AM Maxim Eremenko ***@***.***> wrote:
*MaximEremenko* left a comment (flatironinstitute/finufft#685)
<#685 (comment)>
Hi,
I have version that can pass tests. Problem is here:
in function: verify_type3
ind = (int(0.1789 * n_target_pts),) and assert type3_rel_err < 100 * tol
Original CPU code looks a little different.
I made verify_type3 to ind = tuple(n-1 for n in n_tr + (int(0.1789
*n_pts),)) and it works but it looks like GPU version gives bigger error
compere to CPU and general test case tuple(np.random.randint(0, n) for n in
n_tr + (n_pts,)) does not work correctly.
—
Reply to this email directly, view it on GitHub
<#685 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNZRSSOZFHEX2Y4PVGOAS33AXFTXAVCNFSM6AAAAAB5ZTXJB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMJWGY3TENZXGM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
*-------------------------------------------------------------------~^`^~._.~'
|\ Alex Barnett Center for Computational Mathematics, Flatiron Institute
| \ http://users.flatironinstitute.org/~ahb 646-876-5942
|
Hi @MaximEremenko, Yes, let's leave something sensible that passes here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together!
Some things to discuss here.
@@ -32,10 +41,13 @@ def _invoke_plan(dim, nufft_type, x, y, z, data, out, isign, eps, | |||
n_modes = out.shape[-dim:] | |||
if nufft_type == 2: | |||
n_modes = data.shape[-dim:] | |||
|
|||
if nufft_type == 3: | |||
plan = Plan(nufft_type, dim, n_trans = n_trans, eps=eps, isign=isign, dtype=dtype, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to specify the kwargs explicitly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**kwargs are defined the same way as for nufft_type 1 and 2, matching the invoke_guru CPU implementation:
if tp == 3:
plan = Plan(tp, dim, n_trans, eps, isign, pdtype, **kwargs)
else:
plan = Plan(tp, n_modes, n_trans, eps, isign, pdtype, **kwargs)
Explicit specification of parameters (e.g., n_trans=n_trans, eps=eps, isign=isign, dtype=dtype) is optional. I can modify it if necessary
@@ -332,7 +332,7 @@ def execute(self, data, out=None): | |||
|
|||
_data, data_shape = _ensure_array_shape(_data, "data", req_data_shape, | |||
allow_reshape=True) | |||
if self._type == 1: | |||
if self._type in [1, 3]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -46,7 +58,7 @@ def _invoke_plan(dim, nufft_type, x, y, z, data, out, isign, eps, | |||
|
|||
|
|||
def _get_ntrans(dim, nufft_type, data): | |||
if nufft_type == 1: | |||
if ((nufft_type == 1) | (nufft_type == 3)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be preferable here to have if nufft_type == 1 or nufft_type == 3:
or if nufft_type in [1, 3]:
(see above). The |
operator is a bitwise or.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to if nufft_type in [1, 3]. Thanks
|
||
target_coefs = to_cpu(target_coefs_gpu) | ||
|
||
utils.verify_type3(source_pts, source_coefs, target_pts, target_coefs, tol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline.
@@ -22,6 +22,9 @@ def _real_dtype(complex_dtype): | |||
|
|||
return real_dtype | |||
|
|||
def gen_coef_ind(n_pts, n_tr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why this is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent implementation with "def gen_coef_ind(n_pts, n_tr)" from python/finufft/tests/utils.py
@janden might want to change the tests to align to C++/matlab in a different PR. Agreed. Will make an issue. |
…w line at end of file
This pull request introduces a simplified Python interface for Type 3 NUFFTs (nonuniform-to-nonuniform) in 1D, 2D, and 3D within the cufinufft library. The new functions—nufft1d3, nufft2d3, and nufft3d3—allow users to perform Type 3 transforms with minimal setup, similar to the existing Type 1 and Type 2 interfaces.
Changes
With this update, all NUFFT types (1, 2, and 3) now offer a consistent and simplified Python interface.