mlonmcu 0.3.0.dev0__3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlonmcu/__init__.py +26 -0
- mlonmcu/artifact.py +172 -0
- mlonmcu/cli/__init__.py +19 -0
- mlonmcu/cli/build.py +119 -0
- mlonmcu/cli/cleanup.py +75 -0
- mlonmcu/cli/common.py +227 -0
- mlonmcu/cli/compile.py +87 -0
- mlonmcu/cli/env.py +68 -0
- mlonmcu/cli/export.py +93 -0
- mlonmcu/cli/flow.py +67 -0
- mlonmcu/cli/helper/__init__.py +18 -0
- mlonmcu/cli/helper/filter.py +25 -0
- mlonmcu/cli/helper/parse.py +159 -0
- mlonmcu/cli/init.py +130 -0
- mlonmcu/cli/load.py +87 -0
- mlonmcu/cli/main.py +116 -0
- mlonmcu/cli/models.py +48 -0
- mlonmcu/cli/run.py +56 -0
- mlonmcu/cli/setup.py +136 -0
- mlonmcu/cli/tune.py +48 -0
- mlonmcu/config.py +219 -0
- mlonmcu/context/__init__.py +22 -0
- mlonmcu/context/context.py +545 -0
- mlonmcu/context/read_write_filelock.py +327 -0
- mlonmcu/environment/__init__.py +18 -0
- mlonmcu/environment/config.py +214 -0
- mlonmcu/environment/environment.py +501 -0
- mlonmcu/environment/init.py +191 -0
- mlonmcu/environment/list.py +81 -0
- mlonmcu/environment/loader.py +250 -0
- mlonmcu/environment/templates.py +69 -0
- mlonmcu/environment/writer.py +117 -0
- mlonmcu/feature/__init__.py +18 -0
- mlonmcu/feature/feature.py +230 -0
- mlonmcu/feature/features.py +1537 -0
- mlonmcu/feature/type.py +33 -0
- mlonmcu/flow/__init__.py +61 -0
- mlonmcu/flow/backend.py +234 -0
- mlonmcu/flow/framework.py +69 -0
- mlonmcu/flow/tflm/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/backend.py +47 -0
- mlonmcu/flow/tflm/backend/tflmc.py +129 -0
- mlonmcu/flow/tflm/backend/tflmi.py +385 -0
- mlonmcu/flow/tflm/framework.py +81 -0
- mlonmcu/flow/tvm/__init__.py +23 -0
- mlonmcu/flow/tvm/backend/__init__.py +26 -0
- mlonmcu/flow/tvm/backend/backend.py +282 -0
- mlonmcu/flow/tvm/backend/model_info.py +307 -0
- mlonmcu/flow/tvm/backend/python_utils.py +36 -0
- mlonmcu/flow/tvm/backend/tuner.py +41 -0
- mlonmcu/flow/tvm/backend/tvmaot.py +162 -0
- mlonmcu/flow/tvm/backend/tvmaotplus.py +51 -0
- mlonmcu/flow/tvm/backend/tvmc_utils.py +172 -0
- mlonmcu/flow/tvm/backend/tvmcg.py +102 -0
- mlonmcu/flow/tvm/backend/tvmllvm.py +106 -0
- mlonmcu/flow/tvm/backend/tvmrt.py +151 -0
- mlonmcu/flow/tvm/backend/wrapper.py +645 -0
- mlonmcu/flow/tvm/framework.py +96 -0
- mlonmcu/logging.py +79 -0
- mlonmcu/mlonmcu.py +19 -0
- mlonmcu/models/__init__.py +31 -0
- mlonmcu/models/convert_data.py +107 -0
- mlonmcu/models/frontend.py +571 -0
- mlonmcu/models/group.py +29 -0
- mlonmcu/models/lookup.py +345 -0
- mlonmcu/models/metadata.py +133 -0
- mlonmcu/models/model.py +104 -0
- mlonmcu/models/options.py +64 -0
- mlonmcu/models/utils.py +136 -0
- mlonmcu/platform/__init__.py +27 -0
- mlonmcu/platform/_platform.py +46 -0
- mlonmcu/platform/espidf/__init__.py +25 -0
- mlonmcu/platform/espidf/espidf.py +489 -0
- mlonmcu/platform/espidf/espidf_target.py +257 -0
- mlonmcu/platform/lookup.py +126 -0
- mlonmcu/platform/microtvm/__init__.py +25 -0
- mlonmcu/platform/microtvm/microtvm.py +580 -0
- mlonmcu/platform/microtvm/microtvm_arduino_target.py +68 -0
- mlonmcu/platform/microtvm/microtvm_backend.py +64 -0
- mlonmcu/platform/microtvm/microtvm_espidf_target.py +94 -0
- mlonmcu/platform/microtvm/microtvm_etissvp_target.py +98 -0
- mlonmcu/platform/microtvm/microtvm_host_target.py +46 -0
- mlonmcu/platform/microtvm/microtvm_spike_target.py +230 -0
- mlonmcu/platform/microtvm/microtvm_target.py +189 -0
- mlonmcu/platform/microtvm/microtvm_template_target.py +55 -0
- mlonmcu/platform/microtvm/microtvm_zephyr_target.py +91 -0
- mlonmcu/platform/mlif/__init__.py +25 -0
- mlonmcu/platform/mlif/mlif.py +300 -0
- mlonmcu/platform/mlif/mlif_target.py +86 -0
- mlonmcu/platform/platform.py +244 -0
- mlonmcu/platform/tvm/__init__.py +25 -0
- mlonmcu/platform/tvm/tvm.py +429 -0
- mlonmcu/platform/tvm/tvm_backend.py +57 -0
- mlonmcu/platform/tvm/tvm_target.py +165 -0
- mlonmcu/platform/zephyr/__init__.py +25 -0
- mlonmcu/platform/zephyr/zephyr.py +450 -0
- mlonmcu/platform/zephyr/zephyr_target.py +110 -0
- mlonmcu/plugins.py +26 -0
- mlonmcu/report.py +99 -0
- mlonmcu/session/__init__.py +18 -0
- mlonmcu/session/postprocess/__init__.py +43 -0
- mlonmcu/session/postprocess/postprocess.py +62 -0
- mlonmcu/session/postprocess/postprocesses.py +487 -0
- mlonmcu/session/run.py +1008 -0
- mlonmcu/session/session.py +373 -0
- mlonmcu/setup/__init__.py +18 -0
- mlonmcu/setup/cache.py +147 -0
- mlonmcu/setup/gen_requirements.py +619 -0
- mlonmcu/setup/setup.py +285 -0
- mlonmcu/setup/task.py +380 -0
- mlonmcu/setup/tasks/__init__.py +40 -0
- mlonmcu/setup/tasks/arm_gcc.py +58 -0
- mlonmcu/setup/tasks/cmsisnn.py +151 -0
- mlonmcu/setup/tasks/common.py +36 -0
- mlonmcu/setup/tasks/corstone300.py +64 -0
- mlonmcu/setup/tasks/espidf.py +87 -0
- mlonmcu/setup/tasks/etiss.py +147 -0
- mlonmcu/setup/tasks/llvm.py +67 -0
- mlonmcu/setup/tasks/mlif.py +49 -0
- mlonmcu/setup/tasks/muriscvnn.py +166 -0
- mlonmcu/setup/tasks/pulp.py +192 -0
- mlonmcu/setup/tasks/riscv_gcc.py +146 -0
- mlonmcu/setup/tasks/spike.py +190 -0
- mlonmcu/setup/tasks/tf.py +92 -0
- mlonmcu/setup/tasks/tflite.py +59 -0
- mlonmcu/setup/tasks/tflmc.py +141 -0
- mlonmcu/setup/tasks/tvm.py +172 -0
- mlonmcu/setup/tasks/utvmcg.py +96 -0
- mlonmcu/setup/tasks/zephyr.py +119 -0
- mlonmcu/setup/utils.py +374 -0
- mlonmcu/target/__init__.py +37 -0
- mlonmcu/target/_target.py +41 -0
- mlonmcu/target/arm/__init__.py +3 -0
- mlonmcu/target/arm/corstone300.py +235 -0
- mlonmcu/target/arm/util.py +109 -0
- mlonmcu/target/common.py +194 -0
- mlonmcu/target/elf.py +256 -0
- mlonmcu/target/host_x86.py +84 -0
- mlonmcu/target/metrics.py +75 -0
- mlonmcu/target/riscv/__init__.py +7 -0
- mlonmcu/target/riscv/etiss_pulpino.py +462 -0
- mlonmcu/target/riscv/gvsoc_pulp.py +215 -0
- mlonmcu/target/riscv/ovpsim.py +301 -0
- mlonmcu/target/riscv/riscv.py +185 -0
- mlonmcu/target/riscv/riscv_qemu.py +166 -0
- mlonmcu/target/riscv/spike.py +243 -0
- mlonmcu/target/riscv/util.py +134 -0
- mlonmcu/target/target.py +200 -0
- mlonmcu/utils.py +49 -0
- mlonmcu/version.py +21 -0
- mlonmcu-0.3.0.dev0.dist-info/LICENSE +202 -0
- mlonmcu-0.3.0.dev0.dist-info/METADATA +343 -0
- mlonmcu-0.3.0.dev0.dist-info/NOTICE +8 -0
- mlonmcu-0.3.0.dev0.dist-info/RECORD +376 -0
- mlonmcu-0.3.0.dev0.dist-info/WHEEL +5 -0
- mlonmcu-0.3.0.dev0.dist-info/entry_points.txt +3 -0
- mlonmcu-0.3.0.dev0.dist-info/top_level.txt +1 -0
- resources/frameworks/tvm/crt_config/README.md +7 -0
- resources/frameworks/tvm/crt_config/crt_config.h +53 -0
- resources/frameworks/tvm/tuning_records/riscv_cpu_v0.01.log.best +46 -0
- resources/patches/fix_esp32c3_march.patch +20 -0
- resources/patches/pulp_freertos_support.patch +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/CMakeLists.txt +29 -0
- resources/platforms/espidf/micro_speech_esp32devboard/README.md +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/CMakeLists.txt +78 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/Kconfig +76 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_data.c +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/exit.h +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/ml_interface.h +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/printing.h +31 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface.c +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tflm.cc +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tvm.c +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/CMakeLists.txt +140 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/micro_speech_esp32devboard/example_test.py +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/info.txt +9 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/CMakeLists.txt +58 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.cc +193 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.cc +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.h +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc +132 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc.orig +145 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.h +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/COPYING +11 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/_kiss_fft_guts.h +168 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.c +408 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.h +124 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.c +159 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main.cc +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.cc +204 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.h +37 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.cc +121 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.h +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.cc +23 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.h +43 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/bits.h +102 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.cc +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.cc +69 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.c +134 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.h +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.c +220 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.c +72 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.h +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.c +85 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.h +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_common.h +48 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.cc +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.c +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.h +40 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.c +83 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.h +39 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.c +27 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.c +51 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.c +56 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.h +47 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.c +92 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.h +57 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.c +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.c +73 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.c +14 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.h +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.cc +150 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.h +173 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.c +333 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.h +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/sdkconfig.defaults +36 -0
- resources/platforms/espidf/project/CMakeLists.txt +29 -0
- resources/platforms/espidf/project/README.md +70 -0
- resources/platforms/espidf/project/components/mlif/CMakeLists.txt +77 -0
- resources/platforms/espidf/project/components/mlif/Kconfig +76 -0
- resources/platforms/espidf/project/components/mlif/default_data.c +26 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/project/components/mlif/include/exit.h +26 -0
- resources/platforms/espidf/project/components/mlif/include/ml_interface.h +60 -0
- resources/platforms/espidf/project/components/mlif/include/printing.h +31 -0
- resources/platforms/espidf/project/components/mlif/ml_interface.c +54 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tflm.cc +40 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tvm.c +40 -0
- resources/platforms/espidf/project/components/tflite-lib/CMakeLists.txt +142 -0
- resources/platforms/espidf/project/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/project/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/project/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/project/example_test.py +38 -0
- resources/platforms/espidf/project/main/CMakeLists.txt +25 -0
- resources/platforms/espidf/project/main/main.c +57 -0
- resources/platforms/espidf/project/sdkconfig.defaults +26 -0
- resources/platforms/zephyr/project/CMakeLists.txt +22 -0
- resources/platforms/zephyr/project/Kconfig +101 -0
- resources/platforms/zephyr/project/README.rst +33 -0
- resources/platforms/zephyr/project/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/CMakeLists.txt +31 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_data.c +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.c +36 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.h +47 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project/prj.conf +11 -0
- resources/platforms/zephyr/project/sample.yaml +19 -0
- resources/platforms/zephyr/project/src/main.c +71 -0
- resources/platforms/zephyr/project2/CMakeLists.txt +72 -0
- resources/platforms/zephyr/project2/Kconfig +101 -0
- resources/platforms/zephyr/project2/README.rst +33 -0
- resources/platforms/zephyr/project2/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project2/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project2/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project2/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project2/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project2/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project2/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project2/default_data.c +8 -0
- resources/platforms/zephyr/project2/default_model_support/CMakeLists.txt +3 -0
- resources/platforms/zephyr/project2/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project2/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project2/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project2/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project2/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project2/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project2/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project2/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project2/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project2/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project2/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project2/ml_interface.c +36 -0
- resources/platforms/zephyr/project2/ml_interface.h +47 -0
- resources/platforms/zephyr/project2/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project2/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project2/prj.conf +13 -0
- resources/platforms/zephyr/project2/sample.yaml +19 -0
- resources/platforms/zephyr/project2/settings.json +6 -0
- resources/platforms/zephyr/project2/src/main.c +35 -0
- resources/pycharm/.run/README.md +73 -0
- resources/pycharm/.run/step1_ init env.run.xml +24 -0
- resources/pycharm/.run/step2_ setup.run.xml +25 -0
- resources/pycharm/.run/step3_ run resnet on pulpxpulpissimo.run.xml +25 -0
- resources/templates/default.yml.j2 +258 -0
- resources/templates/dev.yml.j2 +212 -0
- resources/templates/minimal.yml.j2 +234 -0
- resources/templates/phi.yml.j2 +282 -0
- resources/templates/pulp.yml.j2 +267 -0
- resources/templates/research.yml.j2 +237 -0
- resources/templates/tumeda.yml.j2 +239 -0
mlonmcu/models/lookup.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
import os
|
|
21
|
+
import glob
|
|
22
|
+
from itertools import product
|
|
23
|
+
import yaml
|
|
24
|
+
|
|
25
|
+
from .model import Model, ModelFormats
|
|
26
|
+
from .group import ModelGroup
|
|
27
|
+
|
|
28
|
+
from mlonmcu.logging import get_logger
|
|
29
|
+
|
|
30
|
+
logger = get_logger()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_model_directories(context):
|
|
34
|
+
dirs = context.environment.paths["models"]
|
|
35
|
+
dirs = [d.path for d in dirs]
|
|
36
|
+
return dirs
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def find_metadata(directory, model_name=None):
|
|
40
|
+
possible_basenames = ["model", "metadata", "definition"]
|
|
41
|
+
possible_extensions = ["yaml", "yml"]
|
|
42
|
+
directory = Path(directory)
|
|
43
|
+
dirname = directory.name
|
|
44
|
+
if dirname not in possible_basenames:
|
|
45
|
+
possible_basenames.insert(0, dirname)
|
|
46
|
+
if model_name and model_name not in possible_basenames:
|
|
47
|
+
possible_basenames.insert(0, model_name)
|
|
48
|
+
|
|
49
|
+
for combination in product(possible_basenames, possible_extensions):
|
|
50
|
+
filename = f"{combination[0]}.{combination[1]}"
|
|
51
|
+
fullpath = directory / filename
|
|
52
|
+
if fullpath.is_file():
|
|
53
|
+
return fullpath
|
|
54
|
+
# logger.debug("Found match. Ignoring other files")
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def list_models(directory, depth=1, formats=None, config=None): # TODO: get config from environment or cmdline!
|
|
59
|
+
config = config if config is not None else {}
|
|
60
|
+
formats = formats if formats else [ModelFormats.TFLITE]
|
|
61
|
+
assert len(formats) > 0, "No formats provided for model lookup"
|
|
62
|
+
models = []
|
|
63
|
+
for fmt in formats:
|
|
64
|
+
if depth != 1:
|
|
65
|
+
raise NotImplementedError # TODO: implement for arm ml zoo
|
|
66
|
+
# define all allowed extensions + search recusively (with limit?)
|
|
67
|
+
# list(Path(".").rglob(f"*.{ext}")) for ext in allowed_ext
|
|
68
|
+
if not os.path.isdir(directory):
|
|
69
|
+
logger.debug("Not a directory: %s", str(directory))
|
|
70
|
+
return []
|
|
71
|
+
subdirs = [Path(directory) / o for o in os.listdir(directory) if os.path.isdir(os.path.join(directory, o))]
|
|
72
|
+
for subdir in subdirs:
|
|
73
|
+
dirname = subdir.name
|
|
74
|
+
if dirname.startswith("."):
|
|
75
|
+
# logger.debug("Skipping hidden directory: %s", str(dirname))
|
|
76
|
+
continue
|
|
77
|
+
exts = fmt.extensions
|
|
78
|
+
for ext in exts:
|
|
79
|
+
main_model = subdir / f"{dirname}.{ext}"
|
|
80
|
+
if os.path.exists(main_model):
|
|
81
|
+
main_model = f"{dirname}/{dirname}"
|
|
82
|
+
else:
|
|
83
|
+
main_model = None
|
|
84
|
+
submodels = []
|
|
85
|
+
for filename in glob.glob(str(subdir / f"*.{ext}")):
|
|
86
|
+
basename = "".join(Path(filename).name.split(".")[:-1])
|
|
87
|
+
submodels.append(f"{dirname}/{basename}")
|
|
88
|
+
|
|
89
|
+
if len(submodels) == 1:
|
|
90
|
+
main_model = submodels[0]
|
|
91
|
+
|
|
92
|
+
if main_model:
|
|
93
|
+
submodels.remove(main_model)
|
|
94
|
+
|
|
95
|
+
main_base = main_model.split("/")[-1]
|
|
96
|
+
main_config = {}
|
|
97
|
+
main_metadata_path = find_metadata(Path(directory) / dirname, model_name=main_base)
|
|
98
|
+
if main_metadata_path:
|
|
99
|
+
main_config[f"{main_base}.metadata_path"] = main_metadata_path
|
|
100
|
+
main_config.update(config)
|
|
101
|
+
|
|
102
|
+
models.append(
|
|
103
|
+
Model(
|
|
104
|
+
main_base,
|
|
105
|
+
[Path(directory) / f"{main_model}.{ext}"],
|
|
106
|
+
config=main_config,
|
|
107
|
+
alt=main_model,
|
|
108
|
+
formats=[fmt],
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
for submodel in submodels:
|
|
113
|
+
sub_base = submodel.split("/")[-1]
|
|
114
|
+
submodel_config = {}
|
|
115
|
+
submodel_metadata_path = find_metadata(Path(directory) / dirname, model_name=sub_base)
|
|
116
|
+
if submodel_metadata_path:
|
|
117
|
+
submodel_config[f"{sub_base}.metadata_path"] = submodel_metadata_path
|
|
118
|
+
submodel_config.update(config)
|
|
119
|
+
models.append(
|
|
120
|
+
Model(
|
|
121
|
+
submodel,
|
|
122
|
+
[Path(directory) / f"{submodel}.{ext}"],
|
|
123
|
+
config=submodel_config,
|
|
124
|
+
formats=[fmt],
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return models
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def list_modelgroups(directory):
|
|
132
|
+
if not os.path.isdir(directory):
|
|
133
|
+
logger.debug("Not a directory: %s", str(directory))
|
|
134
|
+
return []
|
|
135
|
+
groups = []
|
|
136
|
+
directory = Path(directory)
|
|
137
|
+
possible_basenames = ["modelgroups", "groups"]
|
|
138
|
+
possible_extensions = ["yaml", "yml"]
|
|
139
|
+
for combination in product(possible_basenames, possible_extensions):
|
|
140
|
+
filename = f"{combination[0]}.{combination[1]}"
|
|
141
|
+
fullpath = directory / filename
|
|
142
|
+
if fullpath.is_file():
|
|
143
|
+
logger.debug("Found match. Ignoring other files")
|
|
144
|
+
with open(fullpath, "r") as yamlfile:
|
|
145
|
+
try:
|
|
146
|
+
content = yaml.safe_load(yamlfile)
|
|
147
|
+
for groupname, groupmodels in content.items():
|
|
148
|
+
assert isinstance(groupmodels, list), "Modelgroups should be defined as a YAML list"
|
|
149
|
+
modelgroup = ModelGroup(groupname, groupmodels)
|
|
150
|
+
groups.append(modelgroup)
|
|
151
|
+
except yaml.YAMLError as err:
|
|
152
|
+
raise RuntimeError("Could not open YAML file") from err
|
|
153
|
+
break
|
|
154
|
+
return groups
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def lookup_models_and_groups(directories, formats):
|
|
158
|
+
all_models = []
|
|
159
|
+
all_groups = []
|
|
160
|
+
duplicates = {}
|
|
161
|
+
group_duplicates = {}
|
|
162
|
+
for directory in directories:
|
|
163
|
+
models = list_models(directory, formats=formats)
|
|
164
|
+
if len(all_models) == 0:
|
|
165
|
+
all_models = models
|
|
166
|
+
else:
|
|
167
|
+
all_model_names = [m.name for m in all_models]
|
|
168
|
+
for model in models:
|
|
169
|
+
name = model.name
|
|
170
|
+
if name in all_model_names:
|
|
171
|
+
if name in duplicates:
|
|
172
|
+
duplicates[name] += 1
|
|
173
|
+
else:
|
|
174
|
+
duplicates[name] = 1
|
|
175
|
+
else:
|
|
176
|
+
all_models.append(model)
|
|
177
|
+
groups = list_modelgroups(directory)
|
|
178
|
+
if len(all_groups) == 0:
|
|
179
|
+
all_groups = groups
|
|
180
|
+
else:
|
|
181
|
+
all_group_names = [g.name for g in all_groups]
|
|
182
|
+
for group in groups:
|
|
183
|
+
name = group.name
|
|
184
|
+
if name in all_group_names:
|
|
185
|
+
if name in group_duplicates:
|
|
186
|
+
group_duplicates[name] += 1
|
|
187
|
+
else:
|
|
188
|
+
group_duplicates[name] = 1
|
|
189
|
+
else:
|
|
190
|
+
all_groups.append(group)
|
|
191
|
+
|
|
192
|
+
all_models = sorted(all_models, key=lambda x: x.name)
|
|
193
|
+
|
|
194
|
+
return all_models, all_groups, duplicates, group_duplicates
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def print_paths(directories):
|
|
198
|
+
print("Paths:")
|
|
199
|
+
for directory in directories:
|
|
200
|
+
exists = os.path.exists(directory)
|
|
201
|
+
print(" " + str(directory), end="\n" if exists else " (skipped)\n")
|
|
202
|
+
# if not exists:
|
|
203
|
+
# directories.remove(directory)
|
|
204
|
+
print()
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def print_models(models, duplicates=[], detailed=False):
|
|
208
|
+
print("Models:")
|
|
209
|
+
for model in models:
|
|
210
|
+
name = model.name
|
|
211
|
+
path = model.paths[0]
|
|
212
|
+
meta = "available" if model.metadata is not None else "not available"
|
|
213
|
+
print(" " + name, end="")
|
|
214
|
+
if name in duplicates:
|
|
215
|
+
num = duplicates[name]
|
|
216
|
+
print(f" ({num} duplicates)")
|
|
217
|
+
else:
|
|
218
|
+
print()
|
|
219
|
+
if detailed:
|
|
220
|
+
print(f" Path: {path}")
|
|
221
|
+
print(f" Metadata: {meta}")
|
|
222
|
+
print()
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def print_groups(groups, all_models=[], duplicates=[], detailed=False):
|
|
226
|
+
print("Groups:")
|
|
227
|
+
for group in groups:
|
|
228
|
+
name = group.name
|
|
229
|
+
models = group.models
|
|
230
|
+
all_model_names = [m.name for m in all_models]
|
|
231
|
+
for model in models:
|
|
232
|
+
if model in all_model_names:
|
|
233
|
+
# Groupname conflicts with modelname
|
|
234
|
+
group.name = "~" + group.name
|
|
235
|
+
size = len(models)
|
|
236
|
+
print(f" {name} [{size} models]", end="")
|
|
237
|
+
if name in duplicates:
|
|
238
|
+
num = duplicates[name]
|
|
239
|
+
print(f" ({num} duplicates)")
|
|
240
|
+
else:
|
|
241
|
+
print()
|
|
242
|
+
|
|
243
|
+
if detailed:
|
|
244
|
+
groupmodels = " ".join(models)
|
|
245
|
+
print(f" Models: {groupmodels}")
|
|
246
|
+
print()
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def print_summary(context, detailed=False):
|
|
250
|
+
# TODO: get from context!
|
|
251
|
+
formats = [ModelFormats.TFLITE]
|
|
252
|
+
|
|
253
|
+
directories = get_model_directories(context)
|
|
254
|
+
|
|
255
|
+
models, groups, duplicates, group_duplicates = lookup_models_and_groups(directories, formats)
|
|
256
|
+
|
|
257
|
+
print("Models Summary\n")
|
|
258
|
+
print_paths(directories)
|
|
259
|
+
print_models(models, duplicates=duplicates, detailed=detailed)
|
|
260
|
+
print_groups(groups, duplicates=group_duplicates, all_models=models, detailed=detailed)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def lookup_models(names, frontends=None, context=None):
|
|
264
|
+
if frontends is None:
|
|
265
|
+
assert context is not None
|
|
266
|
+
# TODO: Get defaults frontends from environment (with no config/features)
|
|
267
|
+
raise NotImplementedError
|
|
268
|
+
# frontends = ?
|
|
269
|
+
# allowed_ext = [frontend.fmt.extension for frontend in frontends]
|
|
270
|
+
allowed_fmts = list(dict.fromkeys(sum([frontend.input_formats for frontend in frontends], []))) # Remove duplicates
|
|
271
|
+
allowed_exts = [fmt.extension for fmt in allowed_fmts] # There should nit be duplicates
|
|
272
|
+
|
|
273
|
+
if context:
|
|
274
|
+
directories = get_model_directories(context)
|
|
275
|
+
models, _, _, _ = lookup_models_and_groups(directories, allowed_fmts)
|
|
276
|
+
else:
|
|
277
|
+
models = []
|
|
278
|
+
model_names = [model.name for model in models]
|
|
279
|
+
|
|
280
|
+
hints = []
|
|
281
|
+
for name in names:
|
|
282
|
+
filepath = Path(name)
|
|
283
|
+
real_name = filepath.stem
|
|
284
|
+
ext = filepath.suffix[1:]
|
|
285
|
+
if len(ext) > 0 and filepath.is_file(): # Explicit file
|
|
286
|
+
assert (
|
|
287
|
+
ext in allowed_exts
|
|
288
|
+
), f"Unsupported file extension for model which was explicitly passed by path: {ext}"
|
|
289
|
+
paths = [filepath]
|
|
290
|
+
config = {}
|
|
291
|
+
metadata_path = find_metadata(filepath.parent.resolve(), model_name=real_name)
|
|
292
|
+
if metadata_path:
|
|
293
|
+
config[f"{real_name}.metadata_path"] = metadata_path
|
|
294
|
+
hint = Model(real_name, paths, config=config, formats=[ModelFormats.from_extension(ext)])
|
|
295
|
+
# TODO: look for metadata
|
|
296
|
+
hints.append(hint)
|
|
297
|
+
else:
|
|
298
|
+
assert context is not None, "Context is required for passing models by name"
|
|
299
|
+
assert len(model_names) > 0, "List of available models is empty"
|
|
300
|
+
assert name in model_names, f"Could not find a model matching the name: {name}"
|
|
301
|
+
index = model_names.index(name)
|
|
302
|
+
hint = models[index]
|
|
303
|
+
hints.append(hint)
|
|
304
|
+
|
|
305
|
+
return hints
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def apply_modelgroups(models, context=None):
|
|
309
|
+
assert context is not None
|
|
310
|
+
directories = get_model_directories(context)
|
|
311
|
+
|
|
312
|
+
groups = {}
|
|
313
|
+
for directory in directories:
|
|
314
|
+
for group in list_modelgroups(directory):
|
|
315
|
+
if group.name in groups and groups[group.name] != group.models:
|
|
316
|
+
raise RuntimeError(
|
|
317
|
+
f"The model group '{group.name}' has conflicting definitions. Used the following directories:"
|
|
318
|
+
f" {directories}"
|
|
319
|
+
)
|
|
320
|
+
groups[group.name] = group.models
|
|
321
|
+
|
|
322
|
+
out_models = []
|
|
323
|
+
for model in models:
|
|
324
|
+
out_models.extend(groups.get(model, [model]))
|
|
325
|
+
return list(dict.fromkeys(out_models)) # Drop duplicates
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def map_frontend_to_model(model, frontends, backend=None):
|
|
329
|
+
model_fmts = model.formats
|
|
330
|
+
backend_fmts = backend.get_supported_formats() if backend else []
|
|
331
|
+
for frontend in frontends:
|
|
332
|
+
ins = frontend.input_formats
|
|
333
|
+
outs = frontend.output_formats
|
|
334
|
+
assert len(ins) > 0
|
|
335
|
+
# TODO: instead of picking the first frontend which at least one match, determine the highest overlap
|
|
336
|
+
if any(in_fmt in model_fmts for in_fmt in ins):
|
|
337
|
+
if len(backend_fmts) == 0 or any(out_fmt in backend_fmts for out_fmt in outs):
|
|
338
|
+
new_model = model # TODO: deepcopy?
|
|
339
|
+
for i, fmt in enumerate(model_fmts):
|
|
340
|
+
if fmt not in ins: # Only keep those formqts which are supported by the chosen frontend
|
|
341
|
+
path = model.paths[model_fmts.index(fmt)]
|
|
342
|
+
new_model.formats.remove(fmt)
|
|
343
|
+
new_model.paths.remove(path)
|
|
344
|
+
return new_model, frontend
|
|
345
|
+
raise RuntimeError(f"Unable to find a suitable frontend for model '{model.name}'")
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
import yaml
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def parse_metadata(path):
|
|
23
|
+
content = {}
|
|
24
|
+
with open(path, "r") as yamlfile:
|
|
25
|
+
try:
|
|
26
|
+
content = yaml.safe_load(yamlfile)
|
|
27
|
+
except yaml.YAMLError as err: # pragma: no cover
|
|
28
|
+
raise RuntimeError(f"Could not open YAML file: {path}") from err
|
|
29
|
+
return content
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# class ModelOperator:
|
|
33
|
+
# def __init__(self, name, custom=False, registration=None):
|
|
34
|
+
# self.name = name
|
|
35
|
+
# self.custom = custom
|
|
36
|
+
# self.registration = registration
|
|
37
|
+
#
|
|
38
|
+
#
|
|
39
|
+
# class ModelMetadata:
|
|
40
|
+
# def __init__(
|
|
41
|
+
# self,
|
|
42
|
+
# author="unknown",
|
|
43
|
+
# description="",
|
|
44
|
+
# created_at=None,
|
|
45
|
+
# references=None,
|
|
46
|
+
# comment=None,
|
|
47
|
+
# backend_options_map=None,
|
|
48
|
+
# ):
|
|
49
|
+
# self.author = author if author is not None else "unknown"
|
|
50
|
+
# self.description = description if description is not None else ""
|
|
51
|
+
# self.created_at = created_at
|
|
52
|
+
# self.refrences = references if references is not None else []
|
|
53
|
+
# self.comment = comment
|
|
54
|
+
# self.backend_options_map = (
|
|
55
|
+
# backend_options_map if backend_options_map is not None else {}
|
|
56
|
+
# )
|
|
57
|
+
#
|
|
58
|
+
# def __repr__(self):
|
|
59
|
+
# return "ModelMetadata(" + str(vars(self)) + ")"
|
|
60
|
+
#
|
|
61
|
+
#
|
|
62
|
+
# class TfLitelMetadata(ModelMetadata):
|
|
63
|
+
# def __init__(
|
|
64
|
+
# self,
|
|
65
|
+
# author="unknown",
|
|
66
|
+
# description="",
|
|
67
|
+
# created_at=None,
|
|
68
|
+
# references=None,
|
|
69
|
+
# comment=None,
|
|
70
|
+
# backend_options_map=None,
|
|
71
|
+
# operators=[],
|
|
72
|
+
# ):
|
|
73
|
+
# super().__init__(
|
|
74
|
+
# author=author,
|
|
75
|
+
# description=description,
|
|
76
|
+
# created_at=created_at,
|
|
77
|
+
# references=references,
|
|
78
|
+
# comment=comment,
|
|
79
|
+
# backend_options_map=backend_options_map,
|
|
80
|
+
# operators=operators,
|
|
81
|
+
# )
|
|
82
|
+
# self.operators = operators
|
|
83
|
+
#
|
|
84
|
+
#
|
|
85
|
+
# def parse_metadata(path):
|
|
86
|
+
# with open(path, "r") as yamlfile:
|
|
87
|
+
# try:
|
|
88
|
+
# content = yaml.safe_load(yamlfile)
|
|
89
|
+
# if not content:
|
|
90
|
+
# # file empty
|
|
91
|
+
# return ModelMetadata()
|
|
92
|
+
# if "author" in content:
|
|
93
|
+
# author = content["author"]
|
|
94
|
+
# else:
|
|
95
|
+
# author = None
|
|
96
|
+
# if "description" in content:
|
|
97
|
+
# description = content["description"]
|
|
98
|
+
# else:
|
|
99
|
+
# description = None
|
|
100
|
+
# if "created_at" in content:
|
|
101
|
+
# created_at = content["created_at"]
|
|
102
|
+
# else:
|
|
103
|
+
# created_at = None
|
|
104
|
+
# if "references" in content:
|
|
105
|
+
# references = content["references"]
|
|
106
|
+
# assert isinstance(references, list)
|
|
107
|
+
# else:
|
|
108
|
+
# references = []
|
|
109
|
+
# if "comment" in content:
|
|
110
|
+
# comment = content["comment"]
|
|
111
|
+
# else:
|
|
112
|
+
# comment = None
|
|
113
|
+
# backend_options_map = {}
|
|
114
|
+
# if "backends" in content:
|
|
115
|
+
# backends = content["backends"]
|
|
116
|
+
# for backend in backends:
|
|
117
|
+
# backend_options = parse_model_options_for_backend(
|
|
118
|
+
# backend, backends[backend]
|
|
119
|
+
# )
|
|
120
|
+
# backend_options_map[backend] = backend_options
|
|
121
|
+
# metadata = ModelMetadata(
|
|
122
|
+
# author=author,
|
|
123
|
+
# description=description,
|
|
124
|
+
# created_at=created_at,
|
|
125
|
+
# references=references,
|
|
126
|
+
# comment=comment,
|
|
127
|
+
# backend_options_map=backend_options_map,
|
|
128
|
+
# )
|
|
129
|
+
# return metadata
|
|
130
|
+
# except yaml.YAMLError as err:
|
|
131
|
+
# raise RuntimeError(f"Could not open YAML file: {path}") from err
|
|
132
|
+
#
|
|
133
|
+
# return None
|
mlonmcu/models/model.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
from enum import Enum
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from collections import namedtuple
|
|
22
|
+
|
|
23
|
+
from mlonmcu.config import filter_config
|
|
24
|
+
|
|
25
|
+
from .metadata import parse_metadata
|
|
26
|
+
|
|
27
|
+
ModelFormat = namedtuple("ModelFormat", ["value", "extensions"])
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ModelFormats(Enum):
|
|
31
|
+
@property
|
|
32
|
+
def extensions(self):
|
|
33
|
+
return self.value.extensions
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def extension(self):
|
|
37
|
+
return self.value.extensions[0]
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_extension(cls, ext):
|
|
41
|
+
for fmt in cls:
|
|
42
|
+
if ext in fmt.extensions:
|
|
43
|
+
return fmt
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
NONE = ModelFormat(0, [])
|
|
47
|
+
TFLITE = ModelFormat(1, ["tflite"])
|
|
48
|
+
PACKED = ModelFormat(2, ["tflm"])
|
|
49
|
+
IPYNB = ModelFormat(3, ["ipynb"])
|
|
50
|
+
ONNX = ModelFormat(4, ["onnx"])
|
|
51
|
+
RELAY = ModelFormat(5, ["relay"])
|
|
52
|
+
PB = ModelFormat(6, ["pb"])
|
|
53
|
+
PADDLE = ModelFormat(7, ["pdmodel"])
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def parse_metadata_from_path(path):
|
|
57
|
+
if Path(path).is_file():
|
|
58
|
+
metadata = parse_metadata(path)
|
|
59
|
+
return metadata
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class Model:
|
|
64
|
+
DEFAULTS = {
|
|
65
|
+
"metadata_path": "definition.yml",
|
|
66
|
+
"support_path": "support",
|
|
67
|
+
"inputs_path": "input",
|
|
68
|
+
"outputs_path": "output",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
def __init__(self, name, paths, config=None, alt=None, formats=ModelFormats.TFLITE):
|
|
72
|
+
self.name = name
|
|
73
|
+
self.paths = paths
|
|
74
|
+
if not isinstance(self.paths, list):
|
|
75
|
+
self.paths = [self.path]
|
|
76
|
+
self.alt = alt
|
|
77
|
+
self.formats = formats
|
|
78
|
+
if not isinstance(self.formats, list):
|
|
79
|
+
self.formats = [formats]
|
|
80
|
+
self.config = filter_config(config if config is not None else {}, self.name, self.DEFAULTS, [], [])
|
|
81
|
+
self.metadata = parse_metadata_from_path(self.metadata_path)
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def metadata_path(self):
|
|
85
|
+
return self.config["metadata_path"]
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def support_path(self):
|
|
89
|
+
return self.config["support_path"]
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def inputs_path(self):
|
|
93
|
+
# TODO: fall back to metadata
|
|
94
|
+
return self.config["inputs_path"]
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def outputs_path(self):
|
|
98
|
+
# TODO: fall back to metadata
|
|
99
|
+
return self.config["outputs_path"]
|
|
100
|
+
|
|
101
|
+
def __repr__(self):
|
|
102
|
+
if self.alt:
|
|
103
|
+
return f"Model({self.name},alt={self.alt})"
|
|
104
|
+
return f"Model({self.name})"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BackendModelOptions:
|
|
22
|
+
def __init__(self, backend, supported=True, options={}):
|
|
23
|
+
self.backend = backend
|
|
24
|
+
self.supported = supported
|
|
25
|
+
self.options = options
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TFLMIModelOptions(BackendModelOptions):
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
backend,
|
|
32
|
+
supported=True,
|
|
33
|
+
arena_size=None,
|
|
34
|
+
builtin_ops=None,
|
|
35
|
+
custom_ops=None,
|
|
36
|
+
):
|
|
37
|
+
super().__init__(backend, supported=supported)
|
|
38
|
+
self.arena_size = arena_size
|
|
39
|
+
self.builtin_ops = builtin_ops
|
|
40
|
+
self.custom_ops = custom_ops
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class TVMRTModelOptions(BackendModelOptions):
|
|
44
|
+
def __init__(self, backend, supported=True, arena_size=None):
|
|
45
|
+
super().__init__(backend, supported=supported)
|
|
46
|
+
self.arena_size = arena_size
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse_model_options_for_backend(backend, options):
|
|
50
|
+
backend_types = {
|
|
51
|
+
"tflmi": TFLMIModelOptions,
|
|
52
|
+
"tvmrt": TVMRTModelOptions,
|
|
53
|
+
}
|
|
54
|
+
if backend in backend_types:
|
|
55
|
+
backend_type = backend_types[backend]
|
|
56
|
+
else:
|
|
57
|
+
backend_type = BackendModelOptions
|
|
58
|
+
|
|
59
|
+
backend_options = backend_type(backend)
|
|
60
|
+
|
|
61
|
+
for key, value in options.items():
|
|
62
|
+
setattr(backend_options, key, value)
|
|
63
|
+
|
|
64
|
+
return backend_options
|