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,645 @@
|
|
|
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
|
+
"""TODO"""
|
|
20
|
+
|
|
21
|
+
import string
|
|
22
|
+
from datetime import datetime
|
|
23
|
+
from math import ceil, log2
|
|
24
|
+
|
|
25
|
+
# TODO: use this
|
|
26
|
+
# from tvm.relay.backend.utils import mangle_module_name
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def calc_pages(workspace_size, page_size=2**10):
|
|
30
|
+
# Determine the number of required pages
|
|
31
|
+
assert workspace_size >= 0, "Workspace size can not be negative"
|
|
32
|
+
crtPageSizeLog2 = log2(page_size)
|
|
33
|
+
assert crtPageSizeLog2 == int(crtPageSizeLog2), "Page size has to be a power of two"
|
|
34
|
+
crtNumPages = ceil(workspace_size / page_size)
|
|
35
|
+
return int(crtNumPages), int(crtPageSizeLog2)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def generate_wrapper_header():
|
|
39
|
+
out = """#ifndef TVM_WRAPPER_H
|
|
40
|
+
#define TVM_WRAPPER_H
|
|
41
|
+
|
|
42
|
+
#include <stddef.h>
|
|
43
|
+
|
|
44
|
+
void TVMWrap_Init();
|
|
45
|
+
void *TVMWrap_GetInputPtr(int index);
|
|
46
|
+
size_t TVMWrap_GetInputSize(int index);
|
|
47
|
+
size_t TVMWrap_GetNumInputs();
|
|
48
|
+
void TVMWrap_Run();
|
|
49
|
+
void *TVMWrap_GetOutputPtr(int index);
|
|
50
|
+
size_t TVMWrap_GetOutputSize(int index);
|
|
51
|
+
size_t TVMWrap_GetNumOutputs();
|
|
52
|
+
|
|
53
|
+
#endif // TVM_WRAPPER_H
|
|
54
|
+
"""
|
|
55
|
+
return out
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def generate_header():
|
|
59
|
+
time = datetime.now()
|
|
60
|
+
header = f"""// This file is generated. Do not edit.
|
|
61
|
+
// Generated on: {time}
|
|
62
|
+
"""
|
|
63
|
+
return header
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def generate_common_includes():
|
|
67
|
+
return """
|
|
68
|
+
#include <stdlib.h>
|
|
69
|
+
#include <stdarg.h>
|
|
70
|
+
#include <dlpack/dlpack.h>
|
|
71
|
+
#include "tvm/runtime/crt/error_codes.h"
|
|
72
|
+
#include "tvm/runtime/c_runtime_api.h"
|
|
73
|
+
#include "printing.h"
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def generate_graph_includes():
|
|
78
|
+
out = generate_common_includes()
|
|
79
|
+
out += """
|
|
80
|
+
#include "tvm/runtime/crt/packed_func.h"
|
|
81
|
+
#include "tvm/runtime/crt/crt.h"
|
|
82
|
+
#include "tvm/runtime/crt/graph_executor.h"
|
|
83
|
+
#include "tvm/runtime/crt/page_allocator.h"
|
|
84
|
+
|
|
85
|
+
"""
|
|
86
|
+
return out
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def generate_aot_includes(allocator):
|
|
90
|
+
out = generate_common_includes()
|
|
91
|
+
if allocator:
|
|
92
|
+
out += '#include "tvm/runtime/crt/stack_allocator.h"\n'
|
|
93
|
+
return out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def fill(template, **kwargs):
|
|
97
|
+
return string.Template(template).substitute(**kwargs)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def getSizes(tensors):
|
|
101
|
+
out = "size_t sizes[] = { "
|
|
102
|
+
for t in tensors:
|
|
103
|
+
out += str(t.size) + ", "
|
|
104
|
+
out += "};"
|
|
105
|
+
return out
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def write_tvmrt_wrapper(path, graph, params, model_info, workspace_size):
|
|
109
|
+
with open(path, "w") as f:
|
|
110
|
+
text = generate_tvmrt_wrapper(graph, params, model_info, workspace_size)
|
|
111
|
+
f.write(text)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def generate_tvmrt_wrapper(graph, params, model_info, workspace_size, debug_arena=False):
|
|
115
|
+
crtNumPages, crtPageSizeLog2 = calc_pages(workspace_size)
|
|
116
|
+
|
|
117
|
+
def escapeJson(j):
|
|
118
|
+
return j.replace('"', '\\"').replace("\n", "\\\n")
|
|
119
|
+
|
|
120
|
+
def toCArray(bin):
|
|
121
|
+
result = ""
|
|
122
|
+
for c in bin:
|
|
123
|
+
result += hex(c) + ", "
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
def getMeta(tensors, withNames=False):
|
|
127
|
+
out = ""
|
|
128
|
+
if withNames:
|
|
129
|
+
out = "const char *names[] = { "
|
|
130
|
+
for t in tensors:
|
|
131
|
+
out += '"' + t.name + '", '
|
|
132
|
+
out += "};\n "
|
|
133
|
+
|
|
134
|
+
out += "DLDataType dtypes[] = {"
|
|
135
|
+
for t in tensors:
|
|
136
|
+
if t.dtype == "float32":
|
|
137
|
+
out += "{kDLFloat, 32, 1}"
|
|
138
|
+
elif t.dtype == "uint8":
|
|
139
|
+
out += "{kDLUInt, 8, 1}"
|
|
140
|
+
elif t.dtype == "int8":
|
|
141
|
+
out += "{kDLInt, 8, 1}"
|
|
142
|
+
else:
|
|
143
|
+
raise "Invalid type"
|
|
144
|
+
out += ", "
|
|
145
|
+
out += "};\n "
|
|
146
|
+
|
|
147
|
+
for i, t in enumerate(tensors):
|
|
148
|
+
out += "int64_t shape_" + str(i) + "[] = { "
|
|
149
|
+
for s in t.shape:
|
|
150
|
+
out += str(s) + ", "
|
|
151
|
+
out += "};\n "
|
|
152
|
+
out += "int64_t *shapes[] = { "
|
|
153
|
+
for i, t in enumerate(tensors):
|
|
154
|
+
out += "shape_" + str(i) + ", "
|
|
155
|
+
out += "};\n"
|
|
156
|
+
|
|
157
|
+
out += "size_t ndims[] = { "
|
|
158
|
+
for i, t in enumerate(tensors):
|
|
159
|
+
out += str(len(t.shape)) + ", "
|
|
160
|
+
out += "};\n "
|
|
161
|
+
|
|
162
|
+
for i, t in enumerate(tensors):
|
|
163
|
+
out += " static uint8_t data_" + str(i) + "[" + str(t.size) + "];\n"
|
|
164
|
+
out += " uint8_t *data[] = { "
|
|
165
|
+
for i, t in enumerate(tensors):
|
|
166
|
+
out += "data_" + str(i) + ", "
|
|
167
|
+
out += "};"
|
|
168
|
+
|
|
169
|
+
return out
|
|
170
|
+
|
|
171
|
+
out = ""
|
|
172
|
+
out += generate_header()
|
|
173
|
+
out += generate_graph_includes()
|
|
174
|
+
out += 'const char * const g_graph = "' + escapeJson(graph) + '";\n'
|
|
175
|
+
out += "const char g_params[] = { " + toCArray(params) + "\n};\n"
|
|
176
|
+
out += "const uint64_t g_params_size = " + str(len(params)) + ";\n"
|
|
177
|
+
|
|
178
|
+
mainCode = """
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
#define CRT_MEMORY_NUM_PAGES ${numPages}
|
|
182
|
+
#define CRT_MEMORY_PAGE_SIZE_LOG2 ${pageSizeLog2}
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
if debug_arena: # This will enable the feature only if it is not overwritten by the user/compiler
|
|
186
|
+
mainCode += """
|
|
187
|
+
#ifndef DEBUG_ARENA_USAGE
|
|
188
|
+
#define DEBUG_ARENA_USAGE 1
|
|
189
|
+
#endif
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
mainCode += """
|
|
193
|
+
#ifdef DEBUG_ARENA_USAGE
|
|
194
|
+
size_t max_arena_usage = 0;
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
static uint8_t g_crt_memory[CRT_MEMORY_NUM_PAGES * (1 << CRT_MEMORY_PAGE_SIZE_LOG2)];
|
|
198
|
+
static MemoryManagerInterface* g_memory_manager;
|
|
199
|
+
|
|
200
|
+
/*! \\brief macro to do C API call */
|
|
201
|
+
#define TVM_CCALL(func) \\
|
|
202
|
+
do { \\
|
|
203
|
+
tvm_crt_error_t ret = (func); \\
|
|
204
|
+
if (ret != kTvmErrorNoError) { \\
|
|
205
|
+
TVMLogf("%s: %d: error: %s\\n", __FILE__, __LINE__, TVMGetLastError()); \\
|
|
206
|
+
TVMPlatformAbort(ret); \\
|
|
207
|
+
} \\
|
|
208
|
+
} while (0)
|
|
209
|
+
|
|
210
|
+
TVMModuleHandle TVMArgs_AsModuleHandle(const TVMArgs* args, size_t index);
|
|
211
|
+
|
|
212
|
+
void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t code)
|
|
213
|
+
{
|
|
214
|
+
exit(1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
void TVMLogf(const char* msg, ...)
|
|
218
|
+
{
|
|
219
|
+
va_list args;
|
|
220
|
+
va_start(args, msg);
|
|
221
|
+
DBGPRINTF(msg, args);
|
|
222
|
+
va_end(args);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr)
|
|
226
|
+
{
|
|
227
|
+
tvm_crt_error_t ret = g_memory_manager->Allocate(g_memory_manager, num_bytes, dev, out_ptr);
|
|
228
|
+
#ifdef DEBUG_ARENA_USAGE
|
|
229
|
+
// Use this to estimate the required number of pages
|
|
230
|
+
// Run in DEBUG mode in insert value of MAX printed last into the following equation:
|
|
231
|
+
// (This will round to the next power of 2 which might not be wanted!)
|
|
232
|
+
// num_pages = 2**ceil(log2(MAX/page_size))
|
|
233
|
+
size_t end = (size_t)(*out_ptr-(void*)g_crt_memory)+num_bytes;
|
|
234
|
+
if (end > max_arena_usage)
|
|
235
|
+
{
|
|
236
|
+
max_arena_usage = end;
|
|
237
|
+
}
|
|
238
|
+
#endif
|
|
239
|
+
return ret;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev)
|
|
243
|
+
{
|
|
244
|
+
return g_memory_manager->Free(g_memory_manager, ptr, dev);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
tvm_crt_error_t TVMPlatformTimerStart()
|
|
248
|
+
{
|
|
249
|
+
return kTvmErrorFunctionCallNotImplemented;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds)
|
|
253
|
+
{
|
|
254
|
+
return kTvmErrorFunctionCallNotImplemented;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
void *g_handle = NULL;
|
|
258
|
+
|
|
259
|
+
void TVMWrap_Init()
|
|
260
|
+
{
|
|
261
|
+
int64_t device_type = kDLCPU;
|
|
262
|
+
int64_t device_id = 0;
|
|
263
|
+
|
|
264
|
+
TVMByteArray params;
|
|
265
|
+
params.data = g_params;
|
|
266
|
+
params.size = g_params_size;
|
|
267
|
+
|
|
268
|
+
DLDevice dev;
|
|
269
|
+
dev.device_type = (DLDeviceType)device_type;
|
|
270
|
+
dev.device_id = device_id;
|
|
271
|
+
|
|
272
|
+
// get pointers
|
|
273
|
+
TVM_CCALL(PageMemoryManagerCreate(&g_memory_manager, g_crt_memory, sizeof(g_crt_memory),
|
|
274
|
+
CRT_MEMORY_PAGE_SIZE_LOG2));
|
|
275
|
+
TVM_CCALL(TVMInitializeRuntime());
|
|
276
|
+
TVMPackedFunc pf;
|
|
277
|
+
TVMArgs args = TVMArgs_Create(NULL, NULL, 0);
|
|
278
|
+
TVM_CCALL(TVMPackedFunc_InitGlobalFunc(&pf, "runtime.SystemLib", &args));
|
|
279
|
+
TVM_CCALL(TVMPackedFunc_Call(&pf));
|
|
280
|
+
|
|
281
|
+
TVMModuleHandle mod_syslib = TVMArgs_AsModuleHandle(&pf.ret_value, 0);
|
|
282
|
+
|
|
283
|
+
// run modules
|
|
284
|
+
TVMGraphExecutor* graph_executor = NULL;
|
|
285
|
+
TVM_CCALL(TVMGraphExecutor_Create(g_graph, mod_syslib, &dev, &graph_executor));
|
|
286
|
+
TVM_CCALL(TVMGraphExecutor_LoadParams(graph_executor, params.data, params.size));
|
|
287
|
+
|
|
288
|
+
//return graph_executor;
|
|
289
|
+
g_handle = graph_executor;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
void *TVMWrap_GetInputPtr(int index)
|
|
293
|
+
{
|
|
294
|
+
${inMeta}
|
|
295
|
+
|
|
296
|
+
DLTensor input;
|
|
297
|
+
input.data = (void*)data[index];
|
|
298
|
+
DLDevice device = {kDLCPU, 0};
|
|
299
|
+
input.device = device;
|
|
300
|
+
input.ndim = ndims[index];
|
|
301
|
+
input.dtype = dtypes[index];
|
|
302
|
+
input.shape = shapes[index];
|
|
303
|
+
input.strides = NULL;
|
|
304
|
+
input.byte_offset = 0;
|
|
305
|
+
|
|
306
|
+
TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)g_handle;
|
|
307
|
+
TVMGraphExecutor_SetInput(graph_executor, names[index], &input);
|
|
308
|
+
|
|
309
|
+
return data[index];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
size_t TVMWrap_GetInputSize(int index)
|
|
313
|
+
{
|
|
314
|
+
${inSizes}
|
|
315
|
+
|
|
316
|
+
return sizes[index];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
size_t TVMWrap_GetNumInputs()
|
|
320
|
+
{
|
|
321
|
+
return ${numInputs};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
void TVMWrap_Run()
|
|
325
|
+
{
|
|
326
|
+
TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)g_handle;
|
|
327
|
+
TVMGraphExecutor_Run(graph_executor);
|
|
328
|
+
#if DEBUG_ARENA_USAGE
|
|
329
|
+
DBGPRINTF("\\nGraph executor arena max usage after model invocation: %lu bytes\\n", max_arena_usage);
|
|
330
|
+
#endif // DEBUG_ARENA_USAGE
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
void *TVMWrap_GetOutputPtr(int index)
|
|
334
|
+
{
|
|
335
|
+
${outMeta}
|
|
336
|
+
|
|
337
|
+
DLTensor output;
|
|
338
|
+
output.data = (void*)data[index];
|
|
339
|
+
DLDevice device = {kDLCPU, 0};
|
|
340
|
+
output.device = device;
|
|
341
|
+
output.ndim = ndims[index];
|
|
342
|
+
output.dtype = dtypes[index];
|
|
343
|
+
output.shape = shapes[index];
|
|
344
|
+
output.strides = NULL;
|
|
345
|
+
output.byte_offset = 0;
|
|
346
|
+
|
|
347
|
+
TVMGraphExecutor* graph_executor = (TVMGraphExecutor*)g_handle;
|
|
348
|
+
TVMGraphExecutor_GetOutput(graph_executor, index, &output);
|
|
349
|
+
|
|
350
|
+
return data[index];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
size_t TVMWrap_GetOutputSize(int index)
|
|
354
|
+
{
|
|
355
|
+
${outSizes}
|
|
356
|
+
|
|
357
|
+
return sizes[index];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
size_t TVMWrap_GetNumOutputs()
|
|
361
|
+
{
|
|
362
|
+
return ${numOutputs};
|
|
363
|
+
}
|
|
364
|
+
"""
|
|
365
|
+
out += fill(
|
|
366
|
+
mainCode,
|
|
367
|
+
inMeta=getMeta(model_info.in_tensors, True),
|
|
368
|
+
outMeta=getMeta(model_info.out_tensors),
|
|
369
|
+
inSizes=getSizes(model_info.in_tensors),
|
|
370
|
+
outSizes=getSizes(model_info.out_tensors),
|
|
371
|
+
numInputs=len(model_info.in_tensors),
|
|
372
|
+
numOutputs=len(model_info.out_tensors),
|
|
373
|
+
numPages=crtNumPages,
|
|
374
|
+
pageSizeLog2=crtPageSizeLog2,
|
|
375
|
+
)
|
|
376
|
+
return out
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def generate_tvmaot_wrapper(model_info, workspace_size, mod_name, api="c", debug_arena=False):
|
|
380
|
+
modPrefix = f"tvmgen_{mod_name}"
|
|
381
|
+
|
|
382
|
+
def writeTensors(in_tensors, out_tensors, modPrefix, api):
|
|
383
|
+
if api == "c":
|
|
384
|
+
retStr = """
|
|
385
|
+
// Define data for input and output tensors
|
|
386
|
+
"""
|
|
387
|
+
|
|
388
|
+
def writeTensorsHelper(tensors, prefix, out=False):
|
|
389
|
+
lenTensors = len(tensors)
|
|
390
|
+
direction = "out" if out else "in"
|
|
391
|
+
ret = ""
|
|
392
|
+
names = [f"{direction}put{i}_data" for i in range(lenTensors)]
|
|
393
|
+
for i, t in enumerate(tensors):
|
|
394
|
+
ret += "char " + names[i] + "[" + str(t.size) + "];\n"
|
|
395
|
+
ret += f"void* {direction}puts[] = {{" + ", ".join(names) + "};\n"
|
|
396
|
+
ret += f"struct {prefix}_{direction}puts {prefix}_{direction}puts = {{" + "\n"
|
|
397
|
+
for i, t in enumerate(tensors):
|
|
398
|
+
tensor_name = t.name.replace(":", "_").replace("/", "_").replace(".", "_")
|
|
399
|
+
ret += f" .{tensor_name} = {names[i]}," + "\n"
|
|
400
|
+
ret += "};\n"
|
|
401
|
+
return ret
|
|
402
|
+
|
|
403
|
+
retStr += writeTensorsHelper(in_tensors, modPrefix, False)
|
|
404
|
+
retStr += writeTensorsHelper(out_tensors, modPrefix, True)
|
|
405
|
+
return retStr
|
|
406
|
+
elif api == "packed":
|
|
407
|
+
retStr = """
|
|
408
|
+
// Define data for input and output tensors
|
|
409
|
+
"""
|
|
410
|
+
|
|
411
|
+
def writeTensorsHelper(tensors, prefix, out=False):
|
|
412
|
+
lenTensors = len(tensors)
|
|
413
|
+
direction = "out" if out else "in"
|
|
414
|
+
ret = ""
|
|
415
|
+
names = [f"{direction}put{i}_data" for i in range(lenTensors)]
|
|
416
|
+
for i, t in enumerate(tensors):
|
|
417
|
+
ret += "char " + names[i] + "[" + str(t.size) + "];\n"
|
|
418
|
+
ret += f"void* {direction}puts[] = {{" + ", ".join(names) + "};\n"
|
|
419
|
+
return ret
|
|
420
|
+
|
|
421
|
+
retStr += writeTensorsHelper(in_tensors, modPrefix, False)
|
|
422
|
+
retStr += writeTensorsHelper(out_tensors, modPrefix, True)
|
|
423
|
+
return retStr
|
|
424
|
+
else:
|
|
425
|
+
raise RuntimeError("api has to be either 'c' or 'packed'")
|
|
426
|
+
|
|
427
|
+
out = ""
|
|
428
|
+
out += generate_header()
|
|
429
|
+
includes = generate_aot_includes(workspace_size > 0)
|
|
430
|
+
|
|
431
|
+
if api == "c":
|
|
432
|
+
includes += '#include "${modPrefix}.h"\n'
|
|
433
|
+
|
|
434
|
+
out += fill(includes, modPrefix=modPrefix)
|
|
435
|
+
|
|
436
|
+
out += "\n"
|
|
437
|
+
|
|
438
|
+
out += writeTensors(model_info.in_tensors, model_info.out_tensors, modPrefix, api)
|
|
439
|
+
|
|
440
|
+
logging_code = """
|
|
441
|
+
void TVMLogf(const char* msg, ...)
|
|
442
|
+
{
|
|
443
|
+
va_list args;
|
|
444
|
+
va_start(args, msg);
|
|
445
|
+
DBGPRINTF(msg, args);
|
|
446
|
+
va_end(args);
|
|
447
|
+
}
|
|
448
|
+
"""
|
|
449
|
+
|
|
450
|
+
out += logging_code
|
|
451
|
+
|
|
452
|
+
if workspace_size > 0:
|
|
453
|
+
workspace_code = """
|
|
454
|
+
#define WORKSPACE_SIZE (${workspaceBytes})
|
|
455
|
+
static uint8_t g_aot_memory[WORKSPACE_SIZE];
|
|
456
|
+
tvm_workspace_t app_workspace;
|
|
457
|
+
"""
|
|
458
|
+
|
|
459
|
+
if debug_arena: # This will enable the feature only if it is not overwritten by the user/compiler
|
|
460
|
+
workspace_code += """
|
|
461
|
+
#ifndef DEBUG_ARENA_USAGE
|
|
462
|
+
#define DEBUG_ARENA_USAGE 1
|
|
463
|
+
#endif
|
|
464
|
+
|
|
465
|
+
#ifndef TVMAOT_DEBUG_ALLOCATIONS
|
|
466
|
+
#define TVMAOT_DEBUG_ALLOCATIONS 1
|
|
467
|
+
#endif
|
|
468
|
+
"""
|
|
469
|
+
|
|
470
|
+
workspace_code += """
|
|
471
|
+
#ifdef DEBUG_ARENA_USAGE
|
|
472
|
+
size_t max_arena_usage = 0;
|
|
473
|
+
#endif
|
|
474
|
+
|
|
475
|
+
tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr)
|
|
476
|
+
{
|
|
477
|
+
#ifdef TVMAOT_DEBUG_ALLOCATIONS
|
|
478
|
+
if (num_bytes > (app_workspace.workspace + app_workspace.workspace_size - app_workspace.next_alloc))
|
|
479
|
+
{
|
|
480
|
+
TVMLogf("TVMPlatformMemoryAllocate(%lu): Allocation would overflow arena!\\n", num_bytes);
|
|
481
|
+
return kTvmErrorPlatformNoMemory;
|
|
482
|
+
}
|
|
483
|
+
#endif
|
|
484
|
+
tvm_crt_error_t ret = StackMemoryManager_Allocate(&app_workspace, num_bytes, out_ptr);
|
|
485
|
+
#ifdef DEBUG_ARENA_USAGE
|
|
486
|
+
// Use this to estimate the required number of bytes for the arena
|
|
487
|
+
size_t end = app_workspace.next_alloc-app_workspace.workspace;
|
|
488
|
+
if (end > max_arena_usage)
|
|
489
|
+
{
|
|
490
|
+
max_arena_usage = end;
|
|
491
|
+
}
|
|
492
|
+
#endif
|
|
493
|
+
return ret;
|
|
494
|
+
}
|
|
495
|
+
tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev)
|
|
496
|
+
{
|
|
497
|
+
#ifdef TVMAOT_DEBUG_ALLOCATIONS
|
|
498
|
+
if ((uint8_t*)ptr < app_workspace.workspace || (uint8_t*)ptr >= app_workspace.next_alloc)
|
|
499
|
+
{
|
|
500
|
+
TVMLogf("TVMPlatformMemoryFree(%p): Invalid Memory region to be free'd!\\n", ptr);
|
|
501
|
+
return kTvmErrorPlatformNoMemory;
|
|
502
|
+
}
|
|
503
|
+
#endif
|
|
504
|
+
return StackMemoryManager_Free(&app_workspace, ptr);
|
|
505
|
+
}
|
|
506
|
+
"""
|
|
507
|
+
out += fill(workspace_code, workspaceBytes=int(workspace_size))
|
|
508
|
+
else:
|
|
509
|
+
workspace_code = """
|
|
510
|
+
tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev, void** out_ptr)
|
|
511
|
+
{
|
|
512
|
+
return kTvmErrorFunctionCallNotImplemented;
|
|
513
|
+
}
|
|
514
|
+
tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev)
|
|
515
|
+
{
|
|
516
|
+
return kTvmErrorFunctionCallNotImplemented;
|
|
517
|
+
}
|
|
518
|
+
"""
|
|
519
|
+
out += workspace_code
|
|
520
|
+
|
|
521
|
+
mainCode = ""
|
|
522
|
+
if api == "packed":
|
|
523
|
+
mainCode += (
|
|
524
|
+
"int32_t ${modPrefix}_run(void* args, void* type_code, int num_args,"
|
|
525
|
+
+ " void* out_value, void* out_type_code, void* resource_handle);\n"
|
|
526
|
+
)
|
|
527
|
+
|
|
528
|
+
mainCode += """
|
|
529
|
+
void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t code)
|
|
530
|
+
{
|
|
531
|
+
exit(1);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
TVM_DLL int TVMFuncRegisterGlobal(const char* name, TVMFunctionHandle f, int override)
|
|
535
|
+
{
|
|
536
|
+
return 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
void TVMWrap_Init()
|
|
540
|
+
{
|
|
541
|
+
"""
|
|
542
|
+
if workspace_size > 0:
|
|
543
|
+
mainCode += " StackMemoryManager_Init(&app_workspace, g_aot_memory, WORKSPACE_SIZE);"
|
|
544
|
+
mainCode += """
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
void *TVMWrap_GetInputPtr(int index)
|
|
548
|
+
{
|
|
549
|
+
return inputs[index];
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
size_t TVMWrap_GetInputSize(int index)
|
|
553
|
+
{
|
|
554
|
+
${inSizes}
|
|
555
|
+
|
|
556
|
+
return sizes[index];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
size_t TVMWrap_GetNumInputs()
|
|
560
|
+
{
|
|
561
|
+
return ${numInputs};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
void TVMWrap_Run()
|
|
565
|
+
{"""
|
|
566
|
+
if api == "c":
|
|
567
|
+
mainCode += """
|
|
568
|
+
int ret_val = ${modPrefix}_run(&${modPrefix}_inputs, &${modPrefix}_outputs);
|
|
569
|
+
if (ret_val)
|
|
570
|
+
{
|
|
571
|
+
TVMPlatformAbort(kTvmErrorPlatformCheckFailure);
|
|
572
|
+
}
|
|
573
|
+
"""
|
|
574
|
+
elif api == "packed":
|
|
575
|
+
mainCode += """
|
|
576
|
+
static DLDevice fake_device = {kDLCPU, 0};
|
|
577
|
+
static int64_t fake_dims = 0;
|
|
578
|
+
static int64_t fake_shape = {0};
|
|
579
|
+
|
|
580
|
+
DLTensor tensors[${numInputs} + ${numOutputs}];
|
|
581
|
+
TVMValue values[${numInputs} + ${numOutputs}];
|
|
582
|
+
int32_t typeids[${numInputs} + ${numOutputs}];
|
|
583
|
+
|
|
584
|
+
for (size_t i = 0; i < ${numInputs}+${numOutputs}; i++)
|
|
585
|
+
{
|
|
586
|
+
tensors[i].device = fake_device;
|
|
587
|
+
tensors[i].data = (i < ${numInputs}) ? inputs[i] : outputs[i - ${numInputs}];
|
|
588
|
+
tensors[i].shape = &fake_shape;
|
|
589
|
+
tensors[i].ndim = fake_dims;
|
|
590
|
+
tensors[i].byte_offset = 0;
|
|
591
|
+
tensors[i].strides = NULL;
|
|
592
|
+
values[i].v_handle = &tensors[i];
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
int ret_val = ${modPrefix}_run(values, typeids, 0, NULL, 0, NULL);
|
|
596
|
+
if (ret_val)
|
|
597
|
+
{
|
|
598
|
+
TVMPlatformAbort(kTvmErrorPlatformCheckFailure);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
"""
|
|
602
|
+
else:
|
|
603
|
+
raise RuntimeError("api can only be 'c' or 'packed'")
|
|
604
|
+
|
|
605
|
+
if workspace_size > 0:
|
|
606
|
+
mainCode += """
|
|
607
|
+
#if DEBUG_ARENA_USAGE
|
|
608
|
+
DBGPRINTF("\\nAoT executor arena max usage after model invocation: %lu bytes\\n", max_arena_usage);
|
|
609
|
+
#endif // DEBUG_ARENA_USAGE
|
|
610
|
+
"""
|
|
611
|
+
mainCode += """
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
void *TVMWrap_GetOutputPtr(int index)
|
|
615
|
+
{
|
|
616
|
+
return outputs[index];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
size_t TVMWrap_GetOutputSize(int index)
|
|
620
|
+
{
|
|
621
|
+
${outSizes}
|
|
622
|
+
|
|
623
|
+
return sizes[index];
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
size_t TVMWrap_GetNumOutputs()
|
|
627
|
+
{
|
|
628
|
+
return ${numOutputs};
|
|
629
|
+
}
|
|
630
|
+
"""
|
|
631
|
+
out += fill(
|
|
632
|
+
mainCode,
|
|
633
|
+
inSizes=getSizes(model_info.in_tensors),
|
|
634
|
+
outSizes=getSizes(model_info.out_tensors),
|
|
635
|
+
numInputs=len(model_info.in_tensors),
|
|
636
|
+
numOutputs=len(model_info.out_tensors),
|
|
637
|
+
modPrefix=modPrefix,
|
|
638
|
+
)
|
|
639
|
+
return out
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def write_tvmaot_wrapper(path, model_info, workspace_size, mod_name, api="c"):
|
|
643
|
+
with open(path, "w") as f:
|
|
644
|
+
text = generate_tvmaot_wrapper(model_info, workspace_size, mod_name, api=api)
|
|
645
|
+
f.write(text)
|