[RFC] Introduce `cuda-cccl` as a required dependency
cuda.cccl currently contains two main submodules, cuda.cccl.parallel and cuda.cccl.cooperative. This issue mainly focuses on the former, assuming that the later introduces no interference to CuPy users.
cuda.cccl.parallel
cuda.cccl.parallel is the Python library for easily accessing CCCL’s highly efficient and customizable parallel algorithms, like sort, scan, reduce, transform, etc, that are callable on the host. One can think of it as “pyThrust” (which was how it was referred to when the project was conceived), although we do purposely keep the distinction vague between Thrust and CUB device-wide algorithms.
One notable advantage of cuda.cccl.parallel is that the library size is very small, as we push everything to run-time JIT compilation using NVRTC + nvJitLink (i.e. NVCC is not needed!). This allows us to cover almost all CUB device-wide algorithms in Python without much difficulty. Even C++ fancy iterators are supported in Python!
Algorithm Integration
The plan for integrating with cuda.cccl.parallel is actually pretty "simple": We reimplement the two biggest submodules, cupy.cuda.thrust and cupy.cuda.cub, using cuda.cccl.parallel. This will reduce both build time and binary size significantly. Based on our study of the involved Thrust/CUB algorithms, which is also reported by DeepWiki, we believe the needed Python exposures are immediately within reach.
A future step could be to nuke both modules and refactor the cuda.cccl.parallel calls closer to the actual call sites inside CuPy, so as to reduce the amount of internal abstraction/indirection. However, this does not have to happen as part of this plan.
As for new features such as segmented sort, CuPy is free to choose whether to actually expose them (ex: cupyx.segmented_sort() https://github.com/cupy/cupy/issues/6699), or just direct CuPy users to use cuda.cccl.parallel pythonic APIs, which are supposed to be able to accept CuPy arrays as input arguments (the specifics are not yet fully laid out).
Known Blockers
cuda.cccl.paralleltoday still lists CuPy as a required dependency, which the CUDA Python team is actively addressing so as to avoid circular imports by the time the CuPy integration starts.- numba-cuda (Numba’s CUDA target, now separated from Numba and maintained by the CUDA Python team) is currently used internally by
cuda.cccl.parallel, so if this is unchanged the integration ofcuda.cccl.parallelwill introducenumba-cuda,numba, and its dependencies (such asllvmlite) as transitive dependencies to CuPy. We have a few ideas on how to make numba-cuda an optional dependency, but some work is needed. cuda.cccl(wheel/conda) packages need to be available everywhere CuPy is supported
Source: cupy/cupy