blob: 92c7e1b8d6cf166316132e44673bbe7610085d10 [file] [log] [blame]
Johan Alfven014bc282024-01-25 12:32:13 +01001# SPDX-FileCopyrightText: Copyright 2020-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Tim Hall79d07d22020-04-27 18:20:16 +01002#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Rickard Bolinbc6ee582022-11-04 08:24:29 +000016#
Tim Hall79d07d22020-04-27 18:20:16 +010017# Description:
18# Neural network graph classes and enums.
19# Pass - A packed pass containing one or more Operations.
20# CascadedPass - A scheduled pass containing one or more Passes, as well as a scheduling strategy and block
21# configurations.
22# Subgraph - Holds a neural network subgraph, pointing at Tensors, Operations, Passes, and CascadedPasses.
23# Graph - A full neural network graph with one or more Subgraphs.
Tim Hall79d07d22020-04-27 18:20:16 +010024import enum
patrik.gustavssoneeb85152020-12-21 17:10:40 +000025from typing import List
Tim Hall79d07d22020-04-27 18:20:16 +010026
Louis Verhaardaee5d752020-09-30 09:01:52 +020027from .operation import Op
patrik.gustavssoneeb85152020-12-21 17:10:40 +000028from .shape4d import Shape4D
Louis Verhaardaee5d752020-09-30 09:01:52 +020029
Tim Hall79d07d22020-04-27 18:20:16 +010030
31class PassPlacement(enum.Enum):
32 Unknown = 0
33 Cpu = 1
34 Npu = 2
35 MemoryOnly = 3
36 StartupInit = 4
37
38
39class TensorAllocator(enum.Enum):
40 LinearAlloc = 1
41 Greedy = 2
Louis Verhaardd7002522021-01-20 17:23:54 +010042 HillClimb = 3
Tim Hall79d07d22020-04-27 18:20:16 +010043
44 def __str__(self):
45 return self.name
46
47
Patrik Gustavsson8f1f9aa2021-06-28 07:41:58 +020048class NetworkType(enum.Enum):
49 TFLite = 1
50 TOSA = 2
51
52
Tim Hall79d07d22020-04-27 18:20:16 +010053class Pass:
54 def __init__(self, name, placement, is_element_wise, npu_block_type):
55 self.inputs = []
56 self.intermediates = []
57 self.outputs = []
58 self.ops = []
59 self.primary_op = None
60 self.ifm_tensor = None
61 self.ifm2_tensor = None
62 self.ofm_tensor = None
63 self.weight_tensor = None
64 self.scale_tensor = None
Fredrik Svedberga0c36242020-06-03 15:43:31 +020065 self.lut_tensor = None
Tim Hall79d07d22020-04-27 18:20:16 +010066 self.name = name
67 self.cascade = None
68 self.placement = placement
patrik.gustavssoneeb85152020-12-21 17:10:40 +000069 self.ifm_shapes: List[Shape4D] = []
70 self.ofm_shapes: List[Shape4D] = []
Tim Hall79d07d22020-04-27 18:20:16 +010071
72 # TODO: rename is_element_wise because it is not the same as an ElementWise operator. It is used by the tensor
73 # allocation and requires that the OFM and IFM has the exact same address. Essentially complete overlap.
74 self.is_element_wise = is_element_wise
75 self.npu_block_type = npu_block_type
76 self.block_config = None # will be filled in by scheduler
77 self.shared_buffer = None # will be filled in by scheduler
Tim Halld8339a72021-05-27 18:49:40 +010078 self.scheduling_info = None # will be filled in by scheduler
Tim Hall79d07d22020-04-27 18:20:16 +010079
80 self.predecessors = []
81 self.successors = []
82
83 def __str__(self):
84 return "<nng.Pass '%s', %s, ops=%s>" % (self.name, self.placement, [op.type for op in self.ops])
85
86 __repr__ = __str__
87
88 def get_primary_op_ifm_weights(self):
89 if not self.primary_op:
90 return None, None
91 return self.primary_op.get_ifm_ifm2_weights_ofm()[::2]
92
93 def get_primary_op_ifm_ifm2_weights_ofm(self):
94 if not self.primary_op:
95 return None, None, None, None
96 return self.primary_op.get_ifm_ifm2_weights_ofm()
97
98 def get_primary_op_ifm_weights_biases_ofm(self):
99 if not self.primary_op:
100 return None, None, None, None
101 return self.primary_op.get_ifm_weights_biases_ofm()
102
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200103 def get_primary_op_lut(self):
104 if not self.primary_op:
105 return None
106 return self.primary_op.activation_lut
107
Tim Hall79d07d22020-04-27 18:20:16 +0100108
109class SchedulingStrategy(enum.Enum):
110 Unknown = -1
111 IfmStream = 0
112 WeightStream = 1
113
114
115class SchedulerRewrite(enum.Enum):
116 Nop = 0
117 ChangeTensorSubPurpose = 1
118
119
120class CascadedPass:
121 def __init__(self, name, strat, inputs, intermediates, outputs, passes, placement, is_element_wise):
122 self.name = name
123 self.strategy = strat
124 self.inputs = inputs
125 self.intermediates = intermediates
126 self.outputs = outputs
127 self.passes = passes
128 self.placement = placement
129 self.is_element_wise = is_element_wise
130
131 self.predecessors = []
132 self.successors = []
Tim Halld8339a72021-05-27 18:49:40 +0100133 self.sram_used = 0
Jonas Ohlsson845e2322022-03-01 12:39:55 +0100134 self.time = 0
Tim Hall79d07d22020-04-27 18:20:16 +0100135
136 def __str__(self):
137 return "<nng.CascadedPass strategy=%s x %s '%s', passes=%s, block_configs=%s>" % (
138 self.strategy,
139 len(self.passes),
140 self.name,
141 [ps.name for ps in self.passes],
142 [ps.block_config for ps in self.passes],
143 )
144
145 __repr__ = __str__
146
147
148class Subgraph:
149 def __init__(self, name="<unnamed>", placement=PassPlacement.Cpu):
150 self.output_tensors = []
151 self.input_tensors = []
Johan Alfven9070f0f2023-02-07 13:01:03 +0100152 # Preserve the original input order
153 self.original_inputs = []
154 # Attach virtual outputs to resource variables op
155 # in order to be able to traverse the graph correctly
156 self.virtual_outputs = []
Tim Hall79d07d22020-04-27 18:20:16 +0100157 self.passes = []
158 self.cascaded_passes = []
159 self.name = name
160 self.high_level_command_stream = []
161 self.placement = placement
162 self.command_stream_tensor = None
163 self.flash_tensor = None
Louis Verhaard0b9c9a32020-09-15 14:05:38 +0200164 # Scratch information locally used in the scheduler
Tim Halld8339a72021-05-27 18:49:40 +0100165 self.schedule = None
166 self.sched_ops = []
167
erik.andersson@arm.comad45f792021-02-03 10:20:16 +0100168 self.generated_stream_id = None
Tim Hall79d07d22020-04-27 18:20:16 +0100169
170 self.memory_used = {}
Patrik Gustavssoneca2e952020-05-27 09:15:11 +0200171 self.memory_used_per_type = {}
Tim Hall79d07d22020-04-27 18:20:16 +0100172
173 def __str__(self):
174 return "<nng.Subgraph '%s', n_passes=%d, n_cascaded_passes=%d>" % (
175 self.name,
176 len(self.passes),
177 len(self.cascaded_passes),
178 )
179
180 __repr__ = __str__
181
182 def update_consumers(self):
183 visit_op_set = set()
184 visit_tensor_set = set()
185 self.input_tensors = []
186
187 print_visit = False
188
189 def visit_op(op):
190 if op in visit_op_set:
191 return
192
193 visit_op_set.add(op)
194 for inp in op.inputs:
Jacob Bohlin67e0d8f2020-08-20 10:53:02 +0200195 if not inp:
196 continue
Tim Hall79d07d22020-04-27 18:20:16 +0100197 if print_visit:
198 print(inp, "adding consumer", op)
199 visit_tensor(inp)
200 inp.consumer_list.append(op)
201
Michael McGeaghf3e3ad72020-12-02 12:39:03 +0000202 if op.type in (Op.Placeholder, Op.SubgraphInput):
Tim Hall79d07d22020-04-27 18:20:16 +0100203 assert len(op.outputs) == 1
Fredrik Svedberg33c01e62023-02-13 11:32:12 +0100204 if not op.outputs[0].is_variable:
205 self.input_tensors.append(op.outputs[0])
Tim Hall79d07d22020-04-27 18:20:16 +0100206
207 for out in op.outputs:
208 if out not in visit_tensor_set:
209 out.consumer_list = [] # reset unvisited output, just in case
210
211 def visit_tensor(tens):
212 if tens in visit_tensor_set:
213 return
214 visit_tensor_set.add(tens)
215 tens.consumer_list = []
216 for op in tens.ops:
217 visit_op(op)
218
219 for ps in self.passes:
220 for tens in ps.outputs + ps.inputs:
Jacob Bohlin67e0d8f2020-08-20 10:53:02 +0200221 if not tens:
222 continue
Tim Hall79d07d22020-04-27 18:20:16 +0100223 tens.consumer_list = [] # reset unvisited tensors to start with
224
225 for tens in self.output_tensors:
226 visit_tensor(tens)
227 tens.consumer_list.append(None) # special op to indicate that the graph consumes the result
228
229 print_visit = True
230 for ps in self.passes:
231 for op in ps.ops:
232 visit_op(op)
233 for tens in ps.inputs:
234 visit_tensor(tens)
235
236 def build_pass_links(self):
237 for idx, ps in enumerate(self.passes):
238 ps.time = 2 * idx
239 ps.predecessors = []
240 ps.successors = []
241
242 for ps in self.passes:
243 for tens in ps.inputs:
244 for op in tens.ops:
245 pred_pass = op.scheduled_pass
246 assert pred_pass.time < ps.time
247 if ps not in pred_pass.successors:
248 pred_pass.successors.append(ps)
249
250 if pred_pass not in ps.predecessors:
251 ps.predecessors.append(pred_pass)
252
253 assert tens in pred_pass.outputs
254
255 def build_pass_dag_predecessors(self):
256 for ps in self.passes:
257 ps.dag_predecessors = []
258
259 class State(enum.Enum):
260 NotVisited = 0
261 BeingVisited = 1
262 Visited = 2
263
264 pass_visit_dict = {}
265
266 def visit_pass(ps):
267 state = pass_visit_dict.get(ps, State.NotVisited)
268 if state == State.Visited:
269 return True
270 elif state == State.BeingVisited:
271 return False # this is a loop, need to remove this link
272 elif state == State.NotVisited:
273 pass_visit_dict[ps] = State.BeingVisited
274
275 ps.dag_predecessors = []
276 for pred in ps.predecessors:
277 if visit_pass(pred):
278 ps.dag_predecessors.append(pred)
279
280 pass_visit_dict[ps] = State.Visited
281 return True
282
283 for ps in self.passes:
284 if not ps.successors:
285 visit_pass(ps)
286
287 def build_cascaded_pass_links(self):
288 for cps in self.cascaded_passes:
289 cps.predecessors = []
290 cps.successors = []
291
292 for cps in self.cascaded_passes:
293 for tens in cps.inputs:
294 for op in tens.ops:
295 pred_cpass = op.scheduled_pass.cascade
296 if cps not in pred_cpass.successors:
297 pred_cpass.successors.append(cps)
298
299 if pred_cpass not in cps.predecessors:
300 cps.predecessors.append(pred_cpass)
301
302 assert tens in pred_cpass.outputs
303
304 def refresh_after_modification(self):
Rickard Bolin26c8e842023-05-11 10:53:42 +0000305 try:
306 self.update_consumers()
307 except RecursionError as e:
308 raise RecursionError(
309 "Compilation failed due to exceeding the default maximum recursion depth.\n"
310 'Try increasing the maximum recursion depth with the "--recursion-limit" option.'
311 ) from e
Tim Hall79d07d22020-04-27 18:20:16 +0100312
313 def prune_startup_init_pass(self):
314 assert len(self.passes) >= 1
315 ps = self.passes[0]
316 assert ps.placement == PassPlacement.StartupInit
317
318 ps.outputs = [out_tens for out_tens in ps.outputs if len(out_tens.consumers()) > 0]
319 ps.ops = [op for op in ps.ops if op.outputs[0] in ps.outputs]
320
Johan Alfven014bc282024-01-25 12:32:13 +0100321 # get_all_ops is used when traversing the original graph
Tim Hall79d07d22020-04-27 18:20:16 +0100322 def get_all_ops(self):
323 all_ops = []
324 visit_op_set = set()
325 visit_tensor_set = set()
326
327 def visit_op(op):
328 if op in visit_op_set:
329 return
330 visit_op_set.add(op)
331 for inp in op.inputs:
332 visit_tensor(inp)
333
334 all_ops.append(op)
335
336 def visit_tensor(tens):
Andreas Nevalainene1cc3de2020-09-08 15:31:02 +0200337 if tens is None or tens in visit_tensor_set:
Tim Hall79d07d22020-04-27 18:20:16 +0100338 return
339 visit_tensor_set.add(tens)
340 for op in tens.ops:
341 visit_op(op)
342
343 for tens in self.output_tensors:
344 visit_tensor(tens)
345
346 return all_ops
347
Johan Alfven014bc282024-01-25 12:32:13 +0100348 # get_all_ops_from_passes is used by stats writer to calculate the number of
349 # CPU and NPU ops
350 # Due to a side effect get_all_ops might not be traversing the full graph
351 # after extract_npu_subgraph have been called and should not be used by stats writer.
352 # The reason is that the main graph might have NPU nodes with no visible outputs
353 # and therefore the nodes will be missed.
354 def get_all_ops_from_passes(self):
355 all_ops = []
356 for idx, ps in enumerate(self.passes):
357 for op in ps.ops:
358 all_ops.append(op)
359
360 return all_ops
361
Tim Hallcd035042023-08-08 14:10:17 +0100362 def print_operators(self, ignore_placeholder_const=True, show_attributes=True):
363 print(f"Operators of Subgraph {self.name}")
Tim Hall79d07d22020-04-27 18:20:16 +0100364
Tim Hallcd035042023-08-08 14:10:17 +0100365 ignore_ops = (Op.Const, Op.Identity, Op.Placeholder) if ignore_placeholder_const else ()
366 all_ops = [op for op in self.get_all_ops() if op.type not in ignore_ops]
367
368 if len(all_ops) > 0:
369 max_op_type_len = max([len(op.type.name) for op in all_ops])
370
371 for idx, op in enumerate(all_ops):
372 attrs_str = f" - {op.attrs}" if show_attributes else ""
373 print(f"{idx:3}: {op.type:{max_op_type_len}}{attrs_str} - {op.name}")
374
375 else:
376 print("No Operators")
Tim Hall79d07d22020-04-27 18:20:16 +0100377
Fredrik Svedbergc875aa62021-05-06 09:53:31 +0200378 def print_graph(self, label=None):
379 if label:
380 print(f"\n[ {label} ]")
Michael McGeagh775e3962020-07-28 11:44:22 +0100381 print("print_graph()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100382 all_ops = self.get_all_ops()
383 for idx, op in enumerate(all_ops):
384 print(idx, op.type, op.name)
385
386 def print_graph_with_tensors(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100387 print("print_graph_with_tensors()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100388 all_ops = self.get_all_ops()
389 for idx, op in enumerate(all_ops):
390 print(idx, op.type, op.name)
391 for idx, tens in enumerate(op.inputs):
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200392 if tens:
393 print(
394 f" Input {idx:02d}"
395 f" {tens.purpose.name:>20} {tens.mem_area.name:>20} {tens.mem_type.name:>20} {tens}"
396 )
397 else:
398 print(f" Input {idx:02d} {'-':>20} {'-':>20} {'-':>20} {tens}")
Tim Hall79d07d22020-04-27 18:20:16 +0100399 for idx, tens in enumerate(op.outputs):
Patrik Gustavssoneca2e952020-05-27 09:15:11 +0200400 print(
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200401 f" Output {idx:02d}"
402 f" {tens.purpose.name:>20} {tens.mem_area.name:>20} {tens.mem_type.name:>20} {tens}"
Patrik Gustavssoneca2e952020-05-27 09:15:11 +0200403 )
Tim Hall79d07d22020-04-27 18:20:16 +0100404 print()
405
406 def print_graph_with_tensor_quantization(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100407 print("print_graph_with_tensor_quantization()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100408 all_ops = self.get_all_ops()
409 for idx, op in enumerate(all_ops):
410 print(idx, op.type, op.name)
411 for idx, tens in enumerate(op.inputs):
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200412 if tens:
413 q = tens.quantization
414 if q is None:
415 print(f" Input {idx:02d} {tens.dtype!s:>10} NO QUANTIZATION INFO {tens.name}")
416 else:
417 print(
418 f" Input {idx:02d} {tens.dtype!s:>10}"
419 f" min={q.min} max={q.max} scale={q.scale_f32!s} zero_point={q.zero_point} {tens.name}"
420 )
Tim Hall79d07d22020-04-27 18:20:16 +0100421 else:
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200422 print(f" Input {idx:02d} {'-':>10} {tens}")
Tim Hall79d07d22020-04-27 18:20:16 +0100423 for idx, tens in enumerate(op.outputs):
424 q = tens.quantization
425 if q is None:
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200426 print(f" Output {idx:02d} {tens.dtype!s:>10} NO QUANTIZATION INFO {tens.name}")
Tim Hall79d07d22020-04-27 18:20:16 +0100427 else:
428 print(
Fredrik Svedbergb3d941e2021-10-13 14:06:03 +0200429 f" Output {idx:02d} {tens.dtype!s:>10}"
430 f" min={q.min} max={q.max} scale={q.scale_f32!s} zero_point={q.zero_point} {tens.name}"
Tim Hall79d07d22020-04-27 18:20:16 +0100431 )
432 print()
433
434 def print_passes(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100435 print("print_passes()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100436 for idx, ps in enumerate(self.passes):
437 print("%03d %s" % (idx * 2, ps))
438
439 def print_passes_with_tensors(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100440 print("print_passes_with_tensors()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100441 for idx, ps in enumerate(self.passes):
442 print("%3d %s" % (idx * 2, ps))
443 for idx, tens in enumerate(ps.inputs):
444 print(
445 " Input %2d %-15s %-15s %-15s %s"
446 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
447 )
448 for idx, tens in enumerate(ps.intermediates):
449 print(
450 " Intermediate %2d %-15s %-15s %-15s %s"
451 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
452 )
453 for idx, tens in enumerate(ps.outputs):
454 print(
455 " Output %2d %-15s %-15s %-15s %s"
456 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
457 )
458 print()
459
460 def print_cascaded_passes(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100461 print("print_cascaded_passes()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100462 for idx, ps in enumerate(self.cascaded_passes):
463 print("%3d %s SRAM used %.1f KB" % (idx * 2, ps, ps.sram_used / 1024))
464
465 def print_cascaded_passes_with_tensors(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100466 print("print_cascaded_passes_with_tensors()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100467 for idx, ps in enumerate(self.cascaded_passes):
468 print("%3d %s SRAM used %.1f KB" % (idx * 2, ps, ps.sram_used / 1024))
469 for idx, tens in enumerate(ps.inputs):
470 print(
471 " Input %2d %-15s %-15s %-15s %s"
472 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
473 )
474 for idx, tens in enumerate(ps.intermediates):
475 print(
476 " Intermediate %2d %-15s %-15s %-15s %s"
477 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
478 )
479 for idx, tens in enumerate(ps.outputs):
480 print(
481 " Output %2d %-15s %-15s %-15s %s"
482 % (idx, tens.purpose.name, tens.mem_area.name, tens.format.name, tens.name)
483 )
484 print()
485
486 def print_cascaded_passes_with_tensor_sizes(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100487 print("print_cascaded_passes_with_tensor_sizes()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100488 for idx, ps in enumerate(self.cascaded_passes):
489 print("%3d %s SRAM used %.1f KB" % (idx * 2, ps, ps.sram_used / 1024))
490 for idx, tens in enumerate(ps.inputs):
491 print(
492 " Input %2d %7.1f KB %-24s %-15s %-15s %-20s %s"
493 % (
494 idx,
495 tens.storage_size() / 1024,
496 tens.storage_shape,
497 tens.mem_area.name,
498 tens.purpose.name,
499 tens.format.name,
500 tens.name,
501 )
502 )
503 for idx, tens in enumerate(ps.intermediates):
504 print(
505 " Intermediate %2d %7.1f KB %-24s %-15s %-15s %-20s %s"
506 % (
507 idx,
508 tens.storage_size() / 1024,
509 tens.storage_shape,
510 tens.mem_area.name,
511 tens.purpose.name,
512 tens.format.name,
513 tens.name,
514 )
515 )
516 for idx, tens in enumerate(ps.outputs):
517 print(
518 " Output %2d %7.1f KB %-24s %-15s %-15s %-20s %s"
519 % (
520 idx,
521 tens.storage_size() / 1024,
522 tens.storage_shape,
523 tens.mem_area.name,
524 tens.purpose.name,
525 tens.format.name,
526 tens.name,
527 )
528 )
529 print()
530
531 def print_high_level_command_stream(self):
Michael McGeagh775e3962020-07-28 11:44:22 +0100532 print("print_high_level_command_stream()", self.name)
Tim Hall79d07d22020-04-27 18:20:16 +0100533 for idx, cmd in enumerate(self.high_level_command_stream):
534 print("%3d %s" % (idx, cmd))
535
536
537class Graph:
538 def __init__(self, name="<unnamed>", batch_size=1):
539 self.name = name
540 self.batch_size = batch_size
541 self.subgraphs = []
Michael McGeagh22f74e12020-08-07 16:21:03 +0100542 self.metadata = []
Tim Hall79d07d22020-04-27 18:20:16 +0100543 self.memory_used = {}
Diqing Zhongdb5124c2021-01-11 12:52:48 +0100544 self.total_original_weights = 0
Fredrik Svedbergf5c07c42021-04-23 14:36:42 +0200545 self.total_npu_encoded_weights = 0
Louis Verhaard3c07c972020-05-07 08:12:58 +0200546 self.weight_cache = None # See CompressedWeightCache
Jonas Ohlsson845e2322022-03-01 12:39:55 +0100547 self.bandwidths = 0
548 self.macs = 0
549 self.cycles = 0
Tim Hall79d07d22020-04-27 18:20:16 +0100550
551 def get_root_subgraph(self):
552 return self.subgraphs[0]
553
554 def prune_startup_init_pass(self):
555 for sg in self.subgraphs:
556 sg.prune_startup_init_pass()
557
558 def update_consumers(self):
559 for sg in self.subgraphs:
560 sg.update_consumers()
561
562 def refresh_after_modification(self):
563 for sg in self.subgraphs:
564 sg.refresh_after_modification()
565
Tim Hallcd035042023-08-08 14:10:17 +0100566 def print_operators(self, ignore_placeholder_const=True, show_attributes=True):
Tim Hall79d07d22020-04-27 18:20:16 +0100567 for sg in self.subgraphs:
Tim Hallcd035042023-08-08 14:10:17 +0100568 sg.print_operators(ignore_placeholder_const, show_attributes)
Tim Hall79d07d22020-04-27 18:20:16 +0100569
Fredrik Svedbergc875aa62021-05-06 09:53:31 +0200570 def print_graph(self, label=None):
Tim Hall79d07d22020-04-27 18:20:16 +0100571 for sg in self.subgraphs:
Fredrik Svedbergc875aa62021-05-06 09:53:31 +0200572 sg.print_graph(label)
Tim Hall79d07d22020-04-27 18:20:16 +0100573
574 def print_graph_with_tensors(self):
575 for sg in self.subgraphs:
576 sg.print_graph_with_tensors()
577
578 def print_graph_with_tensor_quantization(self):
579 for sg in self.subgraphs:
580 sg.print_graph_with_tensor_quantization()
581
582 def print_passes(self):
583 for sg in self.subgraphs:
584 sg.print_passes()
585
586 def print_passes_with_tensors(self):
587 for sg in self.subgraphs:
588 sg.print_passes_with_tensors()
589
590 def print_cascaded_passes(self):
591 for sg in self.subgraphs:
592 sg.print_cascaded_passes()
593
594 def print_cascaded_passes_with_tensors(self):
595 for sg in self.subgraphs:
596 sg.print_cascaded_passes_with_tensors()
597
598 def print_cascaded_passes_with_tensor_sizes(self):
599 for sg in self.subgraphs:
600 sg.print_cascaded_passes_with_tensor_sizes()
601
602 def print_high_level_command_stream(self):
603 for sg in self.subgraphs:
604 sg.print_high_level_command_stream()