-
Notifications
You must be signed in to change notification settings - Fork 10
Accelerating grid transformation using CuPy #132
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: main
Are you sure you want to change the base?
Accelerating grid transformation using CuPy #132
Conversation
|
Closes #131. |
|
@hanaol It's always better to use the cuda version when available right? If that is the case I think it makes sense for the code to be more insistent on that default behavior. def get_namespace(arr):
"""Get array namespace (works with numpy, cupy, etc.)"""
if hasattr(arr, '__array_namespace__'):
return arr.__array_namespace__()
return npThat would also allow you to avoid using the gpu flags since the behavior can be automatically determined by the type of the input array --- you might consider a warning or something if you ever see someone use the CPU version when the GPU is available. This also helps you avoid using a flag to determine function behavior which we should usually avoid especially if it is a "mode-switch" type of flag. |
README.md
Outdated
|
|
||
| **Optional GPU Acceleration** | ||
| - Requires `CuPy >= 13.6.0` | ||
| - Install with: `pip install -e .[gpu]` |
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.
Perhaps change to pip install mp-pyrho[gpu], which will be valid at the next PyPI release.
src/pyrho/charge_density.py
Outdated
| grid_out: list[int] | int, | ||
| origin: npt.ArrayLike = (0, 0, 0), | ||
| up_sample: int = 1, | ||
| use_gpu: bool = False, |
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.
Please add a docstring for all functions where you add the use_gpu kwarg. It looks like that should be get_transformed, _transform_data, and get_sc_interp since you got the other ones already.
src/pyrho/utils.py
Outdated
| def interpolate_fourier(arr_in: NDArray, shape: List[int]) -> NDArray: | ||
| def interpolate_fourier( | ||
| arr_in: NDArray, shape: List[int], use_gpu: bool = False | ||
| ) -> NDArray: |
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.
Union[NDArray, "cp.ndarray"]
Hello @jmmshn, and thanks for your comments. I agree that using the array Is that what you’re referring to? |
Hi @hanaol,
If we are sure about it think that'll be an easy change that make the code a bit cleaner. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #132 +/- ##
===========================================
- Coverage 79.27% 68.54% -10.73%
===========================================
Files 5 5
Lines 304 372 +68
===========================================
+ Hits 241 255 +14
- Misses 63 117 +54 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @jmmshn, I’ve updated the |
|
Thanks @hanaol, I can have a look by next Friday. |
Problem
Charge grid transformation becomes a performance bottleneck for large grids.
Proposed Solution
Leverage CuPy to offload memory-intensive operations—including FFT—to the GPU.