Working 'fast' radix
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+49
-21
@@ -210,17 +210,25 @@ void scatter_pass(
|
||||
uint32_t3 local_location: SV_GroupThreadID,
|
||||
uint32_t3 group_location: SV_GroupID, )
|
||||
{
|
||||
uint32_t batch_index = 0;
|
||||
|
||||
for (uint32_t index = group_location.x * WG_HISTO_ELEMENT + local_location.x;
|
||||
index < min(key_buffer.getCount(), (group_location.x + 1) * WG_HISTO_ELEMENT);
|
||||
// uint32_t batch_index = 0;
|
||||
uint32_t start = group_location.x * WG_HISTO_ELEMENT + local_location.x;
|
||||
uint32_t end = min(key_buffer.getCount(), (group_location.x + 1) * WG_HISTO_ELEMENT);
|
||||
uint32_t element_count = key_buffer.getCount() - group_location.x * WG_HISTO_ELEMENT;
|
||||
for (uint32_t index = start;
|
||||
index < (group_location.x + 1) * WG_HISTO_ELEMENT;
|
||||
index += WG_THREAD_COUNT)
|
||||
{
|
||||
uint32_t key = key_buffer[index];
|
||||
uint32_t digit = extract_digit(key, params.pass_index, params.descending);
|
||||
// local_histogram[digit].add(1);
|
||||
uint32_t local_index = index - group_location.x * WG_HISTO_ELEMENT;
|
||||
sort_tokens[local_index] = SortToken(digit, local_index);
|
||||
if (index < end)
|
||||
{
|
||||
uint32_t key = key_buffer[index];
|
||||
uint32_t digit = extract_digit(key, params.pass_index, params.descending);
|
||||
sort_tokens[local_index] = SortToken(digit, local_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
sort_tokens[local_index] = SortToken(0xFFFF, local_index);
|
||||
}
|
||||
}
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
@@ -240,9 +248,9 @@ void scatter_pass(
|
||||
uint32_t sum = 0;
|
||||
for (uint32_t i = 0; i < WE_HISTO_ELEMENTS; i++)
|
||||
{
|
||||
uint32_t bin_digit = ((thread_tokens[i].digit >> radix_pass) & 1) ^ 1;
|
||||
uint32_t bin_digit = (thread_tokens[i].digit >> radix_pass) & 1;
|
||||
thread_prefix[i] = sum;
|
||||
sum += bin_digit;
|
||||
sum += 1 - bin_digit; // Count number of zeroes
|
||||
}
|
||||
|
||||
// Publish sum
|
||||
@@ -262,36 +270,56 @@ void scatter_pass(
|
||||
uint32_t total_zeroes = local_prefix[WG_THREAD_COUNT - 1];
|
||||
|
||||
// Scatter sort tokens
|
||||
|
||||
// Exclusive zero rank of block
|
||||
uint32_t zero_rank = select(local_location.x == 0, 0, local_prefix[local_location.x - 1]);
|
||||
for (uint32_t i = 0; i < WE_HISTO_ELEMENTS; i++)
|
||||
{
|
||||
uint32_t bin_digit = (thread_tokens[i].digit >> radix_pass) & 1;
|
||||
uint32_t index = i + local_location.x * WE_HISTO_ELEMENTS;
|
||||
uint32_t scatter_index = select(bin_digit == 0,
|
||||
thread_prefix[i] + zero_rank,
|
||||
total_zeroes + local_location.x - (thread_prefix[i] + zero_rank));
|
||||
total_zeroes + index - (thread_prefix[i] + zero_rank));
|
||||
sort_tokens[scatter_index] = thread_tokens[i];
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
}
|
||||
|
||||
// Scatter to main memory
|
||||
// Compute local offset by boundary detection
|
||||
if (local_location.x == 0 || sort_tokens[local_location.x].digit != sort_tokens[local_location.x - 1].digit)
|
||||
// Tokens are now sorted in the LDS
|
||||
// Boundary detection
|
||||
for (
|
||||
uint32_t i = local_location.x * WE_HISTO_ELEMENTS;
|
||||
i < min((local_location.x + 1) * WE_HISTO_ELEMENTS, element_count);
|
||||
i++)
|
||||
{
|
||||
local_prefix[sort_tokens[local_location.x].digit] = local_location.x;
|
||||
SortToken token = sort_tokens[i];
|
||||
uint32_t digit = token.digit;
|
||||
if (i == 0 || sort_tokens[i - 1].digit != digit)
|
||||
{
|
||||
local_prefix[digit] = i;
|
||||
}
|
||||
}
|
||||
|
||||
// For each digit, we now know where it starts within the buffer
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
// Scatter keys
|
||||
uint32_t offset = local_location.x * WE_HISTO_ELEMENTS;
|
||||
for (uint32_t i = 0; i < WE_HISTO_ELEMENTS; i++)
|
||||
for (
|
||||
uint32_t i = local_location.x * WE_HISTO_ELEMENTS;
|
||||
i < min((local_location.x + 1) * WE_HISTO_ELEMENTS, element_count);
|
||||
i++)
|
||||
{
|
||||
uint32_t digit = sort_tokens[offset + i].digit;
|
||||
uint32_t index = sort_tokens[offset + i].index;
|
||||
uint32_t digit = sort_tokens[i].digit;
|
||||
uint32_t index = sort_tokens[i].index + group_location.x * WG_HISTO_ELEMENT;
|
||||
uint32_t group_offset = histograms[group_location.x + digit * params.histogram_count];
|
||||
uint32_t digit_offset = histograms[(params.histogram_count) + digit * params.histogram_count];
|
||||
uint32_t digit_offset = histograms[(params.histogram_count - 1) + digit * params.histogram_count];
|
||||
|
||||
uint32_t destination_index = group_offset + digit_offset + (local_location.x - local_prefix[digit]);
|
||||
uint32_t destination_index = group_offset + digit_offset + (i - local_prefix[digit]);
|
||||
|
||||
// dest_key_buffer[i] = local_prefix[local_location.x];
|
||||
// dest_key_buffer[i] = destination_index;
|
||||
// dest_key_buffer[i] = local_prefix[local_location.x];
|
||||
|
||||
dest_key_buffer[destination_index] = key_buffer[index];
|
||||
dest_value_buffer[destination_index] = value_buffer[index];
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user