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,96 @@
|
|
|
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
|
+
"""Definition of tasks used to dynamically install MLonMCU dependencies"""
|
|
20
|
+
|
|
21
|
+
import multiprocessing
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from mlonmcu.setup.task import TaskType
|
|
25
|
+
from mlonmcu.context.context import MlonMcuContext
|
|
26
|
+
from mlonmcu.setup import utils
|
|
27
|
+
from mlonmcu.logging import get_logger
|
|
28
|
+
|
|
29
|
+
from .tvm import _validate_tvm
|
|
30
|
+
from .common import get_task_factory
|
|
31
|
+
|
|
32
|
+
logger = get_logger()
|
|
33
|
+
|
|
34
|
+
Tasks = get_task_factory()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _validate_utvmcg(context: MlonMcuContext, params=None):
|
|
38
|
+
if not _validate_tvm(context, params=params):
|
|
39
|
+
return False
|
|
40
|
+
return context.environment.has_backend("tvmcg")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@Tasks.provides(["utvmcg.src_dir"])
|
|
44
|
+
@Tasks.validate(_validate_utvmcg)
|
|
45
|
+
@Tasks.register(category=TaskType.BACKEND)
|
|
46
|
+
def clone_utvm_staticrt_codegen(
|
|
47
|
+
context: MlonMcuContext, params=None, rebuild=False, verbose=False, threads=multiprocessing.cpu_count()
|
|
48
|
+
):
|
|
49
|
+
"""Clone the uTVM code generator."""
|
|
50
|
+
utvmcgName = utils.makeDirName("utvmcg")
|
|
51
|
+
utvmcgSrcDir = context.environment.paths["deps"].path / "src" / utvmcgName
|
|
52
|
+
if rebuild or not utils.is_populated(utvmcgSrcDir):
|
|
53
|
+
utvmcgRepo = context.environment.repos["utvm_staticrt_codegen"]
|
|
54
|
+
utils.clone(utvmcgRepo.url, utvmcgSrcDir, branch=utvmcgRepo.ref)
|
|
55
|
+
context.cache["utvmcg.src_dir"] = utvmcgSrcDir
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@Tasks.needs(["utvmcg.src_dir", "tvm.src_dir"])
|
|
59
|
+
@Tasks.provides(["utvmcg.build_dir", "utvmcg.exe"])
|
|
60
|
+
@Tasks.param("dbg", False)
|
|
61
|
+
@Tasks.validate(_validate_utvmcg)
|
|
62
|
+
@Tasks.register(category=TaskType.BACKEND)
|
|
63
|
+
def build_utvm_staticrt_codegen(
|
|
64
|
+
context: MlonMcuContext, params=None, rebuild=False, verbose=False, threads=multiprocessing.cpu_count()
|
|
65
|
+
):
|
|
66
|
+
"""Build the uTVM code generator."""
|
|
67
|
+
if not params:
|
|
68
|
+
params = {}
|
|
69
|
+
flags = utils.makeFlags((params["dbg"], "dbg"))
|
|
70
|
+
utvmcgName = utils.makeDirName("utvmcg", flags=flags)
|
|
71
|
+
utvmcgSrcDir = context.cache["utvmcg.src_dir"]
|
|
72
|
+
utvmcgBuildDir = context.environment.paths["deps"].path / "build" / utvmcgName
|
|
73
|
+
utvmcgInstallDir = context.environment.paths["deps"].path / "install" / utvmcgName
|
|
74
|
+
utvmcgExe = utvmcgInstallDir / "compiler"
|
|
75
|
+
if rebuild or not utils.is_populated(utvmcgSrcDir) or not utvmcgExe.is_file():
|
|
76
|
+
utvmcgArgs = []
|
|
77
|
+
utvmcgArgs.append("-DTVM_DIR=" + str(context.cache["tvm.src_dir"]))
|
|
78
|
+
crtConfigPath = context.cache["tvm.src_dir"] / "apps" / "bundle_deploy" / "crt_config"
|
|
79
|
+
if context:
|
|
80
|
+
user_vars = context.environment.vars
|
|
81
|
+
if "tvm.crt_config_dir" in user_vars:
|
|
82
|
+
crtConfigPath = Path(user_vars["tvm.crt_config_dir"])
|
|
83
|
+
utvmcgArgs.append("-DTVM_CRT_CONFIG_DIR=" + str(crtConfigPath))
|
|
84
|
+
utils.mkdirs(utvmcgBuildDir)
|
|
85
|
+
utils.cmake(
|
|
86
|
+
utvmcgSrcDir,
|
|
87
|
+
*utvmcgArgs,
|
|
88
|
+
cwd=utvmcgBuildDir,
|
|
89
|
+
debug=params["dbg"],
|
|
90
|
+
live=verbose,
|
|
91
|
+
)
|
|
92
|
+
utils.make(cwd=utvmcgBuildDir, threads=threads, live=verbose)
|
|
93
|
+
utils.mkdirs(utvmcgInstallDir)
|
|
94
|
+
utils.move(utvmcgBuildDir / "utvm_staticrt_codegen", utvmcgExe)
|
|
95
|
+
context.cache["utvmcg.build_dir", flags] = utvmcgBuildDir
|
|
96
|
+
context.cache["utvmcg.exe", flags] = utvmcgExe
|
|
@@ -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
|
+
"""Definition of tasks used to dynamically install MLonMCU dependencies"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import pkg_resources
|
|
23
|
+
import venv
|
|
24
|
+
import multiprocessing
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
from mlonmcu.setup.task import TaskType
|
|
28
|
+
from mlonmcu.context.context import MlonMcuContext
|
|
29
|
+
from mlonmcu.setup import utils
|
|
30
|
+
from mlonmcu.logging import get_logger
|
|
31
|
+
|
|
32
|
+
from .common import get_task_factory
|
|
33
|
+
|
|
34
|
+
logger = get_logger()
|
|
35
|
+
|
|
36
|
+
Tasks = get_task_factory()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _validate_zephyr(context: MlonMcuContext, params=None):
|
|
40
|
+
return context.environment.has_platform("zephyr")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# @Tasks.needs([])
|
|
44
|
+
@Tasks.provides(["zephyr.install_dir", "zephyr.sdk_dir", "zephyr.venv_dir"])
|
|
45
|
+
@Tasks.validate(_validate_zephyr)
|
|
46
|
+
@Tasks.register(category=TaskType.PLATFORM)
|
|
47
|
+
def install_zephyr(
|
|
48
|
+
context: MlonMcuContext, params=None, rebuild=False, verbose=False, threads=multiprocessing.cpu_count()
|
|
49
|
+
):
|
|
50
|
+
"""Download and install support for the Zephyr Platform."""
|
|
51
|
+
zephyrName = utils.makeDirName("zephyr")
|
|
52
|
+
zephyrInstallDir = context.environment.paths["deps"].path / "install" / zephyrName
|
|
53
|
+
zephyrInstallDir.mkdir(exist_ok=True)
|
|
54
|
+
zephyrSdkDir = zephyrInstallDir / "sdk"
|
|
55
|
+
zephyrVenvDir = zephyrInstallDir / "venv"
|
|
56
|
+
zephyrModulesDir = zephyrInstallDir / "modules"
|
|
57
|
+
user_vars = context.environment.vars
|
|
58
|
+
if "zephyr.install_dir" in user_vars: # TODO: also check command line flags?
|
|
59
|
+
assert "zephyr.sdk_dir" in user_vars
|
|
60
|
+
assert "zephyr.venv_dir" in user_vars
|
|
61
|
+
return False
|
|
62
|
+
# boards = ["espressif"]
|
|
63
|
+
# if "zephyr.boards" in user_vars:
|
|
64
|
+
# boards = user_vars["zephyr.boards"]
|
|
65
|
+
# if not isinstance(boards, str):
|
|
66
|
+
# assert isinstance(boards, list)
|
|
67
|
+
# boards = ",".join(boards)
|
|
68
|
+
if (
|
|
69
|
+
not utils.is_populated(zephyrInstallDir)
|
|
70
|
+
or not utils.is_populated(zephyrSdkDir)
|
|
71
|
+
or not utils.is_populated(zephyrVenvDir)
|
|
72
|
+
or not utils.is_populated(zephyrModulesDir)
|
|
73
|
+
or rebuild
|
|
74
|
+
):
|
|
75
|
+
zephyrVenvScript = zephyrVenvDir / "bin" / "activate"
|
|
76
|
+
if not utils.is_populated(zephyrVenvDir):
|
|
77
|
+
venv.create(zephyrVenvDir)
|
|
78
|
+
utils.exec_getout(f". {zephyrVenvScript} && pip install west", shell=True, print_output=False, live=verbose)
|
|
79
|
+
zephyrRepo = context.environment.repos["zephyr"]
|
|
80
|
+
zephyrUrl = zephyrRepo.url
|
|
81
|
+
if not utils.is_populated(zephyrInstallDir / "zephyr"):
|
|
82
|
+
zephyrVersion = zephyrRepo.ref
|
|
83
|
+
utils.exec_getout(
|
|
84
|
+
f". {zephyrVenvScript} && west init -m {zephyrUrl} --mr {zephyrVersion} {zephyrInstallDir}",
|
|
85
|
+
shell=True,
|
|
86
|
+
print_output=False,
|
|
87
|
+
live=verbose,
|
|
88
|
+
)
|
|
89
|
+
extra = zephyrInstallDir / "zephyr" / "scripts" / "requirements.txt"
|
|
90
|
+
utils.exec_getout(
|
|
91
|
+
f". {zephyrVenvScript} && pip install -r {extra}", shell=True, print_output=False, live=verbose
|
|
92
|
+
)
|
|
93
|
+
env = os.environ.copy()
|
|
94
|
+
env["ZEPHYR_BASE"] = str(zephyrInstallDir / "zephyr")
|
|
95
|
+
utils.exec_getout(f". {zephyrVenvScript} && west update", shell=True, print_output=False, live=verbose, env=env)
|
|
96
|
+
if "zephyr.sdk_version" in user_vars:
|
|
97
|
+
sdkVersion = user_vars["zephyr.sdk_version"]
|
|
98
|
+
else:
|
|
99
|
+
sdkVersion = "0.15.0-rc1"
|
|
100
|
+
sdkDist = "linux-x86_64"
|
|
101
|
+
sdkUrl = f"https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v{sdkVersion}/"
|
|
102
|
+
sdkArchive = f"zephyr-sdk-{sdkVersion}_{sdkDist}.tar.gz"
|
|
103
|
+
if not utils.is_populated(zephyrSdkDir):
|
|
104
|
+
utils.download_and_extract(sdkUrl, sdkArchive, zephyrSdkDir, progress=verbose)
|
|
105
|
+
sdkScript = zephyrSdkDir / "setup.sh"
|
|
106
|
+
# TODO: allow to limit installed toolchains
|
|
107
|
+
utils.exec_getout(sdkScript, "-t", "all", "-h", print_output=False, live=verbose)
|
|
108
|
+
# Apply patch to fix esp32c3 support
|
|
109
|
+
patchFile = Path(
|
|
110
|
+
pkg_resources.resource_filename(
|
|
111
|
+
"mlonmcu", os.path.join("..", "resources", "patches", "zephyr", "fix_esp32c3_march.patch")
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
if patchFile.is_file():
|
|
115
|
+
xtensaDir = zephyrInstallDir / "modules" / "hal" / "xtensa"
|
|
116
|
+
utils.patch(patchFile, cwd=xtensaDir)
|
|
117
|
+
context.cache["zephyr.install_dir"] = zephyrInstallDir
|
|
118
|
+
context.cache["zephyr.sdk_dir"] = zephyrSdkDir
|
|
119
|
+
context.cache["zephyr.venv_dir"] = zephyrVenvDir
|
mlonmcu/setup/utils.py
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
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 signal
|
|
21
|
+
import sys
|
|
22
|
+
import multiprocessing
|
|
23
|
+
import subprocess
|
|
24
|
+
|
|
25
|
+
# import logging
|
|
26
|
+
import tarfile
|
|
27
|
+
import zipfile
|
|
28
|
+
import shutil
|
|
29
|
+
import tempfile
|
|
30
|
+
import urllib.request
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
from typing import Union
|
|
33
|
+
from git import Repo
|
|
34
|
+
from tqdm import tqdm
|
|
35
|
+
|
|
36
|
+
from mlonmcu import logging
|
|
37
|
+
|
|
38
|
+
logger = logging.get_logger()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def makeFlags(*args):
|
|
42
|
+
"""Resolve tuple-like arguments to a list of string.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
args
|
|
47
|
+
List of tuples of the form: [(True, "foo"), (False, "bar")]
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
dirname : str
|
|
52
|
+
The generated directory name
|
|
53
|
+
|
|
54
|
+
Examples
|
|
55
|
+
--------
|
|
56
|
+
>>> makeFlags((True, "foo"), (False, "bar"))
|
|
57
|
+
["foo"]
|
|
58
|
+
"""
|
|
59
|
+
return [name for check, name in args if check]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def makeDirName(base: str, *args, flags: list = None) -> str:
|
|
63
|
+
"""Creates a directory name based on configuration values.
|
|
64
|
+
|
|
65
|
+
Using snake_case style.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
base : str
|
|
70
|
+
Prefix of the filename to be generated.
|
|
71
|
+
args
|
|
72
|
+
List of tuples of the form: [(True, "foo"), (False, "bar")]
|
|
73
|
+
flags : list
|
|
74
|
+
Optional list of additional flags to be added.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
dirname : str
|
|
79
|
+
The generated directory name
|
|
80
|
+
|
|
81
|
+
Examples
|
|
82
|
+
--------
|
|
83
|
+
>>> makeDirName("base", (True, "foo"), (False, "bar"), flags=["flag"])
|
|
84
|
+
"base_foo_flag"
|
|
85
|
+
"""
|
|
86
|
+
names = [base] + makeFlags(*args)
|
|
87
|
+
if flags:
|
|
88
|
+
names = names + flags
|
|
89
|
+
return "_".join(names)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def exec(*args, **kwargs):
|
|
93
|
+
"""Execute a process with the given args and using the given kwards as Popen arguments.
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
args
|
|
98
|
+
The command to be executed.
|
|
99
|
+
"""
|
|
100
|
+
logger.debug("- Executing: " + str(args))
|
|
101
|
+
subprocess.run([i for i in args], **kwargs, check=True)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def exec_getout(*args, live: bool = False, print_output: bool = True, handle_exit=None, prefix="", **kwargs) -> str:
|
|
105
|
+
"""Execute a process with the given args and using the given kwards as Popen arguments and return the output.
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
args
|
|
110
|
+
The command to be executed.
|
|
111
|
+
live : bool
|
|
112
|
+
If the stdout should be updated in real time.
|
|
113
|
+
print_output : bool
|
|
114
|
+
Print the output at the end on non-live mode.
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
output
|
|
119
|
+
The text printed to the command line.
|
|
120
|
+
"""
|
|
121
|
+
logger.debug("- Executing: " + str(args))
|
|
122
|
+
outStr = ""
|
|
123
|
+
if live:
|
|
124
|
+
process = subprocess.Popen([i for i in args], **kwargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
125
|
+
try:
|
|
126
|
+
for line in process.stdout:
|
|
127
|
+
new_line = prefix + line.decode(errors="replace")
|
|
128
|
+
outStr = outStr + new_line
|
|
129
|
+
print(new_line.replace("\n", ""))
|
|
130
|
+
exit_code = None
|
|
131
|
+
while exit_code is None:
|
|
132
|
+
exit_code = process.poll()
|
|
133
|
+
if handle_exit is not None:
|
|
134
|
+
exit_code = handle_exit(exit_code)
|
|
135
|
+
assert exit_code == 0, "The process returned an non-zero exit code {}! (CMD: `{}`)".format(
|
|
136
|
+
exit_code, " ".join(list(map(str, args)))
|
|
137
|
+
)
|
|
138
|
+
except KeyboardInterrupt:
|
|
139
|
+
logger.debug("Interrupted subprocess. Sending SIGINT signal...")
|
|
140
|
+
pid = process.pid
|
|
141
|
+
os.kill(pid, signal.SIGINT)
|
|
142
|
+
|
|
143
|
+
else:
|
|
144
|
+
try:
|
|
145
|
+
p = subprocess.Popen([i for i in args], **kwargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
146
|
+
outStr = p.communicate()[0].decode(errors="replace")
|
|
147
|
+
exit_code = p.poll()
|
|
148
|
+
# outStr = p.stdout.decode(errors="replace")
|
|
149
|
+
if print_output:
|
|
150
|
+
logger.debug(prefix + outStr)
|
|
151
|
+
if handle_exit is not None:
|
|
152
|
+
exit_code = handle_exit(exit_code)
|
|
153
|
+
if exit_code != 0:
|
|
154
|
+
logger.error(outStr)
|
|
155
|
+
assert exit_code == 0, "The process returned an non-zero exit code {}! (CMD: `{}`)".format(
|
|
156
|
+
exit_code, " ".join(list(map(str, args)))
|
|
157
|
+
)
|
|
158
|
+
except KeyboardInterrupt:
|
|
159
|
+
logger.debug("Interrupted subprocess. Sending SIGINT signal...")
|
|
160
|
+
pid = p.pid
|
|
161
|
+
os.kill(pid, signal.SIGINT)
|
|
162
|
+
except subprocess.CalledProcessError as e:
|
|
163
|
+
outStr = e.output.decode(errors="replace")
|
|
164
|
+
logger.error(outStr)
|
|
165
|
+
raise e
|
|
166
|
+
|
|
167
|
+
return outStr
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def python(*args, **kwargs):
|
|
171
|
+
"""Run a python script with the current interpreter."""
|
|
172
|
+
return exec_getout(sys.executable, *args, **kwargs)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# Makes sure all directories at the given path are created.
|
|
176
|
+
def mkdirs(path: Union[str, bytes, os.PathLike]):
|
|
177
|
+
"""Wrapper for os.makedirs which handels the special case where the path already exits."""
|
|
178
|
+
if not os.path.exists(path):
|
|
179
|
+
os.makedirs(path)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
# Clones a git repository at given url into given dir and switches to the given branch.
|
|
183
|
+
def clone(
|
|
184
|
+
url: str,
|
|
185
|
+
dest: Union[str, bytes, os.PathLike],
|
|
186
|
+
branch: str = "",
|
|
187
|
+
recursive: bool = False,
|
|
188
|
+
refresh: bool = False,
|
|
189
|
+
):
|
|
190
|
+
"""Helper function for cloning a repository.
|
|
191
|
+
|
|
192
|
+
Parameters
|
|
193
|
+
----------
|
|
194
|
+
url : str
|
|
195
|
+
Clone URL of the repository.
|
|
196
|
+
dest : Path
|
|
197
|
+
Destination directory path.
|
|
198
|
+
branch : str
|
|
199
|
+
Optional branch name or commit reference/tag.
|
|
200
|
+
recursive : bool
|
|
201
|
+
If the clone should be done recursively.
|
|
202
|
+
refesh : bool
|
|
203
|
+
Enables switching the url/branch if the repo already exists
|
|
204
|
+
"""
|
|
205
|
+
mkdirs(dest)
|
|
206
|
+
|
|
207
|
+
if is_populated(dest):
|
|
208
|
+
if refresh:
|
|
209
|
+
repo = Repo(dest)
|
|
210
|
+
# TODO: backup old remote?
|
|
211
|
+
repo.remotes.origin.set_url(url)
|
|
212
|
+
repo.remotes.origin.fetch()
|
|
213
|
+
repo.git.checkout(branch)
|
|
214
|
+
repo.git.pull("origin", branch) # This should also work for specific commits
|
|
215
|
+
else:
|
|
216
|
+
if branch:
|
|
217
|
+
repo = Repo.clone_from(url, dest, recursive=recursive, no_checkout=True)
|
|
218
|
+
repo.git.checkout(branch)
|
|
219
|
+
if recursive:
|
|
220
|
+
repo.git.submodule("update", "--init", "--recursive")
|
|
221
|
+
else:
|
|
222
|
+
Repo.clone_from(url, dest, recursive=recursive)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def apply(
|
|
226
|
+
repo_dir: Path,
|
|
227
|
+
patch_file: Path,
|
|
228
|
+
):
|
|
229
|
+
"""Helper function for applying a patch to a repository.
|
|
230
|
+
|
|
231
|
+
Parameters
|
|
232
|
+
----------
|
|
233
|
+
repo_dir : Path
|
|
234
|
+
Clone directory of repository.
|
|
235
|
+
patch_file : Path
|
|
236
|
+
Path to patch file.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
repo = Repo(repo_dir)
|
|
240
|
+
repo.git.clean("-xdf") # Undo all changes
|
|
241
|
+
repo.git.apply(patch_file)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def make(*args, threads=multiprocessing.cpu_count(), use_ninja=False, cwd=None, verbose=False, **kwargs):
|
|
245
|
+
if cwd is None:
|
|
246
|
+
raise RuntimeError("Please always pass a cwd to make()")
|
|
247
|
+
if isinstance(cwd, Path):
|
|
248
|
+
cwd = str(cwd.resolve())
|
|
249
|
+
# TODO: make sure that ninja is installed?
|
|
250
|
+
extraArgs = []
|
|
251
|
+
tool = "ninja" if use_ninja else "make"
|
|
252
|
+
extraArgs.append("-j" + str(threads))
|
|
253
|
+
cmd = [tool] + extraArgs + list(args)
|
|
254
|
+
return exec_getout(*cmd, cwd=cwd, print_output=False, **kwargs)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def cmake(src, *args, debug=False, use_ninja=False, cwd=None, **kwargs):
|
|
258
|
+
if cwd is None:
|
|
259
|
+
raise RuntimeError("Please always pass a cwd to cmake()")
|
|
260
|
+
if isinstance(cwd, Path):
|
|
261
|
+
cwd = str(cwd.resolve())
|
|
262
|
+
buildType = "Debug" if debug else "Release"
|
|
263
|
+
extraArgs = []
|
|
264
|
+
extraArgs.append("-DCMAKE_BUILD_TYPE=" + buildType)
|
|
265
|
+
if use_ninja:
|
|
266
|
+
extraArgs.append("-GNinja")
|
|
267
|
+
cmd = ["cmake", str(src)] + extraArgs + list(args)
|
|
268
|
+
return exec_getout(*cmd, cwd=cwd, print_output=False, **kwargs)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
# def move(a, b): # TODO: make every utility compatible with Paths!
|
|
272
|
+
# # This can not handle cross file-system renames!
|
|
273
|
+
# if not isinstance(a, Path):
|
|
274
|
+
# a = Path(a)
|
|
275
|
+
# if not isinstance(b, Path):
|
|
276
|
+
# b = Path(b)
|
|
277
|
+
# a.replace(b)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def download(url, dest, progress=False):
|
|
281
|
+
def hook(t):
|
|
282
|
+
"""Wraps tqdm instance."""
|
|
283
|
+
last_b = [0]
|
|
284
|
+
|
|
285
|
+
def update_to(b=1, bsize=1, tsize=None):
|
|
286
|
+
"""
|
|
287
|
+
b : int, optional
|
|
288
|
+
Number of blocks transferred so far [default: 1].
|
|
289
|
+
bsize : int, optional
|
|
290
|
+
Size of each block (in tqdm units) [default: 1].
|
|
291
|
+
tsize : int, optional
|
|
292
|
+
Total size (in tqdm units). If [default: None] remains unchanged.
|
|
293
|
+
"""
|
|
294
|
+
if tsize is not None:
|
|
295
|
+
t.total = tsize
|
|
296
|
+
t.update((b - last_b[0]) * bsize)
|
|
297
|
+
last_b[0] = b
|
|
298
|
+
|
|
299
|
+
return update_to
|
|
300
|
+
|
|
301
|
+
if progress:
|
|
302
|
+
with tqdm(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc="Downloading File") as t:
|
|
303
|
+
urllib.request.urlretrieve(url, dest, reporthook=hook(t))
|
|
304
|
+
else:
|
|
305
|
+
urllib.request.urlretrieve(url, dest)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def extract(archive, dest, progress=False):
|
|
309
|
+
ext = Path(archive).suffix[1:]
|
|
310
|
+
|
|
311
|
+
def handle(f):
|
|
312
|
+
if progress:
|
|
313
|
+
members = f.getmembers()
|
|
314
|
+
for m in tqdm(iterable=members, total=len(members), desc="Extracting..."):
|
|
315
|
+
f.extract(m, dest)
|
|
316
|
+
else:
|
|
317
|
+
f.extractall(dest)
|
|
318
|
+
|
|
319
|
+
if ext == "zip":
|
|
320
|
+
with zipfile.ZipFile(archive) as zip_file:
|
|
321
|
+
handle(zip_file)
|
|
322
|
+
elif ext in ["tar", "gz", "xz", "tgz", "bz2"]:
|
|
323
|
+
with tarfile.open(archive) as tar_file:
|
|
324
|
+
handle(tar_file)
|
|
325
|
+
else:
|
|
326
|
+
raise RuntimeError("Unable to detect the archive type")
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def remove(path):
|
|
330
|
+
os.remove(path)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def move(src, dest):
|
|
334
|
+
shutil.move(src, dest)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def copy(src, dest):
|
|
338
|
+
shutil.copy(src, dest)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def is_populated(path):
|
|
342
|
+
if not isinstance(path, Path):
|
|
343
|
+
path = Path(path)
|
|
344
|
+
return path.is_dir() and os.listdir(path.resolve())
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def download_and_extract(url, archive, dest, progress=False):
|
|
348
|
+
if isinstance(dest, str):
|
|
349
|
+
dest = Path(dest)
|
|
350
|
+
assert isinstance(dest, Path)
|
|
351
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
352
|
+
tmp_archive = os.path.join(tmp_dir, archive)
|
|
353
|
+
base_name = Path(archive).stem
|
|
354
|
+
if ".tar" in base_name:
|
|
355
|
+
base_name = Path(base_name).stem
|
|
356
|
+
if url[-1] != "/":
|
|
357
|
+
url += "/"
|
|
358
|
+
download(url + archive, tmp_archive, progress=progress)
|
|
359
|
+
extract(tmp_archive, tmp_dir, progress=progress)
|
|
360
|
+
remove(os.path.join(tmp_dir, tmp_archive))
|
|
361
|
+
mkdirs(dest.parent)
|
|
362
|
+
if (Path(tmp_dir) / base_name).is_dir(): # Archive contains a subdirectory with the same name
|
|
363
|
+
move(os.path.join(tmp_dir, base_name), dest)
|
|
364
|
+
else:
|
|
365
|
+
contents = list(Path(tmp_dir).glob("*"))
|
|
366
|
+
if len(contents) == 1:
|
|
367
|
+
tmp_dir_new = Path(tmp_dir) / contents[0]
|
|
368
|
+
if tmp_dir_new.is_dir(): # Archive contains a single subdirectory with a different name
|
|
369
|
+
tmp_dir = tmp_dir_new
|
|
370
|
+
move(tmp_dir, dest)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def patch(path, cwd=None):
|
|
374
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
"""MLonMCU target submodule"""
|
|
20
|
+
|
|
21
|
+
from .target import Target
|
|
22
|
+
from ._target import register_target, get_targets
|
|
23
|
+
from .riscv import EtissPulpinoTarget, SpikeTarget, OVPSimTarget, RiscvQemuTarget
|
|
24
|
+
from .arm import Corstone300Target
|
|
25
|
+
from .host_x86 import HostX86Target
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"register_target",
|
|
29
|
+
"get_targets",
|
|
30
|
+
"Target",
|
|
31
|
+
"EtissPulpinoTarget",
|
|
32
|
+
"SpikeTarget",
|
|
33
|
+
"OVPSimTarget",
|
|
34
|
+
"RiscvQemuTarget",
|
|
35
|
+
"Corstone300Target",
|
|
36
|
+
"HostX86Target",
|
|
37
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# This file is part of MLonMCU.
|
|
2
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
from .riscv import EtissPulpinoTarget, SpikeTarget, OVPSimTarget, RiscvQemuTarget, GvsocPulpTarget
|
|
17
|
+
from .arm import Corstone300Target
|
|
18
|
+
from .host_x86 import HostX86Target
|
|
19
|
+
|
|
20
|
+
TARGET_REGISTRY = {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def register_target(target_name, t, override=False):
|
|
24
|
+
global TARGET_REGISTRY
|
|
25
|
+
|
|
26
|
+
if target_name in TARGET_REGISTRY and not override:
|
|
27
|
+
raise RuntimeError(f"Target {target_name} is already registered")
|
|
28
|
+
TARGET_REGISTRY[target_name] = t
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_targets():
|
|
32
|
+
return TARGET_REGISTRY
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
register_target("etiss_pulpino", EtissPulpinoTarget)
|
|
36
|
+
register_target("host_x86", HostX86Target)
|
|
37
|
+
register_target("corstone300", Corstone300Target)
|
|
38
|
+
register_target("spike", SpikeTarget)
|
|
39
|
+
register_target("ovpsim", OVPSimTarget)
|
|
40
|
+
register_target("riscv_qemu", RiscvQemuTarget)
|
|
41
|
+
register_target("gvsoc_pulp", GvsocPulpTarget)
|