Port the Python bindings to nanobind, ship cp312-abi3 wheels, and use the C++11 string ABI #1188
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1188"
general
weight: 0.35
gigony
<!--
Thank you for contributing to cuCIM :)
Here are some guidelines to help the review process go smoothly.
1. Please write a description in this text box of the changes that are being
made.
2. Please ensure that you have written units tests for the changes made/features
added.
3. If you are closing an issue please use one of the automatic closing words as
noted here: https://help.github.com/articles/closing-issues-using-keywords/
4. If your pull request is not ready for review but you want to make use of the
continuous integration testing facilities please label it with
[WIP].5. If your pull request is ready to be reviewed without requiring additional
work on top of it, then remove the
[WIP]label (if present) and replaceit with
[REVIEW]. If assistance is required to complete the functionality,for example when the C/C++ code of a feature is complete but Python bindings
are still required, then add the label
[HELP-REQ]so that others can triageand assist. The additional changes then can be implemented on top of the
same PR. If the assistance is done by members of the rapidsAI team, then no
additional actions are required by the creator of the original PR for this,
otherwise the original author of the PR needs to give permission to the
person(s) assisting to commit to their personal fork of the project. If that
doesn't happen then a new PR based on the code of the original PR can be
opened by the person assisting, which then will be the PR that will be
merged.
6. Once all work has been done and review has taken place please do not add
features or make changes out of the scope of those requested by the reviewer
(doing this just add delays as already reviewed code ends up having to be
re-reviewed/it is hard to tell what is new etc!). Further, please do not
rebase your branch on main/force push/rewrite history, doing any of these
causes the context of any comments made by reviewers to be lost. If
conflicts occur against main they should be resolved by merging main
into the branch used for making the pull request.
Many thanks in advance for your cooperation!
-->
This PR moves the
cucim.claraPython bindings from pybind11 to nanobind and builds_cucimagainst the CPython 3.12 stable ABI. CI then builds onecp312-abi3wheel and one Python-version-independent conda package per CUDA version and architecture, and tests them on Python 3.12, 3.13, and 3.14. The PR also removes_GLIBCXX_USE_CXX11_ABI=0, so libcucim, its plugins, and_cucimuse the default C++11 string ABI of libstdc++.Closes #1029.
Closes #1163.
Related issues and PRs
None of these is closed. This PR uses no closing keyword for them, and GitHub closing keywords do not close pull requests.
cp311-abi3, a version-independent conda package, stable artifact names, and one build per CUDA version and architecture. This PR delivers those packaging goals with nanobind andcp312-abi3.maindropped Python 3.11 in #1177, and a comment on #1151 explains why nanobind is preferred. Two of #1151's non-goals do not hold here. This PR changes libcucim's string ABI (#1163), and it changes some Python behavior (see "Release notes"). Therapidsai/ci-imgscleanup in #1151 is not done, because it belongs to that repository. Closing #1151 is up to its author.codex/cython-abi3) reduces the build matrix. Commit 7 cherry-picks its one commit unchanged, and commit 8 fixes the docs build that it did not update. Once this PR merges, #1153 is superseded but stays open until someone closes it.Who is affected
cucim.clara. Members of the scoped enumsCacheType,DeviceType, andFileHandleTypeno longer supportint()or__index__().DLDataTypeCodemembers still support both, because the new binding makesDLDataTypeCodeanenum.IntEnum. Boolean arguments accept onlyTrueandFalse, and path and text arguments are stricter. See "Release notes" for the full list. cuCIM's owntest_image_cache.pyusedint(cache.type)and needed a one-line change per assertion, so downstream code may need the same change.cp312-abi3. The conda package is built once on Python 3.12 and installs on Python 3.12 and later. Each PR pipeline builds 4 conda Python packages and 4 wheels instead of 12 of each. The test jobs are unchanged.Commits
Review the PR commit by commit.
1. Add regression tests for the cucim.clara binding surface.
test_bindings.pyandtest_bindings_cuimage.pypin what callers of_cucimobserve. Tests that need no generated image are intest_bindings.py, so they also run whereimagecodecsis missing (aarch64 wheel jobs). On the pybind11 build, every test passes excepttest_profiler_config_keyword, which crashes the interpreter.2. Port the Python bindings from pybind11 to nanobind.
python/pybind11becomespython/nanobind, built with nanobind 3.1 andnanobind_add_module(... STABLE_ABI ...). pybind11, its 2.11 patch, and pybind11_json are removed. This commit kept pybind11's conversions inpython/nanobind/compat.h. Commit 5 removes its string caster, and commit 10 removes the file.3. Tag cucim wheels cp312-abi3 and audit the stable ABI.
setup.pysetspy_limited_apitocp312.ci/validate_wheel.shfails if there is nocp312-abi3wheel, and it runsabi3audit --strict.4. Use the C++11 string ABI. This commit removes all seven
_GLIBCXX_USE_CXX11_ABI=0settings and the old-ABI branch ofImageMetadata. One setting was a PUBLIC compile definition oncucim::cucim, which forced the old ABI on every consumer.5. Use nanobind's stock string caster and take paths as std::filesystem::path. Text parameters accept only
str, and path parameters use nanobind'sstl/filesystem.h.docs/source/api.rstgains a "Path and text arguments" section.6. Make the cucim conda package independent of the Python version. This is Michael Sarahan's recipe change from #1152 (
1a07dd7a), adapted to Python 3.12 and without its Cython build changes.7. Reduce ABI3 build matrix. Michael Sarahan's commit from #1153, cherry-picked unchanged with
-x. Conda and wheel builds keep the lowest Python per CUDA version and architecture, and the CI scripts use--stableartifact names.8. Download the stable conda artifact in the docs build.
ci/build_docs.shdownloads the conda package too, and #1153 did not change it. Without this commit, the docs jobs look for a per-Python artifact that no job uploads.9. Use the canonical SPDX notice in ci/build_wheel.sh.
verify-copyrightrequires it because commit 7 changes the file.10. Use nanobind's own enum and bool behavior and remove compat.h. Enums use
nb::enum_, andDLDataTypeCodekeepsnb::is_arithmetic(). Boolean parameters takebool, and conversions usenb::cast. Two newdocs/source/api.rstsections document the changes. This follows review feedback that slightly preferred the breaking change to the compatibility shims.11. Update .github/CODEOWNERS.
python/nanobindis owned by@rapidsai/cucim-python-codeownersas well as@rapidsai/cucim-cpp-codeowners.12. Update conda/recipes/cucim/meta.yaml. The host requirement
python ={{ py_abi_min }}becomespython {{ py_abi_min }}., matching thepython-abi3line. Conda'sMatchSpectreats both forms aspython=3.12.13. Update conda/recipes/cucim/meta.yaml. The run requirement
python >=3.12becomespython, andpython-gilstays.python-abi3supplies the Python 3.12 lower bound, as described in "Packaging and build".Commits 11 to 13 apply jakirkham's review suggestions.
Release notes
The
cucim.clarabindings use nanobind instead of pybind11 and are built against the CPython 3.12 stable ABI. Onecp312-abi3wheel installs on Python 3.12, 3.13, 3.14, and 3.15. Public names are unchanged.A probe recorded 183 cases on
main(pybind11,8a67a731) and on this branch, and every change below comes from that comparison. The probe and the tests cover only the calls they make.Compatibility note
Equality with integers is preserved. Members of
CacheType,DeviceType, andFileHandleTypecompare unequal to integers in both the previous pybind11 bindings and this branch. For example,io.Device("cuda").type == 2remainsFalse.DLDataTypeCodemembers continue to compare equal to their corresponding integers. For example,DLDataTypeCode.DLUInt == 1remainsTrue. The new binding usesenum.IntEnumto preserve this behavior.Breaking changes
enummodule.cache.CacheType,io.DeviceType, andfilesystem.FileHandleTypeareenum.Enumclasses.DLDataTypeCodeis anenum.IntEnum.-
int(member)andoperator.index(member)raiseTypeErrorforCacheType,DeviceType, andFileHandleType. Usemember.value.- An unknown value, such as
DeviceType(99), raisesValueError. pybind11 returned an unnamed<DeviceType.???: 99>member.-
repr(member)isDeviceType.CUDAinstead of<DeviceType.CUDA: 2>.str()andformat()still giveDeviceType.CUDA.- Members of the three
Enumclasses hash by name instead of by value.-
DLDataTypeCodemembers are nowintinstances and support<and>.TrueorFalse. pybind11 also acceptedNoneand numbers such asnumpy.bool_,0,1, and1.0. Passbool(value)instead.-
read_region(drop_last=, shuffle=),filesystem.CuFileDriver(no_gds=, use_mmap=), andCuImageIterator(ending=)raiseTypeErrorfor other values.-
CuImage.cache(record_stat=)andCuImage.profiler(trace=)read these values fromkwargs, so they raiseRuntimeError: std::bad_cast.-
preadrequires the read-only flag in a buffer's__array_interface__or__cuda_array_interface__data tuple to be abool, and raisesRuntimeErrorotherwise. NumPy and CuPy set abool.pwritedoes not read the flag.bytearraypath raisesTypeError. So does a path with an embedded NUL character, where pybind11 cut the path at the NUL and opened the shorter path. Text arguments that are not paths, such asdim_order, device names, and thefilesystem.openflags, raiseTypeErrorforbytesandbytearray.- A call that matches no signature reports "incompatible function arguments" instead of "incompatible constructor arguments".
- A value that fails to convert inside a binding still raises
RuntimeError, with the message "std::bad_cast". pybind11 reported "Unable to cast Python instance of type ... to C++ type '?'". Examples areCuImage.cache("per_process", capacity="1")and aread_regionlocation that is not an integer.Fixes and additions
CuImage.profiler(trace=True)no longer crashes the interpreter. The pybind11 binding released the GIL and then read its keyword arguments.read_regionaccepts a NumPyint64array forlocation. pybind11 checked only for buffer formatq, and NumPy reportslon 64-bit Linux.DLDataType(code, bits, lanes)also accepts a plain integercodethat names a member, such as1.os.PathLikeobjects. A file name that is not valid UTF-8 can be passed asbytesor as anos.fsdecode()string.docs/source/api.rstdocuments the enum, boolean, path, and text changes.C++ ABI break
std::stringnow usestd::__cxx11::basic_string, so their mangled names change.ImageMetadataalways storesdims_andcoord_sys_asstd::pmr::string. This changes its layout.cucim::cucimCMake target no longer exports the definition, so consumers compile with their compiler's default ABI.A binary built with
_GLIBCXX_USE_CXX11_ABI=0against an older libcucim references string symbols that libcucim no longer exports. It fails at load time or on the first call. Even where no string crosses the boundary, such a binary can disagree on theImageMetadatalayout. Don't mix libcucim or plugin binaries from before and after this change in one process. Python users of the wheel need no action, because the wheel bundles libcucim, the plugins, and_cucim. The cucim conda package requires the libcucim package of the same version.Packaging and build
>=3.1.0,<3.2.0a0) is a build dependency independencies.yaml.pr.yamlandbuild.yamluse thematrix_filterthat cuDF and cuVS use, which keeps the lowest Python per CUDA version and architecture. With the current matrix, that is Python 3.12.python_version_independent: trueagainstpython-abi3. Its build string iscuda<major>_cp312_abi3_….- The recipe's run requirements list
pythonandpython-gilwithout a version.- The Python 3.12 lower bound comes from
python-abi3 3.12, whose run_exports addcpython >=3.12and_python_abi3_support 1.. This was checked in the conda-forge buildhe1d15d4_3.- A package built locally at
17319017depended onpython >=3.12from the recipe at that time, pluscpython >=3.12,_python_abi3_support 1., andpython-gil, with nopython_abipin. No package was built locally from commits 12 and 13, so their package metadata is not verified here.ci/build_python.sh,ci/build_wheel.sh,ci/test_python.sh,ci/test_wheel.sh, andci/build_docs.shname the Python artifacts withrapids-artifact-name --stable../runcopies only_cucim.abi3.so. Python imports a stale_cucim.cpython-3XX-.soin preference to an abi3 module, so a leftover build output would shadow the new module.nanobind_add_moduleusesPROTECT_STACKandNOMINSIZE. Without them, nanobind adds-fno-stack-protectorand-Osafter the conda hardening flags.LICENSE-3rdparty.mdand3rdparty/list nanobind and robin-map instead of pybind11 and pybind11_json.Validation
The branch includes
mainatb715b157(#1190), which skipscucim.skimagetests when GitLab rate-limits sample-data downloads. Below commit 10, the tree differs from17319017only by the seven files that #1190 changes.Hosted CI at
17319017(commits 1 to 9, before #1190):- Conda tests on Python 3.12 (amd64, CUDA 12.2) and 3.14 (amd64, CUDA 13.0).
- Wheel tests on Python 3.12 (amd64), 3.13 (arm64), and 3.14 (amd64).
cucim.skimagetest that got HTTP 429 from GitLab: 21 failed or errored tests in one job and 39 in the other. #1190 fixes this.Hosted CI at
1596499e(commit 10, with #1190). All 35 check runs of run 40776096307 passed. They include the 12 package builds, the docs build, and all 7 test jobs. This description does not report hosted CI for commits 11 to 13.Local, at commit 10. All local checks ran on one x86_64 machine (i9-13900K, RTX A6000) with GCC 14.4 and CUDA 13.3, in conda environments.
./run build_local all releaseat commit 9 with #1190 succeeds. Its only warnings are four-Wclobberedwarnings in cuslide'slibjpeg_turbo.cpp, which this PR does not change. At commit 10, the five binding sources recompile with no warnings.pytest tests/unit tests/performanceinpython/cucimwith the onecp312-abi3module:- Python 3.12 and 3.13: 164 passed, 5 skipped.
- Python 3.14: 161 passed, 5 skipped, 3 xpassed. The 3 xpassed are cases of
test_read_random_region_cpu_memleakmarked xfail for #1043. No pybind11 build was tested on 3.14, so this PR does not claim to fix #1043.- The updated enum and bool tests fail 6 times against the commit-9 build, so they detect the change.
int(),operator.index()andrepr(), boolean arguments, and conversion messages.pre-commit run --hook-stage manual --all-files, as CI runs it, passes on a clean clone.sphinx-build -b dirhtmlsucceeds with the same 5 warnings at commits 9 and 10.Local, at earlier commits. None of these was rerun at commit 10.
auditwheelpassesci/validate_wheel.sh: pydistcheck,twine check --strict, the tag check, andabi3audit --strict. Installed on Python 3.12, 3.13, and 3.14, it passes the test suite of that commit.17319017. libcucim and cucim conda packages build from clean clones with conda-build 26.9.1. The cucim package built once for Python 3.12 installs and passestests/unitandtests/performanceon Python 3.12, 3.13, and 3.14. The recipe before commit 6 produces a package that can't be installed on 3.13 or 3.14.17319017. A script expands each job's matrix with shared-workflows' jq program. Every conda test, wheel test, and docs job downloads an artifact that a build uploads, built on a Python no newer than its own. Without commit 8, the docs jobs fail this check._GLIBCXX_USE_CXX11_ABI.nmshows that libcucim, the plugins, and_cucimimport onlystd::__cxx11string symbols. Before commit 4, libcucim imported 23 old-ABI string symbols.read_regionfor a region, a pyramid level, and batches (compared with tifffile), andcucim convertwith readback all pass.Not validated
67b37775), which this description does not report. Commit 11 changes only.github/CODEOWNERS, and commits 12 and 13 change the conda recipe's Python requirements.manylinux_2_39, and CI buildsmanylinux_2_28wheels.Historical performance measurements
These numbers are from commit 4, measured against
mainat8a67a731. They were not rerun after commits 5 to 10. Commits 6 to 9 change only packaging and CI. Commits 5 and 10 change argument conversion for strings, paths, enums, and booleans, and the benchmark calls few of those.shape,dims,dtype,resolutions,spacing(),channel_names) took 1.1 µs instead of 2.1 µs, 45% less. This is associated with the nanobind build, which also differs from the pybind11 build in LTO and default flags.img.metadatatook 6.3 µs instead of 7.3 µs, 14 to 16% less. This is associated with commit 4, which changes both the C++ string ABI and theImageMetadatamember layout.read_regiontook 17.8 µs instead of 20.0 µs, 11% less. The difference was clear in the second run only.<details>
<summary>Benchmark method and full results (commit 4)</summary>
Three trees were built with
./run build_local all releasein one conda environment (Python 3.12.16, GCC 14.4, CUDA 13.3, nvImageCodec 0.9.0, NumPy 2.5.4, CuPy 14.2.0):8a67a731, pybind11,_GLIBCXX_USE_CXX11_ABI=0._GLIBCXX_USE_CXX11_ABI=0.Each measurement is a fresh process pinned to performance cores. The build order rotates every round. For the 7-round workloads, one build goes first one extra time. Every process checks that libcucim,
_cucim, and the plugins load from its own build tree, and the outputs match across builds. The libcucim tile cache is off, and the files are in the page cache.Lower is better. Each value is the median over processes, with the min to max range and the process count. Each process reports the median of 7 to 15 samples after warmup. "None measurable" means that the ranges overlap or that a Mann-Whitney test gives p ≥ 0.05. It does not mean that the builds perform the same.
| Workload (data) | main (pybind11) | commit 4 | Change | Associated build change |
|---|---|---|---|---|
|
import cucim+ firstCuImage(path), cold process | 543 ms (536 to 572, n=15) | 542 ms (535 to 557, n=15) | none measurable | ||
CuImage(path), 4096x4096 JPEG TIFF | 46.2 µs (43.7 to 48.2, n=7) | 45.5 µs (44.0 to 47.5, n=7) | none measurable | ||
img.metadata(JSON to dict) | 7.3 µs (7.3 to 7.4, n=7) | 6.3 µs (6.2 to 6.4, n=7) | −14% (rerun −16%) | string ABI andImageMetadatalayout commit −18%, nanobind build +3 to +4% ||
shape,dims,dtype,resolutions,spacing(),channel_names| 2.1 µs (2.0 to 2.3, n=7) | 1.1 µs (1.1 to 1.1, n=7) | −45% (rerun −45%) | nanobind build || 16x16
read_region+np.asarray, tiny JPEG TIFF | 20.0 µs (18.2 to 21.3, n=7) | 17.8 µs (16.5 to 18.8, n=7) | −11% in both runs (run 1 p=0.004 with overlapping ranges, run 2 p=0.001) | nanobind build || Full-level
read_region4096x4096, JPEG | 46.4 ms (45.6 to 47.4, n=7) | 46.6 ms (45.7 to 47.8, n=7) | none measurable | || Full-level
read_region4096x4096, deflate | 60.0 ms (59.0 to 65.4, n=7) | 59.8 ms (59.0 to 61.6, n=7) | none measurable | || 256 tiles of 256x256 via
ThreadPoolExecutor(8), JPEG | 6.99 ms (6.78 to 7.48, n=7) | 6.76 ms (6.66 to 6.96, n=7) | none measurable (−3% and −5% in the two runs, ranges overlap) | || Batched iterator, 256 random 256x256 patches,
num_workers=8,batch_size=32| 22.9 ms (22.3 to 24.3, n=7) | 22.8 ms (22.3 to 24.0, n=7) | none measurable | || GPU
read_region(device="cuda")4096x4096 JPEG, synchronized | 45.4 ms (43.9 to 47.7, n=7) | 45.3 ms (44.3 to 45.8, n=7) | none measurable | |A profile of the
metadatawork shows about 25% fewer allocator samples after commit 4. This fits C++11 strings that store short JSON keys and values inline, but the mechanism is inferred, not measured directly.In a
perfprofile of the threaded JPEG tile scan, 76% (pybind11) and 80% (nanobind) of on-CPU samples are in the cuslide plugin, mostly JPEG decoding. The binding modules hold 0.8% and 0.5% of on-CPU samples. These percentages are not the total binding overhead, and they are not fractions of wall time.Limitations:
python/cucim/tests/util/gen_image.py. The deflate file is 185 KB because the pattern compresses well.cucim convertCLI is not benchmarked because it uses OpenSlide and tifffile rather than the bindings.The benchmark scripts and raw measurements (339 processes over two runs) are not part of this PR and can be shared on request.
</details>
Binding build-mode comparison at
67b37775A separate study, run on October 29, 2026 at
67b37775, compared three nanobind configurations with byte-identical libcucim and plugin binaries: linked withSTABLE_ABI(this PR), linked with the full API, and split mode. Its results support keeping the current build.cucim.claratests gave 139 passed and 1 skipped.The study used local builds on CPython 3.12.16 on one desktop machine. It does not validate production wheel or conda packaging at
67b37775, and it is separate from the historical measurements above.Pre-existing issues found, not fixed here
These issues also occur on
main.auditwheelgrafts, so they bypass a cache configured from Python. Current nightly wheels have the same layout.CuFileDriver.preadandpwritebounds check ignoresbuf_offset, so a nonzero offset can access memory past the end of the buffer.repr,metadata, orsave()on a closedCuImagecrashes.read_region(..., device="cuda")on a TIFF that is not JPEG-compressed aborts with "Unsupported compression method".PerProcessImageCache::remove_front. The crash happened in 4 to 7 of 20 runs on each build.Assisted-by: Claude Code