forked from arthurcerveira/Custom-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_data.py
227 lines (174 loc) · 5.41 KB
/
video_data.py
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
226
227
import json
BLOCK_SIZES = {
"128x128": 0,
"128x64": 0,
"64x128": 0,
"64x64": 0,
"64x32": 0,
"32x64": 0,
"32x32": 0,
"64x16": 0,
"16x64": 0,
"32x24": 0,
"24x32": 0,
"32x16": 0,
"16x32": 0,
"64x8": 0,
"8x64": 0,
"16x16": 0,
"32x8": 0,
"8x32": 0,
"64x4": 0,
"4x64": 0,
"16x12": 0,
"12x16": 0,
"16x8": 0,
"8x16": 0,
"32x4": 0,
"4x32": 0,
"8x8": 0,
"16x4": 0,
"4x16": 0,
"8x4": 0,
"4x8": 0
}
MODULES = ("Inter",
"Intra",
"TQ",
"Others",
"Entropy",
"Control",
"Filters")
MODULES_PREDICTION = ("IME",
"IME:RDCost",
"FME",
"FME:RDCost",
"FME:Interpolation",
"Affine",
"Affine:RDCost",
"Geo",
"Geo:RDCost",
"Intra",
"Intra:RDCost",
"Inter")
MODULES_DECODER = ("Inter decoding",
"Intra decoding",
"IT/IQ",
"Others",
"Entropy",
"Control",
"Filters")
class VideoData(object):
def __init__(self):
# Encoded video info
self.title = str()
self.resolution = list()
self.search_range = str()
self.video_encoder = str()
self.encoder_config = str()
self.qp = str()
def set_resolution(self, width, height):
self.resolution.append(width)
self.resolution.append(height)
def __str__(self):
string = f'{ self.video_encoder },'
string += f'{ self.encoder_config },'
string += f'{ self.title },'
string += f'{ self.resolution[0] }x{ self.resolution[1] },'
string += f'{ self.search_range },'
string += f'{ self.qp },'
return string
def clear(self):
self.title = ""
self.resolution.clear()
self.search_range = ""
self.video_encoder = ""
self.encoder_config = ""
class TraceData(VideoData):
def __init__(self):
super().__init__()
# Counter
self.candidate_blocks = 0
self.data_volume = 0
self.size_pu_counter = BLOCK_SIZES
# Aux Variables
self.current_partition = str()
self.current_cu_size = 0
self.current_volume = 0
def increment_candidate_blocks(self, candidate_blocks):
self.candidate_blocks += candidate_blocks
def increment_data_volume(self, volume):
self.data_volume += volume
def set_current_partition(self, size_hor, size_ver):
partition_string = f'{ int(size_hor) }x{ int(size_ver) }'
self.current_partition = partition_string
def increment_pu_counter(self, blocks):
self.size_pu_counter[self.current_partition] += blocks
def __str__(self):
string = str(super())
string += f'{ int(self.candidate_blocks) },'
string += f'{ int(self.data_volume) },'
volume_in_gb = int(self.data_volume) / (1024 * 1024 * 1024)
string += f'{ round(volume_in_gb, 2) },'
for _, counter in self.size_pu_counter.items():
string += f'{ counter },'
string += '\n'
return string
def clear(self):
super().clear()
self.candidate_blocks = 0
self.data_volume = 0
self.current_cu_size = 0
for size in self.size_pu_counter:
self.size_pu_counter[size] = 0
class VtuneData(VideoData):
def __init__(self, modules_list):
super().__init__()
self.modules_list = modules_list
self.modules = dict()
# Initialize the counters in 0
for module in self.modules_list:
self.modules[module] = {"Loads": 0,
"Stores": 0}
def increment_load_counter(self, load_mem, module):
self.modules[module]["Loads"] += load_mem
def increment_store_counter(self, store_mem, module):
self.modules[module]["Stores"] += store_mem
def __str__(self):
string = str()
for metric in ("Loads", "Stores"):
string += super().__str__()
string += f'{ metric },'
for module in self.modules_list:
string += f'{ self.modules[module][metric] },'
string += "\n"
return string
def clear(self):
super().clear()
for module in self.modules:
self.modules[module]["Loads"] = 0
self.modules[module]["Stores"] = 0
class BlockStatsData(VideoData):
def __init__(self):
super().__init__()
self.block_sizes = BLOCK_SIZES
self.invalid_sizes = dict()
def increment_block_size(self, block_size):
try:
self.block_sizes[block_size] += 1
except KeyError:
self.invalid_sizes.setdefault(block_size, 0)
self.invalid_sizes[block_size] += 1
def __str__(self):
string = f'{ self.title },'
string += f'{ self.encoder_config },'
string += f'{ self.qp },'
for _, total in self.block_sizes.items():
string += f'{ total },'
string += '\n'
return string
def clear(self):
super().clear()
for block_size in BLOCK_SIZES:
self.block_sizes[block_size] = 0
self.invalid_sizes = {}