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/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
"""Top-level package for ML on MCU."""
|
|
20
|
+
|
|
21
|
+
__author__ = """TUM Department of Electrical and Computer Engineering - Chair of Electronic Design Automation"""
|
|
22
|
+
__email__ = "philipp.van-kempen@tum.de"
|
|
23
|
+
|
|
24
|
+
from mlonmcu.version import __version__
|
|
25
|
+
|
|
26
|
+
__all__ = ["__version__"]
|
mlonmcu/artifact.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
"""Artifacts defintions internally used to refer to intermediate results."""
|
|
20
|
+
|
|
21
|
+
from enum import Enum
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from mlonmcu.setup import utils
|
|
25
|
+
|
|
26
|
+
# TODO: offer pack/unpack/flatten methods for mlf
|
|
27
|
+
# TODO: implement restore methods
|
|
28
|
+
# TODO: decide if inheritance based scheme would fit better
|
|
29
|
+
# TODO: add artifact flags and lookup utility to find best match
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ArtifactFormat(Enum): # TODO: ArtifactType, ArtifactKind?
|
|
33
|
+
"""Enumeration of artifact types."""
|
|
34
|
+
|
|
35
|
+
UNKNOWN = 0
|
|
36
|
+
SOURCE = 1
|
|
37
|
+
TEXT = 2
|
|
38
|
+
MLF = 3
|
|
39
|
+
MODEL = 4
|
|
40
|
+
IMAGE = 5
|
|
41
|
+
DATA = 6
|
|
42
|
+
NUMPY = 7
|
|
43
|
+
PARAMS = 8
|
|
44
|
+
JSON = 9 # ?
|
|
45
|
+
PATH = 10 # NOT A DIRECTORY?
|
|
46
|
+
RAW = 11
|
|
47
|
+
BIN = 11
|
|
48
|
+
SHARED_OBJECT = 12 # Here: the parent tar archive
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def lookup_artifacts(artifacts, name=None, fmt=None, flags=None, first_only=False):
|
|
52
|
+
"""Utility to get a matching artifact for a given set of properties."""
|
|
53
|
+
matches = []
|
|
54
|
+
# Warning: if neither name, fmt nor flags is provided, the first artifact (first_only=True)
|
|
55
|
+
# or all (first_only=False) are returned
|
|
56
|
+
for artifact in artifacts:
|
|
57
|
+
valid = True
|
|
58
|
+
if name is not None and artifact.name != name:
|
|
59
|
+
valid = False
|
|
60
|
+
if fmt is not None and artifact.fmt != fmt:
|
|
61
|
+
valid = False
|
|
62
|
+
if flags is not None and not all(
|
|
63
|
+
flag in artifact.flags for flag in flags
|
|
64
|
+
): # A valid artifact may have more flags than specified
|
|
65
|
+
valid = False
|
|
66
|
+
if valid:
|
|
67
|
+
matches.append(artifact)
|
|
68
|
+
if len(matches) > 0 and first_only:
|
|
69
|
+
matches = [matches[0]]
|
|
70
|
+
return matches
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Artifact:
|
|
74
|
+
"""Artifact type."""
|
|
75
|
+
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
name,
|
|
79
|
+
content=None,
|
|
80
|
+
path=None,
|
|
81
|
+
data=None,
|
|
82
|
+
raw=None,
|
|
83
|
+
fmt=ArtifactFormat.UNKNOWN,
|
|
84
|
+
flags=None,
|
|
85
|
+
archive=False,
|
|
86
|
+
optional=False,
|
|
87
|
+
):
|
|
88
|
+
# TODO: Allow to store filenames as well as raw data
|
|
89
|
+
self.name = name
|
|
90
|
+
# TODO: too many attributes...
|
|
91
|
+
self.content = content
|
|
92
|
+
self.path = path
|
|
93
|
+
self.data = data
|
|
94
|
+
self.raw = raw
|
|
95
|
+
self.fmt = fmt
|
|
96
|
+
self.flags = flags if flags is not None else {}
|
|
97
|
+
self.archive = archive
|
|
98
|
+
self.optional = optional
|
|
99
|
+
self.validate()
|
|
100
|
+
|
|
101
|
+
def __repr__(self):
|
|
102
|
+
return f"Artifact({self.name}, fmt={self.fmt}, flags={self.flags})"
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def exported(self):
|
|
106
|
+
"""Returns true if the artifact was writtem to disk."""
|
|
107
|
+
return bool(self.path is not None)
|
|
108
|
+
|
|
109
|
+
def validate(self):
|
|
110
|
+
"""Checker for artifact attributes for the given format."""
|
|
111
|
+
if self.fmt in [ArtifactFormat.TEXT, ArtifactFormat.SOURCE]:
|
|
112
|
+
assert self.content is not None
|
|
113
|
+
elif self.fmt in [ArtifactFormat.RAW, ArtifactFormat.BIN]:
|
|
114
|
+
assert self.raw is not None
|
|
115
|
+
elif self.fmt in [ArtifactFormat.MLF, ArtifactFormat.SHARED_OBJECT]:
|
|
116
|
+
assert self.raw is not None
|
|
117
|
+
elif self.fmt in [ArtifactFormat.PATH]:
|
|
118
|
+
assert self.path is not None
|
|
119
|
+
else:
|
|
120
|
+
raise NotImplementedError
|
|
121
|
+
|
|
122
|
+
def export(self, dest, extract=False):
|
|
123
|
+
"""Export the artifact to a given path (file or directory) and update its path.
|
|
124
|
+
|
|
125
|
+
Arguments
|
|
126
|
+
---------
|
|
127
|
+
dest : str
|
|
128
|
+
Path of the destination.
|
|
129
|
+
extract : bool
|
|
130
|
+
If archive: extract to destination.
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
if dest.is_dir():
|
|
134
|
+
filename = Path(dest) / self.name
|
|
135
|
+
else:
|
|
136
|
+
filename = Path(dest)
|
|
137
|
+
if self.fmt in [ArtifactFormat.TEXT, ArtifactFormat.SOURCE]:
|
|
138
|
+
assert not extract, "extract option is only available for ArtifactFormat.MLF"
|
|
139
|
+
with open(filename, "w", encoding="utf-8") as handle:
|
|
140
|
+
handle.write(self.content)
|
|
141
|
+
elif self.fmt in [ArtifactFormat.RAW, ArtifactFormat.BIN]:
|
|
142
|
+
assert not extract, "extract option is only available for ArtifactFormat.MLF"
|
|
143
|
+
with open(filename, "wb") as handle:
|
|
144
|
+
handle.write(self.raw)
|
|
145
|
+
elif self.fmt in [ArtifactFormat.MLF, ArtifactFormat.SHARED_OBJECT]:
|
|
146
|
+
with open(filename, "wb") as handle:
|
|
147
|
+
handle.write(self.raw)
|
|
148
|
+
if extract:
|
|
149
|
+
utils.extract(filename, dest)
|
|
150
|
+
# os.remove(filename)
|
|
151
|
+
elif self.fmt in [ArtifactFormat.PATH]:
|
|
152
|
+
assert not extract, "extract option is only available for ArtifactFormat.MLF"
|
|
153
|
+
utils.copy(self.path, filename)
|
|
154
|
+
else:
|
|
155
|
+
raise NotImplementedError
|
|
156
|
+
self.path = filename if self.path is None else self.path
|
|
157
|
+
|
|
158
|
+
def print_summary(self):
|
|
159
|
+
"""Utility to print information about an artifact to the cmdline."""
|
|
160
|
+
print("Format:", self.fmt)
|
|
161
|
+
print("Optional: ", self.optional)
|
|
162
|
+
if self.fmt in [ArtifactFormat.TEXT, ArtifactFormat.SOURCE]:
|
|
163
|
+
print("Content:")
|
|
164
|
+
print(self.content)
|
|
165
|
+
elif self.fmt in [ArtifactFormat.RAW, ArtifactFormat.BIN]:
|
|
166
|
+
print(f"Data Size: {len(self.raw)}B")
|
|
167
|
+
elif self.fmt in [ArtifactFormat.MLF, ArtifactFormat.SHARED_OBJECT]:
|
|
168
|
+
print(f"Archive Size: {len(self.raw)}B")
|
|
169
|
+
elif self.fmt in [ArtifactFormat.PATH]:
|
|
170
|
+
print(f"File Location: {self.path}")
|
|
171
|
+
else:
|
|
172
|
+
raise NotImplementedError
|
mlonmcu/cli/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
"""Submodule handling the command line interface for mlonmcu."""
|
mlonmcu/cli/build.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
"""Command line subcommand for the build process."""
|
|
20
|
+
|
|
21
|
+
from mlonmcu.flow import get_available_backend_names
|
|
22
|
+
from mlonmcu.cli.common import kickoff_runs
|
|
23
|
+
from mlonmcu.cli.load import handle as handle_load, add_load_options
|
|
24
|
+
from mlonmcu.context.context import MlonMcuContext
|
|
25
|
+
from mlonmcu.session.run import RunStage
|
|
26
|
+
from mlonmcu.platform.lookup import get_platforms_targets, get_platforms_backends
|
|
27
|
+
from .helper.parse import (
|
|
28
|
+
extract_backend_names,
|
|
29
|
+
extract_target_names,
|
|
30
|
+
extract_platform_names,
|
|
31
|
+
extract_config_and_feature_names,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def add_build_options(parser):
|
|
36
|
+
# TODO: rename to build_group
|
|
37
|
+
add_load_options(parser)
|
|
38
|
+
build_parser = parser.add_argument_group("build options")
|
|
39
|
+
build_parser.add_argument(
|
|
40
|
+
"-b",
|
|
41
|
+
"--backend",
|
|
42
|
+
type=str,
|
|
43
|
+
action="append",
|
|
44
|
+
choices=get_available_backend_names(),
|
|
45
|
+
help="Backends to use (default: %(default)s)",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_parser(subparsers, parent=None):
|
|
50
|
+
""" "Define and return a subparser for the build subcommand."""
|
|
51
|
+
parser = subparsers.add_parser(
|
|
52
|
+
"build",
|
|
53
|
+
description="Build model using the ML on MCU flow.",
|
|
54
|
+
parents=[parent] if parent else [],
|
|
55
|
+
add_help=(parent is None),
|
|
56
|
+
)
|
|
57
|
+
parser.set_defaults(flow_func=handle)
|
|
58
|
+
add_build_options(parser)
|
|
59
|
+
return parser
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _handle(args, context, require_target=False):
|
|
63
|
+
handle_load(args, ctx=context)
|
|
64
|
+
backends = extract_backend_names(args, context=context)
|
|
65
|
+
targets = extract_target_names(args, context=context if require_target else None)
|
|
66
|
+
platforms = extract_platform_names(args, context=context)
|
|
67
|
+
|
|
68
|
+
new_config, _, _, _ = extract_config_and_feature_names(args, context=context)
|
|
69
|
+
platform_backends = get_platforms_backends(context, config=new_config) # This will be slow?
|
|
70
|
+
platform_targets = get_platforms_targets(context, config=new_config) # This will be slow?
|
|
71
|
+
|
|
72
|
+
assert len(context.sessions) > 0
|
|
73
|
+
session = context.sessions[-1]
|
|
74
|
+
new_runs = []
|
|
75
|
+
for run in session.runs:
|
|
76
|
+
for target_name in targets:
|
|
77
|
+
for backend_name in backends:
|
|
78
|
+
new_run = run.copy()
|
|
79
|
+
if backend_name is not None:
|
|
80
|
+
platform_name = None
|
|
81
|
+
for platform in platforms:
|
|
82
|
+
candidates = platform_backends[platform]
|
|
83
|
+
if backend_name in candidates:
|
|
84
|
+
try:
|
|
85
|
+
platform_name = platform
|
|
86
|
+
new_run.add_platform_by_name(platform_name, context=context)
|
|
87
|
+
break
|
|
88
|
+
except AssertionError: # TODO: replace with incompatble error
|
|
89
|
+
platform_name = None
|
|
90
|
+
continue
|
|
91
|
+
# assert (
|
|
92
|
+
# platform_name is not None
|
|
93
|
+
# ), f"Unable to find a suitable platform for the backend '{target_name}'"
|
|
94
|
+
# assert platform_name is not None
|
|
95
|
+
|
|
96
|
+
if target_name is not None:
|
|
97
|
+
platform_name = None
|
|
98
|
+
for platform in platforms:
|
|
99
|
+
candidates = platform_targets[platform]
|
|
100
|
+
if target_name in candidates:
|
|
101
|
+
platform_name = platform
|
|
102
|
+
assert (
|
|
103
|
+
platform_name is not None
|
|
104
|
+
), f"Unable to find a suitable platform for the target '{target_name}'"
|
|
105
|
+
new_run.add_platform_by_name(platform_name, context=context)
|
|
106
|
+
new_run.add_target_by_name(target_name, context=context)
|
|
107
|
+
new_run.add_backend_by_name(backend_name, context=context)
|
|
108
|
+
new_runs.append(new_run)
|
|
109
|
+
|
|
110
|
+
session.runs = new_runs
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def handle(args, ctx=None, require_target=False):
|
|
114
|
+
if ctx:
|
|
115
|
+
_handle(args, ctx, require_target=require_target)
|
|
116
|
+
else:
|
|
117
|
+
with MlonMcuContext(path=args.home, deps_lock="read") as context:
|
|
118
|
+
_handle(args, context, require_target=require_target)
|
|
119
|
+
kickoff_runs(args, RunStage.BUILD, context)
|
mlonmcu/cli/cleanup.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
"""Command line subcommand for cleaning up the current environment."""
|
|
20
|
+
from mlonmcu.context.context import MlonMcuContext
|
|
21
|
+
from mlonmcu.setup import setup
|
|
22
|
+
|
|
23
|
+
from mlonmcu.cli.common import (
|
|
24
|
+
add_common_options,
|
|
25
|
+
add_context_options,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_parser(subparsers):
|
|
30
|
+
""" "Define and return a subparser for the cleanup subcommand."""
|
|
31
|
+
parser = subparsers.add_parser("cleanup", description="Cleanup ML on MCU environment.")
|
|
32
|
+
parser.set_defaults(func=handle)
|
|
33
|
+
add_common_options(parser)
|
|
34
|
+
add_context_options(parser)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"-f",
|
|
37
|
+
"--force",
|
|
38
|
+
default=False,
|
|
39
|
+
action="store_true",
|
|
40
|
+
help="Do not ask before removing disk contents (DANGEROUS)",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"-k",
|
|
44
|
+
"--keep",
|
|
45
|
+
metavar="KEEP",
|
|
46
|
+
type=int,
|
|
47
|
+
default=10,
|
|
48
|
+
help="Remove everything except the latest KEEP sessions (default: %(default)s)",
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--deps",
|
|
52
|
+
default=False,
|
|
53
|
+
action="store_true",
|
|
54
|
+
help="Also delete all dependencies from the environment.",
|
|
55
|
+
)
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--cache",
|
|
58
|
+
default=False,
|
|
59
|
+
action="store_true",
|
|
60
|
+
help="Clear the environments dependency cache.",
|
|
61
|
+
)
|
|
62
|
+
return parser
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def handle(args):
|
|
66
|
+
with MlonMcuContext(path=args.home, deps_lock="write") as context:
|
|
67
|
+
interactive = not args.force
|
|
68
|
+
keep = args.keep
|
|
69
|
+
context.cleanup_sessions(keep=keep, interactive=interactive)
|
|
70
|
+
installer = setup.Setup(context=context)
|
|
71
|
+
if args.deps:
|
|
72
|
+
# This will also remove the cache file
|
|
73
|
+
installer.clean_dependencies(interactive=interactive)
|
|
74
|
+
elif args.cache:
|
|
75
|
+
installer.clean_cache(interactive=interactive)
|
mlonmcu/cli/common.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
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 os
|
|
20
|
+
import sys
|
|
21
|
+
import multiprocessing
|
|
22
|
+
import logging
|
|
23
|
+
|
|
24
|
+
from mlonmcu.platform import get_platforms
|
|
25
|
+
from mlonmcu.session.postprocess import SUPPORTED_POSTPROCESSES
|
|
26
|
+
from mlonmcu.feature.features import get_available_feature_names
|
|
27
|
+
from mlonmcu.logging import get_logger, set_log_level
|
|
28
|
+
from .helper.parse import extract_config
|
|
29
|
+
|
|
30
|
+
logger = get_logger()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def handle_logging_flags(args):
|
|
34
|
+
if hasattr(args, "verbose") and hasattr(args, "quiet"):
|
|
35
|
+
if args.verbose and args.quiet:
|
|
36
|
+
raise RuntimeError("--verbose and --quiet can not be used at the same time")
|
|
37
|
+
elif args.verbose:
|
|
38
|
+
set_log_level(logging.DEBUG)
|
|
39
|
+
elif args.quiet:
|
|
40
|
+
set_log_level(logging.WARNING)
|
|
41
|
+
else:
|
|
42
|
+
set_log_level(logging.INFO)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def add_flow_options(parser):
|
|
46
|
+
flow_parser = parser.add_argument_group("flow options")
|
|
47
|
+
flow_parser.add_argument( # TODO: move to compile.py?
|
|
48
|
+
"-t",
|
|
49
|
+
"--target",
|
|
50
|
+
type=str,
|
|
51
|
+
metavar="TARGET",
|
|
52
|
+
# choices=SUPPORTED_TARGETS.keys(),
|
|
53
|
+
action="append",
|
|
54
|
+
# default=None,
|
|
55
|
+
# nargs=1,
|
|
56
|
+
help="The target device/architecture (choices: See --list-targets)",
|
|
57
|
+
)
|
|
58
|
+
flow_parser.add_argument( # TODO: move to compile.py?
|
|
59
|
+
"--list-targets",
|
|
60
|
+
action="store_true",
|
|
61
|
+
help="List the supported targets in the environment",
|
|
62
|
+
)
|
|
63
|
+
flow_parser.add_argument(
|
|
64
|
+
# "-p",
|
|
65
|
+
"--platform",
|
|
66
|
+
type=str,
|
|
67
|
+
metavar="PLATFORM",
|
|
68
|
+
choices=get_platforms().keys(),
|
|
69
|
+
default=None,
|
|
70
|
+
action="append",
|
|
71
|
+
nargs=1,
|
|
72
|
+
help="Explicitly choose the platforms to use (choices: %(choices)s)",
|
|
73
|
+
)
|
|
74
|
+
flow_parser.add_argument(
|
|
75
|
+
# "-p",
|
|
76
|
+
"--postprocess",
|
|
77
|
+
type=str,
|
|
78
|
+
metavar="POSTPROCESS",
|
|
79
|
+
choices=SUPPORTED_POSTPROCESSES.keys(),
|
|
80
|
+
action="append",
|
|
81
|
+
help="Choose the postprocesses to apply (choices: %(choices)s)",
|
|
82
|
+
)
|
|
83
|
+
flow_parser.add_argument(
|
|
84
|
+
"-f",
|
|
85
|
+
"--feature",
|
|
86
|
+
type=str,
|
|
87
|
+
metavar="FEATURE",
|
|
88
|
+
# nargs=1,
|
|
89
|
+
action="append",
|
|
90
|
+
choices=get_available_feature_names(),
|
|
91
|
+
help="Enabled features for target/framework/backend (choices: %(choices)s)",
|
|
92
|
+
)
|
|
93
|
+
flow_parser.add_argument(
|
|
94
|
+
"--feature-gen",
|
|
95
|
+
dest="feature_gen",
|
|
96
|
+
type=str,
|
|
97
|
+
metavar="FEATURES",
|
|
98
|
+
nargs="+",
|
|
99
|
+
action="append",
|
|
100
|
+
help="Generator statement for features.",
|
|
101
|
+
)
|
|
102
|
+
flow_parser.add_argument(
|
|
103
|
+
"-c",
|
|
104
|
+
"--config",
|
|
105
|
+
metavar="KEY=VALUE",
|
|
106
|
+
nargs="+",
|
|
107
|
+
action="append",
|
|
108
|
+
help=(
|
|
109
|
+
"Set a number of key-value pairs "
|
|
110
|
+
"(do not put spaces before or after the = sign). "
|
|
111
|
+
"If a value contains spaces, you should define "
|
|
112
|
+
"it with double quotes: "
|
|
113
|
+
'foo="this is a sentence". Note that '
|
|
114
|
+
"values are always treated as strings."
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
flow_parser.add_argument(
|
|
118
|
+
"--config-gen",
|
|
119
|
+
dest="config_gen",
|
|
120
|
+
metavar="KEY=VALUE",
|
|
121
|
+
nargs="+",
|
|
122
|
+
action="append",
|
|
123
|
+
help="Generator statement for configs.",
|
|
124
|
+
)
|
|
125
|
+
flow_parser.add_argument(
|
|
126
|
+
"--parallel",
|
|
127
|
+
metavar="THREADS",
|
|
128
|
+
nargs="?",
|
|
129
|
+
type=int,
|
|
130
|
+
const=multiprocessing.cpu_count(),
|
|
131
|
+
default=1,
|
|
132
|
+
help="Use multiple threads to process runs in parallel (%(const)s if specified, else %(default)s)",
|
|
133
|
+
)
|
|
134
|
+
flow_parser.add_argument(
|
|
135
|
+
"-p",
|
|
136
|
+
"--progress",
|
|
137
|
+
action="store_true",
|
|
138
|
+
help="Display progress bar (default: %(default)s)",
|
|
139
|
+
)
|
|
140
|
+
flow_parser.add_argument(
|
|
141
|
+
"--resume",
|
|
142
|
+
action="store_true",
|
|
143
|
+
help="Try to resume the latest session (default: %(default)s)",
|
|
144
|
+
)
|
|
145
|
+
flow_parser.add_argument( # TODO: move to compile.py?
|
|
146
|
+
"-l",
|
|
147
|
+
"--label",
|
|
148
|
+
type=str,
|
|
149
|
+
metavar="LABEL",
|
|
150
|
+
default="",
|
|
151
|
+
help="Label for the session (default: %(default)s)",
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def add_common_options(parser):
|
|
156
|
+
parser.add_argument(
|
|
157
|
+
"-v",
|
|
158
|
+
"--verbose",
|
|
159
|
+
action="store_true",
|
|
160
|
+
help="Print detailed messages for easier debugging (default: %(default)s)",
|
|
161
|
+
)
|
|
162
|
+
parser.add_argument(
|
|
163
|
+
"-q",
|
|
164
|
+
"--quiet",
|
|
165
|
+
action="store_true",
|
|
166
|
+
help="Reduce number of logging statements to a minimum (default: %(default)s)",
|
|
167
|
+
)
|
|
168
|
+
parser.add_argument(
|
|
169
|
+
"--docker",
|
|
170
|
+
action="store_true",
|
|
171
|
+
help="Execute run.py inside docker container (default: %(default)s)",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def add_context_options(parser, with_home=True):
|
|
176
|
+
common = parser.add_argument_group("context options")
|
|
177
|
+
if with_home:
|
|
178
|
+
home = os.getenv("MLONMCU_HOME", None)
|
|
179
|
+
common.add_argument(
|
|
180
|
+
"-H",
|
|
181
|
+
"--home",
|
|
182
|
+
"--hint",
|
|
183
|
+
type=str,
|
|
184
|
+
default=home,
|
|
185
|
+
help="The path to the mlonmcu environment (overwriting $MLONMCU_HOME environment variable)",
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def add_model_options(parser):
|
|
190
|
+
parser.add_argument(
|
|
191
|
+
"models",
|
|
192
|
+
metavar="model",
|
|
193
|
+
type=str,
|
|
194
|
+
nargs="+",
|
|
195
|
+
default=None,
|
|
196
|
+
help="Model to process",
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def kickoff_runs(args, until, context):
|
|
201
|
+
assert len(context.sessions) > 0
|
|
202
|
+
session = context.sessions[-1]
|
|
203
|
+
# session.label = args.label
|
|
204
|
+
config = extract_config(args)
|
|
205
|
+
# TODO: move into context/session
|
|
206
|
+
per_stage = True
|
|
207
|
+
print_report = True
|
|
208
|
+
if "runs_per_stage" in config:
|
|
209
|
+
per_stage = bool(config["runs_per_stage"])
|
|
210
|
+
elif "runs_per_stage" in context.environment.vars:
|
|
211
|
+
per_stage = bool(context.environment.vars["runs_per_stage"])
|
|
212
|
+
if "print_report" in config:
|
|
213
|
+
print_report = bool(config["print_report"])
|
|
214
|
+
elif "print_report" in context.environment.vars:
|
|
215
|
+
print_report = bool(context.environment.vars["print_report"])
|
|
216
|
+
success = session.process_runs(
|
|
217
|
+
until=until,
|
|
218
|
+
per_stage=per_stage,
|
|
219
|
+
print_report=print_report,
|
|
220
|
+
num_workers=args.parallel,
|
|
221
|
+
progress=args.progress,
|
|
222
|
+
context=context,
|
|
223
|
+
export=True,
|
|
224
|
+
)
|
|
225
|
+
if not success:
|
|
226
|
+
logger.error("At least one error occured!")
|
|
227
|
+
sys.exit(1)
|