This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
GenMetaBalls is a hybrid Python/CUDA project that demonstrates GPU-accelerated computing from Python. The project uses:
- Build System: scikit-build-core with CMake
- Python Bindings: nanobind (modern, lightweight alternative to pybind11)
- Package Manager: pixi (conda-based dependency management)
- Languages: Python 3.13, C++20, CUDA
Critical Architecture Pattern: The project uses a three-layer architecture:
- CUDA Layer (
genmetaballs/src/cuda/core/): Header-only template kernels (e.g.,add.cuh) - Bindings Layer (
genmetaballs/src/cuda/bindings.cu): nanobind module_genmetaballs_bindingsthat instantiates templates with fixed parameters - Python Layer (
genmetaballs/src/genmetaballs/): User-facing Python API that wraps the bindings
This layering allows compile-time optimization via templates while exposing a simple Python interface.
pixi installpixi reinstall genmetaballsThis triggers scikit-build-core to rebuild the C++/CUDA code and reinstall the Python module.
# C++/CUDA tests (Google Test via ctest)
pixi run ctest
# Python tests (pytest)
pixi run pytest
# All tests
pixi run testWhen pixi install or pixi reinstall genmetaballs runs, scikit-build-core:
- Configures CMake with settings from
pyproject.toml - Builds three CMake targets:
genmetaballs_core: Static library with CUDA kernels and utilities_genmetaballs_bindings: nanobind extension module (installed to Python package)test_add: C++ test executable
- Installs
_genmetaballs_bindings.abi3.sointo thegenmetaballspackage directory - Makes
genmetaballsimportable in Python
Important: The build uses a persistent build directory (build/) specified in pyproject.toml to speed up rebuilds.
GenMetaBalls/
├── CMakeLists.txt # CMake build configuration
├── pyproject.toml # Python project + pixi configuration
├── genmetaballs/
│ └── src/
│ ├── genmetaballs/ # Python package
│ │ ├── __init__.py # Package initialization
│ │ └── gpu_add.py # Python wrapper for GPU functions
│ └── cuda/ # CUDA/C++ source code
│ ├── bindings.cu # Nanobind Python bindings
│ └── core/ # Core CUDA implementation
│ ├── add.cuh # GPU addition kernel (header-only)
│ ├── utils.cu # CUDA error checking implementation
│ └── utils.h # CUDA utilities header
└── tests/
├── test_gpu_add.py # Python test for GPU addition
└── test_add.cu # Standalone C++ test
To add a new GPU function following the existing pattern:
- Create kernel in
cuda/core/: Header-only template (.cuhfile) - Expose in
bindings.cu: Addm.def()call to instantiate template with fixed parameters - Wrap in Python: Create wrapper in
genmetaballs/and export in__init__.py - Rebuild: Run
pixi reinstall genmetaballs - Test: Add C++ test in
tests/test_*.cuand Python test intests/test_*.py
The project has two test suites:
-
C++/CUDA Tests: Configured using Google Test (powered by ctest)
pixi run ctest
-
Python Tests: Configured using pytest
pixi run pytest
-
Run All Tests: Run both test suites together
pixi run test
When pixi install runs, scikit-build-core will:
- Configure CMake with specified options
- Build the C++/CUDA code
- Create the nanobind module
_genmetaballs_bindings - Install the module into the Python package directory
- Make
genmetaballsimportable in Python
- Platform: linux-64 only
- Python: 3.13+ required (uses stable ABI via nanobind)
- CUDA: 12.8.x
- CMake: 4.1+ (note: higher than typical minimum due to CUDA requirements)
- Platform: linux-64 only (specified in pixi config)
- License: MIT
- Authors: Arijit Dasgupta, Matin Ghavami, Xiaoyan Wang
- This is a template project for future metaballs generation implementation
- Current gpu_add is demonstration code to verify the build system works