22 #ifndef SINGA_UTILS_COMMON_H_
23 #define SINGA_UTILS_COMMON_H_
25 #include <google/protobuf/message.h>
26 #include <unordered_map>
31 #include "proto/common.pb.h"
35 std::string IntVecToString(
const std::vector<int>& vec);
36 std::string VStringPrintf(std::string fmt, va_list l);
37 std::string StringPrintf(std::string fmt, ...);
47 int ArgPos(
int argc,
char** arglist,
const char* arg);
48 void CreateFolder(
const std::string name);
57 const std::vector<std::vector<int>>
Slice(
int num,
58 const std::vector<int>& sizes);
66 const std::vector<int>
PartitionSlices(
int num,
const std::vector<int>& slices);
72 int gcd(
int a,
int b);
73 int LeastCommonMultiple(
int a,
int b);
79 std::string GetHostIP();
80 void SetupLog(
const std::string& workspace,
const std::string& model);
88 explicit Metric(
const std::string& str);
97 void Add(
const std::string& name,
float value);
98 void Add(
const std::string& name,
float value,
int count);
117 std::unordered_map<std::string, std::pair<int, float>> entry_;
120 using google::protobuf::Message;
121 void Im2col(
const float* data_im,
const int channels,
122 const int height,
const int width,
const int kernel_h,
const int kernel_w,
123 const int pad_h,
const int pad_w,
const int stride_h,
const int stride_w,
125 void Col2im(
const float* data_col,
const int channels,
126 const int height,
const int width,
const int patch_h,
const int patch_w,
127 const int pad_h,
const int pad_w,
const int stride_h,
const int stride_w,
129 void ForwardMaxPooling(
const float* bottom,
const int num,
const int channels,
130 const int height,
const int width,
const int kernel_h,
const int kernel_w,
131 const int pad_h,
const int pad_w,
const int stride_h,
const int stride_w,
132 float* top,
float* mask);
133 void BackwardMaxPooling(
const float* top,
const float* mask,
const int num,
134 const int channels,
const int height,
const int width,
135 const int kernel_h,
const int kernel_w,
const int pad_h,
const int pad_w,
136 const int stride_h,
const int stride_w,
138 void ForwardAvgPooling(
const float* bottom,
const int num,
const int channels,
139 const int height,
const int width,
const int kernel_h,
const int kernel_w,
140 const int pad_h,
const int pad_w,
const int stride_h,
const int stride_w,
142 void BackwardAvgPooling(
const float* top,
const int num,
const int channels,
143 const int height,
const int width,
const int kernel_h,
const int kernel_w,
144 const int pad_h,
const int pad_w,
const int stride_h,
const int stride_w,
147 void ReadProtoFromTextFile(
const char* filename, Message* proto);
148 void WriteProtoToTextFile(
const Message& proto,
const char* filename);
149 void ReadProtoFromBinaryFile(
const char* filename, Message* proto);
150 void WriteProtoToBinaryFile(
const Message& proto,
const char* filename);
155 #endif // SINGA_UTILS_COMMON_H_
void Add(const std::string &name, float value)
Add one metric.
const std::vector< std::vector< int > > Slice(int num, const std::vector< int > &sizes)
Slice a set of large Params into small pieces such that they can be roughtly equally partitioned into...
std::string ToString() const
Serialize the object into a string.
const std::vector< int > PartitionSlices(int num, const std::vector< int > &slices)
Partition slices into boxes.
void Reset()
reset all metric counter and value to 0
void ParseFrom(const std::string &msg)
Parse the metric from a string.
int ArgPos(int argc, char **arglist, const char *arg)
Locate the position of the arg in arglist.
std::string ToLogString() const
Generate a one-line string for logging.
Performance mtrics.
Definition: common.h:85