Fix off-by-range bug when filter applied to table - #1031
Open
tomk-amd wants to merge 1 commit into
Open
Conversation
…not divisible by the worker count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fix FILTER dropping leftover merged-table rows when the row count is not divisible by the worker count.
Technical Details
A filter that selects all event can lose result rows:
vs no filter:
AI Analysis
This one is a real off-by-range bug. It is just easy to miss on a small table.
The FILTER worker is written as a half-open index range: evaluate rows [start_row, end_row).
rocprofvis_db_table_processor.cpp Ln 603–606:
The main threads pass that correctly: thread i gets [i * rows_per_task, (i + 1) * rows_per_task).
Integer division usually leaves a remainder, so they spawn one more thread for the leftover rows:
rocprofvis_db_table_processor.cpp Ln 630–635:
The last call mixes two conventions. The first argument is a start index. The second is still named
end_rowin the lambda, but they passleftover_rows_count, which is a count (typically 1..thread_count-1), not an exclusive end index.Concrete numbers: 10001 rows, 2 threads (this is the first size where a leftover thread exists; see below).
rows_per_task = 10001 / 2 = 5000
leftover_rows_count = 1
Thread 0: [0, 5000)
Thread 1: [5000, 10000)
Leftover thread: start_row = 10000, end_row = 1
The loop is for (row_index = 10000; row_index < 1; ...). It never runs. Row 10000 is never evaluated, so it never enters m_filter_lookup.
The filtered table size is m_filter_lookup.size(). That last row is treated as a non-match even if it would have passed. You lose at most thread_count - 1 trailing rows, not a random scatter through the table.
The GROUP path next door does the end bound correctly: its last thread gets RowCount() as end_row. FILTER should do the same (start + leftover, or just RowCount()).
Test Plan
Verify no filter and filter that would select all rows return the same count