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
|
@@ -0,0 +1,571 @@
|
|
|
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 tempfile
|
|
20
|
+
import multiprocessing
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from abc import ABC, abstractmethod
|
|
23
|
+
|
|
24
|
+
from mlonmcu.feature.features import get_matching_features
|
|
25
|
+
from mlonmcu.models.model import ModelFormats
|
|
26
|
+
from mlonmcu.feature.type import FeatureType
|
|
27
|
+
from mlonmcu.config import filter_config, str2bool
|
|
28
|
+
from mlonmcu.artifact import Artifact, ArtifactFormat
|
|
29
|
+
from mlonmcu.setup import utils
|
|
30
|
+
|
|
31
|
+
from mlonmcu.logging import get_logger
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
logger = get_logger()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Frontend(ABC):
|
|
38
|
+
FEATURES = ["validate"]
|
|
39
|
+
|
|
40
|
+
DEFAULTS = {
|
|
41
|
+
"use_inout_data": False,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
REQUIRED = []
|
|
45
|
+
OPTIONAL = []
|
|
46
|
+
|
|
47
|
+
def __init__(self, name, input_formats=None, output_formats=None, features=None, config=None):
|
|
48
|
+
self.name = name
|
|
49
|
+
self.input_formats = input_formats if input_formats else []
|
|
50
|
+
self.output_formats = output_formats if output_formats else []
|
|
51
|
+
self.config = config if config else {}
|
|
52
|
+
self.features = self.process_features(features)
|
|
53
|
+
self.config = filter_config(self.config, self.name, self.DEFAULTS, self.OPTIONAL, self.REQUIRED)
|
|
54
|
+
|
|
55
|
+
def __repr__(self):
|
|
56
|
+
probs = []
|
|
57
|
+
if self.name:
|
|
58
|
+
probs.append(self.name)
|
|
59
|
+
if self.features and len(self.features) > 0:
|
|
60
|
+
probs.append(str(self.features))
|
|
61
|
+
if self.config and len(self.config) > 0:
|
|
62
|
+
probs.append(str(self.config))
|
|
63
|
+
return "Frontend(" + ",".join(probs) + ")"
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def use_inout_data(self):
|
|
67
|
+
value = self.config["use_inout_data"]
|
|
68
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
69
|
+
|
|
70
|
+
def supports_formats(self, ins=None, outs=None):
|
|
71
|
+
"""Returs true if the frontend can handle at least one combination of input and output formats."""
|
|
72
|
+
assert ins is not None or outs is not None, "Please provide a list of input formats, outputs formats or both"
|
|
73
|
+
ret = True
|
|
74
|
+
if ins:
|
|
75
|
+
if not isinstance(ins, list):
|
|
76
|
+
ins = [ins]
|
|
77
|
+
supported = any(fmt in self.input_formats for fmt in ins)
|
|
78
|
+
ret = ret and supported
|
|
79
|
+
if outs:
|
|
80
|
+
if not isinstance(outs, list):
|
|
81
|
+
outs = [outs]
|
|
82
|
+
supported = any(fmt in self.output_formats for fmt in ins)
|
|
83
|
+
ret = ret and supported
|
|
84
|
+
return ret
|
|
85
|
+
|
|
86
|
+
def process_features(self, features):
|
|
87
|
+
if features is None:
|
|
88
|
+
return []
|
|
89
|
+
features = get_matching_features(features, FeatureType.FRONTEND)
|
|
90
|
+
for feature in features:
|
|
91
|
+
assert ( # If this assertion occurs, continue with the next frontend instead of failing
|
|
92
|
+
# (TODO: create custom exception type)
|
|
93
|
+
feature.name
|
|
94
|
+
in self.FEATURES
|
|
95
|
+
), f"Incompatible feature: {feature.name}"
|
|
96
|
+
# Instead we might introduce self.compatible and set it to true at this line
|
|
97
|
+
feature.add_frontend_config(self.name, self.config)
|
|
98
|
+
feature.update_formats(self.name, self.input_formats, self.output_formats)
|
|
99
|
+
return features
|
|
100
|
+
|
|
101
|
+
@abstractmethod
|
|
102
|
+
# def produce_artifacts(self, model):
|
|
103
|
+
def produce_artifacts(self, model):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
def process_metadata(self, model, cfg=None):
|
|
107
|
+
model_dir = Path(model.paths[0]).parent.resolve()
|
|
108
|
+
metadata = model.metadata
|
|
109
|
+
in_paths = []
|
|
110
|
+
out_paths = []
|
|
111
|
+
if self.use_inout_data:
|
|
112
|
+
if metadata is not None and "network_parameters" in metadata:
|
|
113
|
+
network = metadata["network_parameters"]
|
|
114
|
+
assert "input_nodes" in network
|
|
115
|
+
ins = network["input_nodes"]
|
|
116
|
+
for inp in ins:
|
|
117
|
+
if "example_input" in inp and "path" in inp["example_input"]:
|
|
118
|
+
in_data_dir = Path(inp["example_input"]["path"])
|
|
119
|
+
# TODO: this will only work with relative paths to model dir! (Fallback to parent directories?)
|
|
120
|
+
in_path = model_dir / in_data_dir
|
|
121
|
+
assert (
|
|
122
|
+
in_path.is_dir()
|
|
123
|
+
), f"Input data directory defined in model metadata does not exist: {in_path}"
|
|
124
|
+
in_paths.append(in_path)
|
|
125
|
+
assert "output_nodes" in network
|
|
126
|
+
outs = network["output_nodes"]
|
|
127
|
+
for outp in outs:
|
|
128
|
+
if "test_output_path" in outp:
|
|
129
|
+
out_data_dir = Path(outp["test_output_path"])
|
|
130
|
+
out_path = model_dir / out_data_dir
|
|
131
|
+
assert (
|
|
132
|
+
in_path.is_dir()
|
|
133
|
+
), f"Output data directory defined in model metadata does not exist: {out_path}"
|
|
134
|
+
out_paths.append(out_path)
|
|
135
|
+
else:
|
|
136
|
+
fallback_in_path = model_dir / "input"
|
|
137
|
+
if fallback_in_path.is_dir():
|
|
138
|
+
in_paths.append(fallback_in_path)
|
|
139
|
+
fallback_out_path = model_dir / "output"
|
|
140
|
+
if fallback_out_path.is_dir():
|
|
141
|
+
out_paths.append(fallback_out_path)
|
|
142
|
+
|
|
143
|
+
if metadata is not None and "backends" in metadata:
|
|
144
|
+
assert cfg is not None
|
|
145
|
+
backend_options = metadata["backends"]
|
|
146
|
+
for backend in backend_options:
|
|
147
|
+
if backend_options[backend] is not None:
|
|
148
|
+
flattened = {f"{backend}.{key}": value for key, value in backend_options[backend].items()}
|
|
149
|
+
cfg.update(flattened)
|
|
150
|
+
|
|
151
|
+
# Detect model support code (Allow overwrite in metadata YAML)
|
|
152
|
+
support_path = model_dir / "support"
|
|
153
|
+
if support_path.is_dir():
|
|
154
|
+
assert cfg is not None
|
|
155
|
+
# TODO: onlu overwrite if unset?
|
|
156
|
+
cfg.update({"mlif.model_support_dir": support_path})
|
|
157
|
+
# cfg.update({"espidf.model_support_dir": support_path})
|
|
158
|
+
# cfg.update({"zephyr.model_support_dir": support_path})
|
|
159
|
+
if len(in_paths) > 0:
|
|
160
|
+
cfg.update({"mlif.input_data_path": in_paths})
|
|
161
|
+
# cfg.update({"espidf.input_data_path": in_paths})
|
|
162
|
+
# cfg.update({"zephyr.input_data_path": in_paths})
|
|
163
|
+
if len(out_paths) > 0:
|
|
164
|
+
cfg.update({"mlif.output_data_path": out_paths})
|
|
165
|
+
# cfg.update({"espidf.output_data_path": out_paths})
|
|
166
|
+
# cfg.update({"zephyr.output_data_path": out_paths})
|
|
167
|
+
|
|
168
|
+
def generate_models(self, model):
|
|
169
|
+
artifacts = []
|
|
170
|
+
|
|
171
|
+
count = len(model.paths)
|
|
172
|
+
assert count == len(model.formats)
|
|
173
|
+
assert count > 0, f"'{self.name}' frontend expects at least one model"
|
|
174
|
+
max_ins = len(self.input_formats)
|
|
175
|
+
assert count <= max_ins, f"'{self.name}' frontend did not expect more than {max_ins} models"
|
|
176
|
+
formats = model.formats
|
|
177
|
+
assert self.supports_formats(formats), f"Invalid model format for '{self.name}' frontend"
|
|
178
|
+
|
|
179
|
+
artifacts = self.produce_artifacts(model)
|
|
180
|
+
if not isinstance(artifacts, list):
|
|
181
|
+
artifacts = [artifacts]
|
|
182
|
+
assert len(artifacts) > 0, f"'{self.name}' frontend should produce at least one model"
|
|
183
|
+
max_outs = len(self.output_formats)
|
|
184
|
+
assert len(artifacts) <= max_outs, f"'{self.name}' frontend should not return more than {max_outs}"
|
|
185
|
+
|
|
186
|
+
# If we want to use the same instance of this Frontend in parallel, we need to get rid of self.artifacts...
|
|
187
|
+
self.artifacts = artifacts
|
|
188
|
+
|
|
189
|
+
def export_models(self, path):
|
|
190
|
+
assert len(self.artifacts) > 0, "No artifacts found, please run generate_models() first"
|
|
191
|
+
|
|
192
|
+
if not isinstance(path, Path):
|
|
193
|
+
path = Path(path)
|
|
194
|
+
|
|
195
|
+
is_dir = len(path.suffix) == 0
|
|
196
|
+
if is_dir:
|
|
197
|
+
assert (
|
|
198
|
+
path.is_dir()
|
|
199
|
+
), "The supplied path does not exists." # Make sure it actually exists (we do not create it by default)
|
|
200
|
+
for artifact in self.artifacts:
|
|
201
|
+
artifact.export(path)
|
|
202
|
+
else:
|
|
203
|
+
raise NotImplementedError
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class SimpleFrontend(Frontend):
|
|
207
|
+
"""An abstract frontend with equivalent input and output formats."""
|
|
208
|
+
|
|
209
|
+
# Assumption: only raw model data
|
|
210
|
+
def __init__(self, name, fmt, features=None, config=None):
|
|
211
|
+
super().__init__(
|
|
212
|
+
name,
|
|
213
|
+
input_formats=[fmt],
|
|
214
|
+
output_formats=[fmt],
|
|
215
|
+
features=features,
|
|
216
|
+
config=config,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
def produce_artifacts(self, model):
|
|
220
|
+
assert len(self.input_formats) == len(self.output_formats) == len(model.paths) == 1
|
|
221
|
+
artifacts = []
|
|
222
|
+
name = model.name
|
|
223
|
+
path = model.paths[0]
|
|
224
|
+
ext = self.input_formats[0].extension
|
|
225
|
+
with open(path, "rb") as handle: # TODO: is an onnx model raw data or text?
|
|
226
|
+
raw = handle.read()
|
|
227
|
+
artifacts.append(Artifact(f"{name}.{ext}", raw=raw, fmt=ArtifactFormat.RAW))
|
|
228
|
+
return artifacts
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# TODO: move to frontends.py
|
|
232
|
+
# TODO: frontend parsed metadata instead of lookup.py?
|
|
233
|
+
# TODO: how to find inout_data?
|
|
234
|
+
class TfLiteFrontend(SimpleFrontend):
|
|
235
|
+
FEATURES = Frontend.FEATURES + ["visualize"]
|
|
236
|
+
|
|
237
|
+
DEFAULTS = {**Frontend.DEFAULTS, "visualize_enable": False, "visualize_script": None}
|
|
238
|
+
|
|
239
|
+
REQUIRED = Frontend.REQUIRED + []
|
|
240
|
+
|
|
241
|
+
def __init__(self, features=None, config=None):
|
|
242
|
+
super().__init__(
|
|
243
|
+
"tflite",
|
|
244
|
+
ModelFormats.TFLITE,
|
|
245
|
+
features=features,
|
|
246
|
+
config=config,
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
@property
|
|
250
|
+
def visualize_enable(self):
|
|
251
|
+
value = self.config["visualize_enable"]
|
|
252
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def visualize_script(self):
|
|
256
|
+
return self.config["visualize_script"]
|
|
257
|
+
|
|
258
|
+
def produce_artifacts(self, model):
|
|
259
|
+
assert len(self.input_formats) == len(model.paths) == 1
|
|
260
|
+
artifacts = []
|
|
261
|
+
|
|
262
|
+
name = model.name
|
|
263
|
+
path = model.paths[0]
|
|
264
|
+
ext = self.input_formats[0].extension
|
|
265
|
+
with open(path, "rb") as handle:
|
|
266
|
+
raw = handle.read()
|
|
267
|
+
artifacts.append(Artifact(f"{name}.{ext}", raw=raw, fmt=ArtifactFormat.RAW))
|
|
268
|
+
|
|
269
|
+
if not self.visualize_enable:
|
|
270
|
+
assert len(self.output_formats) == 1
|
|
271
|
+
else:
|
|
272
|
+
assert len(self.output_formats) == 2
|
|
273
|
+
|
|
274
|
+
assert self.visualize_script is not None
|
|
275
|
+
|
|
276
|
+
in_file = model.paths[0]
|
|
277
|
+
ext = "html"
|
|
278
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
279
|
+
out_file = str(Path(tmpdirname) / f"tflite_visualize.{ext}")
|
|
280
|
+
|
|
281
|
+
utils.python(self.visualize_script, in_file, out_file, print_output=False)
|
|
282
|
+
|
|
283
|
+
with open(out_file, "r") as handle:
|
|
284
|
+
tflite_visualize_text = handle.read()
|
|
285
|
+
|
|
286
|
+
tflite_visualize_artifact = Artifact(
|
|
287
|
+
f"tflite_visualize.{ext}",
|
|
288
|
+
content=tflite_visualize_text,
|
|
289
|
+
fmt=ArtifactFormat.TEXT,
|
|
290
|
+
)
|
|
291
|
+
artifacts.append(tflite_visualize_artifact)
|
|
292
|
+
|
|
293
|
+
return artifacts
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class RelayFrontend(SimpleFrontend):
|
|
297
|
+
FEATURES = Frontend.FEATURES + ["relayviz"]
|
|
298
|
+
|
|
299
|
+
DEFAULTS = {**Frontend.DEFAULTS, "visualize_graph": False, "relayviz_plotter": "term"}
|
|
300
|
+
|
|
301
|
+
REQUIRED = Frontend.REQUIRED + ["tvm.build_dir", "tvm.pythonpath"]
|
|
302
|
+
|
|
303
|
+
def __init__(self, features=None, config=None):
|
|
304
|
+
super().__init__(
|
|
305
|
+
"relay",
|
|
306
|
+
ModelFormats.RELAY,
|
|
307
|
+
features=features,
|
|
308
|
+
config=config,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
@property
|
|
312
|
+
def visualize_graph(self):
|
|
313
|
+
value = self.config["visualize_graph"]
|
|
314
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
315
|
+
|
|
316
|
+
@property
|
|
317
|
+
def relayviz_plotter(self):
|
|
318
|
+
return self.config["relayviz_plotter"]
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
def tvm_build_dir(self):
|
|
322
|
+
return self.config["tvm.build_dir"]
|
|
323
|
+
|
|
324
|
+
@property
|
|
325
|
+
def tvm_pythonpath(self):
|
|
326
|
+
return self.config["tvm.pythonpath"]
|
|
327
|
+
|
|
328
|
+
def produce_artifacts(self, model):
|
|
329
|
+
assert len(self.input_formats) == len(model.paths) == 1
|
|
330
|
+
artifacts = []
|
|
331
|
+
|
|
332
|
+
name = model.name
|
|
333
|
+
path = model.paths[0]
|
|
334
|
+
ext = self.input_formats[0].extension
|
|
335
|
+
with open(path, "rb") as handle: # TODO: is an onnx model raw data or text?
|
|
336
|
+
raw = handle.read()
|
|
337
|
+
artifacts.append(Artifact(f"{name}.{ext}", raw=raw, fmt=ArtifactFormat.RAW))
|
|
338
|
+
|
|
339
|
+
if not self.visualize_graph:
|
|
340
|
+
assert len(self.output_formats) == 1
|
|
341
|
+
else:
|
|
342
|
+
assert len(self.output_formats) == 2
|
|
343
|
+
|
|
344
|
+
def _relayviz(in_file, out_file, plotter_name, env={}):
|
|
345
|
+
import sys
|
|
346
|
+
import os
|
|
347
|
+
|
|
348
|
+
sys.path.append(env["PYTHONPATH"])
|
|
349
|
+
os.environ["TVM_LIBRARY_PATH"] = env["TVM_LIBRARY_PATH"]
|
|
350
|
+
from tvm import parser
|
|
351
|
+
from tvm.contrib import relay_viz
|
|
352
|
+
from tvm.contrib.relay_viz.terminal import TermPlotter
|
|
353
|
+
from tvm.contrib.relay_viz.dot import DotPlotter
|
|
354
|
+
|
|
355
|
+
if plotter_name == "term":
|
|
356
|
+
plotter_cls = TermPlotter
|
|
357
|
+
elif plotter_name == "dot":
|
|
358
|
+
plotter_cls = DotPlotter
|
|
359
|
+
else:
|
|
360
|
+
raise RuntimeError(f"Invalid plotter name: {plotter_name}")
|
|
361
|
+
|
|
362
|
+
with open(in_file, "r", encoding="utf-8") as relay_text:
|
|
363
|
+
text = relay_text.read()
|
|
364
|
+
|
|
365
|
+
mod = parser.fromtext(text)
|
|
366
|
+
|
|
367
|
+
plotter_inst = plotter_cls()
|
|
368
|
+
viz = relay_viz.RelayVisualizer(mod, plotter=plotter_inst)
|
|
369
|
+
out_file_base = os.path.splitext(out_file)[0]
|
|
370
|
+
viz.render(filename=out_file_base)
|
|
371
|
+
|
|
372
|
+
in_file = model.paths[0]
|
|
373
|
+
ext = "" if self.relayviz_plotter == "term" else "pdf"
|
|
374
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
375
|
+
out_file = str(Path(tmpdirname) / (f"relayviz.{ext}" if len(ext) > 0 else "relayviz"))
|
|
376
|
+
proc = multiprocessing.Process(
|
|
377
|
+
target=_relayviz,
|
|
378
|
+
args=[in_file, out_file, self.relayviz_plotter],
|
|
379
|
+
kwargs={"env": {"PYTHONPATH": self.tvm_pythonpath, "TVM_LIBRARY_PATH": self.tvm_build_dir}},
|
|
380
|
+
)
|
|
381
|
+
proc.start()
|
|
382
|
+
proc.join()
|
|
383
|
+
|
|
384
|
+
if self.relayviz_plotter == "term":
|
|
385
|
+
with open(out_file, "r") as handle:
|
|
386
|
+
relayviz_text = handle.read()
|
|
387
|
+
|
|
388
|
+
relayviz_artifact = Artifact(
|
|
389
|
+
"relayviz.txt",
|
|
390
|
+
content=relayviz_text,
|
|
391
|
+
fmt=ArtifactFormat.TEXT,
|
|
392
|
+
)
|
|
393
|
+
else:
|
|
394
|
+
with open(out_file, "rb") as handle:
|
|
395
|
+
relayviz_data = handle.read()
|
|
396
|
+
|
|
397
|
+
relayviz_artifact = Artifact(
|
|
398
|
+
f"relayviz.{ext}",
|
|
399
|
+
raw=relayviz_data,
|
|
400
|
+
fmt=ArtifactFormat.RAW,
|
|
401
|
+
)
|
|
402
|
+
artifacts.append(relayviz_artifact)
|
|
403
|
+
|
|
404
|
+
return artifacts
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
class PackedFrontend(Frontend): # Inherit from TFLiteFrontend? -> how to do constructor?
|
|
408
|
+
FEATURES = Frontend.FEATURES + ["packing", "packed"]
|
|
409
|
+
|
|
410
|
+
DEFAULTS = {
|
|
411
|
+
**Frontend.DEFAULTS,
|
|
412
|
+
"ignore_existing": True,
|
|
413
|
+
"fake_pack": False, # Pretend that every compatible tensor is packable
|
|
414
|
+
# (best case scenerio, TODO: rename to force_pack?)
|
|
415
|
+
"use_packed": True,
|
|
416
|
+
"check": False, # Unimplemented
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
REQUIRED = ["packer.exe"] # TODO move to feature?
|
|
420
|
+
|
|
421
|
+
def __init__(self, features=None, config=None):
|
|
422
|
+
super().__init__(name="packed", features=features, config=config)
|
|
423
|
+
if self.fake_pack or self.ignore_existing:
|
|
424
|
+
# assert self.use_packed
|
|
425
|
+
self.input_formats = [ModelFormats.TFLITE]
|
|
426
|
+
else:
|
|
427
|
+
self.input_formats = [ModelFormats.PACKED, ModelFormats.TFLITE]
|
|
428
|
+
|
|
429
|
+
# if self.use_packed:
|
|
430
|
+
self.output_formats = [
|
|
431
|
+
ModelFormats.PACKED,
|
|
432
|
+
ModelFormats.TFLITE,
|
|
433
|
+
] # Always copy over the input model as intermediate artifact for reproducability
|
|
434
|
+
# TODO: add a Frontend.DEFAULT which can be used to turn off this behavoir (keep intermediate?)
|
|
435
|
+
# else:
|
|
436
|
+
# self.output_formats = [ModelFormats.TFLITE]
|
|
437
|
+
# Order of formats ir irrelevant here, hot for artifacts, the first one will always be the main object
|
|
438
|
+
|
|
439
|
+
@property
|
|
440
|
+
def ignore_existing(self):
|
|
441
|
+
value = self.config["ignore_existing"]
|
|
442
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
443
|
+
|
|
444
|
+
@property
|
|
445
|
+
def fake_pack(self):
|
|
446
|
+
value = self.config["fake_pack"]
|
|
447
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
448
|
+
|
|
449
|
+
@property
|
|
450
|
+
def use_packed(self):
|
|
451
|
+
value = self.config["use_packed"]
|
|
452
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
453
|
+
|
|
454
|
+
@property
|
|
455
|
+
def check(self):
|
|
456
|
+
value = self.config["check"]
|
|
457
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
458
|
+
|
|
459
|
+
def produce_artifacts(self, model):
|
|
460
|
+
tflite_data = None
|
|
461
|
+
packed_data = None
|
|
462
|
+
name = model.name
|
|
463
|
+
|
|
464
|
+
if self.fake_pack or self.ignore_existing: # -> ins: TFLITE
|
|
465
|
+
# assert self.use_packed
|
|
466
|
+
tflite_path = model.paths[0]
|
|
467
|
+
|
|
468
|
+
with open(tflite_path, "rb") as handle:
|
|
469
|
+
tflite_data = handle.read()
|
|
470
|
+
else: # -> ins: TFLITE, PACKED
|
|
471
|
+
for path, fmt in zip(model.paths, model.formats):
|
|
472
|
+
data_in = None
|
|
473
|
+
with open(path, "rb") as handle:
|
|
474
|
+
data_in = handle.read()
|
|
475
|
+
if fmt == ModelFormats.PACKED:
|
|
476
|
+
packed_data = data_in
|
|
477
|
+
break
|
|
478
|
+
elif fmt == ModelFormats.TFLITE:
|
|
479
|
+
# tflite_data_in = data_in
|
|
480
|
+
break
|
|
481
|
+
else:
|
|
482
|
+
raise RuntimeError(f"Unexpected model format: {fmt}")
|
|
483
|
+
|
|
484
|
+
if packed_data is None:
|
|
485
|
+
# Do packing
|
|
486
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
487
|
+
logger.debug("Using temporary directory for packing results: %s", tmpdirname)
|
|
488
|
+
packer_exe = self.config["packer_exe"]
|
|
489
|
+
assert packer_exe is not None
|
|
490
|
+
in_file = Path(tmpdirname) / "in.tflite"
|
|
491
|
+
with open(in_file, "wb") as handle:
|
|
492
|
+
handle.write(tflite_data)
|
|
493
|
+
out_file = Path(tmpdirname) / "out.tflm"
|
|
494
|
+
utils.exec_getout(packer_exe, in_file, out_file)
|
|
495
|
+
with open(out_file, "rb") as handle:
|
|
496
|
+
packed_data = handle.read()
|
|
497
|
+
|
|
498
|
+
if self.check:
|
|
499
|
+
raise NotImplementedError
|
|
500
|
+
|
|
501
|
+
tflite_artifact = Artifact(
|
|
502
|
+
f"{name}.tflite",
|
|
503
|
+
raw=tflite_data,
|
|
504
|
+
fmt=ArtifactFormat.RAW,
|
|
505
|
+
optional=self.use_packed,
|
|
506
|
+
)
|
|
507
|
+
packed_artifact = Artifact(
|
|
508
|
+
f"{name}.tflm",
|
|
509
|
+
raw=packed_data,
|
|
510
|
+
fmt=ArtifactFormat.RAW,
|
|
511
|
+
optional=not self.use_packed,
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
if self.use_packed:
|
|
515
|
+
return [packed_artifact, tflite_artifact]
|
|
516
|
+
else:
|
|
517
|
+
return [tflite_artifact, packed_artifact]
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
class ONNXFrontend(SimpleFrontend):
|
|
521
|
+
FEATURES = Frontend.FEATURES
|
|
522
|
+
|
|
523
|
+
DEFAULTS = {
|
|
524
|
+
**Frontend.DEFAULTS,
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
REQUIRED = Frontend.REQUIRED + []
|
|
528
|
+
|
|
529
|
+
def __init__(self, features=None, config=None):
|
|
530
|
+
super().__init__(
|
|
531
|
+
"onnx",
|
|
532
|
+
ModelFormats.ONNX,
|
|
533
|
+
features=features,
|
|
534
|
+
config=config,
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
class PBFrontend(SimpleFrontend):
|
|
539
|
+
FEATURES = Frontend.FEATURES
|
|
540
|
+
|
|
541
|
+
DEFAULTS = {
|
|
542
|
+
**Frontend.DEFAULTS,
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
REQUIRED = Frontend.REQUIRED + []
|
|
546
|
+
|
|
547
|
+
def __init__(self, features=None, config=None):
|
|
548
|
+
super().__init__(
|
|
549
|
+
"pb",
|
|
550
|
+
ModelFormats.PB,
|
|
551
|
+
features=features,
|
|
552
|
+
config=config,
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
class PaddleFrontend(SimpleFrontend):
|
|
557
|
+
FEATURES = Frontend.FEATURES
|
|
558
|
+
|
|
559
|
+
DEFAULTS = {
|
|
560
|
+
**Frontend.DEFAULTS,
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
REQUIRED = Frontend.REQUIRED + []
|
|
564
|
+
|
|
565
|
+
def __init__(self, features=None, config=None):
|
|
566
|
+
super().__init__(
|
|
567
|
+
"paddle",
|
|
568
|
+
ModelFormats.PADDLE,
|
|
569
|
+
features=features,
|
|
570
|
+
config=config,
|
|
571
|
+
)
|
mlonmcu/models/group.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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 ModelGroup:
|
|
22
|
+
def __init__(self, name, models, description=""):
|
|
23
|
+
self.name = name
|
|
24
|
+
self.models = models
|
|
25
|
+
self.description = description
|
|
26
|
+
|
|
27
|
+
def __repr__(self):
|
|
28
|
+
models_str = ",".join(self.models)
|
|
29
|
+
return f"ModelGroup({self.name},models=[{models_str}])"
|