The Sparta Modeling Framework
Loading...
Searching...
No Matches
HistogramFunctionManager.hpp File Reference
#include <iostream>
#include <functional>
#include <map>
#include <string>
#include "sparta/statistics/Histogram.hpp"
#include "sparta/statistics/CycleHistogram.hpp"
#include "sparta/utils/MetaStructs.hpp"

Go to the source code of this file.

Classes

class  sparta::FunctionManager
 Singleton Function Manager class. This class contains two maps and one constant string token. These maps contain a string as key and function pointers as value. The string key is the same as the name of the free functions as defined by the users and the keys are the function pointers to those methods. One map is dedicated for HistogramTreeNodes while the other is dedicated for CycleHistogramTreeNodes. This was necessary because these two classes do not share a common polymorphic base. More...
 

Namespaces

namespace  sparta
 Macros for handling exponential backoff.
 

Macros

#define REGISTER_HISTOGRAM_STAT_CALC_FCN(histogram_type, fcn_name)
 Function Registration Macro for Histogram/CycleHistogram. This macro is called by the users in their code when they are trying to register a free function for stat collection. This macro takes two parameters, the name of the method they are trying to register and the type of argument this method takes whether it is a HistogramTreeNode or a CycleHistogramTreeNode.
 

Typedefs

template<typename T >
using sparta::HistStatCalcFcn = double(*)(const T *)
 

Detailed Description

This file contains a Singleton Function Manager which stores function names and function pointers as key-value pair in maps. There are two separate maps for histogram and cyclehistogram nodes. This file also contains the macro that users will need in order to register statistic calculation functions.

the following is an example usage. Step 1 - The user writes their free function.

double get_bin_count_greater_than_3_Stdev(
{
double total = 0.0;
const double std_dev = h->getStandardDeviation();
const double uf = h->getUnderflowBinCount();
const double of = h->getOverflowBinCount();
const auto& bin_counts = h->getBinCount();
for(const auto& bin : bin_counts){
if(bin > (3 * std_dev)){
total += bin;
}
}
if(uf > (3 * std_dev)){
total += uf_p;
}
if(of > (3 * std_dev)){
total += of_p;
}
return total;
}
double getStandardDeviation() const
Calculate Standard Deviation of counts in bins. This API also takes into account the count in underfl...

Step 2 - The user registers this method with the registration macro.

REGISTER_HISTOGRAM_STAT_CALC_FCN(HistogramTreeNode, get_bin_count_greater_than_3_Stdev);
#define REGISTER_HISTOGRAM_STAT_CALC_FCN(histogram_type, fcn_name)
Function Registration Macro for Histogram/CycleHistogram. This macro is called by the users in their ...

. Step 3 - User should know the exact fullpath of the histogram they are using in the device tree. Step 4 - If the fullpath of a certain histogram is top.core0.hist_node, then to get their free function as a statdef in reports, they should use the hist_def keyword and make it a prefix in the path string. For example, their yaml could look like this : content: top: hist_def.core0.hist_node.get_bin_count_greater_than_3_Stdev : my_stat top.core0: hist_def.hist_node.get_bin_count_less_than_mean : my_stat2 top.core0.hist_node: hist_def.get_bin_count_greater_than_mean : my_stat3 Using the hist_def keyword is essential as this tells the yaml parser to go and look in the Histogram Function Manager class for the string name.

Definition in file HistogramFunctionManager.hpp.

Macro Definition Documentation

◆ REGISTER_HISTOGRAM_STAT_CALC_FCN

#define REGISTER_HISTOGRAM_STAT_CALC_FCN (   histogram_type,
  fcn_name 
)
Value:
{ \
static_assert(MetaStruct::matches_any<sparta::histogram_type, \
"Invalid class type used for histogram stat calculation registration."); \
std::string key = #fcn_name; \
sparta::HistStatCalcFcn<sparta::histogram_type> callable = fcn_name; \
sparta::FunctionManager::get().add<sparta::histogram_type>(key, callable); \
}
CycleHistogramTreeNode class for uint64_t values.
This templated struct takes a target type and another parameter pack of types and returns a nested bo...

Function Registration Macro for Histogram/CycleHistogram. This macro is called by the users in their code when they are trying to register a free function for stat collection. This macro takes two parameters, the name of the method they are trying to register and the type of argument this method takes whether it is a HistogramTreeNode or a CycleHistogramTreeNode.

Example : Calculate three times the standard deviation of all counts in regular and over/under flow bins. double stdev_x3(const sparta::CycleHistogramTreeNode* h) { return (h->getStandardDeviation()) * 3; }

REGISTER_HISTOGRAM_STAT_CALC_FCN(CycleHistogramTreeNode, stdev_x3);

Definition at line 254 of file HistogramFunctionManager.hpp.