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,545 @@
|
|
|
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 if the contextmanager for mlonmcu environments."""
|
|
20
|
+
|
|
21
|
+
import sys
|
|
22
|
+
import os
|
|
23
|
+
import shutil
|
|
24
|
+
import tempfile
|
|
25
|
+
from typing import List, Union
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
import filelock
|
|
28
|
+
|
|
29
|
+
from mlonmcu.utils import ask_user
|
|
30
|
+
from mlonmcu.logging import get_logger, set_log_file
|
|
31
|
+
from mlonmcu.session.run import Run
|
|
32
|
+
from mlonmcu.session.session import Session
|
|
33
|
+
from mlonmcu.setup.cache import TaskCache
|
|
34
|
+
import mlonmcu.setup.utils as utils
|
|
35
|
+
from mlonmcu.plugins import process_extensions
|
|
36
|
+
from mlonmcu.context.read_write_filelock import ReadFileLock, WriteFileLock, RWLockTimeout
|
|
37
|
+
|
|
38
|
+
from mlonmcu.environment.environment import Environment, UserEnvironment
|
|
39
|
+
|
|
40
|
+
from mlonmcu.environment.list import get_environments_map
|
|
41
|
+
from mlonmcu.environment.config import get_environments_dir, get_plugins_dir
|
|
42
|
+
|
|
43
|
+
logger = get_logger()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def lookup_environment() -> Environment:
|
|
47
|
+
"""Helper function to automatically find a suitable environment.
|
|
48
|
+
|
|
49
|
+
This function is used if neither a name nor a path of the environment was specified by the user.
|
|
50
|
+
The lookup follows a predefined order:
|
|
51
|
+
- Check current working directory
|
|
52
|
+
- Check MLONMCU_HOME environment variable
|
|
53
|
+
- Default environment for current user
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
environment : Path
|
|
58
|
+
The environment (if the lookup was successful).
|
|
59
|
+
"""
|
|
60
|
+
logger.debug("Starting lookup for mlonmcu environment")
|
|
61
|
+
|
|
62
|
+
logger.debug("First checking in local working directory")
|
|
63
|
+
path = os.path.join(os.getcwd(), "environment.yml")
|
|
64
|
+
if os.path.exists(path):
|
|
65
|
+
logger.debug("Found environment directory: %s", path)
|
|
66
|
+
return path
|
|
67
|
+
|
|
68
|
+
logger.debug("Next checking environment variables")
|
|
69
|
+
home = os.environ.get("MLONMCU_HOME")
|
|
70
|
+
if home:
|
|
71
|
+
path = os.path.join(home, "environment.yml")
|
|
72
|
+
if os.path.exists(path):
|
|
73
|
+
logger.debug("Found environment directory: %s", path)
|
|
74
|
+
return path
|
|
75
|
+
|
|
76
|
+
logger.debug("Looking for default environment for current user")
|
|
77
|
+
envs_list = get_environments_map()
|
|
78
|
+
if "default" in envs_list:
|
|
79
|
+
assert "path" in envs_list["default"]
|
|
80
|
+
directory = envs_list["default"]["path"]
|
|
81
|
+
path = os.path.join(directory, "environment.yml")
|
|
82
|
+
if os.path.exists(path):
|
|
83
|
+
logger.debug("Found environment directory: %s", path)
|
|
84
|
+
return path
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_environment_by_path(path: Union[str, Path]) -> Environment:
|
|
89
|
+
"""Utility to find an environment file using a supplied path.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
path : str/Path
|
|
94
|
+
The path of the environment (or its YAML file).
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
Environment:
|
|
99
|
+
The environment (if the lookup was successful).
|
|
100
|
+
"""
|
|
101
|
+
if isinstance(path, str):
|
|
102
|
+
path = Path(path)
|
|
103
|
+
assert isinstance(path, Path)
|
|
104
|
+
if path.is_dir():
|
|
105
|
+
path = path / "environment.yml"
|
|
106
|
+
if path.is_file():
|
|
107
|
+
return path
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_environment_by_name(name: str) -> Environment:
|
|
112
|
+
"""Utility to find an environment file using a supplied name.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
name : str
|
|
117
|
+
The name/alias if the environment.
|
|
118
|
+
|
|
119
|
+
Returns
|
|
120
|
+
-------
|
|
121
|
+
Environment :
|
|
122
|
+
The environment (if the lookup was successful).
|
|
123
|
+
"""
|
|
124
|
+
# TODO: parse the ini file instead
|
|
125
|
+
environments_dir = get_environments_dir()
|
|
126
|
+
if environments_dir.is_dir():
|
|
127
|
+
path = environments_dir / name
|
|
128
|
+
if path.is_dir():
|
|
129
|
+
return get_environment_by_path(path)
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_ids(directory: Path) -> List[int]:
|
|
134
|
+
"""Get a sorted list of ids for sessions/runs found in the given directory.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
directory : Path
|
|
139
|
+
Directory where the sessions/runs are stored.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
list
|
|
143
|
+
List of integers representing the session numbers. Empty list if directory does not exist.
|
|
144
|
+
"""
|
|
145
|
+
if not directory.is_dir():
|
|
146
|
+
return []
|
|
147
|
+
|
|
148
|
+
ids = [int(o) for o in os.listdir(directory) if os.path.isdir(directory / o) and not os.path.islink(directory / o)]
|
|
149
|
+
return sorted(ids) # TODO: sort by session datetime?
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def load_recent_sessions(env: Environment, count: int = None) -> List[Session]:
|
|
153
|
+
"""Get a list of recent sessions for the environment.
|
|
154
|
+
|
|
155
|
+
Parameters
|
|
156
|
+
----------
|
|
157
|
+
env : Environment
|
|
158
|
+
MLonMCU environment which should be used.
|
|
159
|
+
count : int
|
|
160
|
+
Maximum number of sessions to return. Collect all if None.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
list:
|
|
165
|
+
The resulting list of session objects.
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
if count is not None:
|
|
169
|
+
raise NotImplementedError()
|
|
170
|
+
sessions = []
|
|
171
|
+
|
|
172
|
+
sessions_directory = env.paths["temp"].path / "sessions"
|
|
173
|
+
|
|
174
|
+
# TODO: in the future also strs (custom or hash) should be allowed
|
|
175
|
+
session_ids = get_ids(sessions_directory)
|
|
176
|
+
|
|
177
|
+
for sid in session_ids:
|
|
178
|
+
session_directory = sessions_directory / str(sid)
|
|
179
|
+
# session_file = sessions_directory / str(sid) / "session.txt"
|
|
180
|
+
# if not session_file.is_file():
|
|
181
|
+
# continue
|
|
182
|
+
runs_directory = session_directory / "runs"
|
|
183
|
+
run_ids = get_ids(runs_directory)
|
|
184
|
+
runs = []
|
|
185
|
+
for rid in run_ids:
|
|
186
|
+
run_directory = runs_directory / str(rid)
|
|
187
|
+
# run_file = run_directory / "run.txt"
|
|
188
|
+
# run = Run.from_file(run_file) # TODO: actually implement run restore
|
|
189
|
+
run = Run() # TODO: fix
|
|
190
|
+
run.archived = True
|
|
191
|
+
run.dir = run_directory
|
|
192
|
+
runs.append(run)
|
|
193
|
+
session = Session(idx=sid, archived=True, dir=session_directory)
|
|
194
|
+
session.runs = runs
|
|
195
|
+
session.dir = session_directory
|
|
196
|
+
sessions.append(session)
|
|
197
|
+
return sessions
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def resolve_environment_file(name: str = None, path: str = None) -> Path:
|
|
201
|
+
"""Utility to find the environment file by a optionally given name or path.
|
|
202
|
+
|
|
203
|
+
The lookup is performed in a predefined order:
|
|
204
|
+
- If specified: name/path
|
|
205
|
+
- Else: see lookup_environment()
|
|
206
|
+
|
|
207
|
+
Parameters
|
|
208
|
+
----------
|
|
209
|
+
name : str
|
|
210
|
+
Hint for the environment name provided by the user.
|
|
211
|
+
path : str
|
|
212
|
+
Hint for the environment path provided by the user.
|
|
213
|
+
|
|
214
|
+
Returns
|
|
215
|
+
-------
|
|
216
|
+
Path :
|
|
217
|
+
Path to the found environment.yml (if sucessful)
|
|
218
|
+
"""
|
|
219
|
+
if name and path:
|
|
220
|
+
raise RuntimeError("mlonmcu environments are specified either by name OR path")
|
|
221
|
+
if name:
|
|
222
|
+
env_file = get_environment_by_name(name)
|
|
223
|
+
elif path:
|
|
224
|
+
env_file = get_environment_by_path(path)
|
|
225
|
+
else:
|
|
226
|
+
env_file = lookup_environment()
|
|
227
|
+
if not env_file:
|
|
228
|
+
raise RuntimeError("Lookup for mlonmcu environment was not successful.")
|
|
229
|
+
return env_file
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def setup_logging(environment):
|
|
233
|
+
"""Check logging settings for environment and initialize the logs directory.
|
|
234
|
+
|
|
235
|
+
Attributes
|
|
236
|
+
----------
|
|
237
|
+
environment : Environment
|
|
238
|
+
The MLonMCU Environment where paths, repos, features,... are configured.
|
|
239
|
+
"""
|
|
240
|
+
defaults = environment.defaults
|
|
241
|
+
level = defaults.log_level
|
|
242
|
+
to_file = defaults.log_to_file
|
|
243
|
+
rotate = defaults.log_rotate
|
|
244
|
+
if to_file:
|
|
245
|
+
assert "logs" in environment.paths, "To use a logfile, define a logging directory in your environment.yml"
|
|
246
|
+
directory = environment.paths["logs"].path
|
|
247
|
+
if not directory.is_dir():
|
|
248
|
+
directory.mkdir()
|
|
249
|
+
path = directory / "mlonmcu.log"
|
|
250
|
+
set_log_file(path, level=level, rotate=rotate)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class MlonMcuContext:
|
|
254
|
+
"""Contextmanager for mlonmcu environments.
|
|
255
|
+
|
|
256
|
+
Attributes
|
|
257
|
+
----------
|
|
258
|
+
environment : Environment
|
|
259
|
+
The MLonMCU Environment where paths, repos, features,... are configured.
|
|
260
|
+
deps_lock : str ("read" or "write" default "write")
|
|
261
|
+
Read means that the program does not write to the ./deps folder in the env folder.
|
|
262
|
+
sessions : list
|
|
263
|
+
List of sessions for the current environment.
|
|
264
|
+
session_idx : list
|
|
265
|
+
A counter for determining the next session index.
|
|
266
|
+
cache : TaskCache
|
|
267
|
+
The cache where paths of installed dependencies can be looked up.
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
def __init__(self, name: str = None, path: str = None, deps_lock: str = "write"):
|
|
273
|
+
env_file = resolve_environment_file(name=name, path=path)
|
|
274
|
+
assert env_file is not None, "Unable to find a MLonMCU environment"
|
|
275
|
+
self.environment = UserEnvironment.from_file(env_file) # TODO: move to __enter__
|
|
276
|
+
setup_logging(self.environment)
|
|
277
|
+
assert deps_lock in ["read", "write"]
|
|
278
|
+
if deps_lock == "read":
|
|
279
|
+
self.deps_lock = ReadFileLock(os.path.join(self.environment.home, ".deps_lock"))
|
|
280
|
+
elif deps_lock == "write":
|
|
281
|
+
self.deps_lock = WriteFileLock(os.path.join(self.environment.home, ".deps_lock"))
|
|
282
|
+
self.latest_session_link_lock = filelock.FileLock(
|
|
283
|
+
os.path.join(self.environment.home, ".latest_session_link_lock_lock")
|
|
284
|
+
)
|
|
285
|
+
self.sessions = load_recent_sessions(self.environment)
|
|
286
|
+
if self.environment.defaults.cleanup_auto:
|
|
287
|
+
logger.debug("Cleaning up old sessions automaticaly")
|
|
288
|
+
self.cleanup_sessions(keep=self.environment.defaults.cleanup_keep, interactive=False)
|
|
289
|
+
self.sessions = load_recent_sessions(self.environment)
|
|
290
|
+
self.session_idx = self.sessions[-1].idx if len(self.sessions) > 0 else -1
|
|
291
|
+
logger.debug(f"Restored {len(self.sessions)} recent sessions")
|
|
292
|
+
self.cache = TaskCache()
|
|
293
|
+
|
|
294
|
+
def create_session(self, label="", config=None):
|
|
295
|
+
try:
|
|
296
|
+
lock = self.latest_session_link_lock.acquire(timeout=10)
|
|
297
|
+
except filelock.Timeout as err:
|
|
298
|
+
raise RuntimeError("Lock on current context could not be aquired.") from err
|
|
299
|
+
else:
|
|
300
|
+
with lock:
|
|
301
|
+
"""Create a new session in the current context."""
|
|
302
|
+
self.sessions = load_recent_sessions(self.environment)
|
|
303
|
+
idx = self.session_idx + 1
|
|
304
|
+
logger.debug("Creating a new session with idx %s", idx)
|
|
305
|
+
temp_directory = self.environment.paths["temp"].path
|
|
306
|
+
sessions_directory = temp_directory / "sessions"
|
|
307
|
+
session_dir = sessions_directory / str(idx)
|
|
308
|
+
session = Session(idx=idx, label=label, dir=session_dir, config=config)
|
|
309
|
+
self.sessions.append(session)
|
|
310
|
+
self.session_idx = idx
|
|
311
|
+
# TODO: move this to a helper function
|
|
312
|
+
session_link = sessions_directory / "latest"
|
|
313
|
+
if os.path.islink(session_link):
|
|
314
|
+
os.unlink(session_link)
|
|
315
|
+
os.symlink(session_dir, session_link)
|
|
316
|
+
return session
|
|
317
|
+
|
|
318
|
+
def load_cache(self):
|
|
319
|
+
"""If available load the cache.ini file in the deps directory"""
|
|
320
|
+
if self.environment:
|
|
321
|
+
if self.environment.paths:
|
|
322
|
+
if "deps" in self.environment.paths:
|
|
323
|
+
deps_dir = self.environment.paths["deps"].path
|
|
324
|
+
if deps_dir.is_dir():
|
|
325
|
+
cache_file = deps_dir / "cache.ini"
|
|
326
|
+
if cache_file.is_file():
|
|
327
|
+
logger.info("Loading environment cache from file")
|
|
328
|
+
self.cache.read_from_file(cache_file)
|
|
329
|
+
logger.info("Successfully initialized cache")
|
|
330
|
+
return
|
|
331
|
+
logger.info("No cache found in deps directory")
|
|
332
|
+
|
|
333
|
+
def load_extensions(self):
|
|
334
|
+
"""If available load the extensions.py scripts in the plugin directories"""
|
|
335
|
+
|
|
336
|
+
# TODO: check vars.enable_extensions before!
|
|
337
|
+
def _load(plugins_dir, hint="Unknown"):
|
|
338
|
+
if plugins_dir.is_dir():
|
|
339
|
+
extensions_file = plugins_dir / "extensions.py"
|
|
340
|
+
if extensions_file.is_file():
|
|
341
|
+
logger.info(f"Loading extensions.py ({hint})")
|
|
342
|
+
process_extensions(extensions_file)
|
|
343
|
+
|
|
344
|
+
# global (user)
|
|
345
|
+
plugins_dir = Path(get_plugins_dir())
|
|
346
|
+
_load(plugins_dir, hint="User")
|
|
347
|
+
|
|
348
|
+
# local (environment)
|
|
349
|
+
if self.environment:
|
|
350
|
+
if self.environment.paths:
|
|
351
|
+
if "plugins" in self.environment.paths:
|
|
352
|
+
plugins_dir = self.environment.paths["plugins"].path
|
|
353
|
+
_load(plugins_dir, hint="Environment")
|
|
354
|
+
|
|
355
|
+
def get_session(self, label="", resume=False, config=None) -> Session:
|
|
356
|
+
"""Get an active session if available, else create a new one.
|
|
357
|
+
|
|
358
|
+
Returns
|
|
359
|
+
-------
|
|
360
|
+
Session:
|
|
361
|
+
An active session
|
|
362
|
+
"""
|
|
363
|
+
if resume:
|
|
364
|
+
assert len(self.sessions) > 0, "There is no recent session available"
|
|
365
|
+
# session = self.sessions[-1]
|
|
366
|
+
assert False, "The latest session can not be resumed"
|
|
367
|
+
raise NotImplementedError
|
|
368
|
+
|
|
369
|
+
if self.session_idx < 0 or not self.sessions[-1].active:
|
|
370
|
+
self.create_session(label=label, config=config)
|
|
371
|
+
return self.sessions[-1]
|
|
372
|
+
|
|
373
|
+
def __enter__(self):
|
|
374
|
+
logger.debug("Enter MlonMcuContext")
|
|
375
|
+
if self.deps_lock.is_locked:
|
|
376
|
+
raise RuntimeError(
|
|
377
|
+
"Lock on current context could not be acquired. "
|
|
378
|
+
f"Current context is locked via: {self.deps_lock.filepath}"
|
|
379
|
+
)
|
|
380
|
+
if self.deps_lock:
|
|
381
|
+
logger.debug("Locking context")
|
|
382
|
+
try:
|
|
383
|
+
self.deps_lock.acquire()
|
|
384
|
+
except RWLockTimeout as err:
|
|
385
|
+
raise RuntimeError(
|
|
386
|
+
"Lock on current context could not be aquired. "
|
|
387
|
+
f"Current context is locked via: {self.deps_lock.filepath}"
|
|
388
|
+
) from err
|
|
389
|
+
self.load_cache()
|
|
390
|
+
self.load_extensions()
|
|
391
|
+
return self
|
|
392
|
+
|
|
393
|
+
def cleanup(self):
|
|
394
|
+
"""Clean up the context before leaving the context by closing all active sessions"""
|
|
395
|
+
logger.debug("Cleaning up active sessions")
|
|
396
|
+
for session in self.sessions:
|
|
397
|
+
if session.active:
|
|
398
|
+
session.close()
|
|
399
|
+
|
|
400
|
+
@property
|
|
401
|
+
def is_clean(self):
|
|
402
|
+
"""Return true if all sessions in the context are inactive"""
|
|
403
|
+
return not any(sess.active for sess in self.sessions)
|
|
404
|
+
|
|
405
|
+
# WARNING: this will remove the actual session directories!
|
|
406
|
+
def cleanup_sessions(self, keep=10, interactive=True):
|
|
407
|
+
"""Utility to cleanup old sessions from the disk."""
|
|
408
|
+
assert self.is_clean
|
|
409
|
+
all_sessions = self.sessions
|
|
410
|
+
to_keep = all_sessions[-keep:] if keep > 0 else []
|
|
411
|
+
to_remove = self.sessions[:-keep] if keep > 0 else self.sessions
|
|
412
|
+
count = len(to_remove)
|
|
413
|
+
if count > 0:
|
|
414
|
+
temp_dir = self.environment.lookup_path("temp").path
|
|
415
|
+
sessions_dir = temp_dir / "sessions"
|
|
416
|
+
if interactive:
|
|
417
|
+
print(
|
|
418
|
+
f"The following {count} sessions will be removed from the environments temp directory ({temp_dir}):"
|
|
419
|
+
)
|
|
420
|
+
print(" ".join([str(session.idx) for session in to_remove]))
|
|
421
|
+
|
|
422
|
+
if ask_user("Are your sure?", default=not interactive, interactive=interactive):
|
|
423
|
+
for session in to_remove:
|
|
424
|
+
session_dir = sessions_dir / str(session.idx)
|
|
425
|
+
if not session_dir.is_dir():
|
|
426
|
+
# Skip / Dir does not exist
|
|
427
|
+
continue
|
|
428
|
+
shutil.rmtree(session_dir)
|
|
429
|
+
self.sessions = to_keep
|
|
430
|
+
self.session_idx = self.sessions[-1].idx if len(self.sessions) > 0 else -1
|
|
431
|
+
if interactive:
|
|
432
|
+
print("Done")
|
|
433
|
+
else:
|
|
434
|
+
if interactive:
|
|
435
|
+
print("Aborted")
|
|
436
|
+
else:
|
|
437
|
+
if interactive:
|
|
438
|
+
print("No sessions selected for removal")
|
|
439
|
+
# We currently do not support rewirting the indices to start from scratch again as this
|
|
440
|
+
# would lead to inconsitencies with the path in the report/cmake build dirtectory
|
|
441
|
+
|
|
442
|
+
def get_sessions_runs_idx(self):
|
|
443
|
+
sessions_dict = {}
|
|
444
|
+
for session in self.sessions:
|
|
445
|
+
session_runs_idx = [run.idx if run.idx is not None else i for i, run in enumerate(session.runs)]
|
|
446
|
+
sessions_dict[session.idx] = session_runs_idx
|
|
447
|
+
return sessions_dict
|
|
448
|
+
|
|
449
|
+
def print_summary(self, sessions=True, runs=False, labels=True):
|
|
450
|
+
def print_sessions(sessions_runs, with_runs=False, with_labels=True):
|
|
451
|
+
print("Sessions:")
|
|
452
|
+
session_index_map = {session.idx: i for i, session in enumerate(self.sessions)}
|
|
453
|
+
for session, runs in sessions_runs.items():
|
|
454
|
+
print(f" - {session}", end="")
|
|
455
|
+
if with_runs:
|
|
456
|
+
print(" (" + self.sessions[session_index_map[session]].label + ")", end="")
|
|
457
|
+
if with_runs:
|
|
458
|
+
print(" [runs: " + " ".join([str(run) for run in runs]) + "]", end="")
|
|
459
|
+
print()
|
|
460
|
+
|
|
461
|
+
print("Context Summary\n")
|
|
462
|
+
sessions_runs = self.get_sessions_runs_idx()
|
|
463
|
+
print_sessions(sessions_runs, with_runs=runs, with_labels=labels)
|
|
464
|
+
|
|
465
|
+
def export(self, dest, session_ids=None, run_ids=None, interactive=True):
|
|
466
|
+
dest = Path(dest)
|
|
467
|
+
if (dest.is_file() and dest.exists()) or (dest.is_dir() and utils.is_populated(dest)):
|
|
468
|
+
if not ask_user("Destination is already populated! Overwrite?", default=True, interactive=interactive):
|
|
469
|
+
print("Aborted")
|
|
470
|
+
return
|
|
471
|
+
dest_, ext = os.path.splitext(dest)
|
|
472
|
+
if session_ids is None:
|
|
473
|
+
# Can not select all sessions, fall back to latest session
|
|
474
|
+
session_ids = [-1]
|
|
475
|
+
|
|
476
|
+
if run_ids is not None:
|
|
477
|
+
assert len(session_ids) == 1, "Can only choose runs of a single session"
|
|
478
|
+
|
|
479
|
+
def find_session(sid):
|
|
480
|
+
if len(self.sessions) == 0:
|
|
481
|
+
return None
|
|
482
|
+
|
|
483
|
+
if sid == -1:
|
|
484
|
+
assert len(self.sessions) > 0
|
|
485
|
+
return self.sessions[-1]
|
|
486
|
+
|
|
487
|
+
for session in self.sessions:
|
|
488
|
+
if session.idx == sid:
|
|
489
|
+
return session
|
|
490
|
+
return None
|
|
491
|
+
|
|
492
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
493
|
+
tmpdir = Path(tmpdirname)
|
|
494
|
+
for sid in session_ids:
|
|
495
|
+
session = find_session(sid)
|
|
496
|
+
if session is None:
|
|
497
|
+
print(
|
|
498
|
+
f"Lookup for session id {sid} failed. Available:", " ".join([str(s.idx) for s in self.sessions])
|
|
499
|
+
)
|
|
500
|
+
sys.exit(1)
|
|
501
|
+
if len(session_ids) == 1:
|
|
502
|
+
base = tmpdir
|
|
503
|
+
else:
|
|
504
|
+
base = tmpdir / str(sid)
|
|
505
|
+
if run_ids is None:
|
|
506
|
+
src = session.dir / "runs"
|
|
507
|
+
shutil.copytree(
|
|
508
|
+
src, base, dirs_exist_ok=True, symlinks=True
|
|
509
|
+
) # Warning: dirs_exist_ok=True requires python 3.8+
|
|
510
|
+
else:
|
|
511
|
+
base = base / "runs"
|
|
512
|
+
for rid in run_ids:
|
|
513
|
+
if rid >= len(session.runs):
|
|
514
|
+
print(
|
|
515
|
+
f"Lookup for run id {rid} failed in session {sid}. Available:",
|
|
516
|
+
" ".join([str(i) for i in range(len(session.runs))]),
|
|
517
|
+
)
|
|
518
|
+
sys.exit(1)
|
|
519
|
+
run = session.runs[rid] # TODO: We currently do not check if the index actually exists
|
|
520
|
+
if len(run_ids) == 1 and len(session_ids) == 1:
|
|
521
|
+
run_base = tmpdir
|
|
522
|
+
else:
|
|
523
|
+
run_base = base / str(rid)
|
|
524
|
+
src = run.dir
|
|
525
|
+
shutil.copytree(
|
|
526
|
+
src, run_base, dirs_exist_ok=True
|
|
527
|
+
) # Warning: dirs_exist_ok=True requires python 3.8+
|
|
528
|
+
if ext in [".zip", ".tar"]:
|
|
529
|
+
print(f"Creating archive: {dest}")
|
|
530
|
+
shutil.make_archive(dest_, ext[1:], tmpdirname)
|
|
531
|
+
else:
|
|
532
|
+
print(f"Creating directory: {dest}")
|
|
533
|
+
if dest.is_dir():
|
|
534
|
+
shutil.rmtree(dest) # Cleanup old contents
|
|
535
|
+
# dest.mkdir(exist_ok=True)
|
|
536
|
+
shutil.move(tmpdirname, str(dest))
|
|
537
|
+
print("Done")
|
|
538
|
+
|
|
539
|
+
def __exit__(self, exception_type, exception_value, traceback):
|
|
540
|
+
logger.debug("Exit MlonMcuContext")
|
|
541
|
+
self.cleanup()
|
|
542
|
+
if self.deps_lock:
|
|
543
|
+
logger.debug("Releasing lock on context")
|
|
544
|
+
self.deps_lock.release()
|
|
545
|
+
return False
|