Accelerating grid transformation using CuPy#132
Accelerating grid transformation using CuPy#132hanaol wants to merge 7 commits intomaterialsproject:mainfrom
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.
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.
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.
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. |
|
@jmmshn Whenever you have a moment, please review this. Thank you. |
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.