← Back to Pull requests

Install CCCL via rapids-cmake #1241

Merged
grlee77 merged 8 files (207 lines) on Nov 23, 2026 22:48 UTC
View on GitHub
grlee77 grlee77 commented on Nov 19, 2026 20:02 UTC
Author

Context

#1197 uses CUB segmented sort functionality from Python via nanobind wrappers. This MR pulls the addition of the CCCL dependency out into its own standalone MR. The approach using rapids-cmake here was adapted by an agent from what is being done by other rapids projects (cuDF, cuML).

Note that #1147 has also added CCCL dependency but is not using rapids-cmake.

A follow-up MR could update other pre-existing dependencies to also install via rapids-cmake (rapids_cpm_find, etc).

Summary

This PR prepares the cuCIM Python build (python/CMakeLists.txt) for compiled CUDA extension
modules that use CUB/Thrust. It adds no such module and changes no cucim.skimage code: the
existing _cucim module builds as before, and every new packaging step does nothing until a
module exists. The first user is the batch regionprops intensity_median, whose
cub::DeviceSegmentedSort extension will follow in a separate PR.

The setup follows cudf, cuml and cuvs instead of adding cuCIM-specific mechanisms:

  • rapids-cmake is bootstrapped from the same cmake/RAPIDS.cmake and

  • cmake/rapids_config.cmake files those projects use.
  • CCCL comes from rapids_cpm_cccl() (currently CCCL 3.7.0), so every CUDA version builds

  • against the RAPIDS-pinned CCCL instead of the one bundled with the CUDA Toolkit.
  • CUDA architectures default to the RAPIDS list through rapids_cuda_init_architectures.

  • Packaging: compiled modules named _cucim_skimage_<name> are placed in the

  • cucim.skimage package by ./run build_local, the conda recipe and the wheel build.

    Changes

    1. Fetch the RAPIDS-pinned CCCL with rapids-cmake

  • cmake/RAPIDS.cmake is identical to cudf's, cuml's and cuvs's. cmake/rapids_config.cmake

  • matches cuml's (cudf's differs only in a variable name). It reads VERSION and the new
    RAPIDS_BRANCH file (main) to choose the rapids-cmake branch.
  • ci/release/update-version.sh now writes RAPIDS_BRANCH (main, or release/<version> on

  • release branches), as cudf's does.
  • python/CMakeLists.txt includes rapids_config.cmake before project() and calls

  • rapids_cpm_init() and rapids_cpm_cccl(). No target links CCCL::CCCL yet. No export sets
    are passed, so no CCCL install rules are generated.

    rapids_cpm_cccl() looks for the pinned version with find_package(... EXACT), so an older CCCL
    from the toolkit is never picked up silently. CCCL::CCCL also carries the RAPIDS compile
    definitions, for example CUB_DISABLE_NAMESPACE_MAGIC and THRUST_DISABLE_ABI_NAMESPACE. This
    matches cudf's python/cudf/udf_cpp, which also calls rapids_cpm_cccl() directly for a
    Python-side CUDA module.

    2. Enable CUDA in the Python extension build and select architectures

  • project(cucim ... LANGUAGES CXX CUDA).

  • rapids_cuda_init_architectures(cucim) is called before project(), as in every cudf, cuml and

  • cuvs CMake project, including their Python ones. Builds default to the RAPIDS architecture list:
    with rapids-cmake main this is 75-real;80-real;86-real;90a-real;100f-real;120a-real;120.
    CUDAARCHS or CMAKE_CUDA_ARCHITECTURES still override it; for example, CUDAARCHS=NATIVE
    gives faster local builds. Without this call, nvcc would build only its default architecture.
  • CUDA uses the same standard (C++17) and symbol visibility (hidden) as the existing C++ settings.

  • With CUB_DISABLE_NAMESPACE_MAGIC, the CUB and libcu++ symbols a module instantiates are not
    placed in a namespace unique to the module. Hiding them keeps them from interposing with other
    CUB users in the same process, such as CuPy.

    3. Package compiled cucim.skimage extension modules

    A module whose target has OUTPUT_NAME cucim/skimage/_cucim_skimage_<name> (the same scheme as
    cucim/_cucim) and is listed in INSTALL_TARGETS is built as
    lib/cucim/skimage/_cucim_skimage_<name>.abi3.so. Until now, only _cucim was copied into the
    Python sources, so such a module would have been built and installed by CMake but missing from
    wheels and conda packages.

  • python/CMakeLists.txt: install(TARGETS ${INSTALL_TARGETS} ...) instead of only cucim, and

  • a comment describing the naming scheme.
  • run (build_local): copy _cucim_skimage_.abi3.so into src/cucim/skimage/ after removing

  • stale copies.
  • conda/recipes/cucim/recipe.yaml: the install step puts these modules next to _cucim in

  • python/install/lib/, which the recipe copies into cucim/clara/. The recipe now moves them
    into cucim/skimage/.
  • python/cucim/MANIFEST.in: include src/cucim/skimage/.so. Without this line, setuptools

  • leaves the module out of the wheel.

    The PR that adds the first module will also add:

  • static linking of the CUDA runtime (CUDA::cudart_static), as libcucim and its plugins do;

  • a ci/validate_wheel.sh check and a conda import test for that specific module;

  • any change to the wheel size limit its device code requires.
  • Testing

  • CMake configure of python/ fetches rapids-cmake main and CCCL 3.7.0. The existing _cucim

  • module builds after each commit, using the libcucim from a local source build
    (CUCIM_SDK_PATH).
  • Throwaway probe module (not part of this PR). A nanobind module that calls

  • cub::DeviceReduce::Sum and links CCCL::CCCL was added through CMAKE_PROJECT_INCLUDE:
    - it reports CUB_VERSION 300700;
    - it returns the correct sum on an RTX A6000;
    - it contains SASS for sm_75, sm_80, sm_86, sm_90a, sm_100, sm_120 and sm_120a, plus sm_120 PTX;
    - it exports no cub:: or cuda::std symbols, only PyInit_
    and nanobind's exception types.
  • Packaging, in a scratch copy of the branch with the probe built as

  • _cucim_skimage_probe:
    - CMake put it at lib/cucim/skimage/ and installed it at python/install/lib/.
    - The new run and recipe snippets, run under set -eu and set -euo pipefail, moved it into
    src/cucim/skimage/. Without a module they ran without errors and left nothing behind.
    - pip wheel produced a wheel containing cucim/skimage/_cucim_skimage_probe.abi3.so. Without
    the new MANIFEST.in line, the wheel did not contain it.
  • pre-commit: passes on each commit.
  • Not run locally: the conda package and CI wheel builds.

    Notes for reviewers

  • Other dependencies. cuCIM's other third-party dependencies (fmt, json, Catch2, Google

  • Benchmark, NVTX3 and others) are still fetched with FetchContent. Moving the ones rapids-cmake
    supports is left for a follow-up.

    References

    Partially addresses issues:

    https://github.com/rapidsai/cucim/issues/627
    https://github.com/rapidsai/cucim/issues/859

    Diff: 207 lines (+202 / -5) across 8 files Reviewer: bdice Review duration: 5925m
    All Vouch review confidence checks passed
    Residual risk 0.11 = Change Risk (0.45) × (1 − Review Confidence (0.75)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 207 lines diff across 8 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.52 · 5 substantive comment(s)
    0.52
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    75%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.319
    Real PR Conversation Timeline
    23 items
    gforsyth gforsyth commented on code on Nov 19, 2026 20:40 UTC
    Code Review
    conda/recipes/cucim/recipe.yaml:1
    @@ -47,6 +47,13 @@ build:
           ./run build_local cucim "${CUCIM_BUILD_TYPE}"
     
           cp -P python/install/lib/* python/cucim/src/cucim/clara/
    +      # Compiled cucim.skimage extension modules, if any, belong to the
    +      # cucim.skimage package
    +      for ext in python/cucim/src/cucim/clara/_cucim_skimage_*.so; do
    +        if [ -e "${ext}" ]; then
    +          mv "${ext}" python/cucim/src/cucim/skimage/
    +        fi
    +      done

    This seems like it is duplicative of work aready happening in run -- except there it's a cp and here it's a mv.

    I would remove this and keep the object shuffling in one place (or at least one fewer place)

    gforsyth gforsyth commented on code on Nov 19, 2026 20:41 UTC
    Code Review
    conda/recipes/cucim/recipe.yaml:1
    @@ -47,6 +47,13 @@ build:
           ./run build_local cucim "${CUCIM_BUILD_TYPE}"
     
           cp -P python/install/lib/* python/cucim/src/cucim/clara/
    +      # Compiled cucim.skimage extension modules, if any, belong to the
    +      # cucim.skimage package
    +      for ext in python/cucim/src/cucim/clara/_cucim_skimage_*.so; do
    +        if [ -e "${ext}" ]; then
    +          mv "${ext}" python/cucim/src/cucim/skimage/
    +        fi
    +      done

    Alternatively, can the location for these files be handled by cmake? Is this only an issue for the conda packages or is similar handling required for wheels?

    gforsyth gforsyth requested changes on Nov 19, 2026 20:42 UTC
    Changes Requested Reviewer

    Didn't read the description, so might be missing some context here

    bdice bdice commented on code on Nov 19, 2026 23:17 UTC
    Code Review
    cmake/RAPIDS.cmake:1
    @@ -0,0 +1,85 @@
    +# =============================================================================
    +# cmake-format: off
    +# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    +# SPDX-License-Identifier: Apache-2.0
    +# cmake-format: on
    +# =============================================================================
    +#
    +# This is the preferred entry point for projects using rapids-cmake
    +#
    +# Enforce the minimum required CMake version for all users
    +cmake_minimum_required(VERSION 4.0 FATAL_ERROR)

    I believe we are in the process of updating this to 4.3 as a minimum. Just keep that in mind and we can track it for a follow up.

    bdice bdice commented on code on Nov 19, 2026 23:18 UTC
    Code Review
    conda/recipes/cucim/recipe.yaml:1
    @@ -47,6 +47,13 @@ build:
           ./run build_local cucim "${CUCIM_BUILD_TYPE}"
     
           cp -P python/install/lib/* python/cucim/src/cucim/clara/
    +      # Compiled cucim.skimage extension modules, if any, belong to the
    +      # cucim.skimage package
    +      for ext in python/cucim/src/cucim/clara/_cucim_skimage_*.so; do
    +        if [ -e "${ext}" ]; then
    +          mv "${ext}" python/cucim/src/cucim/skimage/
    +        fi
    +      done

    I agree this seems like something that should be done by CMake.

    bdice bdice approved these changes on Nov 19, 2026 23:18 UTC
    Approved Reviewer

    Generally this looks right! Thank you @grlee77.

    grlee77 grlee77 commented on code on Nov 20, 2026 01:59 UTC
    Code Review
    conda/recipes/cucim/recipe.yaml:1
    @@ -47,6 +47,13 @@ build:
           ./run build_local cucim "${CUCIM_BUILD_TYPE}"
     
           cp -P python/install/lib/* python/cucim/src/cucim/clara/
    +      # Compiled cucim.skimage extension modules, if any, belong to the
    +      # cucim.skimage package
    +      for ext in python/cucim/src/cucim/clara/_cucim_skimage_*.so; do
    +        if [ -e "${ext}" ]; then
    +          mv "${ext}" python/cucim/src/cucim/skimage/
    +        fi
    +      done

    Rebased this onto release/26.12 so @cdinea can rebase #1147 on top of this branch.

    I have followed the suggestion to move this into CMake:

  • A compiled cucim.skimage module target is added to CUCIM_SKIMAGE_EXTENSION_TARGETS in python/CMakeLists.txt. Those targets are installed directly into the package in the source tree (python/cucim/src/cucim/skimage), not under CMAKE_INSTALL_PREFIX. Installing them under the prefix wouldn't work for conda, because the recipe copies everything in python/install/lib/ into cucim/clara/.

  • ./run build_local already runs this install step for local, wheel and conda builds, so neither run nor the recipe copies the modules anymore. The recipe is back to its original state, and run only removes stale _cucim_skimage_*.so files before building.
  • jakirkham jakirkham commented on code on Nov 20, 2026 04:37 UTC
    Code Review
    python/CMakeLists.txt:1
    @@ -17,9 +17,18 @@ file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../VERSION VERSION)
     # strip alpha version info
     string(REGEX REPLACE "a.*$" "" VERSION ${VERSION})
     
    +# Fetch rapids-cmake (used to obtain the RAPIDS-pinned CCCL version)
    +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/rapids_config.cmake)
    +
    +# Build for all RAPIDS-supported GPU architectures unless CMAKE_CUDA_ARCHITECTURES
    +# or the CUDAARCHS environment variable is set (e.g. CUDAARCHS=NATIVE for the
    +# GPU(s) in the build machine only).
    +include(rapids-cuda)
    +rapids_cuda_init_architectures(cucim)
    jakirkham jakirkham commented on Nov 20, 2026 04:39 UTC
    Reviewer

    Thanks Greg! 🙏

    Let's go ahead and configure the C++ builds similarly. This will help Cristiana as well

    grlee77 grlee77 commented on code on Nov 20, 2026 18:56 UTC
    Code Review
    python/CMakeLists.txt:1
    @@ -17,9 +17,18 @@ file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../VERSION VERSION)
     # strip alpha version info
     string(REGEX REPLACE "a.*$" "" VERSION ${VERSION})
     
    +# Fetch rapids-cmake (used to obtain the RAPIDS-pinned CCCL version)
    +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/rapids_config.cmake)
    +
    +# Build for all RAPIDS-supported GPU architectures unless CMAKE_CUDA_ARCHITECTURES
    +# or the CUDAARCHS environment variable is set (e.g. CUDAARCHS=NATIVE for the
    +# GPU(s) in the build machine only).
    +include(rapids-cuda)
    +rapids_cuda_init_architectures(cucim)

    Done in 23f6a333. The libcucim project is declared in the top-level CMakeLists.txt (cpp/ is added as a subdirectory), and rapids_cuda_init_architectures has to run before project(), so the change is there. It mirrors python/CMakeLists.txt: rapids_config.cmake + rapids_cuda_init_architectures(libcucim), LANGUAGES CXX CUDA with C++17 and hidden visibility, and rapids_cpm_cccl() (CCCL 3.6.0 on release/26.12). Nothing links CCCL::CCCL yet and no export sets are passed, so libcucim's install output is unchanged.

    Note that the python/ subfolder is a separate CMake project so we still need to keep it there as well.

    grlee77 grlee77 commented on code on Nov 20, 2026 19:01 UTC
    Code Review
    python/CMakeLists.txt:1
    @@ -17,9 +17,18 @@ file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../VERSION VERSION)
     # strip alpha version info
     string(REGEX REPLACE "a.*$" "" VERSION ${VERSION})
     
    +# Fetch rapids-cmake (used to obtain the RAPIDS-pinned CCCL version)
    +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/rapids_config.cmake)
    +
    +# Build for all RAPIDS-supported GPU architectures unless CMAKE_CUDA_ARCHITECTURES
    +# or the CUDAARCHS environment variable is set (e.g. CUDAARCHS=NATIVE for the
    +# GPU(s) in the build machine only).
    +include(rapids-cuda)
    +rapids_cuda_init_architectures(cucim)

    @cdinea: For cuslide2 in #1147 it looks like all CCCL usage is via libcucim (cucim_malloc, etc) so I don't think any changes will be needed in the CMake for the cuslide2 plugin itself.

    grlee77 grlee77 commented on code on Nov 20, 2026 19:02 UTC
    Code Review
    conda/recipes/cucim/recipe.yaml:1
    @@ -47,6 +47,13 @@ build:
           ./run build_local cucim "${CUCIM_BUILD_TYPE}"
     
           cp -P python/install/lib/* python/cucim/src/cucim/clara/
    +      # Compiled cucim.skimage extension modules, if any, belong to the
    +      # cucim.skimage package
    +      for ext in python/cucim/src/cucim/clara/_cucim_skimage_*.so; do
    +        if [ -e "${ext}" ]; then
    +          mv "${ext}" python/cucim/src/cucim/skimage/
    +        fi
    +      done

    @gforsyth, please take another look when you have a chance, thanks

    gforsyth gforsyth approved these changes on Nov 20, 2026 20:27 UTC
    Approved Reviewer

    Approved these changes.

    jakirkham jakirkham commented on code on Nov 23, 2026 20:16 UTC
    Code Review
    cmake/RAPIDS.cmake:1
    @@ -0,0 +1,85 @@
    +# =============================================================================
    +# cmake-format: off
    +# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    +# SPDX-License-Identifier: Apache-2.0
    +# cmake-format: on
    +# =============================================================================
    +#
    +# This is the preferred entry point for projects using rapids-cmake
    +#
    +# Enforce the minimum required CMake version for all users
    +cmake_minimum_required(VERSION 4.0 FATAL_ERROR)

    Actually we recently merged a PR requiring CMake 4.3: https://github.com/rapidsai/cucim/pull/1235

    So let's go ahead and bump this

    cmake_minimum_required(VERSION 4.3 FATAL_ERROR)
    

    jakirkham jakirkham commented on code on Nov 23, 2026 20:18 UTC
    Code Review
    python/CMakeLists.txt:1

    cmake_minimum_required(VERSION 4.3 FATAL_ERROR)
    

    jakirkham jakirkham commented on Nov 23, 2026 20:20 UTC
    Reviewer

    Thanks Greg! 🙏

    Let's require CMake 4.3 throughout given we bumped it recently: https://github.com/rapidsai/cucim/pull/1235

    jakirkham jakirkham commented on code on Nov 23, 2026 22:13 UTC
    Code Review
    cmake/RAPIDS.cmake:1
    @@ -0,0 +1,85 @@
    +# =============================================================================
    +# cmake-format: off
    +# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    +# SPDX-License-Identifier: Apache-2.0
    +# cmake-format: on
    +# =============================================================================
    +#
    +# This is the preferred entry point for projects using rapids-cmake
    +#
    +# Enforce the minimum required CMake version for all users
    +cmake_minimum_required(VERSION 4.3 FATAL_ERROR)

    cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
    

    jakirkham jakirkham commented on code on Nov 23, 2026 22:13 UTC
    Code Review
    python/CMakeLists.txt:1
    @@ -5,7 +5,7 @@
     # cmake-format: on
     #
     
    -cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
    +cmake_minimum_required(VERSION 4.3 FATAL_ERROR)

    cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
    

    jakirkham jakirkham commented on Nov 23, 2026 22:15 UTC
    Reviewer

    Based on discussion, it sounds like we want to defer adopting CMake 4.3 requirements until 27.02: https://github.com/rapidsai/cucim/pull/1248#issuecomment-7115160943

    Given this, think we should revert the 4.3 changes

    Apologies for the back-and-forth here Greg

    gigony gigony approved these changes on Nov 23, 2026 22:22 UTC
    Approved Reviewer

    Thank you @grlee77
    It looks good to me.

    jakirkham jakirkham approved these changes on Nov 23, 2026 22:46 UTC
    Approved Reviewer

    Approved these changes.

    grlee77 grlee77 commented on Nov 23, 2026 22:48 UTC
    Author

    /merge

    Reviewers
    Assignees
    grlee77 grlee77
    Labels
    risk: low confidence: 75% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 75% · Lower = rushed or shallow review
    75%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 11.3% · Safe to merge
    11.3%
    Repository