Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ list(APPEND VIEW_FILES
src/view/src/compute/rocprofvis_compute_summary.cpp
src/view/src/compute/rocprofvis_compute_roofline.cpp
src/view/src/widgets/rocprofvis_compute_widget.cpp
src/view/src/widgets/rocprofvis_charts.cpp
)
endif(COMPUTE_UI_SUPPORT)

Expand Down
184 changes: 183 additions & 1 deletion src/view/src/compute/rocprofvis_compute_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "rocprofvis_data_provider.h"
#include "rocprofvis_event_manager.h"

constexpr float DROPDOWN_SCALE = 15.0f;

namespace RocProfVis
{
namespace View
Expand All @@ -19,6 +21,9 @@ ComputeSummaryView::ComputeSummaryView(
, m_roofline(nullptr)
, m_compute_selection(compute_selection)
, m_client_id(IdGenerator::GetInstance().GenerateId())
, m_workload_id(0)
, m_selected_metric(KernelInfo::ToIndex(KernelMetric::DurationTotal))
, m_selected_chart_id(0)
{
auto workload_changed_handler = [this](std::shared_ptr<RocEvent> e) {
if(auto selection_changed_event =
Expand All @@ -29,6 +34,13 @@ ComputeSummaryView::ComputeSummaryView(
{
return;
}
m_workload_id = selection_changed_event->GetId();
if(m_data_provider.ComputeModel().GetWorkloads().count(m_workload_id) > 0)
{
UpdataChartData(
m_data_provider.ComputeModel().GetWorkloads().at(m_workload_id),
m_selected_metric);
}
if(m_roofline)
{
m_roofline->SetWorkload(selection_changed_event->GetId());
Expand All @@ -51,20 +63,32 @@ ComputeSummaryView::ComputeSummaryView(
}
};

auto font_changed_handler = [this](std::shared_ptr<RocEvent> e) {
this->CalculateCombosWidth();
};
m_font_changed_token = EventManager::GetInstance()->Subscribe(
static_cast<int>(RocEvents::kFontSizeChanged), font_changed_handler);

m_metrics_fetched_token = EventManager::GetInstance()->Subscribe(
static_cast<int>(RocEvents::kComputeMetricsFetched), metrics_fetched_handler);

m_roofline = std::make_unique<Roofline>(m_data_provider);

UpdateKernelMetrics();
CalculateCombosWidth();

m_widget_name = GenUniqueName("ComputeSummaryView");
}

ComputeSummaryView::~ComputeSummaryView() {
ComputeSummaryView::~ComputeSummaryView()
{
EventManager::GetInstance()->Unsubscribe(
static_cast<int>(RocEvents::kComputeWorkloadSelectionChanged),
m_workload_selection_changed_token);
EventManager::GetInstance()->Unsubscribe(
static_cast<int>(RocEvents::kComputeMetricsFetched), m_metrics_fetched_token);
EventManager::GetInstance()->Unsubscribe(
static_cast<int>(RocEvents::kFontSizeChanged), m_font_changed_token);
}

void
Expand All @@ -80,12 +104,170 @@ void
ComputeSummaryView::Render()
{
ImGui::BeginChild("summary");
const std::unordered_map<uint32_t, WorkloadInfo>& workloads =
m_data_provider.ComputeModel().GetWorkloads();
if(workloads.count(m_workload_id) > 0)
{
const WorkloadInfo& workload = workloads.at(m_workload_id);
RenderKernelsTable(workload);

ImGui::SetNextItemWidth(m_chart_combo_width);
if(ImGui::BeginCombo("##ChartView", m_chart_views[m_selected_chart_id].data()))
{
for(uint8_t index = 0; index < m_chart_views.size(); index++)
{
const bool is_selected = (m_selected_chart_id == index);
if(ImGui::Selectable(m_chart_views[index].data(), is_selected))
{
m_selected_chart_id = index;
}

if(is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}

ImGui::SameLine();
ImGui::SetNextItemWidth(m_metric_combo_width);
if(ImGui::BeginCombo("##Metric", m_metric_views[m_selected_metric].data()))
{
for(uint8_t index = 0; index < m_metric_views.size(); index++)
{
const bool is_selected = (m_selected_metric == index);
if(ImGui::Selectable(m_metric_views[index].data(), is_selected))
{
m_selected_metric = index;
UpdataChartData(workload, m_selected_metric);
}

if(is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}

ImGui::BeginChild("Chart");
if(m_selected_chart_id == 0)
m_pie_chart.Render();
else if(m_selected_chart_id == 1)
m_bar_chart.Render();

ImGui::EndChild(); // Chart
}
if(m_roofline)
{
m_roofline->Render();
}
ImGui::EndChild();
}

void
ComputeSummaryView::CalculateCombosWidth()
{
m_chart_combo_width = 0.0f;
m_metric_combo_width = 0.0f;

ImGuiStyle& style = ImGui::GetStyle();

const float frame_padding_lr = style.FramePadding.x * 2.0f;
const float inner_spacing = style.ItemInnerSpacing.x;
const float arrow_area = ImGui::GetFrameHeight(); // approximate arrow / preview area
const float extra_margin_px = 8.0f; // small visual margin
const float min_width_px = 80.0f; // sensible minimum

float max_chart_text_w = 0.0f;
for(const auto& chart : m_chart_views)
{
const ImVec2 ts = ImGui::CalcTextSize(chart.data());
if(ts.x > max_chart_text_w) max_chart_text_w = ts.x;
}

// Compute longest label width for metric views
float max_metric_text_w = 0.0f;
for(const auto& metric : m_metric_views)
{
const ImVec2 ts = ImGui::CalcTextSize(metric.data());
if(ts.x > max_metric_text_w) max_metric_text_w = ts.x;
}

// Final widths include padding, spacing, arrow area and a small margin.
float chart_total = max_chart_text_w + frame_padding_lr + inner_spacing + arrow_area +
extra_margin_px;
float metric_total = max_metric_text_w + frame_padding_lr + inner_spacing +
arrow_area + extra_margin_px;

if(chart_total < min_width_px) chart_total = min_width_px;
if(metric_total < min_width_px) metric_total = min_width_px;

m_chart_combo_width = chart_total;
m_metric_combo_width = metric_total;
}

void
ComputeSummaryView::RenderKernelsTable(const WorkloadInfo& workload)
{
ImGui::BeginChild("kernels", ImVec2(0, 0),
ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY);
ImGui::Text("Kernels");
if(ImGui::BeginTable("", 8,
ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders |
ImGuiTableFlags_SizingStretchSame))
{
ImGui::TableSetupColumn("ID");
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Invocation Count");
ImGui::TableSetupColumn("Total Duration");
ImGui::TableSetupColumn("Min Duration");
ImGui::TableSetupColumn("Max Duration");
ImGui::TableSetupColumn("Mean Duration");
ImGui::TableSetupColumn("Median Duration");
ImGui::TableHeadersRow();
for(const std::pair<const uint32_t, KernelInfo>& kernel : workload.kernels)
{
ImGui::PushID(static_cast<int>(kernel.second.id));
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.id);
ImGui::TableNextColumn();
ImGui::Text(kernel.second.name.c_str());
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.invocation_count);
ImGui::TableNextColumn();
ImGui::Text("%llu", kernel.second.duration_total);
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.duration_min);
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.duration_max);
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.duration_mean);
ImGui::TableNextColumn();
ImGui::Text("%u", kernel.second.duration_median);
ImGui::PopID();
}
ImGui::EndTable();
}
ImGui::EndChild();
}

void
ComputeSummaryView::UpdataChartData(const WorkloadInfo& workload, uint8_t metric_id)
{
ChartData chart_data =
ChartData::GenerateChartData(static_cast<KernelMetric>(metric_id), workload);

m_pie_chart.UpdateData(chart_data);
m_bar_chart.UpdateData(chart_data);
}

void
ComputeSummaryView::UpdateKernelMetrics()
{
for(uint8_t metric_index = 0; metric_index < KernelInfo::ToIndex(KernelMetric::COUNT);
metric_index++)
{
m_metric_views.push_back(
KernelInfo::GetMetricName(static_cast<KernelMetric>(metric_index)));
}
}

} // namespace View
} // namespace RocProfVis
19 changes: 19 additions & 0 deletions src/view/src/compute/rocprofvis_compute_summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once
#include "rocprofvis_event_manager.h"
#include "widgets/rocprofvis_widget.h"
#include "widgets/rocprofvis_charts.h"

namespace RocProfVis
{
Expand All @@ -14,6 +15,8 @@ class DataProvider;
class ComputeSelection;
class Roofline;

struct WorkloadInfo;

class ComputeSummaryView : public RocWidget
{
public:
Expand All @@ -25,15 +28,31 @@ class ComputeSummaryView : public RocWidget
void Render() override;

private:
void CalculateCombosWidth();
void RenderKernelsTable(const WorkloadInfo& workload);
void UpdataChartData(const WorkloadInfo& workload, uint8_t metric_id);
void UpdateKernelMetrics();

DataProvider& m_data_provider;

std::shared_ptr<ComputeSelection> m_compute_selection;
std::unique_ptr<Roofline> m_roofline;
PieChart m_pie_chart;
BarChart m_bar_chart;

const std::vector<std::string_view> m_chart_views = { "Pie Chart", "Bar Chart" };
std::vector<std::string_view> m_metric_views;
uint32_t m_workload_id;
float m_chart_combo_width;
float m_metric_combo_width;
uint8_t m_selected_metric;
uint8_t m_selected_chart_id;

uint64_t m_client_id;

EventManager::SubscriptionToken m_workload_selection_changed_token;
EventManager::SubscriptionToken m_metrics_fetched_token;
EventManager::SubscriptionToken m_font_changed_token;
};

} // namespace View
Expand Down
3 changes: 1 addition & 2 deletions src/view/src/compute/rocprofvis_compute_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace RocProfVis
{
namespace View
{
constexpr float DROPDOWN_SCALE = 15.0f;

ComputeView::ComputeView()
: m_view_created(false)
Expand Down Expand Up @@ -44,8 +45,6 @@ ComputeView::ComputeView()
std::make_shared<ComputeMetricsFetchedEvent>(client_id, trace_path));
}
});


}

ComputeView::~ComputeView() {}
Expand Down
3 changes: 2 additions & 1 deletion src/view/src/compute/rocprofvis_compute_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ComputeWorkloadView: public RocWidget
std::shared_ptr<ComputeSelection> m_compute_selection;
};


class ComputeTester : public RocWidget
{
public:
Expand Down Expand Up @@ -122,7 +123,7 @@ class ComputeTester : public RocWidget
std::unordered_map<rocprofvis_controller_roofline_kernel_intensity_type_t,
const char*>
intensity;
};
};

DataProvider& m_data_provider;
SelectionState m_selections;
Expand Down
Loading