cccl
cccl copied to clipboard
[EPIC]: Thrust/CUB shouldn't invoke user-defined operators on out-of-bounds data
Is this a duplicate?
- [X] I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct
Area
General CCCL
Is your feature request related to a problem? Please describe.
As a user of Thrust/CUB, I can provide a custom operator to the many algorithms. My operator may only be defined for the values that are present in the input. As a result, it can be problematic if that operator is invoked on any other values, including uninitialized values.
However, there have been numerous reports of Thrust/CUB algorithms invoking user-defined operators on uninitialized or otherwise out-of-bound values. See:
- https://github.com/NVIDIA/cccl/issues/780
- https://github.com/NVIDIA/cccl/issues/789
- https://github.com/NVIDIA/cccl/issues/822
- https://github.com/NVIDIA/cccl/issues/458
- https://github.com/NVIDIA/cccl/issues/801
I believe this is because the CUDA algorithm implementations within Thrust and CUB will have threads in a block do things like default construct objects or read past boundaries even if they don't ultimately participate in the work of the algorithm which can ultimately lead to problems like this. This is fine for simple operators like +
, but for custom operators it can cause failures.
Describe the solution you'd like
We should eliminate all cases where Thrust/CUB algorithms will invoke user-defined operators on out-of-bounds or uninitialized values.
### Tasks
- [ ] Verify root cause of issue
- [ ] Identify affected algorithms
- [ ] Design solution to avoid reading out of bounds elements
- [ ] Update affected algorithms with decided upon solution
- [ ] Consider updating testing strategy to identify when operators are invoked on out-of-bounds elements
Describe alternatives you've considered
No response
Additional context
No response
I think we can solve this similarly to how I described here: https://github.com/NVIDIA/cccl/issues/1662#issuecomment-2075009311