15#include "sparta/utils/MathUtils.hpp"
18#include "sparta/statistics/Counter.hpp"
19#include "sparta/statistics/CycleCounter.hpp"
96 const double sum = std::accumulate(
bin_.begin(),
bin_.end(), 0.0)
97 + (*underflow_bin_) + (*overflow_bin_);
102 const std::size_t total_num_bins =
bin_.size() + 2;
104 const double mean = sum / total_num_bins;
107 auto c_get = c.get();
108 accum += pow(c_get - mean, 2);
112 return std::sqrt(accum / (total_num_bins - 1));
124 const double sum = std::accumulate(
bin_.begin(),
bin_.end(), 0.0)
125 + (*underflow_bin_) + (*overflow_bin_);
130 const std::size_t total_num_bins =
bin_.size() + 2;
132 return sum / total_num_bins;
181 bin_prob_vector_.clear();
182 for(
const auto& b :
bin_){
183 bin_prob_vector_.emplace_back(((
static_cast<double>(b))/(
static_cast<double>(*
total_))));
185 return bin_prob_vector_;
206 uint64_t getHistogramUpperValue()
const {
return upper_val_; }
207 uint64_t getHistogramLowerValue()
const {
return lower_val_; }
208 uint64_t getNumBins()
const {
return num_bins_; }
225 const uint64_t upper_val,
226 const uint64_t num_vals_per_bin,
227 const uint64_t idle_value = 0) :
234 "CycleHistogramBase: upper value must be greater than lower value");
236 "CycleHistogramBase: num_vals_per_bin must be power of 2");
238 double actual_num_bins = (upper_val - lower_val)/num_vals_per_bin + 1;
241 "CycleHistogramBase: Actual number of bins (" << actual_num_bins
242 <<
") is not an integer");
251 std::stringstream str;
254 str <<
"\t" << name <<
"[ UF ] = " << running_sum << std::endl;
257 for (uint64_t i = 0; i <
num_bins_; ++i) {
261 running_sum += (
bin_[i]);
263 <<
"[ " << start_val <<
"-" << end_val <<
" ] = "
264 << running_sum <<
'\n';
268 str <<
"\t" << name <<
"[ OF ] = " << running_sum << std::endl;
282 (*underflow_bin_).startCounting(delay);
285 (*overflow_bin_).startCounting(delay);
289 (
bin_.at(idx)).startCounting(delay);
306 (*underflow_bin_).stopCounting(delay);
309 (*overflow_bin_).stopCounting(delay);
313 (
bin_.at(idx)).stopCounting(delay);
330 const std::string &name,
331 const std::string &description,
336 const std::vector<std::string>& histogram_state_names = {})
341 const std::string name_total = name.empty() ? std::string(
"total") : (name +
"_total");
344 const std::string name_uf = name.empty() ? std::string(
"UF") : (name +
"_UF");
350 name_uf +
"_probability",
351 "Probability of underflow",
353 name_uf +
" / " + name_total));
355 utils::ValidValue<InstrumentationNode::visibility_t> count_visibility;
361 std::string weighted_total_nonzero_str;
362 std::string count0_statistic_str;
368 std::ostringstream str(name, std::ios_base::ate);
373 if (str.str().empty()) {
380 if(histogram_state_names.empty()){
381 str <<
"count" << start_val;
394 str <<
"count" << histogram_state_names[i];
397 str <<
"bin_" << start_val <<
"_" << end_val;
399 if (count0_statistic_str.empty() && start_val == 0) {
400 count0_statistic_str = str.str();
408 visibility = stat_vis_general;
414 visibility = stat_vis_detailed;
418 count_visibility = visibility;
423 name.empty() ? std::string(
"cycle_count") : name, i,
424 description +
" histogram bin",
425 sparta::Counter::COUNT_NORMAL,
428 str.str() +
"_probability",
429 str.str() +
" bin probability",
431 str.str() +
"/ " + name_total,
436 weighted_total_str +=
"+ ( " + std::to_string(start_val) +
" * " + str.str() +
" )";
437 if (!count0_statistic_str.empty()) {
439 weighted_total_nonzero_str =
"( " + std::to_string(start_val) +
" * " + str.str() +
" )";
441 weighted_total_nonzero_str +=
"+ ( " + std::to_string(start_val) +
" * " + str.str() +
" )";
446 start_val = end_val + 1;
451 const std::string name_of = name.empty() ? std::string(
"OF") : (name +
"_OF");
457 name_of +
"_probability",
458 "Probability of overflow",
460 name_of +
" / " + name_total));
463 if (!count0_statistic_str.empty()) {
471 total_.reset(
new CycleCounter(sset,
482 name.empty() ? std::string(
"max_value") : (name +
"_max"),
483 "The maximum value in the histogram",
484 CounterBase::COUNT_LATEST,
490 name.empty() ? std::string(
"weighted_avg") : (name +
"_weighted_avg"),
493 "( " + weighted_total_str +
" ) / " + name_total,
494 sparta::StatisticDef::VS_ABSOLUTE,
497 if (!count0_statistic_str.empty()) {
498 const std::string nonzero_weighted_avg_stat_def_name =
499 name.empty() ? std::string(
"weighted_nonzero_avg") : (name +
"_weighted_nonzero_avg");
501 const std::string nonzero_weighted_avg_stat_def_equation =
502 "( " + weighted_total_nonzero_str +
" ) " +
504 "( " + name_total +
" - " + count0_statistic_str +
" )";
506 weighted_non_zero_average_.reset(
new StatisticDef(sset,
507 nonzero_weighted_avg_stat_def_name,
508 "Weighted nonzero average",
510 nonzero_weighted_avg_stat_def_equation,
514 const std::string nonzero_weighted_avg_stat_def_name =
515 name.empty() ? std::string(
"weighted_nonzero_avg") : (name +
"_weighted_nonzero_avg");
517 weighted_non_zero_average_.reset(
new StatisticDef(
519 nonzero_weighted_avg_stat_def_name,
520 "Weighted nonzero average",
529 std::ostringstream fullness_equation;
530 fullness_equation <<
bin_.back().getName() +
" + " + name_of;
531 const std::string fullness_equation_str = fullness_equation.str();
533 const std::string full_name = name.empty() ? std::string(
"full") : (name +
"_full");
538 fullness_equation_str,
540 count_visibility.getValue()));
542 const std::string full_prob_name = full_name +
"_probability";
545 "Fullness probability",
547 full_name +
" / " + name_total,
549 count_visibility.getValue()));
558 std::unique_ptr<sparta::CycleCounter>
total_;
561 std::vector<sparta::CycleCounter>
bin_;
565 std::unique_ptr<sparta::StatisticDef> weighted_non_zero_average_;
574 mutable std::vector<double> bin_prob_vector_;
647 const std::string &name,
648 const std::string &description,
649 const uint64_t lower_val,
650 const uint64_t upper_val,
651 const uint64_t num_vals_per_bin,
652 const uint64_t idle_value = 0,
660 initializeStats_ (sset, clk, name, description, stat_vis_general, stat_vis_detailed, stat_vis_max, stat_vis_avg);
679 const std::string name_;
753 const std::string &histogram_name,
754 const std::string &description,
755 const uint64_t lower_val,
756 const uint64_t upper_val,
757 const uint64_t num_vals_per_bin,
758 const uint64_t idle_value = 0,
763 TreeNode(histogram_name, description),
770 initializeStats_ (&stats_, parent_treenode->
getClock(), std::string(), description,
771 stat_vis_general, stat_vis_detailed, stat_vis_max, stat_vis_avg);
796 using CycleHistogram = CycleHistogramTreeNode;
File that defines the Resource class. Consider using sparta::Unit instead.
#define sparta_assert_context(e, insertions)
Check condition and throw a sparta exception if condition evaluates to false or 0....
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define SPARTA_EXPECT_TRUE(x)
A macro for hinting to the compiler a particular condition should be considered most likely true.
Contains a statistic definition (some useful information which can be computed)
File that defines the StatisticSet class.
Basic Node framework in sparta device tree composite pattern.
File that defines a ValidValue.
A representation of simulated time.
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
Represents a cycle counter.
CycleHistogramBase class for uint64_t values.
CycleHistogramBase(const CycleHistogramBase &)=delete
Not copy-constructable.
CycleHistogramBase(const uint64_t lower_val, const uint64_t upper_val, const uint64_t num_vals_per_bin, const uint64_t idle_value=0)
CycleHistogramBase constructor.
double getStandardDeviation() const
Calculate Standard Deviation of counts in bins. This API also takes into account the count in underfl...
const uint64_t idle_value_
Value to capture when nothing is captured.
const sparta::CycleCounter & getAggCycles() const
Return aggregate clock cycles of this histogram.
const uint64_t upper_val_
Highest value vaptured in normal bins.
void stopCounting_(uint64_t val, uint64_t delay=0)
Stop counting and increment internal count, taking into account the specified delay.
void updateMaxValues_(uint64_t val)
std::vector< std::unique_ptr< sparta::StatisticDef > > probabilities_
Probabilities of each normal bin.
void addValue(uint64_t val)
Add a value to histogram for one cycle, defaulting back to idle value.
void startCounting_(uint64_t val, uint64_t delay=0)
Start counting, taking into account the specified delay.
void operator=(const CycleHistogramBase &)=delete
Not assignable.
std::string getDisplayStringCumulative_(const std::string &name) const
Render the cumulative values of this histogram for use in standalone model.
std::unique_ptr< sparta::StatisticDef > weighted_average_
The weighted average.
const uint64_t lower_val_
Lowest value captured in normal bins.
std::unique_ptr< sparta::StatisticDef > fullness_probability_
Probability of the histogram being in a full state.
sparta::CycleCounter * underflow_bin_
Bin for all underflow.
uint64_t idx_shift_amount_
Number of bits which cannot distinguish between bins for a given input value.
const uint64_t num_vals_per_bin_
Number of values captured by each bin.
void setValue(uint64_t val)
Set a value to histogram until a new value is set.
std::unique_ptr< sparta::Counter > max_value_
The maximum value in the histogram.
CycleHistogramBase()=delete
Not default constructable.
CycleHistogramBase(CycleHistogramBase &&)=delete
Not move-constructable.
const sparta::CycleCounter & getOverflowBin() const
Return count of overflow bin.
std::unique_ptr< sparta::CycleCounter > total_
Total values.
uint64_t num_bins_
Number of bins.
std::unique_ptr< sparta::StatisticDef > underflow_probability_
Probability of underflow.
const sparta::CycleCounter & getUnderflowBin() const
Return count of underflow bin.
double getUnderflowProbability() const
Return underflow probability.
double getOverflowProbability() const
Return overflow probability.
uint64_t last_value_
Last value updated.
std::vector< sparta::CycleCounter > bin_
Regular bins.
std::unique_ptr< sparta::StatisticDef > overflow_probability_
Probability of overflow.
const std::vector< double > & recomputeRegularBinProbabilities() const
Return vector of probabilities regular bins.
double getMeanBinCount() const
Calculate the mean bin count of all the bins. This API also takes into account the count in underflow...
std::unique_ptr< sparta::StatisticDef > fullness_
Sum of the max bin and the overflow bin.
const std::vector< sparta::CycleCounter > & getRegularBin() const
Return vector of regular bin counts.
sparta::CycleCounter * overflow_bin_
Bin for all overflow.
CycleHistogramStandalone class for uint64_t values.
CycleHistogramStandalone(StatisticSet *sset, const Clock *clk, const std::string &name, const std::string &description, const uint64_t lower_val, const uint64_t upper_val, const uint64_t num_vals_per_bin, const uint64_t idle_value=0, const InstrumentationNode::visibility_t stat_vis_general=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_detailed=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_max=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_avg=InstrumentationNode::AUTO_VISIBILITY)
CycleHistogramStandalone constructor.
CycleHistogramStandalone()=delete
Not default constructable.
CycleHistogramStandalone(CycleHistogramStandalone &&)=delete
Not move-constructable.
CycleHistogramStandalone(const CycleHistogramStandalone &)=delete
Not copy-constructable.
void operator=(const CycleHistogramStandalone &)=delete
Not assignable.
std::string getDisplayStringCumulative() const
Render the cumulative values of this histogram for use in standalone model.
CycleHistogramTreeNode class for uint64_t values.
CycleHistogramTreeNode(const CycleHistogramTreeNode &)=delete
Not copy-constructable.
CycleHistogramTreeNode(TreeNode *parent_treenode, const std::string &histogram_name, const std::string &description, const uint64_t lower_val, const uint64_t upper_val, const uint64_t num_vals_per_bin, const uint64_t idle_value=0, const InstrumentationNode::visibility_t stat_vis_general=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_detailed=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_max=InstrumentationNode::AUTO_VISIBILITY, const InstrumentationNode::visibility_t stat_vis_avg=InstrumentationNode::AUTO_VISIBILITY)
CycleHistogramTreeNode constructor.
CycleHistogramTreeNode()=delete
Not default constructable.
CycleHistogramTreeNode(CycleHistogramTreeNode &&)=delete
Not move-constructable.
void operator=(const CycleHistogramTreeNode &)=delete
Not assignable.
std::string getDisplayStringCumulative() const
Render the cumulative values of this histogram for use in standalone model.
static constexpr visibility_t CONTAINER_DEFAULT_VISIBILITY
the actual visibility that the sparta containers such as buffer, queue, and array will use when VIS_S...
uint32_t visibility_t
Continuous visibility level. Several key points along continum are indicated within Visibility.
static constexpr visibility_t DEFAULT_VISIBILITY
Default node visibility.
@ VIS_SUPPORT
Supporting data. Used mainly for counters which contain an intermediate value for the sole purpose of...
static constexpr visibility_t AUTO_VISIBILITY
The default sparta resource visibility value that should be used. This is an alias of VIS_MAX at the ...
@ VS_FRACTIONAL
A fractional number. This value should be in the range [0,1]. Some report formatters could show this ...
@ VS_ABSOLUTE
An absolute number having no units (typical default)
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
CounterT & createCounter(_Args &&... __args)
Allocates a Counter which is owned by this StatisticSet and deleted at its destruction.
Node in a composite tree representing a sparta Tree item.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
const std::string & getName() const override
Gets the name of this node.
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.