Parallelize segmented bitmask binop over words in addition to segments - #23488
Parallelize segmented bitmask binop over words in addition to segments#23488vuule wants to merge 2 commits into
Conversation
The kernel gave each segment one warp, capping parallelism at num_segments * 32 threads regardless of mask size. Use a 2D grid over (destination word, segment) so parallelism scales with the mask size, and move the segment bounds check ahead of the reads it guards.
PerformanceA100 80GB PCIe,
The gain shrinks as segments grow because the old mapping only starts to fill the device once The shipped axes (
Validation
Note that memcheck did not flag the out-of-bounds read on |
Description
closes #23487
segmented_offset_bitmask_binopassigned one warp per segment, capping parallelism atnum_segments * 32threads regardless of mask size. With few segments and large masks -- the shapesuperimpose_nullsproduces -- the kernel left almost the whole GPU idle.The kernel now uses a 2D grid:
xover destination words,yover segments. Each thread computes one destination word, so parallelism scales with the mask size. Since a segment can span many blocks, null counts are reduced per block withcub::BlockReduceand accumulated withatomicAdd, andinplace_segmented_bitmask_binopswitched tomake_zeroed_device_uvector_asyncto zero the accumulator.gridDim.yis capped at 65535, so blocks stride over segments when there are more than that.Every destination word still depends only on the same word index of its sources, so a destination mask may also be a source of another segment.
This also fixes an out-of-bounds read: the kernel indexed
segment_offsetsanddestinationsbefore checkingsegment_id >= num_segments, andnum_blocksrounds up. The bounds check is now the loop condition, ahead of every read.Checklist