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,580 @@
|
|
|
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
|
+
"""MicroTVM Platform"""
|
|
20
|
+
|
|
21
|
+
import re
|
|
22
|
+
import tempfile
|
|
23
|
+
import concurrent
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
from mlonmcu.setup import utils
|
|
27
|
+
from mlonmcu.config import str2bool
|
|
28
|
+
from mlonmcu.logging import get_logger
|
|
29
|
+
from mlonmcu.artifact import Artifact, ArtifactFormat
|
|
30
|
+
|
|
31
|
+
from mlonmcu.flow.tvm.backend.python_utils import prepare_python_environment
|
|
32
|
+
from mlonmcu.flow.tvm.backend.tvmc_utils import (
|
|
33
|
+
get_bench_tvmc_args,
|
|
34
|
+
get_data_tvmc_args,
|
|
35
|
+
get_target_tvmc_args,
|
|
36
|
+
get_rpc_tvmc_args,
|
|
37
|
+
)
|
|
38
|
+
from mlonmcu.flow.tvm.backend.tuner import TVMTuner
|
|
39
|
+
|
|
40
|
+
from ..platform import CompilePlatform, TargetPlatform, BuildPlatform, TunePlatform
|
|
41
|
+
from .microtvm_target import create_microtvm_platform_target, get_microtvm_platform_targets
|
|
42
|
+
from .microtvm_backend import create_microtvm_platform_backend, get_microtvm_platform_backends
|
|
43
|
+
|
|
44
|
+
logger = get_logger()
|
|
45
|
+
# TODO: This file is very similar to the TVM platform -> Reuse as much as possible
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_project_options_from_stdout(out):
|
|
49
|
+
return re.compile(r"^\s+([A-Za-z0-9_]+)=", re.MULTILINE).findall(out)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def filter_project_options(valid, options):
|
|
53
|
+
return {key: value for key, value in options.items() if key in valid}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_project_option_args(template, stage, project_options):
|
|
57
|
+
ret = []
|
|
58
|
+
for key, value in project_options.items():
|
|
59
|
+
ret.append(f"{key}={value}")
|
|
60
|
+
|
|
61
|
+
if len(ret) > 0:
|
|
62
|
+
ret = ["--project-option"] + ret
|
|
63
|
+
|
|
64
|
+
return ret
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MicroTvmPlatform(CompilePlatform, TargetPlatform, BuildPlatform, TunePlatform):
|
|
68
|
+
"""TVM Platform class."""
|
|
69
|
+
|
|
70
|
+
FEATURES = (
|
|
71
|
+
CompilePlatform.FEATURES + TargetPlatform.FEATURES + ["autotune", "tvm_rpc", "tvm_profile"]
|
|
72
|
+
) # TODO: validate?
|
|
73
|
+
|
|
74
|
+
DEFAULTS = {
|
|
75
|
+
**CompilePlatform.DEFAULTS,
|
|
76
|
+
**TargetPlatform.DEFAULTS,
|
|
77
|
+
"project_template": None,
|
|
78
|
+
"project_options": {},
|
|
79
|
+
"project_dir": None,
|
|
80
|
+
"fill_mode": "random",
|
|
81
|
+
"ins_file": None,
|
|
82
|
+
"outs_file": None,
|
|
83
|
+
"print_top": False,
|
|
84
|
+
"profile": False,
|
|
85
|
+
"repeat": 1,
|
|
86
|
+
"use_rpc": False,
|
|
87
|
+
"rpc_key": None,
|
|
88
|
+
"rpc_hostname": None,
|
|
89
|
+
"rpc_port": None,
|
|
90
|
+
"tvmc_extra_args": [],
|
|
91
|
+
"tvmc_custom_script": None,
|
|
92
|
+
"experimental_tvmc_micro_tune": False,
|
|
93
|
+
"experimental_tvmc_tune_tasks": False,
|
|
94
|
+
"experimental_autotvm_visualize": False,
|
|
95
|
+
"experimental_tvmc_print_time": False,
|
|
96
|
+
**{("autotuning_" + key): value for key, value in TVMTuner.DEFAULTS.items()},
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
REQUIRED = ["tvm.build_dir", "tvm.pythonpath", "tvm.configs_dir"]
|
|
100
|
+
|
|
101
|
+
def __init__(self, features=None, config=None):
|
|
102
|
+
super().__init__(
|
|
103
|
+
"microtvm", # Actually: tvmllvm
|
|
104
|
+
features=features,
|
|
105
|
+
config=config,
|
|
106
|
+
)
|
|
107
|
+
self.tempdir = None
|
|
108
|
+
self.project_name = "app"
|
|
109
|
+
self.project_dir = None
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def project_options(self):
|
|
113
|
+
opts = self.config["project_options"]
|
|
114
|
+
if isinstance(opts, str):
|
|
115
|
+
opts_split = opts.split(" ")
|
|
116
|
+
opts = {}
|
|
117
|
+
for opt in opts_split:
|
|
118
|
+
key, value = opt.split("=")[:2]
|
|
119
|
+
opts[key] = value
|
|
120
|
+
assert isinstance(opts, dict)
|
|
121
|
+
return opts
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def fill_mode(self):
|
|
125
|
+
return self.config["fill_mode"]
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def ins_file(self):
|
|
129
|
+
return self.config["ins_file"]
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def outs_file(self):
|
|
133
|
+
return self.config["outs_file"]
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def print_top(self):
|
|
137
|
+
return self.config["print_top"]
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def profile(self):
|
|
141
|
+
value = self.config["profile"]
|
|
142
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def repeat(self):
|
|
146
|
+
return self.config["repeat"]
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def use_rpc(self):
|
|
150
|
+
value = self.config["use_rpc"]
|
|
151
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def rpc_key(self):
|
|
155
|
+
return self.config["rpc_key"]
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def rpc_hostname(self):
|
|
159
|
+
return self.config["rpc_hostname"]
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def rpc_port(self):
|
|
163
|
+
return self.config["rpc_port"]
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def tvmc_extra_args(self):
|
|
167
|
+
return self.config["tvmc_extra_args"]
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def tvmc_custom_script(self):
|
|
171
|
+
return self.config["tvmc_custom_script"]
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
def tvm_pythonpath(self):
|
|
175
|
+
return self.config["tvm.pythonpath"]
|
|
176
|
+
|
|
177
|
+
@property
|
|
178
|
+
def tvm_build_dir(self):
|
|
179
|
+
return self.config["tvm.build_dir"]
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def tvm_configs_dir(self):
|
|
183
|
+
return self.config["tvm.configs_dir"]
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def project_template(self):
|
|
187
|
+
return self.config["project_template"]
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def visualize_tuning(self):
|
|
191
|
+
# Visualize the tuning progress via matplotlib
|
|
192
|
+
value = self.config["visualize_tuning"]
|
|
193
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def tune_tasks(self):
|
|
197
|
+
# Effectively select which tasks should be tuned in the session
|
|
198
|
+
return self.config["tune_tasks"]
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
def experimental_tvmc_micro_tune(self):
|
|
202
|
+
value = self.config["experimental_tvmc_micro_tune"]
|
|
203
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def experimental_tvmc_tune_tasks(self):
|
|
207
|
+
value = self.config["experimental_tvmc_tune_tasks"]
|
|
208
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def experimental_tvmc_tune_visualize(self):
|
|
212
|
+
value = self.config["experimental_tvmc_tune_visualize"]
|
|
213
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def experimental_tvmc_print_time(self):
|
|
217
|
+
value = self.config["experimental_tvmc_print_time"]
|
|
218
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
219
|
+
|
|
220
|
+
def init_directory(self, path=None, context=None):
|
|
221
|
+
if self.project_dir is not None:
|
|
222
|
+
self.project_dir.mkdir(exist_ok=True)
|
|
223
|
+
logger.debug("Project directory already initialized")
|
|
224
|
+
return
|
|
225
|
+
dir_name = self.name
|
|
226
|
+
if path is not None:
|
|
227
|
+
self.project_dir = Path(path)
|
|
228
|
+
elif self.config["project_dir"] is not None:
|
|
229
|
+
self.project_dir = Path(self.config["project_dir"])
|
|
230
|
+
else:
|
|
231
|
+
if context:
|
|
232
|
+
assert "temp" in context.environment.paths
|
|
233
|
+
self.project_dir = (
|
|
234
|
+
context.environment.paths["temp"].path / dir_name
|
|
235
|
+
) # TODO: Need to lock this for parallel builds
|
|
236
|
+
else:
|
|
237
|
+
logger.debug(
|
|
238
|
+
"Creating temporary directory because no context was available "
|
|
239
|
+
"and 'espidf.project_dir' was not supplied"
|
|
240
|
+
)
|
|
241
|
+
self.tempdir = tempfile.TemporaryDirectory()
|
|
242
|
+
self.project_dir = Path(self.tempdir.name) / dir_name
|
|
243
|
+
logger.debug("Temporary project directory: %s", self.project_dir)
|
|
244
|
+
self.project_dir.mkdir(exist_ok=True)
|
|
245
|
+
|
|
246
|
+
def get_supported_backends(self):
|
|
247
|
+
backend_names = get_microtvm_platform_backends()
|
|
248
|
+
return backend_names
|
|
249
|
+
|
|
250
|
+
def create_backend(self, name):
|
|
251
|
+
supported = self.get_supported_backends()
|
|
252
|
+
assert name in supported, f"{name} is not a valid MicroTVM platform backend"
|
|
253
|
+
base = supported[name]
|
|
254
|
+
return create_microtvm_platform_backend(name, self, base=base)
|
|
255
|
+
|
|
256
|
+
def get_supported_targets(self):
|
|
257
|
+
return get_microtvm_platform_targets()
|
|
258
|
+
|
|
259
|
+
def create_target(self, name):
|
|
260
|
+
supported = self.get_supported_targets()
|
|
261
|
+
assert name in supported, f"{name} is not a valid MicroTVM device"
|
|
262
|
+
base = supported[name]
|
|
263
|
+
return create_microtvm_platform_target(name, self, base=base)
|
|
264
|
+
|
|
265
|
+
def get_tvmc_run_args(self, path, device, list_options=False):
|
|
266
|
+
if self.use_rpc:
|
|
267
|
+
raise RuntimeError("RPC is only supported for tuning with microtvm platform")
|
|
268
|
+
if self.profile:
|
|
269
|
+
assert (
|
|
270
|
+
self.experimental_tvmc_print_time
|
|
271
|
+
), "MicroTVM profiloing is only supported in environments with microtvm.experimental_tvmc_print_time=1"
|
|
272
|
+
ret = [
|
|
273
|
+
path,
|
|
274
|
+
*["--device", device],
|
|
275
|
+
*get_data_tvmc_args(
|
|
276
|
+
mode=self.fill_mode, ins_file=self.ins_file, outs_file=self.outs_file, print_top=self.print_top
|
|
277
|
+
),
|
|
278
|
+
*get_bench_tvmc_args(
|
|
279
|
+
print_time=self.experimental_tvmc_print_time and not self.profile,
|
|
280
|
+
profile=self.profile and self.experimental_tvmc_print_time,
|
|
281
|
+
end_to_end=False,
|
|
282
|
+
# repeat=self.repeat if self.experimental_tvmc_print_time else None,
|
|
283
|
+
# number=self.number if self.experimental_tvmc_print_time else None,
|
|
284
|
+
),
|
|
285
|
+
# *get_rpc_tvmc_args(self.use_rpc, self.rpc_key, self.rpc_hostname, self.rpc_port),
|
|
286
|
+
]
|
|
287
|
+
if list_options:
|
|
288
|
+
ret.append("--list-options")
|
|
289
|
+
return ret
|
|
290
|
+
|
|
291
|
+
def get_tvmc_micro_args(self, command, path, mlf_path, template, list_options=False, tune_args=None):
|
|
292
|
+
ret = [command]
|
|
293
|
+
if "create" in command:
|
|
294
|
+
ret.extend(["--force", path, mlf_path])
|
|
295
|
+
elif command == "tune":
|
|
296
|
+
if tune_args:
|
|
297
|
+
ret.extend(tune_args)
|
|
298
|
+
if list_options:
|
|
299
|
+
ret.extend(["--output", "-", "_"])
|
|
300
|
+
else:
|
|
301
|
+
ret.append(path)
|
|
302
|
+
ret.extend(template)
|
|
303
|
+
if list_options:
|
|
304
|
+
ret.append("--help")
|
|
305
|
+
return ret
|
|
306
|
+
|
|
307
|
+
def invoke_tvmc(self, command, *args, target=None, prefix=""):
|
|
308
|
+
env = prepare_python_environment(self.tvm_pythonpath, self.tvm_build_dir, self.tvm_configs_dir)
|
|
309
|
+
if target:
|
|
310
|
+
target.update_environment(env)
|
|
311
|
+
if self.tvmc_custom_script is None:
|
|
312
|
+
pre = ["-m", "tvm.driver.tvmc"]
|
|
313
|
+
else:
|
|
314
|
+
pre = [self.tvmc_custom_script]
|
|
315
|
+
return utils.python(*pre, command, *args, live=self.print_outputs, print_output=False, env=env, prefix=prefix)
|
|
316
|
+
|
|
317
|
+
def collect_available_project_options(self, command, path, mlf_path, template, micro=True, target=None):
|
|
318
|
+
args = self.get_tvmc_micro_args(command, path, mlf_path, template, list_options=True)
|
|
319
|
+
out = self.invoke_tvmc("micro", *args, target=target)
|
|
320
|
+
return parse_project_options_from_stdout(out)
|
|
321
|
+
|
|
322
|
+
def invoke_tvmc_micro(
|
|
323
|
+
self, command, path, mlf_path, template, target, extra_args=None, micro=True, tune_args=None, prefix=""
|
|
324
|
+
):
|
|
325
|
+
args = self.get_tvmc_micro_args(command, path, mlf_path, template, tune_args=tune_args)
|
|
326
|
+
options = filter_project_options(
|
|
327
|
+
self.collect_available_project_options(command, path, mlf_path, template, target=target), target.get_project_options()
|
|
328
|
+
)
|
|
329
|
+
args += get_project_option_args(template, command, options)
|
|
330
|
+
return self.invoke_tvmc("micro", *args, target=target, prefix=prefix)
|
|
331
|
+
|
|
332
|
+
def collect_available_run_project_options(self, path, device):
|
|
333
|
+
args = self.get_tvmc_run_args(path, device, list_options=True)
|
|
334
|
+
out = self.invoke_tvmc("run", *args)
|
|
335
|
+
return parse_project_options_from_stdout(out)
|
|
336
|
+
|
|
337
|
+
def invoke_tvmc_run(self, path, device, template, target, micro=True):
|
|
338
|
+
args = self.get_tvmc_run_args(path, device)
|
|
339
|
+
if micro:
|
|
340
|
+
options = filter_project_options(
|
|
341
|
+
self.collect_available_run_project_options(path, device), target.get_project_options()
|
|
342
|
+
)
|
|
343
|
+
args.extend(get_project_option_args(template, "run", options))
|
|
344
|
+
return self.invoke_tvmc("run", *args, target=target)
|
|
345
|
+
|
|
346
|
+
def close(self):
|
|
347
|
+
if self.tempdir:
|
|
348
|
+
self.tempdir.cleanup()
|
|
349
|
+
|
|
350
|
+
def get_template_args(self, target):
|
|
351
|
+
template = target.template
|
|
352
|
+
if target.template_path:
|
|
353
|
+
template = "template"
|
|
354
|
+
template_path = target.template_path
|
|
355
|
+
else:
|
|
356
|
+
if template == "template":
|
|
357
|
+
assert self.project_template is not None
|
|
358
|
+
template_path = self.project_template
|
|
359
|
+
else:
|
|
360
|
+
template_path = None
|
|
361
|
+
if template_path:
|
|
362
|
+
return ("template", "--template-dir", template_path)
|
|
363
|
+
else:
|
|
364
|
+
return (template,)
|
|
365
|
+
|
|
366
|
+
def prepare(self, mlf, target):
|
|
367
|
+
out = self.invoke_tvmc_micro("create", self.project_dir, mlf, self.get_template_args(target), target)
|
|
368
|
+
return out
|
|
369
|
+
|
|
370
|
+
def compile(self, target):
|
|
371
|
+
out = ""
|
|
372
|
+
# TODO: build with cmake options
|
|
373
|
+
out += self.invoke_tvmc_micro("build", self.project_dir, None, self.get_template_args(target), target)
|
|
374
|
+
# TODO: support self.num_threads (e.g. patch esp-idf)
|
|
375
|
+
return out
|
|
376
|
+
|
|
377
|
+
def generate_elf(self, src, target, model=None, data_file=None):
|
|
378
|
+
# TODO: name missleading as we are not interested in the ELF
|
|
379
|
+
src = Path(src) / "default.tar" # TODO: lookup for *.tar file
|
|
380
|
+
artifacts = []
|
|
381
|
+
out = self.prepare(src, target)
|
|
382
|
+
out += self.compile(target)
|
|
383
|
+
stdout_artifact = Artifact(
|
|
384
|
+
"microtvm_out.log", content=out, fmt=ArtifactFormat.TEXT # TODO: split into one file per command
|
|
385
|
+
)
|
|
386
|
+
artifacts.append(stdout_artifact)
|
|
387
|
+
self.artifacts = artifacts
|
|
388
|
+
|
|
389
|
+
def flash(self, elf, target, timeout=120):
|
|
390
|
+
# Ignore elf, as we use self.project_dir instead
|
|
391
|
+
# TODO: add alternative approach which allows passing elf instead
|
|
392
|
+
if elf is not None:
|
|
393
|
+
logger.debug("Ignoring ELF file for microtvm platform")
|
|
394
|
+
# TODO: implement timeout
|
|
395
|
+
logger.debug("Flashing target software using MicroTVM ProjectAPI")
|
|
396
|
+
output = self.invoke_tvmc_micro("flash", self.project_dir, None, self.get_template_args(target), target)
|
|
397
|
+
return output
|
|
398
|
+
|
|
399
|
+
def run(self, elf, target, timeout=120):
|
|
400
|
+
# TODO: implement timeout
|
|
401
|
+
output = self.flash(elf, target)
|
|
402
|
+
output += self.invoke_tvmc_run(
|
|
403
|
+
str(self.project_dir), "micro", self.get_template_args(target), target, micro=True
|
|
404
|
+
)
|
|
405
|
+
return output
|
|
406
|
+
|
|
407
|
+
def get_micro_tune_args(self, model, backend, out):
|
|
408
|
+
tuner = self.config.get("autotuning_tuner", "ga")
|
|
409
|
+
assert tuner in ["ga", "gridsearch", "random", "xgb", "xgb_knob", "xgb-rank"]
|
|
410
|
+
trials = self.config.get("autotuning_trials", 10)
|
|
411
|
+
if not isinstance(trials, int):
|
|
412
|
+
trials = int(trials)
|
|
413
|
+
early_stopping = self.config.get("autotuning_early_stopping", None)
|
|
414
|
+
if early_stopping is None:
|
|
415
|
+
early_stopping = max(trials, 10) # Let's see if this default works out...
|
|
416
|
+
early_stopping = int(early_stopping)
|
|
417
|
+
max_parallel = int(self.config.get("autotuning_max_parallel", 1))
|
|
418
|
+
timeout = int(self.config.get("autotuning_timeout", 1000))
|
|
419
|
+
results_file = self.config.get("autotuning_results_file", None)
|
|
420
|
+
desired_layout = backend.config.get("desired_layout", None)
|
|
421
|
+
ret = [
|
|
422
|
+
*get_target_tvmc_args(
|
|
423
|
+
"c",
|
|
424
|
+
extra_target=backend.extra_target,
|
|
425
|
+
target_details=backend.get_target_details(),
|
|
426
|
+
),
|
|
427
|
+
*(["--desired-layout", desired_layout] if desired_layout is not None else []),
|
|
428
|
+
*get_rpc_tvmc_args(self.use_rpc, self.rpc_key, self.rpc_hostname, self.rpc_port),
|
|
429
|
+
# TODO: missing: pass config, disabled_pass, etc.
|
|
430
|
+
*["--tuner", tuner],
|
|
431
|
+
*(["--early-stopping", str(early_stopping)] if early_stopping > 0 else []),
|
|
432
|
+
*["--parallel", str(max_parallel)],
|
|
433
|
+
*["--timeout", str(timeout * max_parallel)],
|
|
434
|
+
*["--trials", str(trials)],
|
|
435
|
+
*["--number", str(1)], # TODO: variable
|
|
436
|
+
*["--repeat", str(1)], # TODO: variable
|
|
437
|
+
*(["--tuning-records", results_file] if results_file is not None else []),
|
|
438
|
+
*["--output", str(out)],
|
|
439
|
+
# "--target-c-link-params",
|
|
440
|
+
# "1",
|
|
441
|
+
]
|
|
442
|
+
if self.config["autotuning_visualize"]:
|
|
443
|
+
assert (
|
|
444
|
+
self.experimental_tvmc_tune_tasks
|
|
445
|
+
), f"{self.name}.visualize_tuning requires experimental_autotvm_visualize"
|
|
446
|
+
ret.append("--visualize")
|
|
447
|
+
if self.config["autotuning_tasks"]:
|
|
448
|
+
assert self.experimental_tvmc_tune_tasks, f"{self.name}.tune_tasks requires experimental_tvmc_tune_tasks"
|
|
449
|
+
ret.extend(["--tasks", str(self.config["autotuning_tasks"])])
|
|
450
|
+
ret.append(model)
|
|
451
|
+
return ret
|
|
452
|
+
|
|
453
|
+
def tune_model(self, model_path, backend, target):
|
|
454
|
+
assert self.experimental_tvmc_micro_tune, "Microtvm tuning requires experimental_tvmc_micro_tune"
|
|
455
|
+
enable = self.config["autotuning_enable"]
|
|
456
|
+
results_file = self.config["autotuning_results_file"]
|
|
457
|
+
append = self.config["autotuning_append"]
|
|
458
|
+
num_workers = int(self.config["autotuning_num_workers"])
|
|
459
|
+
artifacts = []
|
|
460
|
+
verbose = False
|
|
461
|
+
if self.print_outputs:
|
|
462
|
+
verbose = True
|
|
463
|
+
|
|
464
|
+
content = ""
|
|
465
|
+
if enable:
|
|
466
|
+
if append:
|
|
467
|
+
if results_file is not None:
|
|
468
|
+
with open(results_file, "r") as handle:
|
|
469
|
+
content = handle.read()
|
|
470
|
+
|
|
471
|
+
if num_workers > 1:
|
|
472
|
+
assert self.experimental_tvmc_tune_tasks, "num_workers>1 requires experimental_tvmc_tune_tasks=1"
|
|
473
|
+
# TODO: fix
|
|
474
|
+
assert self.config["autotuning_tasks"] is None, "tune_tasks not supported together with num_workers > 1"
|
|
475
|
+
|
|
476
|
+
def get_tune_tasks():
|
|
477
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
478
|
+
out_file = Path(tmp_dir) / "tuning_results.log.txt"
|
|
479
|
+
tune_args = self.get_micro_tune_args(model_path, backend, out_file)
|
|
480
|
+
out = self.invoke_tvmc_micro(
|
|
481
|
+
"tune",
|
|
482
|
+
self.project_dir,
|
|
483
|
+
None,
|
|
484
|
+
self.get_template_args(target),
|
|
485
|
+
target,
|
|
486
|
+
tune_args=tune_args + ["--task", "list"],
|
|
487
|
+
)
|
|
488
|
+
lines = out.split("\n")
|
|
489
|
+
for i, line in enumerate(lines):
|
|
490
|
+
if "Available Tasks for tuning" in line:
|
|
491
|
+
lines = lines[i + 1 :]
|
|
492
|
+
break
|
|
493
|
+
tasks = [line.split(". ", 1)[1] for line in lines if len(line.strip()) > 0]
|
|
494
|
+
return tasks
|
|
495
|
+
|
|
496
|
+
num_tasks = len(get_tune_tasks())
|
|
497
|
+
workers = []
|
|
498
|
+
with concurrent.futures.ThreadPoolExecutor(num_workers) as executor:
|
|
499
|
+
for i in range(num_tasks):
|
|
500
|
+
print(f"Created worker for task {i}")
|
|
501
|
+
|
|
502
|
+
def do_work(idx, prepend):
|
|
503
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
504
|
+
out_file = Path(tmp_dir) / "tuning_results.log.txt"
|
|
505
|
+
with open(out_file, "w") as handle:
|
|
506
|
+
handle.write(prepend)
|
|
507
|
+
tune_args = self.get_micro_tune_args(model_path, backend, out_file)
|
|
508
|
+
out = self.invoke_tvmc_micro(
|
|
509
|
+
"tune",
|
|
510
|
+
self.project_dir,
|
|
511
|
+
None,
|
|
512
|
+
self.get_template_args(target),
|
|
513
|
+
target,
|
|
514
|
+
tune_args=tune_args + ["--task", str(idx)],
|
|
515
|
+
prefix=f"[worker-{idx}] ",
|
|
516
|
+
)
|
|
517
|
+
with open(out_file, "r") as handle:
|
|
518
|
+
content = handle.read()
|
|
519
|
+
return (out, content)
|
|
520
|
+
|
|
521
|
+
workers.append(executor.submit(do_work, i, content))
|
|
522
|
+
all_out = ""
|
|
523
|
+
all_content = ""
|
|
524
|
+
for i, w in enumerate(workers):
|
|
525
|
+
print(f"Worker {i}: done")
|
|
526
|
+
ret = w.result()
|
|
527
|
+
out, content = ret
|
|
528
|
+
all_out += out
|
|
529
|
+
all_content += content
|
|
530
|
+
out = all_out
|
|
531
|
+
content = all_content
|
|
532
|
+
else:
|
|
533
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
534
|
+
out_file = Path(tmp_dir) / "tuning_results.log.txt"
|
|
535
|
+
with open(out_file, "w") as handle:
|
|
536
|
+
handle.write(content)
|
|
537
|
+
tune_args = self.get_micro_tune_args(model_path, backend, out_file)
|
|
538
|
+
out = self.invoke_tvmc_micro(
|
|
539
|
+
"tune", self.project_dir, None, self.get_template_args(target), target, tune_args=tune_args
|
|
540
|
+
)
|
|
541
|
+
with open(out_file, "r") as handle:
|
|
542
|
+
content = handle.read()
|
|
543
|
+
|
|
544
|
+
artifact = Artifact("tuning_results.log.txt", content=content, fmt=ArtifactFormat.TEXT)
|
|
545
|
+
artifacts.append(artifact)
|
|
546
|
+
|
|
547
|
+
# pick best records
|
|
548
|
+
def _pick_best(backend, records, verbose=False):
|
|
549
|
+
content_best = ""
|
|
550
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
551
|
+
in_file = Path(tmp_dir) / "tuning_results.log.txt"
|
|
552
|
+
with open(in_file, "w") as handle:
|
|
553
|
+
handle.write(records)
|
|
554
|
+
out_file = Path(tmp_dir) / "best_tuning_results.log.txt"
|
|
555
|
+
args = [
|
|
556
|
+
"--mode",
|
|
557
|
+
"pick",
|
|
558
|
+
"--i",
|
|
559
|
+
in_file,
|
|
560
|
+
"--o",
|
|
561
|
+
out_file,
|
|
562
|
+
]
|
|
563
|
+
env = prepare_python_environment(self.tvm_pythonpath, self.tvm_build_dir, self.tvm_configs_dir)
|
|
564
|
+
utils.python("-m", "tvm.autotvm.record", *args, live=verbose, env=env)
|
|
565
|
+
with open(out_file, "r") as handle:
|
|
566
|
+
content_best = handle.read()
|
|
567
|
+
return content_best
|
|
568
|
+
|
|
569
|
+
content_best = _pick_best(backend, content, verbose=verbose)
|
|
570
|
+
if len(content_best) > 0:
|
|
571
|
+
artifact_ = Artifact("best_tuning_results.log.txt", content=content_best, fmt=ArtifactFormat.TEXT)
|
|
572
|
+
artifacts.append(artifact_)
|
|
573
|
+
|
|
574
|
+
if enable:
|
|
575
|
+
stdout_artifact = Artifact(
|
|
576
|
+
"tvmc_micro_tune_out.log", content=out, fmt=ArtifactFormat.TEXT
|
|
577
|
+
) # TODO: rename to tvmaot_out.log?
|
|
578
|
+
artifacts.append(stdout_artifact)
|
|
579
|
+
|
|
580
|
+
return artifacts
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from mlonmcu.target.target import Target
|
|
22
|
+
|
|
23
|
+
from mlonmcu.logging import get_logger
|
|
24
|
+
|
|
25
|
+
from .microtvm_template_target import TemplateMicroTvmPlatformTarget
|
|
26
|
+
|
|
27
|
+
logger = get_logger()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ArduinoMicroTvmPlatformTarget(TemplateMicroTvmPlatformTarget):
|
|
31
|
+
FEATURES = Target.FEATURES + []
|
|
32
|
+
|
|
33
|
+
DEFAULTS = {
|
|
34
|
+
**Target.DEFAULTS,
|
|
35
|
+
"project_type": None,
|
|
36
|
+
"warning_as_error": False,
|
|
37
|
+
"arduino_board": "?",
|
|
38
|
+
# "arduino_cli_cmd": None,
|
|
39
|
+
"verbose": False,
|
|
40
|
+
"port": -1,
|
|
41
|
+
}
|
|
42
|
+
REQUIRED = Target.REQUIRED + ["arduino.install_dir"]
|
|
43
|
+
|
|
44
|
+
def __init__(self, name=None, features=None, config=None):
|
|
45
|
+
super().__init__(name=name, features=features, config=config)
|
|
46
|
+
self.template_path = None
|
|
47
|
+
# self.option_names = ["project_type", "warning_as_error", "arduino_board", "verbose", "port"]
|
|
48
|
+
self.option_names = ["project_type", "warning_as_error", "arduino_board", "port"]
|
|
49
|
+
# self.platform = platform
|
|
50
|
+
# self.template = name2template(name)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def arduino_install_dir(self):
|
|
54
|
+
return Path(self.config["arduino.install_dir"])
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def port(self):
|
|
58
|
+
return Path(self.config["port"])
|
|
59
|
+
|
|
60
|
+
def get_project_options(self):
|
|
61
|
+
ret = super().get_project_options()
|
|
62
|
+
ret.update({"arduino_cli_cmd": self.arduino_install_dir / "arduino-cli"})
|
|
63
|
+
return ret
|
|
64
|
+
|
|
65
|
+
def update_environment(self, env):
|
|
66
|
+
super().update_environment(env)
|
|
67
|
+
if self.port:
|
|
68
|
+
env["ESPTOOL_PORT"] = self.port # TODO: required?
|