Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::RadixHTLocalSourceState Class Reference
Inheritance diagram for duckdb::RadixHTLocalSourceState:
Collaboration diagram for duckdb::RadixHTLocalSourceState:

Public Member Functions

 RadixHTLocalSourceState (ExecutionContext &context, const RadixPartitionedHashTable &radix_ht)
void ExecuteTask (RadixHTGlobalSinkState &sink, RadixHTGlobalSourceState &gstate, DataChunk &chunk)
 Do the work this thread has been assigned.
bool TaskFinished ()
 Whether this thread has finished the work it has been assigned.
Public Member Functions inherited from duckdb::LocalSourceState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

RadixHTSourceTaskType task
 Current task and index.
idx_t task_idx
unique_ptr< GroupedAggregateHashTable > ht
 Thread-local HT that is re-used to Finalize.
RadixHTScanStatus scan_status
 Current status of a Scan.

Private Member Functions

void Finalize (RadixHTGlobalSinkState &sink, RadixHTGlobalSourceState &gstate)
 Execute the finalize or scan task.
void Scan (RadixHTGlobalSinkState &sink, RadixHTGlobalSourceState &gstate, DataChunk &chunk)

Private Attributes

TupleDataLayout layout
 Allocator and layout for finalizing state.
ArenaAllocator aggregate_allocator
RowOperationsState row_state
TupleDataScanState scan_state
 State and chunk for scanning.
DataChunk scan_chunk

Constructor & Destructor Documentation

◆ RadixHTLocalSourceState()

duckdb::RadixHTLocalSourceState::RadixHTLocalSourceState ( ExecutionContext & context,
const RadixPartitionedHashTable & radix_ht )
explicit
207774 : task(RadixHTSourceTaskType::NO_TASK), task_idx(DConstants::INVALID_INDEX), scan_status(RadixHTScanStatus::DONE),
207775 layout(radix_ht.GetLayout().Copy()), aggregate_allocator(BufferAllocator::Get(context.client)),
207776 row_state(aggregate_allocator) {
207777 auto &allocator = BufferAllocator::Get(context.client);
207778 auto scan_chunk_types = radix_ht.group_types;
207779 for (auto &aggr_type : radix_ht.op.aggregate_return_types) {
207780 scan_chunk_types.push_back(aggr_type);
207781 }
207782 scan_chunk.Initialize(allocator, scan_chunk_types);
207783}
RadixHTScanStatus scan_status
Current status of a Scan.
Definition duckdb.cpp:207715
RadixHTSourceTaskType task
Current task and index.
Definition duckdb.cpp:207709
TupleDataLayout layout
Allocator and layout for finalizing state.
Definition duckdb.cpp:207719
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

Member Function Documentation

◆ ExecuteTask()

void duckdb::RadixHTLocalSourceState::ExecuteTask ( RadixHTGlobalSinkState & sink,
RadixHTGlobalSourceState & gstate,
DataChunk & chunk )

Do the work this thread has been assigned.

207786 {
207787 D_ASSERT(task != RadixHTSourceTaskType::NO_TASK);
207788 switch (task) {
207789 case RadixHTSourceTaskType::FINALIZE:
207790 Finalize(sink, gstate);
207791 break;
207792 case RadixHTSourceTaskType::SCAN:
207793 Scan(sink, gstate, chunk);
207794 break;
207795 default:
207796 throw InternalException("Unexpected RadixHTSourceTaskType in ExecuteTask!");
207797 }
207798}
void Finalize(RadixHTGlobalSinkState &sink, RadixHTGlobalSourceState &gstate)
Execute the finalize or scan task.
Definition duckdb.cpp:207800
Here is the call graph for this function:

◆ TaskFinished()

bool duckdb::RadixHTLocalSourceState::TaskFinished ( )

Whether this thread has finished the work it has been assigned.

207911 {
207912 switch (task) {
207913 case RadixHTSourceTaskType::FINALIZE:
207914 return true;
207915 case RadixHTSourceTaskType::SCAN:
207916 return scan_status == RadixHTScanStatus::DONE;
207917 default:
207918 D_ASSERT(task == RadixHTSourceTaskType::NO_TASK);
207919 return true;
207920 }
207921}

◆ Finalize()

void duckdb::RadixHTLocalSourceState::Finalize ( RadixHTGlobalSinkState & sink,
RadixHTGlobalSourceState & gstate )
private

Execute the finalize or scan task.

207800 {
207801 D_ASSERT(task == RadixHTSourceTaskType::FINALIZE);
207802 D_ASSERT(scan_status != RadixHTScanStatus::IN_PROGRESS);
207803 auto &partition = *sink.partitions[task_idx];
207804
207805 if (!ht) {
207806 // This capacity would always be sufficient for all data
207807 const auto capacity = GroupedAggregateHashTable::GetCapacityForCount(partition.data->Count());
207808
207809 // However, we will limit the initial capacity so we don't do a huge over-allocation
207810 const auto n_threads = NumericCast<idx_t>(TaskScheduler::GetScheduler(gstate.context).NumberOfThreads());
207811 const auto memory_limit = BufferManager::GetBufferManager(gstate.context).GetMaxMemory();
207812 const idx_t thread_limit = LossyNumericCast<idx_t>(0.6 * double(memory_limit) / double(n_threads));
207813
207814 const idx_t size_per_entry = partition.data->SizeInBytes() / MaxValue<idx_t>(partition.data->Count(), 1) +
207815 idx_t(GroupedAggregateHashTable::LOAD_FACTOR * sizeof(ht_entry_t));
207816 // but not lower than the initial capacity
207817 const auto capacity_limit =
207818 MaxValue(NextPowerOfTwo(thread_limit / size_per_entry), GroupedAggregateHashTable::InitialCapacity());
207819
207820 ht = sink.radix_ht.CreateHT(gstate.context, MinValue<idx_t>(capacity, capacity_limit), 0);
207821 } else {
207822 ht->Abandon();
207823 }
207824
207825 // Now combine the uncombined data using this thread's HT
207826 ht->Combine(*partition.data, &partition.progress);
207827 partition.progress = 1;
207828
207829 // Move the combined data back to the partition
207830 partition.data = make_uniq<TupleDataCollection>(BufferManager::GetBufferManager(gstate.context),
207831 sink.radix_ht.GetLayoutPtr(), MemoryTag::HASH_TABLE);
207832 partition.data->Combine(*ht->AcquirePartitionedData()->GetPartitions()[0]);
207833
207834 // Update thread-global state
207835 auto guard = sink.Lock();
207836 sink.stored_allocators.emplace_back(ht->GetAggregateAllocator());
207837 if (task_idx == sink.partitions.size()) {
207838 ht.reset();
207839 }
207840 const auto finalizes_done = ++sink.finalize_done;
207841 D_ASSERT(finalizes_done <= sink.partitions.size());
207842 if (finalizes_done == sink.partitions.size()) {
207843 // All finalizes are done, set remaining size to 0
207844 sink.temporary_memory_state->SetZero();
207845 }
207846
207847 // Update partition state
207848 auto partition_guard = partition.Lock();
207850 partition.UnblockTasks(partition_guard);
207851
207852 // This thread will scan the partition
207853 task = RadixHTSourceTaskType::SCAN;
207854 scan_status = RadixHTScanStatus::INIT;
207855}
static idx_t GetCapacityForCount(idx_t count)
Capacity that can hold 'count' entries without resizing.
Definition duckdb.cpp:146206
static idx_t InitialCapacity()
Initial capacity of the HT.
Definition duckdb.cpp:146202
static constexpr double LOAD_FACTOR
The hash table load factor, when a resize is triggered.
Definition duckdb.cpp:145833
unique_ptr< GroupedAggregateHashTable > ht
Thread-local HT that is re-used to Finalize.
Definition duckdb.cpp:207713
int partition(const std::vector< _Tp > &_vec, std::vector< int > &labels, _EqPredicate predicate=_EqPredicate())
@ READY_TO_SCAN
Finalized, ready to scan.
Definition duckdb.cpp:207053
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scan()

void duckdb::RadixHTLocalSourceState::Scan ( RadixHTGlobalSinkState & sink,
RadixHTGlobalSourceState & gstate,
DataChunk & chunk )
private
207857 {
207858 D_ASSERT(task == RadixHTSourceTaskType::SCAN);
207859 D_ASSERT(scan_status != RadixHTScanStatus::DONE);
207860
207861 auto &partition = *sink.partitions[task_idx];
207863 auto &data_collection = *partition.data;
207864
207865 if (scan_status == RadixHTScanStatus::INIT) {
207866 data_collection.InitializeScan(scan_state, gstate.column_ids, sink.scan_pin_properties);
207867 scan_status = RadixHTScanStatus::IN_PROGRESS;
207868 }
207869
207870 if (!data_collection.Scan(scan_state, scan_chunk)) {
207871 if (sink.scan_pin_properties == TupleDataPinProperties::DESTROY_AFTER_DONE) {
207872 data_collection.Reset();
207873 }
207874 scan_status = RadixHTScanStatus::DONE;
207875 auto guard = sink.Lock();
207876 if (++gstate.task_done == sink.partitions.size()) {
207877 gstate.finished = true;
207878 }
207879 return;
207880 }
207881
207882 const auto group_cols = layout.ColumnCount() - 1;
207883 RowOperations::FinalizeStates(row_state, layout, scan_state.chunk_state.row_locations, scan_chunk, group_cols);
207884
207885 if (sink.scan_pin_properties == TupleDataPinProperties::DESTROY_AFTER_DONE && layout.HasDestructor()) {
207886 RowOperations::DestroyStates(row_state, layout, scan_state.chunk_state.row_locations, scan_chunk.size());
207887 }
207888
207889 auto &radix_ht = sink.radix_ht;
207890 idx_t chunk_index = 0;
207891 for (auto &entry : radix_ht.grouping_set) {
207892 chunk.data[entry].Reference(scan_chunk.data[chunk_index++]);
207893 }
207894 for (auto null_group : radix_ht.null_groups) {
207895 chunk.data[null_group].SetVectorType(VectorType::CONSTANT_VECTOR);
207896 ConstantVector::SetNull(chunk.data[null_group], true);
207897 }
207898 D_ASSERT(radix_ht.grouping_set.size() + radix_ht.null_groups.size() == radix_ht.op.GroupCount());
207899 for (idx_t col_idx = 0; col_idx < radix_ht.op.aggregates.size(); col_idx++) {
207900 chunk.data[radix_ht.op.GroupCount() + col_idx].Reference(
207901 scan_chunk.data[radix_ht.group_types.size() + col_idx]);
207902 }
207903 D_ASSERT(radix_ht.op.grouping_functions.size() == radix_ht.grouping_values.size());
207904 for (idx_t i = 0; i < radix_ht.op.grouping_functions.size(); i++) {
207905 chunk.data[radix_ht.op.GroupCount() + radix_ht.op.aggregates.size() + i].Reference(radix_ht.grouping_values[i]);
207906 }
207907 chunk.SetCardinality(scan_chunk);
207908 D_ASSERT(chunk.size() != 0);
207909}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
TupleDataScanState scan_state
State and chunk for scanning.
Definition duckdb.cpp:207724
@ DESTROY_AFTER_DONE
Destroys blocks after they are done (for reading only).
Definition duckdb.cpp:56603
static void FinalizeStates(RowOperationsState &state, TupleDataLayout &layout, Vector &addresses, DataChunk &result, idx_t aggr_idx)
finalize - unaligned addresses, updated
Definition duckdb.cpp:99866
static void DestroyStates(RowOperationsState &state, TupleDataLayout &layout, Vector &addresses, idx_t count)
destructor - unaligned addresses, updated
Definition duckdb.cpp:99798

The documentation for this class was generated from the following file: