Migrate PyCUDA C++ wrappers from Boost.Python to pybind11#501
Draft
Migrate PyCUDA C++ wrappers from Boost.Python to pybind11#501
Conversation
Draft
Co-authored-by: inducer <352067+inducer@users.noreply.github.com> Agent-Logs-Url: https://github.com/inducer/pycuda/sessions/e0f3cd25-483e-4b96-abaf-0462ac278c6d
… types, numpy API Co-authored-by: inducer <352067+inducer@users.noreply.github.com> Agent-Logs-Url: https://github.com/inducer/pycuda/sessions/e0f3cd25-483e-4b96-abaf-0462ac278c6d
Copilot
AI
changed the title
[WIP] Migrate to pybind11
Migrate PyCUDA C++ wrappers from Boost.Python to pybind11
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes the migration of all PyCUDA C++ extension wrapper code from Boost.Python to pybind11.
API Replacements
BOOST_PYTHON_MODULEPYBIND11_MODULEpy::extract<T>.cast<T>()py::optional<T>py::stl_input_iterator<T>/PYTHON_FOREACHpy::wrapper<T>+py::pure_virtualPYBIND11_OVERRIDE_PUREtrampolinepy::with_custodian_and_ward_postcallpy::keep_alivepy::return_value_policy<manage_new_object>py::return_value_policy::take_ownershippy::return_self<>()py::return_value_policy::referencepy::bases<T>.staticmethod("name").def_static("name", fn)add_property(...)def_property_readonly(...)py::no_initFiles Changed
wrap_cudadrv.cpp— main driver bindings, full migrationmempool.cpp—expose_memory_pooltemplate updated: replacedWrapper::wrapped_type(Boost.Python-specific) with explicitPoolTypetemplate parameterwrap_cudagl.cpp,wrap_curand.cpp— migrated to pybind11py::module_ &mpatterncuda.hpp,cuda_gl.hpp— replacedpy::extract<>,py::handle<>with pybind11 equivalentswrap_helpers.hpp,tools.hpp— globalnamespace py = pybind11, addednumpy/npy_2_compat.hNumpy 2.0 Compatibility
Updated deprecated numpy C API calls:
tp_descr->elsize→PyDataType_ELSIZE(tp_descr)PyArray_CORDER/PyArray_FORTRANORDER→NPY_CORDER/NPY_FORTRANORDERNPY_FARRAY/NPY_CARRAY→NPY_ARRAY_FARRAY/NPY_ARRAY_CARRAYPyArray_BASE()→PyArray_SetBaseObject()✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.