From 1538dce9f07a310587f057aee5fbe25509963879 Mon Sep 17 00:00:00 2001 From: Rickard Bolin Date: Mon, 25 Apr 2022 11:07:56 +0000 Subject: MLBEDSW-4783: Add config file directory structure Add directory structure to support third party config files. Config files should now be placed in an appropriately named directory under the config_files directory, but can also be accessed by providing its absolute path to vela --config. Signed-off-by: Rickard Bolin Change-Id: I2fcf52e7b2ddd2c4491dc370c85c0b3937d18062 --- OPTIONS.md | 40 ++++++++++-- README.md | 13 +++- ethosu/config_files/Arm/vela.ini | 135 +++++++++++++++++++++++++++++++++++++++ ethosu/vela/vela.py | 50 +++++++++++++-- setup.py | 2 + vela.ini | 135 --------------------------------------- 6 files changed, 227 insertions(+), 148 deletions(-) create mode 100644 ethosu/config_files/Arm/vela.ini delete mode 100644 vela.ini diff --git a/OPTIONS.md b/OPTIONS.md index e24f9638..b4132d3a 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -66,6 +66,19 @@ the required Network argument. vela --supported-ops-report ``` +### List Configuration Files + +Displays the configuration files in the `ethosu/config_files` directory. All +configuration files must have the .ini extension and be placed in an +appropriately named directory under `ethosu/config_files`. Note that the file +depth from `ethosu/config_files` must be exactly 2 for the file to be +discovered (e.g. `config_files/directory_name/my_config_file.ini`). Can be +used without the required Network argument. + +```bash +vela --list-config-files +``` + ### Output Directory Specifies the output directory of the optimised network model as well as the @@ -93,12 +106,15 @@ vela network.tflite --enable-debug-db Specifies the path to the Vela configuration file. The format of the file is a Python ConfigParser `.ini` file. This option can be specified multiple times to allow multiple files to be searched for the required system config and memory -mode. More details can be found in the Configuration File section below. +mode. Custom configuration files can be used by adding a .ini file in an +appropriate directory under the `ethosu/config_files` directory or by providing +its absolute path. More details can be found in the Configuration File and List +Configuration Files sections. **Type: POSIX path** **Default: use default configuration** ```bash -vela network.tflite --config my_vela_cfg1.ini --config my_vela_cfg2.ini --system-config My_Sys_Cfg --memory-mode My_Mem_Mode +vela network.tflite --config DirectoryName/my_vela_cfg1.ini --config absolute/path/to/my_vela_cfg2.ini --system-config My_Sys_Cfg --memory-mode My_Mem_Mode ``` ### Timing @@ -400,11 +416,25 @@ To see the configuration values being used by Vela use the `--verbose_config` CLI option. This can also be used to display the internal-default values and to see a full list of all the available options. -An example Vela configuration file, called `vela_cfg.ini`, is included in the -directory containing this file. Example usage based on this file is: +An example Vela configuration file, called `vela.ini`, is included in the +`ethosu/config_files/Arm` directory. Example usage based on this file is: + +```bash +vela network.tflite --accelerator-config ethos-u55-256 --config Arm/vela.ini --system-config Ethos_U55_High_End_Embedded --memory-mode Shared_Sram +``` + +Hardware vendors and/or users may wish to contribute their own configuration +files for various SoC platforms by adding a .ini file in an appropriate +directory under the ethosu/config_files directory. This can be done by +following the process outlined in CONTRIBUTIONS.md. These can then be accessed +with `--config /config.ini` as in the example above. + +To use configuration files located outside the config_files directory, provide +its absolute path to `--config`. The `--list-config-files` option can be used to +view all available configuration files: ```bash -vela network.tflite --accelerator-config ethos-u55-256 --config vela_cfg.ini --system-config Ethos_U55_High_End_Embedded --memory-mode Shared_Sram +vela --list-config-files ``` The following is an in-line explanation of the Vela configuration file format: diff --git a/README.md b/README.md index eb8871e3..9ed36028 100644 --- a/README.md +++ b/README.md @@ -163,13 +163,20 @@ vela --optimise Performance --arena-cache-size 300000 my_model.tflite 7) Compile a network using a particular embedded system configuration defined in Vela's configuration file. The following command selects the `My_Sys_Config` -system configuration along with the `My_Mem_Mode` memory mode from the `vela_cfg.ini` configuration file. +system configuration along with the `My_Mem_Mode` memory mode from the `vela.ini` +configuration file located in the config_files directory. ```bash -vela --config vela_cfg.ini --system-config My_Sys_Config --memory-mode My_Mem_Mode my_model.tflite +vela --config Arm/vela.ini --system-config My_Sys_Config --memory-mode My_Mem_Mode my_model.tflite ``` -8) To get a list of all available options (see CLI Options section below): +8) To get a list of all available configuration files in the config_files directory: + +```bash +vela --list-config-files +``` + +9) To get a list of all available options (see CLI Options section below): ```bash vela --help diff --git a/ethosu/config_files/Arm/vela.ini b/ethosu/config_files/Arm/vela.ini new file mode 100644 index 00000000..bcc33573 --- /dev/null +++ b/ethosu/config_files/Arm/vela.ini @@ -0,0 +1,135 @@ +; Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. +; +; SPDX-License-Identifier: Apache-2.0 +; +; Licensed under the Apache License, Version 2.0 (the License); you may +; not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an AS IS BASIS, WITHOUT +; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. + +; ----------------------------------------------------------------------------- +; Vela configuration file + +; ----------------------------------------------------------------------------- +; System Configuration + +; Ethos-U55 Deep Embedded: SRAM (1.6 GB/s) and Flash (0.1 GB/s) +[System_Config.Ethos_U55_Deep_Embedded] +core_clock=200e6 +axi0_port=Sram +axi1_port=OffChipFlash +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +OffChipFlash_clock_scale=0.0625 +OffChipFlash_burst_length=128 +OffChipFlash_read_latency=64 +OffChipFlash_write_latency=64 + +; Ethos-U55 High-End Embedded: SRAM (4 GB/s) and Flash (0.5 GB/s) +[System_Config.Ethos_U55_High_End_Embedded] +core_clock=500e6 +axi0_port=Sram +axi1_port=OffChipFlash +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +OffChipFlash_clock_scale=0.125 +OffChipFlash_burst_length=128 +OffChipFlash_read_latency=64 +OffChipFlash_write_latency=64 + +; Ethos-U65 Embedded: SRAM (8 GB/s) and Flash (0.5 GB/s) +[System_Config.Ethos_U65_Embedded] +core_clock=500e6 +axi0_port=Sram +axi1_port=OffChipFlash +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +OffChipFlash_clock_scale=0.0625 +OffChipFlash_burst_length=128 +OffChipFlash_read_latency=64 +OffChipFlash_write_latency=64 + +; Ethos-U65 Mid-End: SRAM (8 GB/s) and DRAM (3.75 GB/s) +[System_Config.Ethos_U65_Mid_End] +core_clock=500e6 +axi0_port=Sram +axi1_port=Dram +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +Dram_clock_scale=0.46875 +Dram_burst_length=128 +Dram_read_latency=500 +Dram_write_latency=250 + +; Ethos-U65 High-End: SRAM (16 GB/s) and DRAM (3.75 GB/s) +[System_Config.Ethos_U65_High_End] +core_clock=1e9 +axi0_port=Sram +axi1_port=Dram +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +Dram_clock_scale=0.234375 +Dram_burst_length=128 +Dram_read_latency=500 +Dram_write_latency=250 + +; Ethos-U65 Client-Server: SRAM (16 GB/s) and DRAM (12 GB/s) +[System_Config.Ethos_U65_Client_Server] +core_clock=1e9 +axi0_port=Sram +axi1_port=Dram +Sram_clock_scale=1.0 +Sram_burst_length=32 +Sram_read_latency=32 +Sram_write_latency=32 +Dram_clock_scale=0.75 +Dram_burst_length=128 +Dram_read_latency=500 +Dram_write_latency=250 + +; ----------------------------------------------------------------------------- +; Memory Mode + +; SRAM Only: only one AXI port is used and the SRAM is used for all storage +[Memory_Mode.Sram_Only] +const_mem_area=Axi0 +arena_mem_area=Axi0 +cache_mem_area=Axi0 + +; Shared SRAM: the SRAM is shared between the Ethos-U and the Cortex-M software +; The non-SRAM memory is assumed to be read-only +[Memory_Mode.Shared_Sram] +const_mem_area=Axi1 +arena_mem_area=Axi0 +cache_mem_area=Axi0 + +; Dedicated SRAM: the SRAM (384KB) is only for use by the Ethos-U +; The non-SRAM memory is assumed to be read-writeable +[Memory_Mode.Dedicated_Sram] +const_mem_area=Axi1 +arena_mem_area=Axi1 +cache_mem_area=Axi0 +arena_cache_size=393216 + +; Dedicated SRAM 512KB: the SRAM (512KB) is only for use by the Ethos-U +; The non-SRAM memory is assumed to be read-writeable +[Memory_Mode.Dedicated_Sram_512KB] +inherit=Memory_Mode.Dedicated_Sram +arena_cache_size=524288 diff --git a/ethosu/vela/vela.py b/ethosu/vela/vela.py index 2108e209..b5f9f986 100644 --- a/ethosu/vela/vela.py +++ b/ethosu/vela/vela.py @@ -18,6 +18,7 @@ # # Provides command line interface, options parsing, and network loading. Before calling the compiler driver. import argparse +import glob import os import sys import time @@ -49,6 +50,8 @@ from .tosa_model_semantic import TosaSemantic from .tosa_supported_operators import TosaSupportedOperators from ethosu.vela.architecture_features import ArchitectureFeatures +CONFIG_FILES_PATH = os.path.abspath(f"{__file__}/../../config_files") + def process(input_name, enable_debug_db, arch, model_reader_options, compiler_options, scheduler_options): if compiler_options.timing: @@ -282,6 +285,12 @@ def generate_supported_ops(): print(f"Report file: {filepath}") +def list_config_files(): + print("\nAvailable config files:\n") + for config in glob.glob(os.path.join(CONFIG_FILES_PATH, "*", "*.ini")): + print(config.lstrip(CONFIG_FILES_PATH + os.path.sep)) + + def main(args=None): try: if args is None: @@ -298,6 +307,15 @@ def main(args=None): help="Generate the SUPPORTED_OPS.md file in the current working directory and exit", ) + parser.add_argument( + "--list-config-files", + action="store_true", + help=( + "Display all available configurations in the `config_files` folder and exit. To select config file, " + "use the --config argument with one of the listed config files (For example: --config Arm/vela.ini )" + ), + ) + # set network nargs to be optional to allow the support-ops-report CLI option to be used standalone parser.add_argument( "network", @@ -428,14 +446,36 @@ def main(args=None): generate_supported_ops() return 0 + if args.list_config_files: + list_config_files() + return 0 + if args.network is None: parser.error("the following argument is required: NETWORK") + def _parse_config(config): + if not config.endswith(".ini"): + raise InputFileError(config, "Configuration files must use the .ini extension") + + if len(config.split(os.path.sep)) == 2 and not config.startswith(os.path.sep): + config_path = os.path.join(CONFIG_FILES_PATH, config) + else: + print( + f"Warning: Configuration file `{config}` not located in a folder directly under the " + "`config_files` directory. Note that the file depth from the `config_files` directory must be " + "exactly 2 to be discovered via the --list-config-files mechanism " + "(e.g. `config_files/directory_name/my_config_file.ini`). This config file will still be " + "parsed however, and treated as an absolute path config instead." + ) + config_path = config + + if not os.access(config_path, os.R_OK): + raise InputFileError(config_path, "File not found or is not readable") + + return config_path + # check all config files exist because they will be read as a group - if args.config is not None: - for filename in args.config: - if not os.access(filename, os.R_OK): - raise InputFileError(filename, "File not found or is not readable") + config_files = [_parse_config(cfg) for cfg in args.config] if args.config else None if args.cpu_tensor_alignment < 16 or args.cpu_tensor_alignment & (args.cpu_tensor_alignment - 1) != 0: parser.error( @@ -457,7 +497,7 @@ def main(args=None): sys.setrecursionlimit(args.recursion_limit) arch = architecture_features.ArchitectureFeatures( - vela_config_files=args.config, + vela_config_files=config_files, system_config=args.system_config, memory_mode=args.memory_mode, accelerator_config=args.accelerator_config, diff --git a/setup.py b/setup.py index 244fc4ed..d6e03b1d 100644 --- a/setup.py +++ b/setup.py @@ -83,12 +83,14 @@ setup( ], keywords=["ethos-u", "vela compiler", "tflite", "npu"], packages=[ + "ethosu", "ethosu.vela", "ethosu.vela.ethos_u55_regs", "ethosu.vela.tflite", "ethosu.vela.tosa", "ethosu.mlw_codec", ], + package_data={"ethosu": ["config_files/*/*.ini"]}, python_requires="~=3.7", install_requires=[ "flatbuffers==1.12.0", diff --git a/vela.ini b/vela.ini deleted file mode 100644 index bcc33573..00000000 --- a/vela.ini +++ /dev/null @@ -1,135 +0,0 @@ -; Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. -; -; SPDX-License-Identifier: Apache-2.0 -; -; Licensed under the Apache License, Version 2.0 (the License); you may -; not use this file except in compliance with the License. -; You may obtain a copy of the License at -; -; www.apache.org/licenses/LICENSE-2.0 -; -; Unless required by applicable law or agreed to in writing, software -; distributed under the License is distributed on an AS IS BASIS, WITHOUT -; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; See the License for the specific language governing permissions and -; limitations under the License. - -; ----------------------------------------------------------------------------- -; Vela configuration file - -; ----------------------------------------------------------------------------- -; System Configuration - -; Ethos-U55 Deep Embedded: SRAM (1.6 GB/s) and Flash (0.1 GB/s) -[System_Config.Ethos_U55_Deep_Embedded] -core_clock=200e6 -axi0_port=Sram -axi1_port=OffChipFlash -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -OffChipFlash_clock_scale=0.0625 -OffChipFlash_burst_length=128 -OffChipFlash_read_latency=64 -OffChipFlash_write_latency=64 - -; Ethos-U55 High-End Embedded: SRAM (4 GB/s) and Flash (0.5 GB/s) -[System_Config.Ethos_U55_High_End_Embedded] -core_clock=500e6 -axi0_port=Sram -axi1_port=OffChipFlash -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -OffChipFlash_clock_scale=0.125 -OffChipFlash_burst_length=128 -OffChipFlash_read_latency=64 -OffChipFlash_write_latency=64 - -; Ethos-U65 Embedded: SRAM (8 GB/s) and Flash (0.5 GB/s) -[System_Config.Ethos_U65_Embedded] -core_clock=500e6 -axi0_port=Sram -axi1_port=OffChipFlash -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -OffChipFlash_clock_scale=0.0625 -OffChipFlash_burst_length=128 -OffChipFlash_read_latency=64 -OffChipFlash_write_latency=64 - -; Ethos-U65 Mid-End: SRAM (8 GB/s) and DRAM (3.75 GB/s) -[System_Config.Ethos_U65_Mid_End] -core_clock=500e6 -axi0_port=Sram -axi1_port=Dram -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -Dram_clock_scale=0.46875 -Dram_burst_length=128 -Dram_read_latency=500 -Dram_write_latency=250 - -; Ethos-U65 High-End: SRAM (16 GB/s) and DRAM (3.75 GB/s) -[System_Config.Ethos_U65_High_End] -core_clock=1e9 -axi0_port=Sram -axi1_port=Dram -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -Dram_clock_scale=0.234375 -Dram_burst_length=128 -Dram_read_latency=500 -Dram_write_latency=250 - -; Ethos-U65 Client-Server: SRAM (16 GB/s) and DRAM (12 GB/s) -[System_Config.Ethos_U65_Client_Server] -core_clock=1e9 -axi0_port=Sram -axi1_port=Dram -Sram_clock_scale=1.0 -Sram_burst_length=32 -Sram_read_latency=32 -Sram_write_latency=32 -Dram_clock_scale=0.75 -Dram_burst_length=128 -Dram_read_latency=500 -Dram_write_latency=250 - -; ----------------------------------------------------------------------------- -; Memory Mode - -; SRAM Only: only one AXI port is used and the SRAM is used for all storage -[Memory_Mode.Sram_Only] -const_mem_area=Axi0 -arena_mem_area=Axi0 -cache_mem_area=Axi0 - -; Shared SRAM: the SRAM is shared between the Ethos-U and the Cortex-M software -; The non-SRAM memory is assumed to be read-only -[Memory_Mode.Shared_Sram] -const_mem_area=Axi1 -arena_mem_area=Axi0 -cache_mem_area=Axi0 - -; Dedicated SRAM: the SRAM (384KB) is only for use by the Ethos-U -; The non-SRAM memory is assumed to be read-writeable -[Memory_Mode.Dedicated_Sram] -const_mem_area=Axi1 -arena_mem_area=Axi1 -cache_mem_area=Axi0 -arena_cache_size=393216 - -; Dedicated SRAM 512KB: the SRAM (512KB) is only for use by the Ethos-U -; The non-SRAM memory is assumed to be read-writeable -[Memory_Mode.Dedicated_Sram_512KB] -inherit=Memory_Mode.Dedicated_Sram -arena_cache_size=524288 -- cgit v1.2.1