Install CCCL via rapids-cmake #1241
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)
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?
Didn't read the description, so might be missing some context here
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.
I agree this seems like something that should be done by CMake.
Generally this looks right! Thank you @grlee77.
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:
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.Let's also add this to [cpp/CMakeLists.txt]( https://github.com/rapidsai/cucim/blob/release/26.12/cpp/CMakeLists.txt )
Thanks Greg! 🙏
Let's go ahead and configure the C++ builds similarly. This will help Cristiana as well
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.
@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.
@gforsyth, please take another look when you have a chance, thanks
Approved these changes.
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)
cmake_minimum_required(VERSION 4.3 FATAL_ERROR)
Thanks Greg! 🙏
Let's require CMake 4.3 throughout given we bumped it recently: https://github.com/rapidsai/cucim/pull/1235
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
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
Thank you @grlee77
It looks good to me.
Approved these changes.
/merge
bdice
grlee77
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 extensionmodules that use CUB/Thrust. It adds no such module and changes no
cucim.skimagecode: theexisting
_cucimmodule builds as before, and every new packaging step does nothing until amodule exists. The first user is the batch
regionpropsintensity_median, whosecub::DeviceSegmentedSortextension will follow in a separate PR.The setup follows cudf, cuml and cuvs instead of adding cuCIM-specific mechanisms:
cmake/RAPIDS.cmakeandcmake/rapids_config.cmakefiles those projects use.rapids_cpm_cccl()(currently CCCL 3.7.0), so every CUDA version buildsagainst the RAPIDS-pinned CCCL instead of the one bundled with the CUDA Toolkit.
rapids_cuda_init_architectures._cucim_skimage_<name>are placed in thecucim.skimagepackage by./run build_local, the conda recipe and the wheel build.Changes
1. Fetch the RAPIDS-pinned CCCL with rapids-cmake
cmake/RAPIDS.cmakeis identical to cudf's, cuml's and cuvs's.cmake/rapids_config.cmakematches cuml's (cudf's differs only in a variable name). It reads
VERSIONand the newRAPIDS_BRANCHfile (main) to choose the rapids-cmake branch.ci/release/update-version.shnow writesRAPIDS_BRANCH(main, orrelease/<version>onrelease branches), as cudf's does.
python/CMakeLists.txtincludesrapids_config.cmakebeforeproject()and callsrapids_cpm_init()andrapids_cpm_cccl(). No target linksCCCL::CCCLyet. No export setsare passed, so no CCCL install rules are generated.
rapids_cpm_cccl()looks for the pinned version withfind_package(... EXACT), so an older CCCLfrom the toolkit is never picked up silently.
CCCL::CCCLalso carries the RAPIDS compiledefinitions, for example
CUB_DISABLE_NAMESPACE_MAGICandTHRUST_DISABLE_ABI_NAMESPACE. Thismatches cudf's
python/cudf/udf_cpp, which also callsrapids_cpm_cccl()directly for aPython-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 beforeproject(), as in every cudf, cuml andcuvs 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.CUDAARCHSorCMAKE_CUDA_ARCHITECTURESstill override it; for example,CUDAARCHS=NATIVEgives faster local builds. Without this call, nvcc would build only its default architecture.
With
CUB_DISABLE_NAMESPACE_MAGIC, the CUB and libcu++ symbols a module instantiates are notplaced 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 ascucim/_cucim) and is listed inINSTALL_TARGETSis built aslib/cucim/skimage/_cucim_skimage_<name>.abi3.so. Until now, only_cucimwas copied into thePython 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 onlycucim, anda comment describing the naming scheme.
run(build_local): copy_cucim_skimage_.abi3.sointosrc/cucim/skimage/after removingstale copies.
conda/recipes/cucim/recipe.yaml: the install step puts these modules next to_cuciminpython/install/lib/, which the recipe copies intocucim/clara/. The recipe now moves theminto
cucim/skimage/.python/cucim/MANIFEST.in:include src/cucim/skimage/.so. Without this line, setuptoolsleaves the module out of the wheel.
The PR that adds the first module will also add:
CUDA::cudart_static), as libcucim and its plugins do;ci/validate_wheel.shcheck and a conda import test for that specific module;Testing
python/fetches rapids-cmake main and CCCL 3.7.0. The existing_cucimmodule builds after each commit, using the libcucim from a local source build
(
CUCIM_SDK_PATH).cub::DeviceReduce::Sumand linksCCCL::CCCLwas added throughCMAKE_PROJECT_INCLUDE:- it reports
CUB_VERSION300700;- 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::orcuda::stdsymbols, onlyPyInit_and nanobind's exception types._cucim_skimage_probe:- CMake put it at
lib/cucim/skimage/and installed it atpython/install/lib/.- The new
runand recipe snippets, run underset -euandset -euo pipefail, moved it intosrc/cucim/skimage/. Without a module they ran without errors and left nothing behind.-
pip wheelproduced a wheel containingcucim/skimage/_cucim_skimage_probe.abi3.so. Withoutthe new
MANIFEST.inline, the wheel did not contain it.Not run locally: the conda package and CI wheel builds.
Notes for reviewers
Benchmark, NVTX3 and others) are still fetched with
FetchContent. Moving the ones rapids-cmakesupports is left for a follow-up.
References
Partially addresses issues:
https://github.com/rapidsai/cucim/issues/627
https://github.com/rapidsai/cucim/issues/859