Repository navigation
Open
Epic
0 / 20 of 2 issues completed
Copy link
Description
Is this a duplicate?
- 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, out-of-bound values or on repeatedly applying the reduction operator on items. See:
- inclusive_scan passing invalid data to AssociativeOperator #780
- reduce_by_key passing invalid data to BinaryFunction operator #789
- set_intersection improperly compares keys not in the input #822
- [BUG]:
DeviceScanalgorithms load uninitialized/clobbered scratch memory and perform operations on these #458 - inclusive_scan_by_keys calls the 'sum' operator needlessly #801
There may be multiple root causes to this, particularly for the scan operation:
- The CUDA algorithm implementations within CUB will have threads in a block do things like default construct objects, read past boundaries even if they don't ultimately participate in the work, or repeatedly apply the reduction operation more than once on some items. This is fine for simple operators like
+but for custom operators it can cause failures. - The decoupled look-back algorithm processes windows of 32 tile states at a time. It waits until all tile states of this window are not flagged as
SCAN_TILE_INVALIDanymore. I.e., each tile state of that window contains one of the following three values: (1) a tile's aggregate, (2) a tile's inclusive prefix, or (3) an out-of-bounds value, which is some "uninitialized" value. The decoupled look-back algorithm will then process this window, computing aTailSegmentedReduceover this window to compute the inclusive prefix.TailSegmentedReducestarts from the "rightmost" tile for which the inclusive prefix is available computing the reduction operation over this window. If there's no inclusive prefix amongst any of the tile states, it will just compute the aggregate across this window and continue processing the next window. We need to investigate whetherTailSegmentedReduceis mathematically correct, or whether the reduction operation is applied on some invalid data (e.g., invoking the reduction operation on an aggregate and an itemx, wherexwas already incorporated in the aggregate, hence breaking the invariant the user has on their data). - The decoupled look-back algorithm initializes the the first 32 tile states with the
SCAN_TILE_OOBflag, to make sure we can process the full window that includes the very first "valid" tile state without having to account for reading beyond the beginning of tile states. These out-of-bounds tiles states are processed byTailSegmentedReduceand, hence, are passing invalid data to the reduction operation.
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
- Make sure
cub::DeviceScaninvokes the reduction operator only with valid data #5017 - Make sure
thrust::set_intersectioninvokes the reduction operator only with valid data - Make sure
thrust::reduce_by_key/cub::DeviceReduce::ReduceByKeyinvokes the reduction operator only with valid data
Describe alternatives you've considered
No response
Additional context
No response
Sub-issues
Collapse Sub-issuesSub-issues
Loading 2 sub-issues
Activity
jrhemstad commentedon Apr 24, 2024
I think we can solve this similarly to how I described here: #1662 (comment)
sarda-devesh commentedon Feb 21, 2025
Coming to this epic from #3890. I am just wondering if there is a plan to include a warning about this in the cub docs while this issue is being resolved? The docs make it seem like the reduction operator only gets called for passed-in values but if that is not the case then that should be documented somewhere so that users can write their code keeping that in mind. I am planning to use thrust/cub with custom operators and am concerned about being able to distinguish between cub passing out-of-bounds data to my operator versus bug in some other part of the code that causes unexpected data to be passed to these operators
cub::DeviceScaninvokes the reduction operator only with valid data #5017