blob: efe8edbb05eead8c70e6b377e0a5cdf1927381dd [file] [log] [blame]
erik.andersson@arm.comad45f792021-02-03 10:20:16 +01001# Copyright (C) 2020-2021 Arm Limited or its affiliates. All rights reserved.
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.
Tim Hall79d07d22020-04-27 18:20:16 +010016# Description:
17# Main entry point for the Vela compiler.
18#
19# Provides command line interface, options parsing, and network loading. Before calling the compiler driver.
Diego Russoe8a10452020-04-21 17:39:10 +010020import argparse
Tim Hall1bd531d2020-11-01 20:59:36 +000021import os
Diego Russoea6111a2020-04-14 18:41:58 +010022import sys
Tim Hall79d07d22020-04-27 18:20:16 +010023import time
Tim Hall79d07d22020-04-27 18:20:16 +010024
erik.andersson@arm.comad45f792021-02-03 10:20:16 +010025import flatbuffers
26
Tim Hall79d07d22020-04-27 18:20:16 +010027from . import architecture_features
Diego Russoe8a10452020-04-21 17:39:10 +010028from . import compiler_driver
29from . import model_reader
Diqing Zhong5e5a7842021-08-16 17:24:09 +020030from . import rawdata_writer
Diego Russoe8a10452020-04-21 17:39:10 +010031from . import scheduler
Tim Hall79d07d22020-04-27 18:20:16 +010032from . import stats_writer
33from . import tflite_writer
Tim Hall79d07d22020-04-27 18:20:16 +010034from ._version import __version__
Louis Verhaard11831ce2020-11-18 18:53:24 +010035from .api import API_VERSION
Tim Halle6ccd872020-11-09 16:46:37 +000036from .debug_database import DebugDatabase
Louis Verhaard7db78962020-05-25 15:05:26 +020037from .errors import InputFileError
Henrik G Olssonea9b23c2021-03-23 17:34:49 +010038from .errors import VelaError
Jonas Ohlsson45e653d2021-07-26 16:13:12 +020039from .nn_graph import NetworkType
Diego Russoe8a10452020-04-21 17:39:10 +010040from .nn_graph import TensorAllocator
Diego Russoea6111a2020-04-14 18:41:58 +010041from .tensor import MemArea
Jacob Bohlin0628a8c2020-08-28 13:25:14 +020042from .tensor import Tensor
erik.andersson@arm.comad45f792021-02-03 10:20:16 +010043from .tflite.Model import Model
Michael McGeagh837dc1b2020-11-10 12:38:25 +000044from .tflite_mapping import builtin_operator_map
Tim Halla3fe6652022-03-03 17:43:16 +000045from .tflite_mapping import builtin_operator_name_map
Jonas Ohlsson45e653d2021-07-26 16:13:12 +020046from .tflite_model_semantic import TFLiteSemantic
47from .tflite_supported_operators import TFLiteSupportedOperators
48from .tosa_model_semantic import TosaSemantic
49from .tosa_supported_operators import TosaSupportedOperators
Louis Verhaard52078302020-11-18 13:35:06 +010050from ethosu.vela.architecture_features import ArchitectureFeatures
Tim Hall79d07d22020-04-27 18:20:16 +010051
52
Tim Halle6ccd872020-11-09 16:46:37 +000053def process(input_name, enable_debug_db, arch, model_reader_options, compiler_options, scheduler_options):
Tim Hall79d07d22020-04-27 18:20:16 +010054 if compiler_options.timing:
55 start = time.time()
56
Tim Halle6ccd872020-11-09 16:46:37 +000057 os.makedirs(compiler_options.output_dir, exist_ok=True)
58 output_basename = os.path.join(compiler_options.output_dir, os.path.splitext(os.path.basename(input_name))[0])
59 DebugDatabase.show_warnings = enable_debug_db
60
Patrik Gustavsson8f1f9aa2021-06-28 07:41:58 +020061 nng, network_type = model_reader.read_model(input_name, model_reader_options)
Tim Hall79d07d22020-04-27 18:20:16 +010062
63 if not nng:
Michael McGeagh7a6f8432020-12-02 15:29:22 +000064 raise InputFileError(input_name, "Input file could not be read")
Tim Hall79d07d22020-04-27 18:20:16 +010065
66 if compiler_options.verbose_operators:
67 nng.print_operators()
68
69 if compiler_options.timing:
70 stop = time.time()
71 print("Model reading took %f s" % (stop - start))
72 start = time.time()
73
Patrik Gustavsson8f1f9aa2021-06-28 07:41:58 +020074 compiler_driver.compiler_driver(nng, arch, compiler_options, scheduler_options, network_type)
Tim Hall79d07d22020-04-27 18:20:16 +010075
Tim Halle6ccd872020-11-09 16:46:37 +000076 summary_csv_file = "{0}_summary_{1}.csv".format(output_basename, arch.system_config)
Tim Hall79d07d22020-04-27 18:20:16 +010077 stats_writer.write_summary_metrics_csv(nng, summary_csv_file, arch)
78
Fredrik Svedbergf5c07c42021-04-23 14:36:42 +020079 stats_writer.print_performance_metrics(
80 nng,
81 show_cpu_operations=compiler_options.show_cpu_operations,
82 verbose_weights=compiler_options.verbose_weights,
83 arch=arch,
84 )
Tim Hall79d07d22020-04-27 18:20:16 +010085
Diqing Zhong5e5a7842021-08-16 17:24:09 +020086 output_tfl_filename = output_basename + "_vela.tflite"
Patrik Gustavssonb081d672021-08-25 13:49:25 +020087 if input_name.endswith(".tflite"):
Diqing Zhong5e5a7842021-08-16 17:24:09 +020088 tflite_writer.write_tflite(nng, output_tfl_filename)
Patrik Gustavssonc74682c2021-08-17 14:26:38 +020089 if input_name.endswith(".tosa"):
Diqing Zhong5e5a7842021-08-16 17:24:09 +020090 rawdata_writer.write_rawdata_output(nng, arch, output_basename)
Tim Halle6ccd872020-11-09 16:46:37 +000091
92 if enable_debug_db:
Diqing Zhong5e5a7842021-08-16 17:24:09 +020093 file_offsets = calculate_operator_file_offsets(output_tfl_filename)
erik.andersson@arm.comad45f792021-02-03 10:20:16 +010094 for idx, offset in enumerate(sorted(file_offsets)):
95 sg = find_subgraph_with_command_stream_order(nng, idx)
96 if sg is not None:
97 DebugDatabase.set_stream_offset(sg, offset)
Tim Halle6ccd872020-11-09 16:46:37 +000098 debug_filename = output_basename + "_debug.xml"
Diqing Zhong5e5a7842021-08-16 17:24:09 +020099 DebugDatabase.write(debug_filename, input_name, output_tfl_filename)
Tim Hall79d07d22020-04-27 18:20:16 +0100100
101 if compiler_options.timing:
102 stop = time.time()
103 print("Compiler driver took %f s" % (stop - start))
104
105 return nng
106
107
erik.andersson@arm.comad45f792021-02-03 10:20:16 +0100108def find_subgraph_with_command_stream_order(nng, idx):
109 for sg in nng.subgraphs:
110 if sg.generated_stream_id == idx:
111 return sg
112 return None
113
114
115def calculate_operator_file_offsets(name: str):
116 # Read the vela optimized tflite file
117 with open(name, "rb") as f:
118 buf = bytearray(f.read())
119 # Calculate the file offsets for each custom operator
120 file_offsets = []
121 model = Model.GetRootAsModel(buf, 0)
122 for idx in range(model.SubgraphsLength()): # However only one subgraph is supported as of now
123 sg = model.Subgraphs(idx)
124 for idx in range(sg.OperatorsLength()):
125 operator = sg.Operators(idx)
126 if model.OperatorCodes(operator.OpcodeIndex()).CustomCode() is not None:
127 tensor_idx = operator.Inputs(0)
128 tensor = sg.Tensors(tensor_idx)
129 buffer = model.Buffers(tensor.Buffer())
130 offset = flatbuffers.number_types.UOffsetTFlags.py_type(buffer._tab.Offset(4))
131 file_offsets.append(buffer._tab.Vector(offset))
132 return file_offsets
133
134
Tim Hall79d07d22020-04-27 18:20:16 +0100135def print_subgraph_io_summary(nng):
136 """Print a summary of all the input and output tensor sizes for all subgraphs.
137 Also displays the total tensor size and the memory used area for sram.
138 """
139
140 print("Subgraph IO Summary")
141 print("-------------------")
James Ward93389782021-10-14 12:58:02 +0100142 print(f"NNG: {nng.name}")
Tim Hall79d07d22020-04-27 18:20:16 +0100143 max_sg_size = 0
144 for sg in reversed(nng.subgraphs):
James Ward93389782021-10-14 12:58:02 +0100145 print(f" NNG Subgraph: {sg.name} = {sg.placement}")
Tim Hall79d07d22020-04-27 18:20:16 +0100146 sg_size = 0
147
James Ward93389782021-10-14 12:58:02 +0100148 if hasattr(sg, "scratch_tensor") and sg.scratch_tensor is not None:
149 sg_tensors = sg.input_tensors + [sg.scratch_tensor] + sg.output_tensors
150 else:
151 sg_tensors = sg.input_tensors + sg.output_tensors
Tim Hall79d07d22020-04-27 18:20:16 +0100152
James Ward93389782021-10-14 12:58:02 +0100153 for tens in sg_tensors:
154 if tens in sg.input_tensors:
155 tens_dir = "In"
156 elif tens in sg.output_tensors:
157 tens_dir = "Out"
158 else:
159 tens_dir = "In/Out"
Tim Hall79d07d22020-04-27 18:20:16 +0100160
James Ward93389782021-10-14 12:58:02 +0100161 size = tens.elements() * tens.element_size() / 1024.0
162 sg_size = sg_size + size
163 print(f" Tensor [{tens_dir}]: {tens.name} = {size} KiB")
164
165 print(f" Total Size = {sg_size} KiB")
166 print(f" SRAM Memory Used = {sg.memory_used.get(MemArea.Sram, 0) / 1024.0} KiB")
Tim Hall79d07d22020-04-27 18:20:16 +0100167 max_sg_size = max(sg_size, max_sg_size)
168
James Ward93389782021-10-14 12:58:02 +0100169 print(f" Maximum NNG Subgraph Size = {max_sg_size} KiB")
Tim Hall79d07d22020-04-27 18:20:16 +0100170
171
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000172def generate_supported_ops():
Jonas Ohlsson0957e3e2021-09-01 15:57:21 +0200173 # Exclude network type from generation by adding value to exclude list.
174 # To easily exclude NetworkType from generated documentation.
175 exclude_generation_network_type_value = [NetworkType.TOSA.value]
176
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000177 lines = [
178 "# Supported Ops",
179 "",
180 "This file was automatically generated by Vela using the `--supported-ops-report` parameter. ",
181 f"Vela version: `{__version__}`",
182 "",
Michael McGeagh54a61112020-11-24 14:58:51 +0000183 "This file complies with",
184 "[**Gitiles Markdown syntax**](https://github.com/google/gitiles/blob/master/Documentation/markdown.md)",
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000185 "",
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200186 "Summary table of constraints for:",
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000187 ]
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200188
189 for network_type in NetworkType:
Jonas Ohlsson0957e3e2021-09-01 15:57:21 +0200190 if network_type.value in exclude_generation_network_type_value:
191 continue
192
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200193 lines += [
194 f"- [{network_type.name}](#{network_type.name.lower()}-summary-table)",
195 ]
196
197 for network_type in NetworkType:
Jonas Ohlsson0957e3e2021-09-01 15:57:21 +0200198 if network_type.value in exclude_generation_network_type_value:
199 continue
200
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000201 lines += [
202 "",
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200203 f"## {network_type.name} Summary Table",
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000204 "",
205 ]
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200206 if network_type == NetworkType.TFLite:
207 lines += [
208 "The table below contains TFLite operators that can be placed on the Ethos-U NPU. ",
209 "If the constraints are not met, then that operator will be scheduled on the CPU instead. ",
210 "For any other TFLite operator not listed, will be left untouched and scheduled on the CPU. ",
211 "Please check the supported operator list for your chosen runtime for further information.",
212 "",
213 "| Operator | TFLite Constraints |",
214 "| --- | --- |",
215 ]
216 semantic_checker = TFLiteSemantic()
217 supported = TFLiteSupportedOperators()
218 elif network_type == NetworkType.TOSA:
219 lines += [
220 "The table below contains TOSA operators that can be placed on the Ethos-U NPU. ",
221 "Note: There is limited support for compiling a TOSA neural network (EXPERIMENTAL). ",
222 "The related constraints have not yet been populated in the list.",
223 "",
224 "| Operator | TOSA Constraints |",
225 "| --- | --- |",
226 ]
227 semantic_checker = TosaSemantic()
228 supported = TosaSupportedOperators()
229 else:
230 raise ValueError
231
232 op_constraint_links = []
Tim Halla3fe6652022-03-03 17:43:16 +0000233 op_list = sorted(((op, builtin_operator_name_map[op]) for op in builtin_operator_map), key=lambda x: x[1])
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200234 for op, name in op_list:
235 internal_op = builtin_operator_map[op][0]
236 if internal_op in TFLiteSupportedOperators.supported_operators:
237 links = f"[Generic](#{network_type.name.lower()}-generic-constraints)"
238 if (
239 internal_op in supported.specific_constraints
240 or internal_op in semantic_checker.specific_constraints
241 ):
242 links += f", [Specific](#{network_type.name.lower()}-{name.lower()}-constraints)"
243 op_constraint_links.append((internal_op, name))
244 lines.append(f"| {name} | {links} |")
245 lines += [
246 "",
247 f"### {network_type.name} Generic Constraints",
248 "",
249 "This is a list of constraints that all NPU operators must satisfy in order to be scheduled on the NPU.",
250 "",
251 ]
252 for constraint in semantic_checker.generic_constraints:
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000253 # Markdown needs two spaces at the end of a line to render it as a separate line
254 reason = constraint.__doc__.replace("\n", " \n")
255 lines.append(f"- {reason}")
Jonas Ohlsson45e653d2021-07-26 16:13:12 +0200256 for constraint in supported.generic_constraints:
257 # Markdown needs two spaces at the end of a line to render it as a separate line
258 reason = constraint.__doc__.replace("\n", " \n")
259 lines.append(f"- {reason}")
260 for op, name in op_constraint_links:
261 lines += [
262 "",
263 f"### {network_type.name} {name} Constraints",
264 "",
265 f"This is a list of constraints that the {name} operator must satisfy in order to be scheduled on the"
266 " NPU.",
267 "",
268 ]
269 for constraint in semantic_checker.specific_constraints[op]:
270 # Markdown needs two spaces at the end of a line to render it as a separate line
271 reason = constraint.__doc__.replace("\n", " \n")
272 lines.append(f"- {reason}")
273 for constraint in supported.specific_constraints[op]:
274 # Markdown needs two spaces at the end of a line to render it as a separate line
275 reason = constraint.__doc__.replace("\n", " \n")
276 lines.append(f"- {reason}")
Michael McGeagh837dc1b2020-11-10 12:38:25 +0000277
278 # Note. this will generate the file in the CWD
279 filepath = os.path.join(os.getcwd(), "SUPPORTED_OPS.md")
280 with open(filepath, "wt") as md:
281 md.writelines(line + "\n" for line in lines)
282 print(f"Report file: {filepath}")
283
284
Tim Hall79d07d22020-04-27 18:20:16 +0100285def main(args=None):
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100286 try:
287 if args is None:
288 args = sys.argv[1:]
Tim Hall79d07d22020-04-27 18:20:16 +0100289
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100290 parser = argparse.ArgumentParser(prog="vela", description="Neural network model compiler for Arm Ethos-U NPUs")
291 parser.add_argument("--version", action="version", version=__version__)
292 parser.add_argument(
293 "--api-version", action="version", version=API_VERSION, help="Displays the version of the external API."
294 )
295 parser.add_argument(
296 "--supported-ops-report",
297 action="store_true",
298 help="Generate the SUPPORTED_OPS.md file in the current working directory and exit",
Tim Hallb9b515c2020-11-01 21:27:19 +0000299 )
Jacob Bohlin0628a8c2020-08-28 13:25:14 +0200300
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100301 # set network nargs to be optional to allow the support-ops-report CLI option to be used standalone
302 parser.add_argument(
303 "network",
304 metavar="NETWORK",
305 type=str,
306 default=None,
307 nargs="?",
308 help="Filename of the input TensorFlow Lite for Microcontrollers network",
309 )
310 parser.add_argument(
311 "--output-dir", type=str, default="output", help="Output directory to write files to (default: %(default)s)"
312 )
313 parser.add_argument(
314 "--enable-debug-db",
315 action="store_true",
316 default=None,
317 help="Enables the calculation and writing of a network debug database to output directory",
318 )
319 parser.add_argument(
320 "--config",
321 type=str,
322 action="append",
323 help="Vela configuration file(s) in Python ConfigParser .ini file format",
324 )
325 parser.add_argument("--verbose-all", action="store_true", help="Enable all verbose options")
326 parser.add_argument(
327 "--verbose-config", action="store_true", help="Verbose system configuration and memory mode"
328 )
329 parser.add_argument("--verbose-graph", action="store_true", help="Verbose graph rewriter")
330 parser.add_argument("--verbose-quantization", action="store_true", help="Verbose quantization")
331 parser.add_argument("--verbose-packing", action="store_true", help="Verbose pass packing")
332 parser.add_argument("--verbose-tensor-purpose", action="store_true", help="Verbose tensor purpose")
333 parser.add_argument("--verbose-tensor-format", action="store_true", help="Verbose tensor format")
334 parser.add_argument("--verbose-schedule", action="store_true", help="Verbose schedule")
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100335 parser.add_argument("--verbose-allocation", action="store_true", help="Verbose tensor allocation")
336 parser.add_argument(
337 "--verbose-high-level-command-stream", action="store_true", help="Verbose high level command stream"
338 )
339 parser.add_argument(
340 "--verbose-register-command-stream", action="store_true", help="Verbose register command stream"
341 )
342 parser.add_argument("--verbose-operators", action="store_true", help="Verbose operator list")
Fredrik Svedbergf5c07c42021-04-23 14:36:42 +0200343 parser.add_argument("--verbose-weights", action="store_true", help="Verbose weights information")
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100344 parser.add_argument(
345 "--show-cpu-operations", action="store_true", help="Show the operations that fall back to the CPU"
346 )
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100347 parser.add_argument("--timing", action="store_true", help="Time the compiler doing operations")
348 parser.add_argument(
349 "--accelerator-config",
350 type=str,
351 default="ethos-u55-256",
352 choices=list(architecture_features.Accelerator.member_list()),
353 help="Accelerator configuration to use (default: %(default)s)",
354 )
355 parser.add_argument(
356 "--system-config",
357 type=str,
358 default=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG,
359 help="System configuration to select from the Vela configuration file (default: %(default)s)",
360 )
361 parser.add_argument(
362 "--memory-mode",
363 type=str,
364 default=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG,
365 help="Memory mode to select from the Vela configuration file (default: %(default)s)",
366 )
367 parser.add_argument(
368 "--tensor-allocator",
369 default=TensorAllocator.HillClimb,
370 type=lambda s: TensorAllocator[s],
371 choices=list(TensorAllocator),
372 help="Tensor Allocator algorithm (default: %(default)s)",
373 )
374 parser.add_argument(
375 "--show-subgraph-io-summary",
376 action="store_true",
377 help="Shows a summary of all the subgraphs and their inputs and outputs",
378 )
379 parser.add_argument(
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100380 "--max-block-dependency",
381 type=int,
382 default=architecture_features.ArchitectureFeatures.MAX_BLOCKDEP,
383 choices=range(0, architecture_features.ArchitectureFeatures.MAX_BLOCKDEP + 1),
384 help=(
385 "Set the maximum value that can be used for the block dependency between npu kernel operations"
386 " (default: %(default)s)"
387 ),
388 )
389 parser.add_argument(
Tim Halld8339a72021-05-27 18:49:40 +0100390 "--optimise",
391 type=lambda s: scheduler.OptimizationStrategy[s],
392 default=scheduler.OptimizationStrategy.Performance,
393 choices=list(scheduler.OptimizationStrategy),
394 help=(
395 "Set the optimisation strategy. The Size strategy results in minimal SRAM usage (does not use"
396 " arena-cache-size). The Performance strategy results in maximal performance (uses the arena-cache-size"
397 " if specified) (default: %(default)s)"
398 ),
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100399 )
400 parser.add_argument(
Tim Halld8339a72021-05-27 18:49:40 +0100401 "--arena-cache-size",
402 type=int,
403 help=(
404 "Set the size of the arena cache memory area, in bytes. If specified, this option overrides the memory"
405 " mode attribute with the same name in a Vela configuration file"
406 ),
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100407 )
408 parser.add_argument(
409 "--cpu-tensor-alignment",
410 type=int,
411 default=Tensor.AllocationQuantum,
412 help=(
413 "Controls the allocation byte alignment of cpu tensors including Ethos-U Custom"
414 " operator inputs and outputs (default: %(default)s)"
415 ),
416 )
Dwight Lidmanb9c95422021-08-18 19:24:14 +0200417 parser.add_argument(
418 "--recursion-limit",
419 type=int,
420 default=1000,
421 help="Set the recursion depth limit, may result in RecursionError if too low (default: %(default)s)",
422 )
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100423 args = parser.parse_args(args=args)
Louis Verhaard52078302020-11-18 13:35:06 +0100424
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100425 # Generate the supported ops report and exit
426 if args.supported_ops_report:
427 generate_supported_ops()
428 return 0
Louis Verhaard52078302020-11-18 13:35:06 +0100429
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100430 if args.network is None:
431 parser.error("the following argument is required: NETWORK")
Michael McGeagh2fa40ae2020-12-02 10:55:04 +0000432
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100433 # check all config files exist because they will be read as a group
434 if args.config is not None:
435 for filename in args.config:
436 if not os.access(filename, os.R_OK):
437 raise InputFileError(filename, "File not found or is not readable")
Tim Hall79d07d22020-04-27 18:20:16 +0100438
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100439 if args.cpu_tensor_alignment < 16 or args.cpu_tensor_alignment & (args.cpu_tensor_alignment - 1) != 0:
440 parser.error(
441 "Invalid argument to --cpu-tensor-alignment = {} (must be greater than or equal to 16 and a power of 2)"
442 "".format(args.cpu_tensor_alignment)
443 )
Tim Hall79d07d22020-04-27 18:20:16 +0100444
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100445 if args.system_config == ArchitectureFeatures.DEFAULT_CONFIG:
446 print(f"Warning: Using {ArchitectureFeatures.DEFAULT_CONFIG} values for system configuration")
Tim Hall79d07d22020-04-27 18:20:16 +0100447
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100448 if args.memory_mode == ArchitectureFeatures.DEFAULT_CONFIG:
449 print(f"Warning: Using {ArchitectureFeatures.DEFAULT_CONFIG} values for memory mode")
Tim Hall79d07d22020-04-27 18:20:16 +0100450
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100451 if args.verbose_all:
452 for v in vars(args):
453 if v.startswith("verbose") and v != "verbose_all":
454 setattr(args, v, True)
455
Dwight Lidmanb9c95422021-08-18 19:24:14 +0200456 sys.setrecursionlimit(args.recursion_limit)
457
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100458 arch = architecture_features.ArchitectureFeatures(
459 vela_config_files=args.config,
460 system_config=args.system_config,
461 memory_mode=args.memory_mode,
462 accelerator_config=args.accelerator_config,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100463 max_blockdep=args.max_block_dependency,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100464 verbose_config=args.verbose_config,
Tim Halld8339a72021-05-27 18:49:40 +0100465 arena_cache_size=args.arena_cache_size,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100466 )
467
468 compiler_options = compiler_driver.CompilerOptions(
469 verbose_graph=args.verbose_graph,
470 verbose_quantization=args.verbose_quantization,
471 verbose_packing=args.verbose_packing,
472 verbose_tensor_purpose=args.verbose_tensor_purpose,
473 verbose_tensor_format=args.verbose_tensor_format,
474 verbose_allocation=args.verbose_allocation,
475 verbose_high_level_command_stream=args.verbose_high_level_command_stream,
476 verbose_register_command_stream=args.verbose_register_command_stream,
477 verbose_operators=args.verbose_operators,
Fredrik Svedbergf5c07c42021-04-23 14:36:42 +0200478 verbose_weights=args.verbose_weights,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100479 show_cpu_operations=args.show_cpu_operations,
480 tensor_allocator=args.tensor_allocator,
481 timing=args.timing,
482 output_dir=args.output_dir,
483 cpu_tensor_alignment=args.cpu_tensor_alignment,
484 )
485
486 scheduler_options = scheduler.SchedulerOptions(
Tim Halld8339a72021-05-27 18:49:40 +0100487 optimization_strategy=args.optimise,
488 sram_target=arch.arena_cache_size,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100489 verbose_schedule=args.verbose_schedule,
Henrik G Olssonea9b23c2021-03-23 17:34:49 +0100490 )
491
492 model_reader_options = model_reader.ModelReaderOptions()
493
494 nng = process(
495 args.network, args.enable_debug_db, arch, model_reader_options, compiler_options, scheduler_options
496 )
497
498 if args.show_subgraph_io_summary:
499 print_subgraph_io_summary(nng)
500
501 return 0
502 except VelaError as e:
503 print(e.data)
504 return 1