-
Notifications
You must be signed in to change notification settings - Fork 3
/
liblsb_internal.hpp
178 lines (147 loc) · 4.51 KB
/
liblsb_internal.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright (c) 2015 ETH-Zurich. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "config.h"
#include "liblsb_lvector.hpp"
#include "uthash/uthash.h"
#include "liblsb.h"
#define MAX_DOUBLE 1e99
//#define HAVE_MPI 1
#define USE_LVECTOR
#ifdef USE_LVECTOR
#define VECTOR_TYPE lvector
#else
#define VECTOR_TYPE std::vector
#endif
#ifdef HAVE_PAPI
#include <papi.h> /* This needs to be included every time you use PAPI */
#endif
#ifdef HAVE_UNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#endif
#include <stdlib.h>
#include <vector>
#include <signal.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <stdarg.h>
#ifdef HAVE_LIKWID
extern "C" {
#include <bstrlib.h>
#include <cpuid.h>
#include <msr.h>
#include <numa.h>
#include <perfmon.h>
#include <timer.h>
#include <registers.h>
#include <hashTable.h>
#include <likwid.h>
}
#endif
/**
* a single record field to be inserted during each record call
*/
typedef struct {
#ifdef HAVE_PAPI
long long papictr1; ///< first PAPI counter values
long long papictr2; ///< second PAPI counter values
#endif
#ifdef HAVE_LIKWID
long long PMcounter0; ///< likwid MSR counter values
long long PMcounter1; ///< likwid MSR counter values
long long PMcounter2; ///< likwid MSR counter values
long long PMcounter3; ///< likwid MSR counter values
long long PMcounter4; ///< likwid MSR counter values
long long PMcounter5; ///< likwid MSR counter values
long long PMcounter6; ///< likwid MSR counter values
long long PMcounter7; ///< likwid MSR counter values
long long PMcounter8; ///< likwid MSR counter values
long long PMcounter9; ///< likwid MSR counter values
#endif
double tduration; ///< the duration of the current epoch
unsigned long toverhead; ///< the duration (overhead) of profiling for this epoch
unsigned int id; ///< the user-specified kernel id
} t_rec;
typedef struct {
unsigned int id; ///< the user-specified kernel id
int int1; ///< integer 1
int int2; ///< integer 2
} t_recint;
typedef struct {
unsigned int id; ///< the user-specified kernel id
int int1; ///< integer
double dbl; ///< double
} t_recintdbl;
typedef enum{
LSB_INT=0, LSB_DBL, LSB_STR, LSB_LNG
} lsb_type_t;
typedef struct{
unsigned int start_idx;
const char * pindex;
lsb_type_t type;
union{
int value;
const char * str;
double dbl;
int64_t lng;
};
} t_recparam;
/*hash table*/
typedef struct{
const char * pname;
int value;
UT_hash_handle hh;
} t_hparam;
/**
* the global data for the profiler
* this holds all state related with the profiling session
*/
typedef struct {
VECTOR_TYPE<t_rec> recs; ///< records
VECTOR_TYPE<t_recint> recints; ///< recorded integers
VECTOR_TYPE<t_recintdbl> recintdbl; ///< recorded integer/double pairs
VECTOR_TYPE<t_recparam> recparams;
#ifdef HAVE_PAPI
int eventset; ///< PAPI eventset config
int papi1, papi2;
#endif
#ifdef HAVE_UNWIND
VECTOR_TYPE< std::vector<long> > iptrace; ///< the instruction pointer values for the stack for each epoch
#endif
int r; ///< MPI rank
int p; ///< MPI processes in world
FILE *outfd; ///< the output file
double tstart; ///< the program start time
double tlast; ///< lasttime starttime of the current epoch
char print; ///< internal flag if this process prints or not
char write_file; ///< internal flag if this process writes a file or not
char rec_enabled; ///< true if recording is enabled, false if it is not
char lsb_disabled; ///< true if lsb is completely disabled
int write_header;
int next;
#if defined(SYNC_WINDOW) && defined(HAVE_MPI)
double sync_window;
MPI_Comm sync_comm;
#endif
} LSB_Data;
#define CHK_DISABLED if(lsb_data->lsb_disabled) return;
void lsb_sort (double *data, int count);
double lsb_median_from_sorted_data (const double sorted_data[], const size_t stride, const size_t n);
double lsb_quantile_from_sorted_data (const double sorted_data[], const size_t stride, const size_t n, const double f);
int lsb_fit_linear (const double *x, const size_t xstride, const double *y, const size_t ystride, const size_t n, double *c0, double *c1, double *cov_00, double *cov_01, double *cov_11, double *sumsq);
double lsb_mean (const double data[], const size_t stride, const size_t size);
double min(double a, double b);
double max(double a, double b);
// prototypes
#include "liblsb.h"