Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 1 | # Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. |
| 2 | # |
| 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 Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 16 | # 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 Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 20 | import argparse |
| 21 | import ast |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 22 | import os |
Diego Russo | ea6111a | 2020-04-14 18:41:58 +0100 | [diff] [blame] | 23 | import sys |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 24 | import time |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 25 | |
| 26 | from . import architecture_features |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 27 | from . import compiler_driver |
| 28 | from . import model_reader |
| 29 | from . import scheduler |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 30 | from . import stats_writer |
| 31 | from . import tflite_writer |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 32 | from ._version import __version__ |
Patrik Gustavsson | c8a22f1 | 2020-11-18 17:05:50 +0100 | [diff] [blame] | 33 | from .api import api_version |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 34 | from .debug_database import DebugDatabase |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 35 | from .errors import InputFileError |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 36 | from .nn_graph import PassPlacement |
| 37 | from .nn_graph import TensorAllocator |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 38 | from .scheduler import ParetoMetric |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 39 | from .supported_operators import SupportedOperators |
Diego Russo | ea6111a | 2020-04-14 18:41:58 +0100 | [diff] [blame] | 40 | from .tensor import MemArea |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 41 | from .tensor import Tensor |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 42 | from .tflite_mapping import builtin_operator_map |
| 43 | from .tflite_mapping import builtin_type_name |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 44 | |
| 45 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 46 | def process(input_name, enable_debug_db, arch, model_reader_options, compiler_options, scheduler_options): |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 47 | if compiler_options.timing: |
| 48 | start = time.time() |
| 49 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 50 | os.makedirs(compiler_options.output_dir, exist_ok=True) |
| 51 | output_basename = os.path.join(compiler_options.output_dir, os.path.splitext(os.path.basename(input_name))[0]) |
| 52 | DebugDatabase.show_warnings = enable_debug_db |
| 53 | |
| 54 | nng = model_reader.read_model(input_name, model_reader_options) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 55 | |
| 56 | if not nng: |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 57 | raise InputFileError(input_name, "input file could not be read") |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 58 | |
| 59 | if compiler_options.verbose_operators: |
| 60 | nng.print_operators() |
| 61 | |
| 62 | if compiler_options.timing: |
| 63 | stop = time.time() |
| 64 | print("Model reading took %f s" % (stop - start)) |
| 65 | start = time.time() |
| 66 | |
| 67 | compiler_driver.compiler_driver(nng, arch, compiler_options, scheduler_options) |
| 68 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 69 | passes_csv_file = "{0}_pass-breakdown_{1}.csv".format(output_basename, arch.system_config) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 70 | stats_writer.write_pass_metrics_csv(nng, passes_csv_file) |
| 71 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 72 | summary_csv_file = "{0}_summary_{1}.csv".format(output_basename, arch.system_config) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 73 | stats_writer.write_summary_metrics_csv(nng, summary_csv_file, arch) |
| 74 | |
| 75 | stats_writer.print_performance_metrics(nng, show_cpu_operations=compiler_options.show_cpu_operations, arch=arch) |
| 76 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 77 | output_filename = output_basename + "_vela.tflite" |
| 78 | if input_name.endswith(".tflite"): |
| 79 | tflite_writer.write_tflite(nng, output_filename) |
| 80 | |
| 81 | if enable_debug_db: |
| 82 | debug_filename = output_basename + "_debug.xml" |
| 83 | DebugDatabase.write(debug_filename, input_name, output_filename) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 84 | |
| 85 | if compiler_options.timing: |
| 86 | stop = time.time() |
| 87 | print("Compiler driver took %f s" % (stop - start)) |
| 88 | |
| 89 | return nng |
| 90 | |
| 91 | |
| 92 | def print_subgraph_io_summary(nng): |
| 93 | """Print a summary of all the input and output tensor sizes for all subgraphs. |
| 94 | Also displays the total tensor size and the memory used area for sram. |
| 95 | """ |
| 96 | |
| 97 | print("Subgraph IO Summary") |
| 98 | print("-------------------") |
| 99 | print("NNG: {0}".format(nng.name)) |
| 100 | max_sg_size = 0 |
| 101 | for sg in reversed(nng.subgraphs): |
| 102 | print(" Subgraph: {0} = {1}".format(sg.name, sg.placement)) |
| 103 | sg_size = 0 |
| 104 | |
| 105 | if sg.placement == PassPlacement.Npu: |
| 106 | for tens in sg.input_tensors + [sg.scratch_tensor] + sg.output_tensors: |
| 107 | if tens in sg.input_tensors: |
| 108 | tens_dir = "In" |
| 109 | elif tens in sg.output_tensors: |
| 110 | tens_dir = "Out" |
| 111 | else: |
| 112 | tens_dir = "In/Out" |
| 113 | |
| 114 | size = tens.elements() * tens.element_size() / 1024.0 |
| 115 | sg_size = sg_size + size |
| 116 | print(" Tensor [{0}]: {1} = {2} KiB".format(tens_dir, tens.name, size)) |
| 117 | |
| 118 | print(" Total Size = {0} KiB".format(sg_size)) |
| 119 | print(" SRAM Memory Used = {0} KiB".format(sg.memory_used.get(MemArea.Sram, 0) / 1024.0)) |
| 120 | max_sg_size = max(sg_size, max_sg_size) |
| 121 | |
| 122 | print(" Maximum Subgraph Size = {0} KiB".format(max_sg_size)) |
| 123 | |
| 124 | |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 125 | def generate_supported_ops(): |
| 126 | lines = [ |
| 127 | "# Supported Ops", |
| 128 | "", |
| 129 | "This file was automatically generated by Vela using the `--supported-ops-report` parameter. ", |
| 130 | f"Vela version: `{__version__}`", |
| 131 | "", |
| 132 | "This file complies with [**CommonMark.**](https://commonmark.org)", |
| 133 | "", |
| 134 | "## Summary Table", |
| 135 | "", |
| 136 | "The table below contains TFLite operators that can be placed on the Ethos-U NPU. ", |
| 137 | "If the constraints are not met, then that operator will be scheduled on the CPU instead. ", |
| 138 | "For any other TFLite operator not listed, will be left untouched and scheduled on the CPU. ", |
| 139 | "Please check the supported operator list for your chosen runtime for further information.", |
| 140 | "", |
| 141 | "| Operator | Constraints |", |
| 142 | "| - | - |", |
| 143 | ] |
| 144 | supported = SupportedOperators() |
| 145 | op_constraint_links = [] |
| 146 | op_list = sorted(((op, builtin_type_name(op)) for op in builtin_operator_map), key=lambda x: x[1]) |
| 147 | for op, name in op_list: |
| 148 | internal_op = builtin_operator_map[op][0] |
| 149 | if internal_op in SupportedOperators.supported_operators: |
| 150 | links = "[Generic](#generic-constraints)" |
| 151 | if internal_op in supported.specific_constraints: |
| 152 | links += f", [Specific](#{name.lower()}-constraints)" |
| 153 | op_constraint_links.append((internal_op, name)) |
| 154 | lines.append(f"| {name} | {links} |") |
| 155 | lines += [ |
| 156 | "", |
| 157 | "## Generic Constraints", |
| 158 | "", |
| 159 | "This is a list of constraints that all NPU operators must satisfy in order to be scheduled on the NPU.", |
| 160 | "", |
| 161 | ] |
| 162 | for constraint in supported.generic_constraints: |
| 163 | # Markdown needs two spaces at the end of a line to render it as a separate line |
| 164 | reason = constraint.__doc__.replace("\n", " \n") |
| 165 | lines.append(f"- {reason}") |
| 166 | for op, name in op_constraint_links: |
| 167 | lines += [ |
| 168 | "", |
| 169 | f"## {name} Constraints", |
| 170 | "", |
| 171 | f"This is a list of constraints that the {name} operator must satisfy in order to be scheduled on the NPU.", |
| 172 | "", |
| 173 | ] |
| 174 | for constraint in supported.specific_constraints[op]: |
| 175 | # Markdown needs two spaces at the end of a line to render it as a separate line |
| 176 | reason = constraint.__doc__.replace("\n", " \n") |
| 177 | lines.append(f"- {reason}") |
| 178 | |
| 179 | # Note. this will generate the file in the CWD |
| 180 | filepath = os.path.join(os.getcwd(), "SUPPORTED_OPS.md") |
| 181 | with open(filepath, "wt") as md: |
| 182 | md.writelines(line + "\n" for line in lines) |
| 183 | print(f"Report file: {filepath}") |
| 184 | |
| 185 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 186 | def main(args=None): |
| 187 | if args is None: |
| 188 | args = sys.argv[1:] |
| 189 | |
Tim Hall | c8a7386 | 2020-10-27 12:43:14 +0000 | [diff] [blame] | 190 | parser = argparse.ArgumentParser(prog="vela", description="Neural network model compiler for Ethos-U") |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 191 | parser.add_argument("--version", action="version", version=__version__) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 192 | parser.add_argument( |
Patrik Gustavsson | c8a22f1 | 2020-11-18 17:05:50 +0100 | [diff] [blame] | 193 | "--api-version", action="version", version=api_version, help="Displays the version of the external API." |
| 194 | ) |
| 195 | parser.add_argument( |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 196 | "--supported-ops-report", |
| 197 | action="store_true", |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 198 | help="Generate the SUPPORTED_OPS.md file in the current working directory and exit", |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 199 | ) |
| 200 | |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 201 | # set network nargs to be optional to allow the support-ops-report CLI option to be used standalone |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 202 | parser.add_argument( |
| 203 | "network", metavar="NETWORK", type=str, default=None, nargs="?", help="Filename of network to process" |
| 204 | ) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 205 | parser.add_argument( |
| 206 | "--output-dir", type=str, default="output", help="Output directory to write files to (default: %(default)s)" |
| 207 | ) |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 208 | parser.add_argument( |
| 209 | "--enable-debug-db", |
| 210 | action="store_true", |
| 211 | default=None, |
| 212 | help="Enables the calculation and writing of a network debug database to output directory", |
| 213 | ) |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 214 | parser.add_argument( |
| 215 | "--config", type=str, action="append", help="Vela configuration file(s) in Python ConfigParser .ini file format" |
| 216 | ) |
| 217 | parser.add_argument("--verbose-config", action="store_true", help="Verbose system configuration and memory mode") |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 218 | parser.add_argument("--verbose-graph", action="store_true", help="Verbose graph rewriter") |
| 219 | parser.add_argument("--verbose-quantization", action="store_true", help="Verbose quantization") |
| 220 | parser.add_argument("--verbose-packing", action="store_true", help="Verbose pass packing") |
| 221 | parser.add_argument("--verbose-tensor-purpose", action="store_true", help="Verbose tensor purpose") |
| 222 | parser.add_argument("--verbose-tensor-format", action="store_true", help="Verbose tensor format") |
| 223 | parser.add_argument("--verbose-schedule", action="store_true", help="Verbose schedule") |
| 224 | parser.add_argument( |
| 225 | "--verbose-pareto-frontier-schedules", |
| 226 | action="store_true", |
| 227 | help="Show all schedules along the pareto frontier of optimisation criteria", |
| 228 | ) |
| 229 | parser.add_argument("--verbose-allocation", action="store_true", help="Verbose tensor allocation") |
| 230 | parser.add_argument( |
| 231 | "--verbose-high-level-command-stream", action="store_true", help="Verbose high level command stream" |
| 232 | ) |
| 233 | parser.add_argument( |
| 234 | "--verbose-register-command-stream", action="store_true", help="Verbose register command stream" |
| 235 | ) |
| 236 | parser.add_argument("--verbose-operators", action="store_true", help="Verbose operator list") |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 237 | parser.add_argument( |
| 238 | "--show-cpu-operations", action="store_true", help="Show the operations that fall back to the CPU" |
| 239 | ) |
| 240 | parser.add_argument( |
Andreas Nevalainen | 897cc14 | 2020-10-28 15:42:08 +0100 | [diff] [blame] | 241 | "--keep-scale-placement", action="store_true", help="Keep scale tensors memory placement during scheduling" |
| 242 | ) |
| 243 | parser.add_argument( |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 244 | "--cascading", |
| 245 | type=ast.literal_eval, |
| 246 | default=True, |
| 247 | choices=[True, False], |
| 248 | help="Controls the packing of multiple passes into a cascade (default: %(default)s)", |
| 249 | ) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 250 | parser.add_argument("--force-block-config", type=str, default="", help="Force a specific block configuration HxWxC") |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 251 | parser.add_argument("--timing", action="store_true", help="Time the compiler doing operations") |
| 252 | parser.add_argument( |
| 253 | "--accelerator-config", |
| 254 | type=str, |
| 255 | default="ethos-u55-256", |
Manupa Karunaratne | d83d2e1 | 2020-07-20 12:05:32 +0100 | [diff] [blame] | 256 | choices=list(architecture_features.Accelerator.member_list()), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 257 | help="Accelerator configuration to use (default: %(default)s)", |
| 258 | ) |
| 259 | parser.add_argument( |
| 260 | "--system-config", |
| 261 | type=str, |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 262 | default=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG, |
| 263 | help="System configuration to select from the Vela configuration file (default: %(default)s)", |
| 264 | ) |
| 265 | parser.add_argument( |
| 266 | "--memory-mode", |
| 267 | type=str, |
| 268 | default=architecture_features.ArchitectureFeatures.DEFAULT_CONFIG, |
| 269 | help="Memory mode to select from the Vela configuration file (default: %(default)s)", |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 270 | ) |
| 271 | parser.add_argument( |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 272 | "--tensor-allocator", |
| 273 | default=TensorAllocator.Greedy, |
| 274 | type=lambda s: TensorAllocator[s], |
| 275 | choices=list(TensorAllocator), |
| 276 | help="Tensor Allocator algorithm (default: %(default)s)", |
| 277 | ) |
| 278 | parser.add_argument( |
| 279 | "--show-subgraph-io-summary", |
| 280 | action="store_true", |
| 281 | help="Shows a summary of all the subgraphs and their inputs and outputs", |
| 282 | ) |
| 283 | parser.add_argument( |
| 284 | "--ifm-streaming", |
| 285 | type=ast.literal_eval, |
| 286 | default=True, |
| 287 | choices=[True, False], |
| 288 | help="Controls scheduler IFM streaming search (default: %(default)s)", |
| 289 | ) |
| 290 | parser.add_argument( |
| 291 | "--block-config-limit", |
| 292 | type=int, |
| 293 | default=16, |
| 294 | help="Limit block config search space, use zero for unlimited (default: %(default)s)", |
| 295 | ) |
| 296 | parser.add_argument( |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 297 | "--pareto-metric", |
| 298 | default=ParetoMetric.BwCycMem, |
| 299 | type=lambda s: ParetoMetric[s], |
| 300 | choices=list(ParetoMetric), |
| 301 | help="Controls the calculation of the pareto metric (default: %(default)s)", |
| 302 | ) |
| 303 | parser.add_argument( |
| 304 | "--recursion-limit", |
| 305 | type=int, |
| 306 | default=10000, |
| 307 | help="Set the recursion depth limit, may result in RecursionError if too low (default: %(default)s)", |
| 308 | ) |
| 309 | parser.add_argument( |
| 310 | "--max-block-dependency", |
| 311 | type=int, |
| 312 | default=architecture_features.ArchitectureFeatures.MAX_BLOCKDEP, |
| 313 | choices=range(0, architecture_features.ArchitectureFeatures.MAX_BLOCKDEP + 1), |
| 314 | help=( |
Tim Hall | b9b515c | 2020-11-01 21:27:19 +0000 | [diff] [blame^] | 315 | "Set the maximum value that can be used for the block dependency between npu kernel operations" |
| 316 | " (default: %(default)s)" |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 317 | ), |
| 318 | ) |
Charles Xu | 7b8823f | 2020-05-29 13:53:10 +0200 | [diff] [blame] | 319 | parser.add_argument( |
| 320 | "--nhcwb16-between-cascaded-passes", |
| 321 | type=ast.literal_eval, |
| 322 | default=True, |
| 323 | choices=[True, False], |
| 324 | help="Control if NHCWB16 or NHWC should be used in between cascaded passes (default: %(default)s)", |
| 325 | ) |
Fredrik Svedberg | a0c3624 | 2020-06-03 15:43:31 +0200 | [diff] [blame] | 326 | parser.add_argument( |
Patrik Gustavsson | 90831bc | 2020-08-24 16:26:11 +0200 | [diff] [blame] | 327 | "--weight-estimation-scaling", |
| 328 | type=float, |
| 329 | default=1.0, |
| 330 | help=("Performs an additional scaling of weight compression scale estimate (default: %(default)s)"), |
| 331 | ) |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 332 | parser.add_argument( |
Tim Hall | b9b515c | 2020-11-01 21:27:19 +0000 | [diff] [blame^] | 333 | "--cpu-tensor-alignment", |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 334 | type=int, |
| 335 | default=Tensor.AllocationQuantum, |
Tim Hall | b9b515c | 2020-11-01 21:27:19 +0000 | [diff] [blame^] | 336 | help=( |
| 337 | "Controls the allocation byte alignment of cpu tensors including Ethos-U Custom operator inputs and outputs" |
| 338 | " (default: %(default)s)" |
| 339 | ), |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 340 | ) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 341 | args = parser.parse_args(args=args) |
| 342 | |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 343 | # Generate the supported ops report and exit |
| 344 | if args.supported_ops_report: |
| 345 | generate_supported_ops() |
| 346 | return 0 |
| 347 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 348 | if args.network is None: |
| 349 | parser.error("the following argument is required: NETWORK") |
| 350 | |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 351 | # check all config files exist because they will be read as a group |
| 352 | if args.config is not None: |
| 353 | for filename in args.config: |
| 354 | if not os.access(filename, os.R_OK): |
| 355 | raise InputFileError(filename, "File not found or is not readable.") |
| 356 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 357 | sys.setrecursionlimit(args.recursion_limit) |
| 358 | |
| 359 | if args.force_block_config: |
| 360 | force_block_config = architecture_features.Block.from_string(args.force_block_config) |
| 361 | else: |
| 362 | force_block_config = None |
| 363 | |
Tim Hall | b9b515c | 2020-11-01 21:27:19 +0000 | [diff] [blame^] | 364 | if args.cpu_tensor_alignment < 16 or args.cpu_tensor_alignment & (args.cpu_tensor_alignment - 1) != 0: |
| 365 | parser.error( |
| 366 | "Invalid argument to --cpu-tensor-alignment = {} (must be greater than or equal to 16 and a power of 2)" |
| 367 | "".format(args.cpu_tensor_alignment) |
| 368 | ) |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 369 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 370 | arch = architecture_features.ArchitectureFeatures( |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 371 | vela_config_files=args.config, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 372 | system_config=args.system_config, |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 373 | memory_mode=args.memory_mode, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 374 | accelerator_config=args.accelerator_config, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 375 | override_block_config=force_block_config, |
| 376 | block_config_limit=args.block_config_limit, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 377 | max_blockdep=args.max_block_dependency, |
Patrik Gustavsson | 90831bc | 2020-08-24 16:26:11 +0200 | [diff] [blame] | 378 | weight_estimation_scaling=args.weight_estimation_scaling, |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 379 | verbose_config=args.verbose_config, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 380 | ) |
| 381 | |
| 382 | compiler_options = compiler_driver.CompilerOptions( |
| 383 | verbose_graph=args.verbose_graph, |
| 384 | verbose_quantization=args.verbose_quantization, |
| 385 | verbose_packing=args.verbose_packing, |
| 386 | verbose_tensor_purpose=args.verbose_tensor_purpose, |
| 387 | verbose_tensor_format=args.verbose_tensor_format, |
| 388 | verbose_allocation=args.verbose_allocation, |
| 389 | verbose_high_level_command_stream=args.verbose_high_level_command_stream, |
| 390 | verbose_register_command_stream=args.verbose_register_command_stream, |
| 391 | verbose_operators=args.verbose_operators, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 392 | show_cpu_operations=args.show_cpu_operations, |
| 393 | tensor_allocator=args.tensor_allocator, |
| 394 | timing=args.timing, |
| 395 | output_dir=args.output_dir, |
Tim Hall | b9b515c | 2020-11-01 21:27:19 +0000 | [diff] [blame^] | 396 | cpu_tensor_alignment=args.cpu_tensor_alignment, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 397 | ) |
| 398 | |
| 399 | scheduler_options = scheduler.SchedulerOptions( |
| 400 | use_cascading=args.cascading, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 401 | verbose_schedule=args.verbose_schedule, |
| 402 | verbose_pareto_frontier_schedules=args.verbose_pareto_frontier_schedules, |
| 403 | use_ifm_streaming=args.ifm_streaming, |
| 404 | pareto_metric=args.pareto_metric, |
Charles Xu | 7b8823f | 2020-05-29 13:53:10 +0200 | [diff] [blame] | 405 | use_nhcwb16_between_cascaded_passes=args.nhcwb16_between_cascaded_passes, |
Andreas Nevalainen | 897cc14 | 2020-10-28 15:42:08 +0100 | [diff] [blame] | 406 | keep_scale_placement=args.keep_scale_placement, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 407 | ) |
| 408 | |
Tim Hall | 284223e | 2020-06-09 13:17:21 +0100 | [diff] [blame] | 409 | model_reader_options = model_reader.ModelReaderOptions() |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 410 | |
Tim Hall | e6ccd87 | 2020-11-09 16:46:37 +0000 | [diff] [blame] | 411 | nng = process(args.network, args.enable_debug_db, arch, model_reader_options, compiler_options, scheduler_options) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 412 | |
| 413 | if args.show_subgraph_io_summary: |
| 414 | print_subgraph_io_summary(nng) |
| 415 | |
| 416 | return 0 |