Skip to content

Add CuPy interface#218

Open
frostedoyster wants to merge 2 commits intomainfrom
cupy
Open

Add CuPy interface#218
frostedoyster wants to merge 2 commits intomainfrom
cupy

Conversation

@frostedoyster
Copy link
Copy Markdown
Collaborator

@frostedoyster frostedoyster commented Mar 28, 2026

As in the title; closes #217. The implementation follows lab-cosmo/mops#37. CuPy support is also made available through the pre-built wheels

@frostedoyster
Copy link
Copy Markdown
Collaborator Author

cscs-ci run

@frostedoyster
Copy link
Copy Markdown
Collaborator Author

cscs-ci run

1 similar comment
@frostedoyster
Copy link
Copy Markdown
Collaborator Author

cscs-ci run

@frostedoyster
Copy link
Copy Markdown
Collaborator Author

I've downloaded and tested the pre-built linux-x86 wheel and it works

Copy link
Copy Markdown
Contributor

@Luthaf Luthaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but we might want to reduce the number of functions we have in the C API; especially if we add a new device through SyCL. It should also make things like #219 which need to update every function easier

Comment on lines +300 to +309
lib.sphericart_cuda_spherical_harmonics_compute_array_with_hessians.restype = None
lib.sphericart_cuda_spherical_harmonics_compute_array_with_hessians.argtypes = [
sphericart_cuda_spherical_harmonics_calculator_t,
ctypes.POINTER(ctypes.c_double),
ctypes.c_size_t,
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.c_void_p,
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but should we look into simplifying the API a bit? Maybe adding explicit device parameter like vesin, and a separate sph_kind="SphericalHarmonics | SolidHarmonics"?

Comment on lines +40 to +51
# if CUDA is available, install the appropriate cupy version
bash -c 'if command -v nvcc >/dev/null 2>&1; then \
CUDA_MAJOR=$(nvcc --version | sed -n "s/.*release \([0-9][0-9]*\)\..*/\1/p" | head -n 1); \
if [ "$CUDA_MAJOR" = "12" ]; then \
python -m pip install -U cupy-cuda12x; \
elif [ "$CUDA_MAJOR" = "13" ]; then \
python -m pip install -U cupy-cuda13x; \
elif [ -n "$CUDA_MAJOR" ]; then \
echo "Unsupported CUDA major version for CuPy wheels: $CUDA_MAJOR"; \
exit 1; \
fi; \
fi'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, I have a slightly more robust script on vesin, that does not required having the cuda toolkit installed, only the drivers: https://github.com/Luthaf/vesin/blob/main/scripts/install-cupy.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CuPy support

2 participants