Skip to content

Commit

Permalink
update batch parameters after flush (#708)
Browse files Browse the repository at this point in the history
* update batch parameters after flush

In the case where we end up a batch before a flush, we are never
updating from flush, which lead to unoptimal batch parameters.

* rename update_after_flush to update_after_empty_flush
  • Loading branch information
rjodinchr authored Aug 13, 2024
1 parent de1dda0 commit 39a7e99
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ cl_int cvk_command_queue::flush_no_lock() {

// Early exit if there are no commands in the queue
if (m_groups.front()->commands.size() == 0) {
for (auto& controller : m_controllers) {
controller->update_after_empty_flush();
}
return CL_SUCCESS;
}

Expand Down
56 changes: 32 additions & 24 deletions src/queue_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,49 @@ cvk_queue_controller_batch_parameters::cvk_queue_controller_batch_parameters(
TRACE_CNT(last_batch_size_counter, m_last_batch_size);
}

void cvk_queue_controller_batch_parameters::update_trace_counter() {
TRACE_CNT(max_cmd_batch_size_counter, m_queue->m_max_cmd_batch_size);
TRACE_CNT(max_first_cmd_batch_size_counter,
m_queue->m_max_first_cmd_batch_size);
TRACE_CNT(max_first_cmd_batch_size_limit_counter,
m_max_first_cmd_batch_size_limit);
TRACE_CNT(max_first_cmd_batch_size_limit_hit_counter,
m_max_first_cmd_batch_size_limit_hit);
TRACE_CNT(last_batch_size_counter, m_last_batch_size);
}

void cvk_queue_controller_batch_parameters::reset_after_flush() {
if (m_queue->m_nb_batch_in_flight > 1 &&
!m_no_batch_in_flight_since_last_flush) {
// Increase max_cmd_batch_size if there was always batches in flight
// since last flush.
m_queue->m_max_cmd_batch_size += m_queue->m_nb_batch_in_flight;
}
// Reset after flush
m_last_batch_size = 0;
m_no_batch_in_flight_since_last_flush = false;
}

void cvk_queue_controller_batch_parameters::update_after_empty_flush() {
TRACE_FUNCTION();
reset_after_flush();
update_trace_counter();
}

void cvk_queue_controller_batch_parameters::
update_after_end_current_command_batch(bool from_flush) {
TRACE_FUNCTION();
auto reset_after_flush = [this]() {
if (m_queue->m_nb_batch_in_flight > 1 &&
!m_no_batch_in_flight_since_last_flush) {
// Increase max_cmd_batch_size if there was always batches in flight
// since last flush.
m_queue->m_max_cmd_batch_size += m_queue->m_nb_batch_in_flight;
}
// Reset after flush
m_last_batch_size = 0;
m_no_batch_in_flight_since_last_flush = false;
};
auto trace = [this]() {
TRACE_CNT(max_cmd_batch_size_counter, m_queue->m_max_cmd_batch_size);
TRACE_CNT(max_first_cmd_batch_size_counter,
m_queue->m_max_first_cmd_batch_size);
TRACE_CNT(max_first_cmd_batch_size_limit_counter,
m_max_first_cmd_batch_size_limit);
TRACE_CNT(max_first_cmd_batch_size_limit_hit_counter,
m_max_first_cmd_batch_size_limit_hit);
TRACE_CNT(last_batch_size_counter, m_last_batch_size);
};
if (!m_queue->m_command_batch) {
if (from_flush) {
reset_after_flush();
}
trace();
update_trace_counter();
return;
}
auto batch_size = m_queue->m_command_batch->batch_size();
if (m_last_batch_size == 0) {
m_last_batch_size = batch_size;
trace();
update_trace_counter();
return;
}

Expand Down Expand Up @@ -147,5 +155,5 @@ void cvk_queue_controller_batch_parameters::
if (m_queue->m_max_cmd_batch_size < m_queue->m_max_first_cmd_batch_size) {
m_queue->m_max_first_cmd_batch_size = m_queue->m_max_cmd_batch_size;
}
trace();
update_trace_counter();
}
7 changes: 7 additions & 0 deletions src/queue_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct cvk_queue_controller {
(void)from_flush;
}

virtual void update_after_empty_flush() {}

protected:
cvk_command_queue* m_queue;
};
Expand All @@ -34,7 +36,12 @@ struct cvk_queue_controller_batch_parameters : public cvk_queue_controller {

void update_after_end_current_command_batch(bool from_flush) override final;

void update_after_empty_flush() override final;

private:
void update_trace_counter();
void reset_after_flush();

cl_uint m_max_cmd_batch_size_limit;
cl_uint m_max_first_cmd_batch_size_limit;
cl_uint m_max_first_cmd_batch_size_limit_hit;
Expand Down

0 comments on commit 39a7e99

Please sign in to comment.