-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathengine1.cpp
More file actions
226 lines (197 loc) · 7.69 KB
/
engine1.cpp
File metadata and controls
226 lines (197 loc) · 7.69 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
__ __ ______ _______ _______ ______ ________
/ \ / | / \ / \ / \ / \ / |
$$ \ /$$ |/$$$$$$ |$$$$$$$ |$$$$$$$ |/$$$$$$ |$$$$$$$$/
$$$ \ /$$$ |$$ | $$/ $$ |__$$ |$$ |__$$ |$$ | $$ |$$ |__
$$$$ /$$$$ |$$ | $$ $$/ $$ $$< $$ | $$ |$$ |
$$ $$ $$/$$ |$$ | __ $$$$$$$/ $$$$$$$ |$$ | $$ |$$$$$/
$$ |$$$/ $$ |$$ \__/ |$$ | $$ | $$ |$$ \__$$ |$$ |
$$ | $/ $$ |$$ $$/ $$ | $$ | $$ |$$ $$/ $$ |
$$/ $$/ $$$$$$/ $$/ $$/ $$/ $$$$$$/ $$/
A Memory and Communication Profiler
* This file is a part of MCPROF.
* https://bitbucket.org/imranashraf/mcprof
*
* Copyright (c) 2014-2016 TU Delft, The Netherlands.
* All rights reserved.
*
* MCPROF is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MCPROF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MCPROF. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Imran Ashraf
*
*/
#include "globals.h"
#include "shadow.h"
#include "engine1.h"
#include "commatrix.h"
#include "symbols.h"
#include "callstack.h"
extern CallStackType CallStack;
extern Matrix2D ComMatrix;
extern Symbols symTable;
extern bool TrackObjects;
extern bool TrackTasks;
extern bool DoTrace;
extern std::ofstream traceout;
extern UINT64 gInstrCount;
extern map<IDNoType,u64> funcReads;
extern map<IDNoType,u64> funcWrites;
extern map<IDNoType,u64> objReads;
extern map<IDNoType,u64> objWrites;
// un-comment the following to generate read/write traces
// #define GENRATE_TRACES
// un-comment the following to generate selected read/write traces
// #define GENRATE_SELECTED_TRACES
void RecordWriteEngine1(uptr addr, u32 size)
{
if(DoTrace)
{
IDNoType prod = CallStack.Top();
IDNoType objid = GetObjectID(addr);
D2ECHO("Recording Write of " << VAR(size) << " by " << FUNC(prod) << " at " << ADDR(addr));
#ifdef GENRATE_TRACES
// Generate Write Trace
switch (size)
{
case 1:
traceout << gInstrCount << " W " << size << " " << HEXA(addr) << " " << HEXV( *((u8*)addr)) << endl;
break;
case 2:
traceout << gInstrCount << " W " << size << " " << HEXA(addr) << " " << HEXV( *((u16*)addr)) << endl;
break;
case 4:
traceout << gInstrCount << " W " << size << " " << HEXA(addr) << " " << HEXV( *((u32*)addr)) << endl;
break;
case 8:
traceout << gInstrCount << " W " << size << " " << HEXA(addr) << " " << HEXV( *((u64*)addr)) << endl;
break;
default:
ECHO("traceout, write size is : " << size );
break;
}
#endif
#if 1
if(TrackTasks)
{
// Added for allocation dependencies
// TODO this can be a problem when same stack addresses are reused
// these will appear as write after write dependencies
for(u32 i=0; i<size; i++)
{
IDNoType prevProd = GetProducer(addr+i);
ComMatrix.RecordCommunication(prevProd, prod, 1);
D2ECHO( "AllocDepend " << FUNC(prevProd) << " " << FUNC(prod) << " at " << ADDR(addr) );
}
}
#endif
if( (objid == UnknownID) || (TrackObjects == false) )
{
for(u32 i=0; i<size; i++)
{
SetProducer(prod, addr+i);
}
// Update write memory accesses
funcWrites[prod] += size;
}
else
{
D2ECHO("Recording comm of " << VAR(size) << " b/w " << FUNC(prod)
<< " and " << symTable.GetSymName(objid) << dec);
for(u32 i=0; i<size; i++)
{
SetProducer(prod, addr+i);
}
ComMatrix.RecordCommunication(prod, objid, size);
// Update write memory accesses
funcWrites[prod] += size;
objWrites[objid] += size;
#ifdef GENRATE_SELECTED_TRACES
// Generate Write Trace of a selected function to selected objects
if(
// For canny: tmpimg objects(10) AND gaussian_smooth1(11) function.
// For canny: nms(20) object AND non_max_supp1(22) function.
(objid==20) && (prod==22)
)
{
traceout << "W of "<< size << " to " << objid << " by " << prod << " at " << HEXA(addr) << endl;
}
#endif
}
}
}
void RecordReadEngine1(uptr addr, u32 size)
{
if(DoTrace)
{
IDNoType cons = CallStack.Top();
D2ECHO("Recording Read of " << VAR(size) << " by " << FUNC(cons) << " at " << ADDR(addr) << dec);
#ifdef GENRATE_TRACES
// Generate Read Trace
switch (size)
{
case 1:
traceout << gInstrCount << " R " << size << " " << HEXA(addr) << " " << HEXV( *((u8*)addr)) << endl;
break;
case 2:
traceout << gInstrCount << " R " << size << " " << HEXA(addr) << " " << HEXV( *((u16*)addr)) << endl;
break;
case 4:
traceout << gInstrCount << " R " << size << " " << HEXA(addr) << " " << HEXV( *((u32*)addr)) << endl;
break;
case 8:
traceout << gInstrCount << " R " << size << " " << HEXA(addr) << " " << HEXV( *((u64*)addr)) << endl;
break;
default:
ECHO("traceout, write size is : " << size );
break;
}
#endif
IDNoType objid = GetObjectID(addr);
D2ECHO( ADDR(addr) << " " << symTable.GetSymName(objid) << "(" << objid << ")" );
if( (objid == UnknownID) || (TrackObjects == false) )
{
D2ECHO("Recording comm of " << VAR(size) << " b/w function "
<< FUNC( GetProducer(addr) ) << " and " << FUNC(cons) << dec);
for(u32 i=0; i<size; i++)
{
IDNoType prod = GetProducer(addr+i);
ComMatrix.RecordCommunication(prod, cons, 1);
}
// Update read memory accesses
funcReads[cons] += size;
}
else
{
D2ECHO("Recording comm of " << VAR(size) << " b/w object "
<< symTable.GetSymName(objid) << " and " << FUNC(cons) << dec);
ComMatrix.RecordCommunication(objid, cons, size);
// Update read memory accesses
funcReads[cons] += size;
objReads[objid] += size;
// set last consumer to reader(cons) as it is reading now (AE/PE)
SetLastConsumers(addr, size, cons);
#ifdef GENRATE_SELECTED_TRACES
// Generate Read Trace by a selected function from selected objects
if(
// For canny: image(4) OR kernel(9) objects AND gaussian_smooth1(11) function.
// For canny: magnitude(18) OR delta_x(13) OR delta_y(14) objects AND non_max_supp1(22) function.
(objid==18 || objid==13 || objid==14) && (cons==22)
)
{
traceout << "R of "<< size << " from " << objid << " by " << cons << " at " << HEXA(addr) << endl;
}
#endif
}
}
}