Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions rocprim/include/rocprim/device/detail/device_reduce_by_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ namespace detail
template<class Key, class Value>
struct carry_out
{
ROCPRIM_DEVICE inline
carry_out& operator=(carry_out rhs)
{
key = rhs.key;
value = rhs.value;
destination = rhs.destination;
next_has_carry_in = rhs.next_has_carry_in;
return *this;
}

Key key;
Value value; // carry-out of the current batch
unsigned int destination;
Expand All @@ -53,6 +63,14 @@ struct carry_out
template<class Value>
struct scan_by_key_pair
{
ROCPRIM_DEVICE inline
scan_by_key_pair& operator=(scan_by_key_pair rhs)
{
key = rhs.key;
value = rhs.value;
return *this;
}

unsigned int key;
Value value;
};
Expand Down Expand Up @@ -339,7 +357,7 @@ void reduce_by_key(KeysInputIterator keys_input,
};
unsigned int unique_count;
bool has_carry_in;
result_type carry_in;
detail::raw_storage<result_type> carry_in;
} storage;

const unsigned int flat_id = ::rocprim::flat_block_thread_id();
Expand Down Expand Up @@ -394,7 +412,7 @@ void reduce_by_key(KeysInputIterator keys_input,
if(bi > 0 && flat_id == 0 && storage.has_carry_in)
{
// Apply carry-out of the previous block as carry-in for the first segment
values[0] = reduce_op(storage.carry_in, values[0]);
values[0] = reduce_op(storage.carry_in.get(), values[0]);
}

bool head_flags[ItemsPerThread];
Expand Down Expand Up @@ -489,7 +507,7 @@ void reduce_by_key(KeysInputIterator keys_input,
{
// Save carry-out to use it as carry-in for the next block of the current batch
storage.has_carry_in = !tail_flags[ItemsPerThread - 1];
storage.carry_in = values[ItemsPerThread - 1];
storage.carry_in.get() = values[ItemsPerThread - 1];
}
}
if(batch_id > 0 && block_start == batch_start)
Expand Down