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::WindowGlobalSourceState Class Reference
Inheritance diagram for duckdb::WindowGlobalSourceState:
Collaboration diagram for duckdb::WindowGlobalSourceState:

Public Types

using WindowHashGroupPtr = unique_ptr<WindowHashGroup>
using ScannerPtr = unique_ptr<TupleDataChunkIterator>
using Task = WindowSourceTask
using TaskPtr = optional_ptr<Task>
using PartitionBlock = std::pair<idx_t, idx_t>

Public Member Functions

 WindowGlobalSourceState (ClientContext &context_p, WindowGlobalSinkState &gsink_p)
bool HasMoreTasks () const
 Are there any more tasks?
bool HasUnfinishedTasks () const
bool TryNextTask (TaskPtr &task, Task &task_local)
 Get the next task given the current state.
idx_t MaxThreads () override
Public Member Functions inherited from duckdb::GlobalSourceState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
Public Member Functions inherited from duckdb::StateWithBlockableTasks
unique_lock< mutex > Lock ()
void PreventBlocking (const unique_lock< mutex > &guard)
bool BlockTask (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
 Add a task to 'blocked_tasks' before returning SourceResultType::BLOCKED (must hold the lock).
bool CanBlock (const unique_lock< mutex > &guard) const
bool UnblockTasks (const unique_lock< mutex > &guard)
 Unblock all tasks (must hold the lock).
SinkResultType BlockSink (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
SourceResultType BlockSource (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
void VerifyLock (const unique_lock< mutex > &guard) const

Public Attributes

ClientContext & client
 Context for executing computations.
WindowGlobalSinkState & gsink
 All the sunk data.
unique_ptr< GlobalSourceState > hashed_source
 The hashed sort global source state for delayed sorting.
vector< WindowHashGroupPtr > window_hash_groups
 The sorted hash groups.
idx_t total_blocks = 0
 The total number of blocks to process;.
vector< PartitionBlock > partition_blocks
 The sorted list of (blocks, group_idx) pairs.
vector< idx_t > active_groups
 The ordered set of active groups.
atomic< idx_t > next_group
 The number of started tasks.
atomic< idx_t > locals
 The number of local states.
idx_t total_tasks = 0
 The total number of tasks.
atomic< idx_t > started
 The number of started tasks.
atomic< idx_t > finished
 The number of finished tasks.
atomic< bool > stopped
 Stop producing tasks.
atomic< idx_t > completed
 The number of tasks completed. This will combine both build and evaluate.

Protected Member Functions

void CreateTaskList ()
 Build task list.
void FinishTask (TaskPtr task)
 Finish a task.

Constructor & Destructor Documentation

◆ WindowGlobalSourceState()

duckdb::WindowGlobalSourceState::WindowGlobalSourceState ( ClientContext & context_p,
WindowGlobalSinkState & gsink_p )
164834 : client(client), gsink(gsink_p), next_group(0), locals(0), started(0), finished(0), stopped(false), completed(0) {
164835 auto &sort_strategy = *gsink.sort_strategy;
164836 hashed_source = sort_strategy.GetGlobalSourceState(client, *gsink.strategy_sink);
164837 auto &hash_groups = sort_strategy.GetHashGroups(*hashed_source);
164838 window_hash_groups.resize(hash_groups.size());
164839
164840 for (idx_t group_idx = 0; group_idx < hash_groups.size(); ++group_idx) {
164841 const auto block_count = hash_groups[group_idx].chunks;
164842 if (!block_count) {
164843 continue;
164844 }
164845
164846 auto window_hash_group = make_uniq<WindowHashGroup>(gsink, hash_groups[group_idx], group_idx);
164847 window_hash_group->batch_base = total_blocks;
164848 total_blocks += block_count;
164849
164850 window_hash_groups[group_idx] = std::move(window_hash_group);
164851 }
164852
164853 CreateTaskList();
164854}
atomic< bool > stopped
Stop producing tasks.
Definition duckdb.cpp:164817
void CreateTaskList()
Build task list.
Definition duckdb.cpp:164856
atomic< idx_t > finished
The number of finished tasks.
Definition duckdb.cpp:164815
ClientContext & client
Context for executing computations.
Definition duckdb.cpp:164793
vector< WindowHashGroupPtr > window_hash_groups
The sorted hash groups.
Definition duckdb.cpp:164799
atomic< idx_t > completed
The number of tasks completed. This will combine both build and evaluate.
Definition duckdb.cpp:164819
atomic< idx_t > started
The number of started tasks.
Definition duckdb.cpp:164813
atomic< idx_t > locals
The number of local states.
Definition duckdb.cpp:164809
atomic< idx_t > next_group
The number of started tasks.
Definition duckdb.cpp:164807
idx_t total_blocks
The total number of blocks to process;.
Definition duckdb.cpp:164801
WindowGlobalSinkState & gsink
All the sunk data.
Definition duckdb.cpp:164795
unique_ptr< GlobalSourceState > hashed_source
The hashed sort global source state for delayed sorting.
Definition duckdb.cpp:164797
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ HasMoreTasks()

bool duckdb::WindowGlobalSourceState::HasMoreTasks ( ) const
inline

Are there any more tasks?

164783 {
164784 return !stopped && started < total_tasks;
164785 }
idx_t total_tasks
The total number of tasks.
Definition duckdb.cpp:164811
Here is the caller graph for this function:

◆ HasUnfinishedTasks()

bool duckdb::WindowGlobalSourceState::HasUnfinishedTasks ( ) const
inline
164786 {
164787 return !stopped && finished < total_tasks;
164788 }

◆ TryNextTask()

bool duckdb::WindowGlobalSourceState::TryNextTask ( TaskPtr & task,
Task & task_local )

Get the next task given the current state.

165295 {
165296 auto guard = Lock();
165297 FinishTask(task);
165298
165299 if (!HasMoreTasks()) {
165300 task = nullptr;
165301 return false;
165302 }
165303
165304 // Run through the active groups looking for one that can assign a task
165305 for (const auto &group_idx : active_groups) {
165306 auto &window_hash_group = window_hash_groups[group_idx];
165307 if (window_hash_group->TryPrepareNextStage()) {
165308 UnblockTasks(guard);
165309 }
165310 if (window_hash_group->TryNextTask(task_local)) {
165311 task = task_local;
165312 ++started;
165313 return true;
165314 }
165315 }
165316
165317 // All active groups are busy or blocked, so start the next one (if any)
165318 while (next_group < partition_blocks.size()) {
165319 const auto group_idx = partition_blocks[next_group++].second;
165320 active_groups.emplace_back(group_idx);
165321
165322 auto &window_hash_group = window_hash_groups[group_idx];
165323 if (window_hash_group->TryPrepareNextStage()) {
165324 UnblockTasks(guard);
165325 }
165326 if (!window_hash_group->TryNextTask(task_local)) {
165327 // Group has no tasks (empty?)
165328 continue;
165329 }
165330
165331 task = task_local;
165332 ++started;
165333 return true;
165334 }
165335
165336 task = nullptr;
165337
165338 return false;
165339}
bool UnblockTasks(const unique_lock< mutex > &guard)
Unblock all tasks (must hold the lock).
Definition duckdb.hpp:21906
vector< idx_t > active_groups
The ordered set of active groups.
Definition duckdb.cpp:164805
vector< PartitionBlock > partition_blocks
The sorted list of (blocks, group_idx) pairs.
Definition duckdb.cpp:164803
void FinishTask(TaskPtr task)
Finish a task.
Definition duckdb.cpp:165341
bool HasMoreTasks() const
Are there any more tasks?
Definition duckdb.cpp:164783
Here is the call graph for this function:

◆ MaxThreads()

idx_t duckdb::WindowGlobalSourceState::MaxThreads ( )
inlineoverridevirtual

Reimplemented from duckdb::GlobalSourceState.

164822 {
164823 return total_blocks;
164824 }

◆ CreateTaskList()

void duckdb::WindowGlobalSourceState::CreateTaskList ( )
protected

Build task list.

164856 {
164857 // Sort the groups from largest to smallest
164858 if (window_hash_groups.empty()) {
164859 return;
164860 }
164861
164862 for (idx_t group_idx = 0; group_idx < window_hash_groups.size(); ++group_idx) {
164863 auto &window_hash_group = window_hash_groups[group_idx];
164864 if (!window_hash_group) {
164865 continue;
164866 }
164867 partition_blocks.emplace_back(window_hash_group->blocks, group_idx);
164868 }
164869 std::sort(partition_blocks.begin(), partition_blocks.end(), std::greater<PartitionBlock>());
164870
164871 // Schedule the largest group on as many threads as possible
164872 auto &ts = TaskScheduler::GetScheduler(client);
164873 const auto threads = NumericCast<idx_t>(ts.NumberOfThreads());
164874
164875 const auto &max_block = partition_blocks.front();
164876
164877 // To compute masks in parallel, we need to have the row count of the number of chunks per thread
164878 // be a multiple of the mask entry size. Usually, this is not a problem because
164879 // STANDARD_VECTOR_SIZE >> ValidityMask::BITS_PER_VALUE, but if STANDARD_VECTOR_SIZE is say 2,
164880 // we need to align the chunk count to the mask width.
164881 const auto aligned_scale = MaxValue<idx_t>(ValidityMask::BITS_PER_VALUE / STANDARD_VECTOR_SIZE, 1);
164882 const auto aligned_count = WindowHashGroup::BinValue(max_block.first, aligned_scale);
164883 const auto per_thread = aligned_scale * WindowHashGroup::BinValue(aligned_count, threads);
164884 if (!per_thread) {
164885 throw InternalException("No blocks per thread! %ld threads, %ld groups, %ld blocks, %ld hash group", threads,
164886 partition_blocks.size(), max_block.first, max_block.second);
164887 }
164888
164889 for (const auto &b : partition_blocks) {
164890 total_tasks += window_hash_groups[b.second]->InitTasks(per_thread);
164891 }
164892}

◆ FinishTask()

void duckdb::WindowGlobalSourceState::FinishTask ( TaskPtr task)
protected

Finish a task.

165341 {
165342 if (!task) {
165343 return;
165344 }
165345
165346 const auto group_idx = task->group_idx;
165347 auto &finished_hash_group = window_hash_groups[group_idx];
165348 D_ASSERT(finished_hash_group);
165349
165350 if (++finished_hash_group->completed >= finished_hash_group->GetTaskCount()) {
165351 finished_hash_group.reset();
165352 // Remove it from the active groups
165353 auto &v = active_groups;
165354 v.erase(std::remove(v.begin(), v.end(), group_idx), v.end());
165355 }
165356
165357 // Count the global tasks completed.
165358 ++completed;
165359}
uint32_t v
Here is the caller graph for this function:

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