Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#78: Fix vt-tv bugs to work with vt data #79

Merged
merged 4 commits into from
Jun 25, 2024
Merged
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
58 changes: 41 additions & 17 deletions src/vt-tv/api/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ struct Info {
ranks_.try_emplace(r.getRankID(), std::move(r));
}

void setSelectedPhase(PhaseType selected_phase) {
selected_phase_ = selected_phase;
}

/**
* \brief Get all object info
*
Expand Down Expand Up @@ -395,14 +399,23 @@ struct Info {
the maximum volume by iterated through object ids.
*/
auto n_phases = this->getNumPhases();
for (PhaseType phase = 0; phase < n_phases; phase++) {
auto const& objects = this->getPhaseObjects(phase);
for (auto const& [obj_id, obj_work] : objects) {
auto obj_max_v = obj_work.getMaxVolume();
if (obj_max_v > ov_max) ov_max = obj_max_v;

if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
auto const& objects = this->getPhaseObjects(selected_phase_);
for (auto const& [obj_id, obj_work] : objects) {
auto obj_max_v = obj_work.getMaxVolume();
if (obj_max_v > ov_max) ov_max = obj_max_v;
}
} else {
for (PhaseType phase = 0; phase < n_phases; phase++) {{
auto const& objects = this->getPhaseObjects(phase);
for (auto const& [obj_id, obj_work] : objects) {
auto obj_max_v = obj_work.getMaxVolume();
if (obj_max_v > ov_max) ov_max = obj_max_v;
}
}
}
}

return ov_max;
}

Expand All @@ -415,14 +428,22 @@ struct Info {
double ol_max = 0.;

auto n_phases = this->getNumPhases();
for (PhaseType phase = 0; phase < n_phases; phase++) {
auto const& objects = this->getPhaseObjects(phase);

if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
auto const& objects = this->getPhaseObjects(selected_phase_);
for (auto const& [obj_id, obj_work] : objects) {
auto obj_load = obj_work.getLoad();
if (obj_load > ol_max) ol_max = obj_load;
}
} else {
for (PhaseType phase = 0; phase < n_phases; phase++) {
auto const& objects = this->getPhaseObjects(phase);
for (auto const& [obj_id, obj_work] : objects) {
auto obj_load = obj_work.getLoad();
if (obj_load > ol_max) ol_max = obj_load;
}
}
}

return ol_max;
}

Expand Down Expand Up @@ -569,25 +590,25 @@ struct Info {
}

// loop through ranks and add communications
fmt::print("Updating communications for phase {}.\n", phase);
// fmt::print("Updating communications for phase {}.\n", phase);
for (auto &[rank_id, rank]: ranks_) {
fmt::print(" Checking objects in rank {}.\n", rank_id);
// fmt::print(" Checking objects in rank {}.\n", rank_id);
auto &phaseWork = rank.getPhaseWork();
auto &phaseWorkAtPhase = phaseWork.at(phase);
auto &objects = phaseWorkAtPhase.getObjectWork();
for (auto &[obj_id, obj_work]: objects) {
fmt::print(" Checking if object {} needs to be updated.\n", obj_id);
fmt::print(" Communications to update:\n");
// fmt::print(" Checking if object {} needs to be updated.\n", obj_id);
// fmt::print(" Communications to update:\n");
uint64_t i = 0;
for (auto &[object_to_update, sender_id, recipient_id, bytes]: communications_to_add) {
fmt::print(" {} needs to be updated in {} -> {} communication of {} bytes.\n", object_to_update,
sender_id, recipient_id, bytes);
// fmt::print(" {} needs to be updated in {} -> {} communication of {} bytes.\n", object_to_update,
// sender_id, recipient_id, bytes);
if (object_to_update == "sender" && sender_id == obj_id) {
fmt::print(" Sender to be updated is object on this rank. Updating.\n");
// fmt::print(" Sender to be updated is object on this rank. Updating.\n");
rank.addObjectSentCommunicationAtPhase(phase, obj_id, recipient_id, bytes);
communications_to_add.erase(communications_to_add.begin() + i);
} else if (object_to_update == "recipient" && recipient_id == obj_id) {
fmt::print(" Recipient to be updated is object on this rank. Updating.\n");
// fmt::print(" Recipient to be updated is object on this rank. Updating.\n");
rank.addObjectReceivedCommunicationAtPhase(phase, obj_id, sender_id, bytes);
communications_to_add.erase(communications_to_add.begin() + i);
}
Expand Down Expand Up @@ -875,6 +896,9 @@ struct Info {

/// Work for each rank across phases
std::unordered_map<NodeType, Rank> ranks_;

/// The current phase (or indication to use all phases)
PhaseType selected_phase_;
};

} /* end namespace vt::tv */
Expand Down
108 changes: 62 additions & 46 deletions src/vt-tv/render/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ Render::Render(Info in_info)
, n_ranks_(in_info.getNumRanks())
, n_phases_(in_info.getNumPhases())
{
// Generically set rank grid dimensions according to the total number of ranks
// If selected_phase is not provided, use all phases
selected_phase_ = std::numeric_limits<PhaseType>::max();

// Generically set rank grid dimensions according to the total number of ranks
grid_size_[2] = 1; // we assume 2D representation

int sqrt_n_ranks = std::sqrt(n_ranks_);
Expand All @@ -76,10 +78,14 @@ Render::Render(Info in_info)
}
max_o_per_dim_ = 0;

// Set the info selected_phase
this->info_.setSelectedPhase(selected_phase_);

// Normalize communication edges
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if ( selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase ) {
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
this->info_.normalizeEdges(selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
this->info_.normalizeEdges(phase);
}
}
Expand Down Expand Up @@ -131,10 +137,6 @@ Render::Render(
, save_pngs_(in_save_pngs)
, selected_phase_(in_selected_phase)
{
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
n_phases_ = std::max(selected_phase_ + 1, n_phases_);
}

// initialize number of ranks
n_ranks_ = info_.getNumRanks();

Expand All @@ -144,13 +146,15 @@ Render::Render(
}
max_o_per_dim_ = 0;

// Set the info selected_phase
this->info_.setSelectedPhase(selected_phase_);

// Normalize communication edges
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
this->info_.normalizeEdges(phase);
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
this->info_.normalizeEdges(selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
this->info_.normalizeEdges(phase);
}
}

Expand Down Expand Up @@ -185,31 +189,36 @@ std::variant<std::pair<double, double>, std::set<std::variant<double,int>>> Rend
double oq;
std::set<std::variant<double,int>> oq_all;

// Iterate over all ranks
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
auto const& objects = this->info_.getPhaseObjects(phase);
for (auto const& [obj_id, obj_work] : objects) {
// Update maximum object qoi
oq = info_.getObjectQoi(obj_id, phase, this->object_qoi_);
if (!continuous_object_qoi_) {
// Allow for integer categorical QOI (i.e. rank_id)
if (oq == static_cast<int>(oq)) {
oq_all.insert(static_cast<int>(oq));
} else {
oq_all.insert(oq);
}
if(oq_all.size() > 20) {
oq_all.clear();
continuous_object_qoi_ = true;
}
// Update the QOI range
auto updateQoiRange = [&](auto const& objects, PhaseType phase) {
for (auto const& [obj_id, obj_work] : objects) {
// Update maximum object qoi
oq = info_.getObjectQoi(obj_id, phase, this->object_qoi_);
if (!continuous_object_qoi_) {
// Allow for integer categorical QOI (i.e. rank_id)
if (oq == static_cast<int>(oq)) {
oq_all.insert(static_cast<int>(oq));
} else {
oq_all.insert(oq);
}
if(oq_all.size() > 20) {
oq_all.clear();
continuous_object_qoi_ = true;
}
if (oq > oq_max) oq_max = oq;
if (oq < oq_min) oq_min = oq;
}
if (oq > oq_max) oq_max = oq;
if (oq < oq_min) oq_min = oq;
}
};

// Iterate over all ranks
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
auto const& objects = this->info_.getPhaseObjects(selected_phase_);
updateQoiRange(objects, selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
auto const& objects = this->info_.getPhaseObjects(phase);
updateQoiRange(objects, phase);
}
}

Expand Down Expand Up @@ -920,8 +929,12 @@ void Render::renderPNG(
// Add field data text information to render
// Create text
std::stringstream ss;
ss << "Phase: " << phase << "/" << (this->n_phases_ - 1) << "\n"
<< "Load Imbalance: " << std::fixed << std::setprecision(2) << this->info_.getImbalance(phase);
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
ss << "Phase: " << phase << "\n";
} else {
ss << "Phase: " << phase << "/" << (this->n_phases_ - 1) << "\n";
}
ss << "Load Imbalance: " << std::fixed << std::setprecision(2) << this->info_.getImbalance(phase);
// Setup text actor
vtkSmartPointer<vtkTextActor> text_actor = vtkSmartPointer<vtkTextActor>::New();
text_actor->SetInput(ss.str().c_str());
Expand Down Expand Up @@ -975,15 +988,11 @@ void Render::generate(uint64_t font_size, uint64_t win_size) {

fmt::print("selected phase={}\n", selected_phase_);

for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
auto createMeshAndRender = [&](PhaseType phase) {
vtkNew<vtkPolyData> object_mesh = this->createObjectMesh_(phase);
vtkNew<vtkPolyData> rank_mesh = this->createRankMesh_(phase);

if (save_meshes_){
if (save_meshes_) {
fmt::print("== Writing object mesh for phase {}\n", phase);
vtkNew<vtkXMLPolyDataWriter> writer;
std::string object_mesh_filename = output_dir_ + output_file_stem_ + "_object_mesh_" + std::to_string(phase) + ".vtp";
Expand All @@ -999,7 +1008,7 @@ void Render::generate(uint64_t font_size, uint64_t win_size) {
writer2->Write();
}

if (save_pngs_){
if (save_pngs_) {
fmt::print("== Rendering visualization PNG for phase {}\n", phase);

std::pair<double, double> obj_qoi_range;
Expand Down Expand Up @@ -1030,6 +1039,13 @@ void Render::generate(uint64_t font_size, uint64_t win_size) {
output_file_stem_
);
}
};

if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
createMeshAndRender(selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
createMeshAndRender(phase);
}
}
}
Expand Down
Loading