SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
|
1 #ifndef _UTILITY_UTILS_H_
2 #define _UTILITY_UTILS_H_
8 #include "smaug/core/datatypes.h"
9 #include "gem5/m5ops.h"
15 int product(std::vector<T> array) {
17 for (
auto val : array)
27 std::vector<T>
sum(std::vector<T> array0, std::vector<T> array1) {
28 assert(array0.size() == array1.size());
29 std::vector<T>
sum(array0.size());
30 for (
int i = 0; i < array0.size(); i++)
31 sum[i] = array0[i] + array1[i];
36 void variadicToVector(std::vector<T>& vector, T elem) {
37 vector.push_back(elem);
43 template <
typename T,
typename... Args>
44 void variadicToVector(std::vector<T>& vector, T e, Args... elems) {
46 variadicToVector(vector, elems...);
56 template <
typename T,
typename... Args>
58 return {{ i, elems... }};
93 void dumpStats(
const char* msg,
int period = 0);
121 const char* _endLabel,
122 bool _resetStats =
true);
126 const char* startLabel;
127 const char* endLabel;
134 constexpr
const char* kNetworkStart =
"Network start";
135 constexpr
const char* kNetworkEnd =
"Network end";
136 constexpr
const char* kReorderingStart =
"Reordering start";
137 constexpr
const char* kReorderingEnd =
"Reordering end";
138 constexpr
const char* kTensorPrepStart =
"Tensor preparation start";
139 constexpr
const char* kTensorPrepEnd =
"Tensor preparation end";
140 constexpr
const char* kTensorFinalStart =
"Tensor finalization start";
141 constexpr
const char* kTensorFinalEnd =
"Tensor finalization end";
A RAII helper class which dumps and/or resets gem5 stats at construction and destruction.
int getCpuId()
Returns the logical CPU number.
void * malloc_aligned(size_t size, bool zeroOut)
Return heap-allocated cacheline-aligned memory.
std::vector< T > sum(std::vector< T > array0, std::vector< T > array1)
Returns the elementwise-sum of the two arrays, which must be of the same size.
void wakeCpu(int id)
Wakes up a quiesced CPU.
The smaug namespace is the parent namespace of all C++ code in SMAUG.
int calc_padding(int value, unsigned alignment)
Return the difference between value and the next multiple of alignment.
std::string dataLayoutToStr(DataLayout layout)
Get the string version of DataLayout.
void quiesce()
Puts the CPU to sleep.
void dumpStats(const char *msg, int period)
Dumps gem5 stats to the stats.txt file.
void switchCpu()
Switches to the next CPU type.
std::array< T, sizeof...(Args)+1 > variadicToArray(T i, Args... elems)
Returns a std::array populated with the given elements.
void dumpResetStats(const char *msg, int period)
Dumps gem5 stats to the stats.txt file and resets all stats.