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,282 @@
|
|
|
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 multiprocessing
|
|
20
|
+
|
|
21
|
+
from mlonmcu.flow.backend import Backend
|
|
22
|
+
from mlonmcu.setup import utils
|
|
23
|
+
from mlonmcu.config import str2bool
|
|
24
|
+
from .model_info import get_model_info, get_supported_formats
|
|
25
|
+
from .python_utils import prepare_python_environment
|
|
26
|
+
from .tvmc_utils import (
|
|
27
|
+
get_target_tvmc_args,
|
|
28
|
+
get_pass_config_tvmc_args,
|
|
29
|
+
get_disabled_pass_tvmc_args,
|
|
30
|
+
get_runtime_executor_tvmc_args,
|
|
31
|
+
get_input_shapes_tvmc_args,
|
|
32
|
+
get_tuning_records_tvmc_args,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TVMBackend(Backend):
|
|
37
|
+
registry = {}
|
|
38
|
+
|
|
39
|
+
name = None
|
|
40
|
+
|
|
41
|
+
FEATURES = ["autotuned", "cmsisnnbyoc", "muriscvnnbyoc", "disable_legalize", "moiopt"]
|
|
42
|
+
|
|
43
|
+
DEFAULTS = {
|
|
44
|
+
"print_outputs": False,
|
|
45
|
+
"opt_level": 3,
|
|
46
|
+
"target_device": None,
|
|
47
|
+
"target_mcpu": None,
|
|
48
|
+
"target_march": None,
|
|
49
|
+
"target_model": None,
|
|
50
|
+
"target_mtriple": None,
|
|
51
|
+
"target_mabi": None,
|
|
52
|
+
"target_mattr": None,
|
|
53
|
+
"extra_target": None,
|
|
54
|
+
"extra_target_mcpu": None,
|
|
55
|
+
"desired_layout": None, # optional: NCHW or NHWC
|
|
56
|
+
"disabled_passes": [], # i.e. AlterOpLayout
|
|
57
|
+
"extra_pass_config": {}, # TODO: some example (fuse_max_depth etc.)
|
|
58
|
+
"use_tuning_results": False,
|
|
59
|
+
"tvmc_extra_args": [], # Currently compile subcommand only!
|
|
60
|
+
"tvmc_custom_script": None,
|
|
61
|
+
# See https://github.com/apache/tvm/blob/1115fd9bc261619ffa0539746ae0aebc46232dc6/python/tvm/autotvm/tophub.py
|
|
62
|
+
"tophub_url": None,
|
|
63
|
+
"num_threads": multiprocessing.cpu_count(),
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
REQUIRED = []
|
|
67
|
+
|
|
68
|
+
OPTIONAL = ["tvm.build_dir", "tvm.pythonpath", "tvm.configs_dir", "tvm.use_tlcpack"]
|
|
69
|
+
|
|
70
|
+
def __init__(self, target="c", executor=None, runtime="crt", fmt="mlf", features=None, config=None):
|
|
71
|
+
super().__init__(framework="tvm", features=features, config=config)
|
|
72
|
+
|
|
73
|
+
self.model = None # Actual filename!
|
|
74
|
+
self.model_info = None
|
|
75
|
+
self.input_shapes = None
|
|
76
|
+
self.supported_formats = get_supported_formats()
|
|
77
|
+
self.target = target
|
|
78
|
+
self.runtime = runtime
|
|
79
|
+
self.executor = executor
|
|
80
|
+
self.fmt = fmt
|
|
81
|
+
|
|
82
|
+
self.prefix = "default"
|
|
83
|
+
self.artifacts = (
|
|
84
|
+
[]
|
|
85
|
+
) # TODO: either make sure that ony one model is processed at a time or move the artifacts to the methods
|
|
86
|
+
self._tuning_records = None
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def tuning_records(self):
|
|
90
|
+
if self._tuning_records:
|
|
91
|
+
return self._tuning_records
|
|
92
|
+
elif "autotuning_results_file" in self.config and self.config["autotuning_results_file"]:
|
|
93
|
+
return self.config["autotuning_results_file"]
|
|
94
|
+
else:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
@tuning_records.setter
|
|
98
|
+
def tuning_records(self, filepath):
|
|
99
|
+
self._tuning_records = filepath
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def pass_config(self):
|
|
103
|
+
base = {"tir.disable_vectorize": True}
|
|
104
|
+
extra = self.config["extra_pass_config"]
|
|
105
|
+
if isinstance(extra, str):
|
|
106
|
+
import ast
|
|
107
|
+
|
|
108
|
+
extra = ast.literal_eval(extra)
|
|
109
|
+
assert isinstance(extra, dict)
|
|
110
|
+
base.update(extra)
|
|
111
|
+
return base
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def target_device(self):
|
|
115
|
+
return self.config["target_device"]
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def target_mcpu(self):
|
|
119
|
+
return self.config["target_mcpu"]
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def target_march(self):
|
|
123
|
+
return self.config["target_march"]
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def target_mtriple(self):
|
|
127
|
+
return self.config["target_mtriple"]
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def target_mabi(self):
|
|
131
|
+
return self.config["target_mabi"]
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def target_mattr(self):
|
|
135
|
+
return self.config["target_mattr"]
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def target_model(self):
|
|
139
|
+
return self.config["target_model"]
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def extra_target(self):
|
|
143
|
+
return self.config["extra_target"]
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def extra_target_mcpu(self):
|
|
147
|
+
return self.config["extra_target_mcpu"]
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def desired_layout(self):
|
|
151
|
+
return self.config["desired_layout"]
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def opt_level(self):
|
|
155
|
+
return self.config["opt_level"]
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def use_tuning_results(self):
|
|
159
|
+
value = self.config["use_tuning_results"]
|
|
160
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
def tvmc_extra_args(self):
|
|
164
|
+
return self.config["tvmc_extra_args"]
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def tvmc_custom_script(self):
|
|
168
|
+
return self.config["tvmc_custom_script"]
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def disabled_passes(self):
|
|
172
|
+
return self.config["disabled_passes"]
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def tvm_pythonpath(self):
|
|
176
|
+
return self.config["tvm.pythonpath"]
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def tvm_build_dir(self):
|
|
180
|
+
return self.config["tvm.build_dir"]
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def tvm_configs_dir(self):
|
|
184
|
+
return self.config["tvm.configs_dir"]
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def tophub_url(self):
|
|
188
|
+
return self.config["tophub_url"]
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def print_outputs(self):
|
|
192
|
+
value = self.config["print_outputs"]
|
|
193
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def use_tlcpack(self):
|
|
197
|
+
value = self.config["tvm.use_tlcpack"]
|
|
198
|
+
return str2bool(value, allow_none=True) if not isinstance(value, (bool, int)) else value
|
|
199
|
+
|
|
200
|
+
def num_threads(self):
|
|
201
|
+
return self.config["num_threads"]
|
|
202
|
+
|
|
203
|
+
def get_target_details(self):
|
|
204
|
+
ret = {}
|
|
205
|
+
if self.target_device:
|
|
206
|
+
ret["device"] = self.target_device
|
|
207
|
+
if self.target_mcpu:
|
|
208
|
+
ret["mcpu"] = self.target_mcpu
|
|
209
|
+
if self.target_march:
|
|
210
|
+
ret["march"] = self.target_march
|
|
211
|
+
if self.target_mtriple:
|
|
212
|
+
ret["mtriple"] = self.target_mtriple
|
|
213
|
+
if self.target_mabi:
|
|
214
|
+
ret["mabi"] = self.target_mabi
|
|
215
|
+
if self.target_mattr:
|
|
216
|
+
ret["mattr"] = self.target_mattr
|
|
217
|
+
if self.target_model:
|
|
218
|
+
ret["model"] = self.target_model
|
|
219
|
+
return ret
|
|
220
|
+
|
|
221
|
+
def get_extra_target_details(self):
|
|
222
|
+
ret = {}
|
|
223
|
+
if self.extra_target_mcpu:
|
|
224
|
+
ret["mcpu"] = self.extra_target_mcpu
|
|
225
|
+
return ret
|
|
226
|
+
|
|
227
|
+
def get_tvmc_compile_args(self, out, dump=None):
|
|
228
|
+
assert self.executor is not None
|
|
229
|
+
assert self.executor in ["aot", "graph"], "Unsupported TVM executor"
|
|
230
|
+
args = [
|
|
231
|
+
self.model,
|
|
232
|
+
*get_target_tvmc_args(
|
|
233
|
+
self.target,
|
|
234
|
+
extra_target=self.extra_target,
|
|
235
|
+
target_details=self.get_target_details(),
|
|
236
|
+
extra_target_details=self.get_extra_target_details(),
|
|
237
|
+
),
|
|
238
|
+
*get_runtime_executor_tvmc_args(self.runtime, self.executor),
|
|
239
|
+
*get_pass_config_tvmc_args(self.pass_config),
|
|
240
|
+
*get_disabled_pass_tvmc_args(self.disabled_passes),
|
|
241
|
+
*get_input_shapes_tvmc_args(self.input_shapes),
|
|
242
|
+
*get_tuning_records_tvmc_args(self.use_tuning_results, self.tuning_records),
|
|
243
|
+
*(["--desired-layout", self.desired_layout] if self.desired_layout is not None else []),
|
|
244
|
+
*(["--dump-code", ",".join(dump)] if dump is not None else []),
|
|
245
|
+
*self.tvmc_extra_args,
|
|
246
|
+
*["--opt-level", str(self.opt_level)],
|
|
247
|
+
*["--output", str(out)],
|
|
248
|
+
*["-f", self.fmt],
|
|
249
|
+
*["--model-format", self.model_format],
|
|
250
|
+
]
|
|
251
|
+
return args
|
|
252
|
+
|
|
253
|
+
def invoke_tvmc(self, command, *args, cwd=None):
|
|
254
|
+
env = prepare_python_environment(
|
|
255
|
+
None if self.use_tlcpack else self.tvm_pythonpath,
|
|
256
|
+
None if self.use_tlcpack else self.tvm_build_dir,
|
|
257
|
+
None if self.use_tlcpack else self.tvm_configs_dir,
|
|
258
|
+
tophub_url=self.tophub_url,
|
|
259
|
+
num_threads=self.num_threads,
|
|
260
|
+
)
|
|
261
|
+
if self.use_tlcpack:
|
|
262
|
+
pre = ["tvmc"]
|
|
263
|
+
return utils.exec_getout(
|
|
264
|
+
*pre, command, *args, live=self.print_outputs, print_output=False, env=env, cwd=cwd
|
|
265
|
+
)
|
|
266
|
+
else:
|
|
267
|
+
if self.tvmc_custom_script is None:
|
|
268
|
+
pre = ["-m", "tvm.driver.tvmc"]
|
|
269
|
+
else:
|
|
270
|
+
pre = [self.tvmc_custom_script]
|
|
271
|
+
return utils.python(*pre, command, *args, live=self.print_outputs, print_output=False, env=env, cwd=cwd)
|
|
272
|
+
|
|
273
|
+
def invoke_tvmc_compile(self, out, dump=None, cwd=None):
|
|
274
|
+
args = self.get_tvmc_compile_args(out)
|
|
275
|
+
return self.invoke_tvmc("compile", *args, cwd=cwd)
|
|
276
|
+
|
|
277
|
+
def load_model(self, model):
|
|
278
|
+
self.model = model
|
|
279
|
+
# TODO: path model class instead of path!
|
|
280
|
+
# fmt = self.model.formats[0]
|
|
281
|
+
self.model_format, self.model_info = get_model_info(model, backend_name=self.name)
|
|
282
|
+
self.input_shapes = {tensor.name: tensor.shape for tensor in self.model_info.in_tensors}
|
|
@@ -0,0 +1,307 @@
|
|
|
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 re
|
|
20
|
+
import os
|
|
21
|
+
|
|
22
|
+
from mlonmcu.models.model import ModelFormats
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TensorInfo:
|
|
26
|
+
def __init__(self, name, shape, dtype, fix_names=False):
|
|
27
|
+
self.name = name
|
|
28
|
+
if fix_names:
|
|
29
|
+
self.name = self.name.replace("/", "_").replace(";", "_")
|
|
30
|
+
assert isinstance(shape, (tuple, list))
|
|
31
|
+
self.shape = shape
|
|
32
|
+
size_lookup = {
|
|
33
|
+
"float32": 4,
|
|
34
|
+
"uint8": 1,
|
|
35
|
+
"int8": 1,
|
|
36
|
+
"int32": 4,
|
|
37
|
+
"int64": 8,
|
|
38
|
+
}
|
|
39
|
+
assert dtype in size_lookup
|
|
40
|
+
self.dtype = dtype
|
|
41
|
+
self.type_size = size_lookup[self.dtype]
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def size(self):
|
|
45
|
+
ret = self.type_size
|
|
46
|
+
for dim in self.shape:
|
|
47
|
+
ret *= dim
|
|
48
|
+
return ret
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class TfLiteTensorInfo(TensorInfo):
|
|
52
|
+
def __init__(self, t, fix_names=False):
|
|
53
|
+
# Local imports to get rid of tflite dependency for non-tflite models
|
|
54
|
+
from tflite.TensorType import TensorType as TType
|
|
55
|
+
|
|
56
|
+
name = t.Name().decode()
|
|
57
|
+
shape = tuple([t.Shape(si) for si in range(0, t.ShapeLength())])
|
|
58
|
+
|
|
59
|
+
type_lookup = {
|
|
60
|
+
TType.FLOAT32: "float32",
|
|
61
|
+
TType.UINT8: "uint8",
|
|
62
|
+
TType.INT8: "int8",
|
|
63
|
+
TType.INT32: "int32",
|
|
64
|
+
TType.BOOL: "int8",
|
|
65
|
+
TType.INT64: "int64",
|
|
66
|
+
}
|
|
67
|
+
dtype = type_lookup[t.Type()]
|
|
68
|
+
super().__init__(name, shape, dtype, fix_names=fix_names)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class RelayTensorInfo(TensorInfo):
|
|
72
|
+
def __init__(self, name, shape, dtype, fix_names=False):
|
|
73
|
+
super().__init__(name, shape, dtype, fix_names=fix_names)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ModelInfo:
|
|
77
|
+
def __init__(self, in_tensors, out_tensors, fix_names=False):
|
|
78
|
+
self.in_tensors = in_tensors
|
|
79
|
+
self.out_tensors = out_tensors
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class TfLiteModelInfo(ModelInfo):
|
|
83
|
+
def __init__(self, model, fix_names=False):
|
|
84
|
+
assert model.SubgraphsLength() == 1
|
|
85
|
+
g = model.Subgraphs(0)
|
|
86
|
+
|
|
87
|
+
in_tensors = []
|
|
88
|
+
for i in range(0, g.InputsLength()):
|
|
89
|
+
t = g.Tensors(g.Inputs(i))
|
|
90
|
+
in_tensors.append(TfLiteTensorInfo(t, fix_names=fix_names))
|
|
91
|
+
|
|
92
|
+
out_tensors = []
|
|
93
|
+
for i in range(0, g.OutputsLength()):
|
|
94
|
+
t = g.Tensors(g.Outputs(i))
|
|
95
|
+
out_tensors.append(TfLiteTensorInfo(t, fix_names=fix_names))
|
|
96
|
+
super().__init__(in_tensors, out_tensors)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def shape_from_str(shape_str):
|
|
100
|
+
return tuple(map(int, shape_str.replace(" ", "").split(",")))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def parse_relay_main(line):
|
|
104
|
+
input_tensors = []
|
|
105
|
+
output_tensors = []
|
|
106
|
+
|
|
107
|
+
input_tensors_strs = re.compile(r"%[a-zA-Z0-9_]+: Tensor\[\((?:\d+)(?:,\s*\d+)*\), (?:[a-zA-Z0-9_]+)\]").findall(
|
|
108
|
+
line
|
|
109
|
+
)
|
|
110
|
+
for input_tensors_str in input_tensors_strs:
|
|
111
|
+
res = re.compile(r"%([a-zA-Z0-9]+): Tensor\[\((\d+(?:, \d+)+)\), ([a-zA-Z0-9_]+)\]").match(input_tensors_str)
|
|
112
|
+
assert res is not None
|
|
113
|
+
groups = res.groups()
|
|
114
|
+
assert len(groups) == 3
|
|
115
|
+
input_name, input_shape_str, input_type = groups
|
|
116
|
+
input_shape = shape_from_str(input_shape_str)
|
|
117
|
+
input_tensor = TensorInfo(input_name, input_shape, input_type)
|
|
118
|
+
input_tensors.append(input_tensor)
|
|
119
|
+
|
|
120
|
+
output_tensor_names_str = re.compile(r"output_tensor_names=\[(\".*\")\]").findall(line)
|
|
121
|
+
output_tensor_names = re.compile(r"\"([a-zA-Z0-9_]+)\"").findall(output_tensor_names_str[0])
|
|
122
|
+
|
|
123
|
+
output_tensors_str = re.compile(r"-> (.+) {").findall(line)
|
|
124
|
+
output_tensor_strs = re.compile(r"Tensor\[\(\d+(?:, \d+)+\), [a-zA-Z0-9_]+\]").findall(output_tensors_str[0])
|
|
125
|
+
|
|
126
|
+
assert len(output_tensor_names) == len(output_tensor_strs)
|
|
127
|
+
|
|
128
|
+
for i, output_name in enumerate(output_tensor_names):
|
|
129
|
+
res = re.compile(r"Tensor\[\((\d+(?:, \d+)+)\), ([a-zA-Z0-9_]+)\]").match(output_tensor_strs[i])
|
|
130
|
+
assert res is not None
|
|
131
|
+
groups = res.groups()
|
|
132
|
+
assert len(groups) == 2
|
|
133
|
+
output_shape_str, output_type = groups
|
|
134
|
+
output_shape = shape_from_str(output_shape_str)
|
|
135
|
+
output_tensor = TensorInfo(output_name, output_shape, output_type)
|
|
136
|
+
output_tensors.append(output_tensor)
|
|
137
|
+
return input_tensors, output_tensors
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class RelayModelInfo(ModelInfo):
|
|
141
|
+
def __init__(self, mod_text, fix_names=False):
|
|
142
|
+
in_tensors = None
|
|
143
|
+
out_tensors = None
|
|
144
|
+
for line in mod_text.split("\n"):
|
|
145
|
+
if "def @main(" in line:
|
|
146
|
+
in_tensors, out_tensors = parse_relay_main(line)
|
|
147
|
+
break
|
|
148
|
+
assert in_tensors is not None and out_tensors is not None
|
|
149
|
+
super().__init__(in_tensors, out_tensors)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def get_tfgraph_inout(graph):
|
|
153
|
+
ops = graph.get_operations()
|
|
154
|
+
outputs_set = set(ops)
|
|
155
|
+
inputs = []
|
|
156
|
+
for op in ops:
|
|
157
|
+
if op.type == "Placeholder":
|
|
158
|
+
inputs.append(op)
|
|
159
|
+
else:
|
|
160
|
+
for input_tensor in op.inputs:
|
|
161
|
+
if input_tensor.op in outputs_set:
|
|
162
|
+
outputs_set.remove(input_tensor.op)
|
|
163
|
+
outputs = list(outputs_set)
|
|
164
|
+
return (inputs, outputs)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class PBModelInfo(ModelInfo):
|
|
168
|
+
def __init__(self, model_file):
|
|
169
|
+
import tensorflow as tf
|
|
170
|
+
|
|
171
|
+
with tf.io.gfile.GFile(model_file, "rb") as f:
|
|
172
|
+
graph_def = tf.compat.v1.GraphDef()
|
|
173
|
+
graph_def.ParseFromString(f.read())
|
|
174
|
+
with tf.Graph().as_default() as graph:
|
|
175
|
+
tf.import_graph_def(graph_def)
|
|
176
|
+
inputs, outputs = get_tfgraph_inout(graph)
|
|
177
|
+
in_tensors = [TensorInfo(t.name, t.shape.as_list(), t.dtype.name) for op in inputs for t in op.outputs]
|
|
178
|
+
out_tensors = [TensorInfo(t.name, t.shape.as_list(), t.dtype.name) for op in outputs for t in op.outputs]
|
|
179
|
+
super().__init__(in_tensors, out_tensors)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class ONNXModelInfo(ModelInfo):
|
|
183
|
+
def __init__(self, model_file):
|
|
184
|
+
from google.protobuf.json_format import MessageToDict
|
|
185
|
+
import onnx
|
|
186
|
+
from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE
|
|
187
|
+
|
|
188
|
+
model = onnx.load(model_file)
|
|
189
|
+
|
|
190
|
+
def _helper(tensors):
|
|
191
|
+
ret = []
|
|
192
|
+
for tensor in tensors:
|
|
193
|
+
d = MessageToDict(tensor)
|
|
194
|
+
name = d["name"]
|
|
195
|
+
tensor_type = d["type"]["tensorType"]
|
|
196
|
+
elem_type = tensor_type["elemType"]
|
|
197
|
+
dims = tensor_type["shape"]["dim"]
|
|
198
|
+
shape = [int(x["dimValue"]) if "dimValue" in x else 40 for x in dims] # TODO: dyn shape
|
|
199
|
+
dtype = str(TENSOR_TYPE_TO_NP_TYPE[elem_type])
|
|
200
|
+
ret.append(TensorInfo(name, shape, dtype))
|
|
201
|
+
return ret
|
|
202
|
+
|
|
203
|
+
in_tensors = _helper(model.graph.input)
|
|
204
|
+
out_tensors = _helper(model.graph.output)
|
|
205
|
+
|
|
206
|
+
# TVM seems to ignore the original output names for ONNX models
|
|
207
|
+
for i, t in enumerate(out_tensors):
|
|
208
|
+
t.name = f"output{i}"
|
|
209
|
+
super().__init__(in_tensors, out_tensors)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class PaddleModelInfo(ModelInfo):
|
|
213
|
+
def __init__(self, model_file):
|
|
214
|
+
import paddle
|
|
215
|
+
|
|
216
|
+
paddle.enable_static()
|
|
217
|
+
paddle.disable_signal_handler()
|
|
218
|
+
|
|
219
|
+
exe = paddle.static.Executor(paddle.CPUPlace())
|
|
220
|
+
prefix = "".join(model_file.strip().split(".")[:-1])
|
|
221
|
+
program, _, _ = paddle.static.load_inference_model(prefix, exe)
|
|
222
|
+
|
|
223
|
+
output_names = list()
|
|
224
|
+
for block in program.blocks:
|
|
225
|
+
for op in block.ops:
|
|
226
|
+
if op.type == "fetch":
|
|
227
|
+
output_names.append(op.input("X")[0])
|
|
228
|
+
|
|
229
|
+
def _convert_dtype_value(val):
|
|
230
|
+
"""Converts a Paddle type id to a string."""
|
|
231
|
+
# See: https://github.com/apache/tvm/blob/cc769fdc951707b8be991949864817b955a4dbc7/python/tvm/
|
|
232
|
+
# relay/frontend/paddlepaddle.py#L70
|
|
233
|
+
|
|
234
|
+
convert_dtype_map = {
|
|
235
|
+
21: "int8",
|
|
236
|
+
20: "uint8",
|
|
237
|
+
6: "float64",
|
|
238
|
+
5: "float32",
|
|
239
|
+
4: "float16",
|
|
240
|
+
3: "int64",
|
|
241
|
+
2: "int32",
|
|
242
|
+
1: "int16",
|
|
243
|
+
0: "bool",
|
|
244
|
+
}
|
|
245
|
+
if val not in convert_dtype_map:
|
|
246
|
+
msg = "Paddle data type value %d is not handled yet." % (val)
|
|
247
|
+
raise NotImplementedError(msg)
|
|
248
|
+
return convert_dtype_map[val]
|
|
249
|
+
|
|
250
|
+
raise NotImplementedError
|
|
251
|
+
# super().__init__(in_tensors, out_tensors)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def get_tflite_model_info(model_buf):
|
|
255
|
+
# Local imports to get rid of tflite dependency for non-tflite models
|
|
256
|
+
import tflite
|
|
257
|
+
|
|
258
|
+
tflite_model = tflite.Model.GetRootAsModel(model_buf, 0)
|
|
259
|
+
model_info = TfLiteModelInfo(tflite_model)
|
|
260
|
+
return model_info
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def get_relay_model_info(mod_text):
|
|
264
|
+
model_info = RelayModelInfo(mod_text)
|
|
265
|
+
return model_info
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def get_pb_model_info(model_file):
|
|
269
|
+
model_info = PBModelInfo(model_file)
|
|
270
|
+
return model_info
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def get_paddle_model_info(model_file):
|
|
274
|
+
model_info = PaddleModelInfo(model_file)
|
|
275
|
+
return model_info
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def get_onnx_model_info(model_file):
|
|
279
|
+
model_info = ONNXModelInfo(model_file)
|
|
280
|
+
return model_info
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def get_model_info(model, backend_name="unknown"):
|
|
284
|
+
ext = os.path.splitext(model)[1][1:]
|
|
285
|
+
fmt = ModelFormats.from_extension(ext)
|
|
286
|
+
if fmt == ModelFormats.TFLITE:
|
|
287
|
+
with open(model, "rb") as handle:
|
|
288
|
+
model_buf = handle.read()
|
|
289
|
+
return "tflite", get_tflite_model_info(model_buf)
|
|
290
|
+
elif fmt == ModelFormats.RELAY:
|
|
291
|
+
# Warning: the wrapper generateion does currently not work because of the
|
|
292
|
+
# missing possibility to get the relay models input names and shapes
|
|
293
|
+
with open(model, "r") as handle:
|
|
294
|
+
mod_text = handle.read()
|
|
295
|
+
return "relay", get_relay_model_info(mod_text)
|
|
296
|
+
elif fmt == ModelFormats.PB:
|
|
297
|
+
return "pb", get_pb_model_info(model)
|
|
298
|
+
elif fmt == ModelFormats.ONNX:
|
|
299
|
+
return "onnx", get_onnx_model_info(model)
|
|
300
|
+
elif fmt == ModelFormats.PADDLE:
|
|
301
|
+
return "pdmodel", get_pb_model_info(model)
|
|
302
|
+
else:
|
|
303
|
+
raise RuntimeError(f"Unsupported model format '{fmt.name}' for backend '{backend_name}'")
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def get_supported_formats():
|
|
307
|
+
return [ModelFormats.TFLITE, ModelFormats.RELAY, ModelFormats.PB, ModelFormats.ONNX, ModelFormats.PADDLE]
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
|
|
21
|
+
|
|
22
|
+
def prepare_python_environment(pythonpath, tvm_build_dir, tvm_configs_dir, tophub_url=None, num_threads=None):
|
|
23
|
+
env = os.environ.copy()
|
|
24
|
+
if pythonpath:
|
|
25
|
+
env["PYTHONPATH"] = str(pythonpath)
|
|
26
|
+
if tvm_build_dir:
|
|
27
|
+
env["TVM_LIBRARY_PATH"] = str(tvm_build_dir)
|
|
28
|
+
if tvm_configs_dir:
|
|
29
|
+
env["TVM_CONFIGS_JSON_DIR"] = str(tvm_configs_dir)
|
|
30
|
+
if tophub_url:
|
|
31
|
+
env["TOPHUB_LOCATION"] = tophub_url
|
|
32
|
+
if num_threads:
|
|
33
|
+
env["TVM_NUM_THREADS"] = str(num_threads)
|
|
34
|
+
# Use all cores/threads for building models and let OS scheduler decide on the mapping
|
|
35
|
+
env["TVM_BIND_THREADS"] = str(0)
|
|
36
|
+
return env
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TVMTuner:
|
|
22
|
+
DEFAULTS = {
|
|
23
|
+
"enable": False,
|
|
24
|
+
"print_outputs": False,
|
|
25
|
+
"results_file": None,
|
|
26
|
+
"append": None,
|
|
27
|
+
"tuner": "ga", # Options: ga,gridsearch,random,xgb,xgb_knob,xgb-rank
|
|
28
|
+
"trials": 10, # TODO: increase to 100?
|
|
29
|
+
"early_stopping": None, # calculate default dynamically
|
|
30
|
+
"num_workers": 1,
|
|
31
|
+
"max_parallel": 1,
|
|
32
|
+
"use_rpc": False,
|
|
33
|
+
"timeout": 100,
|
|
34
|
+
"mode": "autotvm", # Options: autotvm, auto_scheduler
|
|
35
|
+
"visualize": False,
|
|
36
|
+
"tasks": None,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def __init__(self, backend, config=None):
|
|
40
|
+
self.backend = backend
|
|
41
|
+
self.config = config if config is not None else {}
|