Skip to content

Commit

Permalink
Refactor topology stats into its own struct. Stats are now collected …
Browse files Browse the repository at this point in the history
…and saved in this struct immediately after evaluation.
  • Loading branch information
angshuman-parashar committed Jan 3, 2020
1 parent a9d08f0 commit a264b30
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 58 deletions.
85 changes: 36 additions & 49 deletions src/model/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ std::shared_ptr<NetworkSpecs> Topology::Specs::GetNetwork(unsigned network_id) c
// Topology //
//--------------------------------------------//

std::ostream& operator<<(std::ostream& out, const Topology& topology)
std::ostream& operator << (std::ostream& out, const Topology& topology)
{
// Save ios format state.
std::ios state(NULL);
Expand Down Expand Up @@ -263,9 +263,9 @@ std::ostream& operator<<(std::ostream& out, const Topology& topology)

if (topology.is_evaluated_)
{
out << "Total topology energy: " << topology.Energy() << " pJ" << std::endl;
out << "Total topology area: " << topology.Area() << " um^2" << std::endl;
out << "Max topology cycles: " << topology.Cycles() << std::endl;
out << "Total topology energy: " << topology.stats_.energy << " pJ" << std::endl;
out << "Total topology area: " << topology.stats_.area << " um^2" << std::endl;
out << "Max topology cycles: " << topology.stats_.cycles << std::endl;
}

out << std::endl;
Expand All @@ -278,16 +278,16 @@ std::ostream& operator<<(std::ostream& out, const Topology& topology)

if (topology.is_evaluated_)
{
out << "Utilization: " << topology.Utilization() << std::endl;
out << "Cycles: " << topology.Cycles() << std::endl;
out << "Energy: " << topology.Energy() / 1000000 << " uJ" << std::endl;
out << "Utilization: " << topology.stats_.utilization << std::endl;
out << "Cycles: " << topology.stats_.cycles << std::endl;
out << "Energy: " << topology.stats_.energy / 1000000 << " uJ" << std::endl;
}
out << "Area: " << topology.Area() / 1000000 << " mm^2" << std::endl;
out << "Area: " << topology.stats_.area / 1000000 << " mm^2" << std::endl;
out << std::endl;

if (topology.is_evaluated_)
{
auto num_maccs = topology.MACCs();
auto num_maccs = topology.stats_.maccs;
out << "MACCs = " << num_maccs << std::endl;
out << "pJ/MACC" << std::endl;

Expand Down Expand Up @@ -863,24 +863,24 @@ std::vector<EvalStatus> Topology::Evaluate(Mapping& mapping,
}

if (success_accum)
{
is_evaluated_ = true;
ComputeStats();
}

return eval_status;
}

double Topology::Energy() const
void Topology::ComputeStats()
{
// Energy.
double energy = 0;
for (auto level : levels_)
{
assert(level->Energy() >= 0);
energy += level->Energy();
}

// for (unsigned i = 1 /*note*/; i < NumLevels(); i++)
// {
// energy += std::static_pointer_cast<BufferLevel>(GetLevel(i))->network_.Energy();
// }
for (auto& network: networks_)
{
//poan: users might add a network to the arch but never connect/use it
Expand All @@ -890,55 +890,44 @@ double Topology::Energy() const
energy += e;
}

return energy;
}
stats_.energy = energy;

double Topology::Area() const
{
// Area.
double area = 0;
for (auto level : levels_)
{
assert(level->Area() >= 0);
area += level->Area();
}
return area;
}
stats_.area = area;

std::uint64_t Topology::Cycles() const
{
// Cycles.
std::uint64_t cycles = 0;
for (auto level : levels_)
{
cycles = std::max(cycles, level->Cycles());
}
return cycles;
}
stats_.cycles = cycles;

double Topology::Utilization() const
{
// Utilization.
// FIXME.
return (GetArithmeticLevel()->IdealCycles() / Cycles());
}
stats_.utilization = GetArithmeticLevel()->IdealCycles() / stats_.cycles;

std::vector<problem::PerDataSpace<std::uint64_t>> Topology::TileSizes() const
{
std::vector<problem::PerDataSpace<std::uint64_t>> tile_sizes;
// Tile sizes.
stats_.tile_sizes.clear();
for (unsigned storage_level_id = 0; storage_level_id < NumStorageLevels(); storage_level_id++)
{
problem::PerDataSpace<std::uint64_t> uc;
problem::PerDataSpace<std::uint64_t> ts;
for (unsigned pvi = 0; pvi < problem::GetShape()->NumDataSpaces; pvi++)
{
auto pv = problem::Shape::DataSpaceID(pvi);
uc[pv] = GetStorageLevel(storage_level_id)->UtilizedCapacity(pv);
ts[pv] = GetStorageLevel(storage_level_id)->UtilizedCapacity(pv);
}
tile_sizes.push_back(uc);
stats_.tile_sizes.push_back(ts);
}
return tile_sizes;
}

std::vector<problem::PerDataSpace<std::uint64_t>> Topology::UtilizedInstances() const
{
std::vector<problem::PerDataSpace<std::uint64_t>> utilized_instances;
// Utilized instances.
stats_.utilized_instances.clear();
for (unsigned storage_level_id = 0; storage_level_id < NumStorageLevels(); storage_level_id++)
{
problem::PerDataSpace<std::uint64_t> uc;
Expand All @@ -947,21 +936,19 @@ std::vector<problem::PerDataSpace<std::uint64_t>> Topology::UtilizedInstances()
auto pv = problem::Shape::DataSpaceID(pvi);
uc[pv] = GetStorageLevel(storage_level_id)->UtilizedInstances(pv);
}
utilized_instances.push_back(uc);
stats_.utilized_instances.push_back(uc);
}
return utilized_instances;
}

std::uint64_t Topology::MACCs() const
{
return GetArithmeticLevel()->MACCs();
}
// MACCs.
stats_.maccs = GetArithmeticLevel()->MACCs();

std::uint64_t Topology::LastLevelAccesses() const
{
return GetStorageLevel(NumStorageLevels()-1)->Accesses();
// Last-level accesses.
stats_.last_level_accesses = GetStorageLevel(NumStorageLevels()-1)->Accesses();
}

//
// Floorplanner.
//
void Topology::FloorPlan()
{
// Area of all the compute + buffer elements in inner levels
Expand Down
45 changes: 36 additions & 9 deletions src/model/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ bool isNetworkClass(std::string className);
class Topology : public Module
{
public:

//
// Specs.
//
class Specs
{
private:
Expand Down Expand Up @@ -135,13 +139,29 @@ class Topology : public Module
std::shared_ptr<LegacyNetwork::Specs> GetInferredNetwork(unsigned network_id) const;
std::shared_ptr<NetworkSpecs> GetNetwork(unsigned network_id) const;
};


//
// Stats.
//
struct Stats
{
double energy;
double area;
std::uint64_t cycles;
double utilization;
std::vector<problem::PerDataSpace<std::uint64_t>> tile_sizes;
std::vector<problem::PerDataSpace<std::uint64_t>> utilized_instances;
std::uint64_t maccs;
std::uint64_t last_level_accesses;
};

private:
std::vector<std::shared_ptr<Level>> levels_;
std::map<std::string, std::shared_ptr<Network>> networks_;
std::map<unsigned, double> tile_area_;

Specs specs_;
Stats stats_;

// Serialization
friend class boost::serialization::access;
Expand All @@ -160,6 +180,7 @@ class Topology : public Module
std::shared_ptr<BufferLevel> GetStorageLevel(unsigned storage_level_id) const;
std::shared_ptr<ArithmeticUnits> GetArithmeticLevel() const;
void FloorPlan();
void ComputeStats();

public:

Expand All @@ -181,6 +202,7 @@ class Topology : public Module

tile_area_ = other.tile_area_;
specs_ = other.specs_;
stats_ = other.stats_;
}

// Copy-and-swap idiom.
Expand All @@ -193,6 +215,7 @@ class Topology : public Module
swap(first.networks_, second.networks_);
swap(first.tile_area_, second.tile_area_);
swap(first.specs_, second.specs_);
swap(first.stats_, second.stats_);
}

Topology& operator = (Topology other)
Expand All @@ -215,14 +238,18 @@ class Topology : public Module
std::vector<EvalStatus> PreEvaluationCheck(const Mapping& mapping, analysis::NestAnalysis* analysis, bool break_on_failure);
std::vector<EvalStatus> Evaluate(Mapping& mapping, analysis::NestAnalysis* analysis, const problem::Workload& workload, bool break_on_failure);

double Energy() const;
double Area() const;
std::uint64_t Cycles() const;
double Utilization() const;
std::vector<problem::PerDataSpace<std::uint64_t>> TileSizes() const;
std::vector<problem::PerDataSpace<std::uint64_t>> UtilizedInstances() const;
std::uint64_t MACCs() const;
std::uint64_t LastLevelAccesses() const;
const Stats& GetStats() const { return stats_; }

// FIXME: these stat-specific accessors are deprecated and only exist for
// backwards-compatibility with some applications.
double Energy() const { return stats_.energy; }
double Area() const { return stats_.area; }
std::uint64_t Cycles() const { return stats_.cycles; }
double Utilization() const { return stats_.utilization; }
std::vector<problem::PerDataSpace<std::uint64_t>> TileSizes() const { return stats_.tile_sizes; }
std::vector<problem::PerDataSpace<std::uint64_t>> UtilizedInstances() const { return stats_.utilized_instances; }
std::uint64_t MACCs() const { return stats_.maccs; }
std::uint64_t LastLevelAccesses() const { return stats_.last_level_accesses; }

friend std::ostream& operator<<(std::ostream& out, const Topology& sh);
};
Expand Down

0 comments on commit a264b30

Please sign in to comment.