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.
Files changed (376) hide show
  1. mlonmcu/__init__.py +26 -0
  2. mlonmcu/artifact.py +172 -0
  3. mlonmcu/cli/__init__.py +19 -0
  4. mlonmcu/cli/build.py +119 -0
  5. mlonmcu/cli/cleanup.py +75 -0
  6. mlonmcu/cli/common.py +227 -0
  7. mlonmcu/cli/compile.py +87 -0
  8. mlonmcu/cli/env.py +68 -0
  9. mlonmcu/cli/export.py +93 -0
  10. mlonmcu/cli/flow.py +67 -0
  11. mlonmcu/cli/helper/__init__.py +18 -0
  12. mlonmcu/cli/helper/filter.py +25 -0
  13. mlonmcu/cli/helper/parse.py +159 -0
  14. mlonmcu/cli/init.py +130 -0
  15. mlonmcu/cli/load.py +87 -0
  16. mlonmcu/cli/main.py +116 -0
  17. mlonmcu/cli/models.py +48 -0
  18. mlonmcu/cli/run.py +56 -0
  19. mlonmcu/cli/setup.py +136 -0
  20. mlonmcu/cli/tune.py +48 -0
  21. mlonmcu/config.py +219 -0
  22. mlonmcu/context/__init__.py +22 -0
  23. mlonmcu/context/context.py +545 -0
  24. mlonmcu/context/read_write_filelock.py +327 -0
  25. mlonmcu/environment/__init__.py +18 -0
  26. mlonmcu/environment/config.py +214 -0
  27. mlonmcu/environment/environment.py +501 -0
  28. mlonmcu/environment/init.py +191 -0
  29. mlonmcu/environment/list.py +81 -0
  30. mlonmcu/environment/loader.py +250 -0
  31. mlonmcu/environment/templates.py +69 -0
  32. mlonmcu/environment/writer.py +117 -0
  33. mlonmcu/feature/__init__.py +18 -0
  34. mlonmcu/feature/feature.py +230 -0
  35. mlonmcu/feature/features.py +1537 -0
  36. mlonmcu/feature/type.py +33 -0
  37. mlonmcu/flow/__init__.py +61 -0
  38. mlonmcu/flow/backend.py +234 -0
  39. mlonmcu/flow/framework.py +69 -0
  40. mlonmcu/flow/tflm/__init__.py +23 -0
  41. mlonmcu/flow/tflm/backend/__init__.py +23 -0
  42. mlonmcu/flow/tflm/backend/backend.py +47 -0
  43. mlonmcu/flow/tflm/backend/tflmc.py +129 -0
  44. mlonmcu/flow/tflm/backend/tflmi.py +385 -0
  45. mlonmcu/flow/tflm/framework.py +81 -0
  46. mlonmcu/flow/tvm/__init__.py +23 -0
  47. mlonmcu/flow/tvm/backend/__init__.py +26 -0
  48. mlonmcu/flow/tvm/backend/backend.py +282 -0
  49. mlonmcu/flow/tvm/backend/model_info.py +307 -0
  50. mlonmcu/flow/tvm/backend/python_utils.py +36 -0
  51. mlonmcu/flow/tvm/backend/tuner.py +41 -0
  52. mlonmcu/flow/tvm/backend/tvmaot.py +162 -0
  53. mlonmcu/flow/tvm/backend/tvmaotplus.py +51 -0
  54. mlonmcu/flow/tvm/backend/tvmc_utils.py +172 -0
  55. mlonmcu/flow/tvm/backend/tvmcg.py +102 -0
  56. mlonmcu/flow/tvm/backend/tvmllvm.py +106 -0
  57. mlonmcu/flow/tvm/backend/tvmrt.py +151 -0
  58. mlonmcu/flow/tvm/backend/wrapper.py +645 -0
  59. mlonmcu/flow/tvm/framework.py +96 -0
  60. mlonmcu/logging.py +79 -0
  61. mlonmcu/mlonmcu.py +19 -0
  62. mlonmcu/models/__init__.py +31 -0
  63. mlonmcu/models/convert_data.py +107 -0
  64. mlonmcu/models/frontend.py +571 -0
  65. mlonmcu/models/group.py +29 -0
  66. mlonmcu/models/lookup.py +345 -0
  67. mlonmcu/models/metadata.py +133 -0
  68. mlonmcu/models/model.py +104 -0
  69. mlonmcu/models/options.py +64 -0
  70. mlonmcu/models/utils.py +136 -0
  71. mlonmcu/platform/__init__.py +27 -0
  72. mlonmcu/platform/_platform.py +46 -0
  73. mlonmcu/platform/espidf/__init__.py +25 -0
  74. mlonmcu/platform/espidf/espidf.py +489 -0
  75. mlonmcu/platform/espidf/espidf_target.py +257 -0
  76. mlonmcu/platform/lookup.py +126 -0
  77. mlonmcu/platform/microtvm/__init__.py +25 -0
  78. mlonmcu/platform/microtvm/microtvm.py +580 -0
  79. mlonmcu/platform/microtvm/microtvm_arduino_target.py +68 -0
  80. mlonmcu/platform/microtvm/microtvm_backend.py +64 -0
  81. mlonmcu/platform/microtvm/microtvm_espidf_target.py +94 -0
  82. mlonmcu/platform/microtvm/microtvm_etissvp_target.py +98 -0
  83. mlonmcu/platform/microtvm/microtvm_host_target.py +46 -0
  84. mlonmcu/platform/microtvm/microtvm_spike_target.py +230 -0
  85. mlonmcu/platform/microtvm/microtvm_target.py +189 -0
  86. mlonmcu/platform/microtvm/microtvm_template_target.py +55 -0
  87. mlonmcu/platform/microtvm/microtvm_zephyr_target.py +91 -0
  88. mlonmcu/platform/mlif/__init__.py +25 -0
  89. mlonmcu/platform/mlif/mlif.py +300 -0
  90. mlonmcu/platform/mlif/mlif_target.py +86 -0
  91. mlonmcu/platform/platform.py +244 -0
  92. mlonmcu/platform/tvm/__init__.py +25 -0
  93. mlonmcu/platform/tvm/tvm.py +429 -0
  94. mlonmcu/platform/tvm/tvm_backend.py +57 -0
  95. mlonmcu/platform/tvm/tvm_target.py +165 -0
  96. mlonmcu/platform/zephyr/__init__.py +25 -0
  97. mlonmcu/platform/zephyr/zephyr.py +450 -0
  98. mlonmcu/platform/zephyr/zephyr_target.py +110 -0
  99. mlonmcu/plugins.py +26 -0
  100. mlonmcu/report.py +99 -0
  101. mlonmcu/session/__init__.py +18 -0
  102. mlonmcu/session/postprocess/__init__.py +43 -0
  103. mlonmcu/session/postprocess/postprocess.py +62 -0
  104. mlonmcu/session/postprocess/postprocesses.py +487 -0
  105. mlonmcu/session/run.py +1008 -0
  106. mlonmcu/session/session.py +373 -0
  107. mlonmcu/setup/__init__.py +18 -0
  108. mlonmcu/setup/cache.py +147 -0
  109. mlonmcu/setup/gen_requirements.py +619 -0
  110. mlonmcu/setup/setup.py +285 -0
  111. mlonmcu/setup/task.py +380 -0
  112. mlonmcu/setup/tasks/__init__.py +40 -0
  113. mlonmcu/setup/tasks/arm_gcc.py +58 -0
  114. mlonmcu/setup/tasks/cmsisnn.py +151 -0
  115. mlonmcu/setup/tasks/common.py +36 -0
  116. mlonmcu/setup/tasks/corstone300.py +64 -0
  117. mlonmcu/setup/tasks/espidf.py +87 -0
  118. mlonmcu/setup/tasks/etiss.py +147 -0
  119. mlonmcu/setup/tasks/llvm.py +67 -0
  120. mlonmcu/setup/tasks/mlif.py +49 -0
  121. mlonmcu/setup/tasks/muriscvnn.py +166 -0
  122. mlonmcu/setup/tasks/pulp.py +192 -0
  123. mlonmcu/setup/tasks/riscv_gcc.py +146 -0
  124. mlonmcu/setup/tasks/spike.py +190 -0
  125. mlonmcu/setup/tasks/tf.py +92 -0
  126. mlonmcu/setup/tasks/tflite.py +59 -0
  127. mlonmcu/setup/tasks/tflmc.py +141 -0
  128. mlonmcu/setup/tasks/tvm.py +172 -0
  129. mlonmcu/setup/tasks/utvmcg.py +96 -0
  130. mlonmcu/setup/tasks/zephyr.py +119 -0
  131. mlonmcu/setup/utils.py +374 -0
  132. mlonmcu/target/__init__.py +37 -0
  133. mlonmcu/target/_target.py +41 -0
  134. mlonmcu/target/arm/__init__.py +3 -0
  135. mlonmcu/target/arm/corstone300.py +235 -0
  136. mlonmcu/target/arm/util.py +109 -0
  137. mlonmcu/target/common.py +194 -0
  138. mlonmcu/target/elf.py +256 -0
  139. mlonmcu/target/host_x86.py +84 -0
  140. mlonmcu/target/metrics.py +75 -0
  141. mlonmcu/target/riscv/__init__.py +7 -0
  142. mlonmcu/target/riscv/etiss_pulpino.py +462 -0
  143. mlonmcu/target/riscv/gvsoc_pulp.py +215 -0
  144. mlonmcu/target/riscv/ovpsim.py +301 -0
  145. mlonmcu/target/riscv/riscv.py +185 -0
  146. mlonmcu/target/riscv/riscv_qemu.py +166 -0
  147. mlonmcu/target/riscv/spike.py +243 -0
  148. mlonmcu/target/riscv/util.py +134 -0
  149. mlonmcu/target/target.py +200 -0
  150. mlonmcu/utils.py +49 -0
  151. mlonmcu/version.py +21 -0
  152. mlonmcu-0.3.0.dev0.dist-info/LICENSE +202 -0
  153. mlonmcu-0.3.0.dev0.dist-info/METADATA +343 -0
  154. mlonmcu-0.3.0.dev0.dist-info/NOTICE +8 -0
  155. mlonmcu-0.3.0.dev0.dist-info/RECORD +376 -0
  156. mlonmcu-0.3.0.dev0.dist-info/WHEEL +5 -0
  157. mlonmcu-0.3.0.dev0.dist-info/entry_points.txt +3 -0
  158. mlonmcu-0.3.0.dev0.dist-info/top_level.txt +1 -0
  159. resources/frameworks/tvm/crt_config/README.md +7 -0
  160. resources/frameworks/tvm/crt_config/crt_config.h +53 -0
  161. resources/frameworks/tvm/tuning_records/riscv_cpu_v0.01.log.best +46 -0
  162. resources/patches/fix_esp32c3_march.patch +20 -0
  163. resources/patches/pulp_freertos_support.patch +55 -0
  164. resources/platforms/espidf/micro_speech_esp32devboard/CMakeLists.txt +29 -0
  165. resources/platforms/espidf/micro_speech_esp32devboard/README.md +70 -0
  166. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/CMakeLists.txt +78 -0
  167. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/Kconfig +76 -0
  168. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_data.c +26 -0
  169. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_input.c +35 -0
  170. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_output.c +45 -0
  171. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/exit.h +26 -0
  172. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/ml_interface.h +70 -0
  173. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/printing.h +31 -0
  174. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface.c +74 -0
  175. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tflm.cc +64 -0
  176. resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tvm.c +53 -0
  177. resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/CMakeLists.txt +140 -0
  178. resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/Kconfig +8 -0
  179. resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/CMakeLists.txt +66 -0
  180. resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/Kconfig +7 -0
  181. resources/platforms/espidf/micro_speech_esp32devboard/example_test.py +38 -0
  182. resources/platforms/espidf/micro_speech_esp32devboard/info.txt +9 -0
  183. resources/platforms/espidf/micro_speech_esp32devboard/main/CMakeLists.txt +58 -0
  184. resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.cc +193 -0
  185. resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.h +49 -0
  186. resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.cc +53 -0
  187. resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.h +35 -0
  188. resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc +132 -0
  189. resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc.orig +145 -0
  190. resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.h +55 -0
  191. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/COPYING +11 -0
  192. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/_kiss_fft_guts.h +168 -0
  193. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.c +408 -0
  194. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.h +124 -0
  195. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.c +159 -0
  196. resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.h +46 -0
  197. resources/platforms/espidf/micro_speech_esp32devboard/main/main.cc +63 -0
  198. resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.cc +204 -0
  199. resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.h +37 -0
  200. resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.cc +121 -0
  201. resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.h +38 -0
  202. resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.cc +23 -0
  203. resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.h +43 -0
  204. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/bits.h +102 -0
  205. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.cc +52 -0
  206. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.h +50 -0
  207. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.cc +69 -0
  208. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.h +34 -0
  209. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.c +134 -0
  210. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.h +63 -0
  211. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.c +220 -0
  212. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.h +50 -0
  213. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.c +72 -0
  214. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.h +64 -0
  215. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.c +85 -0
  216. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.h +52 -0
  217. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_common.h +48 -0
  218. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.cc +8 -0
  219. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.h +34 -0
  220. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.c +30 -0
  221. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.h +40 -0
  222. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.c +83 -0
  223. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.h +39 -0
  224. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.c +27 -0
  225. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.h +45 -0
  226. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.c +51 -0
  227. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.h +46 -0
  228. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.c +45 -0
  229. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.h +50 -0
  230. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.c +56 -0
  231. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.h +47 -0
  232. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.c +92 -0
  233. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.h +57 -0
  234. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.c +70 -0
  235. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.h +49 -0
  236. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.c +73 -0
  237. resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.h +45 -0
  238. resources/platforms/espidf/micro_speech_esp32devboard/main/pins.c +14 -0
  239. resources/platforms/espidf/micro_speech_esp32devboard/main/pins.h +30 -0
  240. resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.cc +150 -0
  241. resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.h +173 -0
  242. resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.c +333 -0
  243. resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.h +74 -0
  244. resources/platforms/espidf/micro_speech_esp32devboard/sdkconfig.defaults +36 -0
  245. resources/platforms/espidf/project/CMakeLists.txt +29 -0
  246. resources/platforms/espidf/project/README.md +70 -0
  247. resources/platforms/espidf/project/components/mlif/CMakeLists.txt +77 -0
  248. resources/platforms/espidf/project/components/mlif/Kconfig +76 -0
  249. resources/platforms/espidf/project/components/mlif/default_data.c +26 -0
  250. resources/platforms/espidf/project/components/mlif/default_model_support/process_input.c +35 -0
  251. resources/platforms/espidf/project/components/mlif/default_model_support/process_output.c +45 -0
  252. resources/platforms/espidf/project/components/mlif/include/exit.h +26 -0
  253. resources/platforms/espidf/project/components/mlif/include/ml_interface.h +60 -0
  254. resources/platforms/espidf/project/components/mlif/include/printing.h +31 -0
  255. resources/platforms/espidf/project/components/mlif/ml_interface.c +54 -0
  256. resources/platforms/espidf/project/components/mlif/ml_interface_tflm.cc +40 -0
  257. resources/platforms/espidf/project/components/mlif/ml_interface_tvm.c +40 -0
  258. resources/platforms/espidf/project/components/tflite-lib/CMakeLists.txt +142 -0
  259. resources/platforms/espidf/project/components/tflite-lib/Kconfig +8 -0
  260. resources/platforms/espidf/project/components/tvm-lib/CMakeLists.txt +66 -0
  261. resources/platforms/espidf/project/components/tvm-lib/Kconfig +7 -0
  262. resources/platforms/espidf/project/example_test.py +38 -0
  263. resources/platforms/espidf/project/main/CMakeLists.txt +25 -0
  264. resources/platforms/espidf/project/main/main.c +57 -0
  265. resources/platforms/espidf/project/sdkconfig.defaults +26 -0
  266. resources/platforms/zephyr/project/CMakeLists.txt +22 -0
  267. resources/platforms/zephyr/project/Kconfig +101 -0
  268. resources/platforms/zephyr/project/README.rst +33 -0
  269. resources/platforms/zephyr/project/cmake/AddAllSubdirs.cmake +21 -0
  270. resources/platforms/zephyr/project/cmake/ChooseTarget.cmake +22 -0
  271. resources/platforms/zephyr/project/cmake/LinkTFLite.cmake +223 -0
  272. resources/platforms/zephyr/project/cmake/LinkTVM.cmake +68 -0
  273. resources/platforms/zephyr/project/cmake/LookupClang.cmake +41 -0
  274. resources/platforms/zephyr/project/cmake/backends/tflmc.cmake +5 -0
  275. resources/platforms/zephyr/project/cmake/backends/tflmi.cmake +5 -0
  276. resources/platforms/zephyr/project/cmake/backends/tvmaot.cmake +10 -0
  277. resources/platforms/zephyr/project/cmake/backends/tvmaotplus.cmake +10 -0
  278. resources/platforms/zephyr/project/cmake/backends/tvmcg.cmake +10 -0
  279. resources/platforms/zephyr/project/cmake/backends/tvmllvm.cmake +8 -0
  280. resources/platforms/zephyr/project/cmake/backends/tvmrt.cmake +8 -0
  281. resources/platforms/zephyr/project/cmake/extras.cmake +9 -0
  282. resources/platforms/zephyr/project/cmake/features/auto_vectorize_gcc.cmake +65 -0
  283. resources/platforms/zephyr/project/cmake/features/auto_vectorize_llvm.cmake +20 -0
  284. resources/platforms/zephyr/project/cmake/features/cmsisnn.cmake +86 -0
  285. resources/platforms/zephyr/project/cmake/features/muriscvnn.cmake +87 -0
  286. resources/platforms/zephyr/project/cmake/frameworks/tflm.cmake +1 -0
  287. resources/platforms/zephyr/project/cmake/frameworks/tflm_mlif.cmake +8 -0
  288. resources/platforms/zephyr/project/cmake/frameworks/tvm.cmake +1 -0
  289. resources/platforms/zephyr/project/cmake/frameworks/tvm_mlif.cmake +37 -0
  290. resources/platforms/zephyr/project/lib/CMakeLists.txt +13 -0
  291. resources/platforms/zephyr/project/lib/drivers/fake_input.c +10 -0
  292. resources/platforms/zephyr/project/lib/drivers/fake_input.h +8 -0
  293. resources/platforms/zephyr/project/lib/ml_interface/CMakeLists.txt +31 -0
  294. resources/platforms/zephyr/project/lib/ml_interface/default_data.c +8 -0
  295. resources/platforms/zephyr/project/lib/ml_interface/default_model_support/CMakeLists.txt +2 -0
  296. resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_input.c +17 -0
  297. resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_output.c +27 -0
  298. resources/platforms/zephyr/project/lib/ml_interface/ml_interface.c +36 -0
  299. resources/platforms/zephyr/project/lib/ml_interface/ml_interface.h +47 -0
  300. resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tflm.cc +22 -0
  301. resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tvm.c +22 -0
  302. resources/platforms/zephyr/project/lib/support/CMakeLists.txt +2 -0
  303. resources/platforms/zephyr/project/lib/support/dummy.c +0 -0
  304. resources/platforms/zephyr/project/lib/support/exit.h +8 -0
  305. resources/platforms/zephyr/project/lib/support/printing.h +11 -0
  306. resources/platforms/zephyr/project/lib/support/quantize.h +23 -0
  307. resources/platforms/zephyr/project/lib/targets/corstone300.c +62 -0
  308. resources/platforms/zephyr/project/lib/targets/default.c +2 -0
  309. resources/platforms/zephyr/project/lib/targets/etiss_pulpino.c +112 -0
  310. resources/platforms/zephyr/project/lib/targets/generic_riscv.c +112 -0
  311. resources/platforms/zephyr/project/lib/targets/riscv_qemu.c +112 -0
  312. resources/platforms/zephyr/project/lib/targets/target.h +2 -0
  313. resources/platforms/zephyr/project/prj.conf +11 -0
  314. resources/platforms/zephyr/project/sample.yaml +19 -0
  315. resources/platforms/zephyr/project/src/main.c +71 -0
  316. resources/platforms/zephyr/project2/CMakeLists.txt +72 -0
  317. resources/platforms/zephyr/project2/Kconfig +101 -0
  318. resources/platforms/zephyr/project2/README.rst +33 -0
  319. resources/platforms/zephyr/project2/cmake/AddAllSubdirs.cmake +21 -0
  320. resources/platforms/zephyr/project2/cmake/ChooseTarget.cmake +22 -0
  321. resources/platforms/zephyr/project2/cmake/LinkTFLite.cmake +223 -0
  322. resources/platforms/zephyr/project2/cmake/LinkTVM.cmake +68 -0
  323. resources/platforms/zephyr/project2/cmake/LookupClang.cmake +41 -0
  324. resources/platforms/zephyr/project2/cmake/backends/tflmc.cmake +5 -0
  325. resources/platforms/zephyr/project2/cmake/backends/tflmi.cmake +5 -0
  326. resources/platforms/zephyr/project2/cmake/backends/tvmaot.cmake +10 -0
  327. resources/platforms/zephyr/project2/cmake/backends/tvmaotplus.cmake +10 -0
  328. resources/platforms/zephyr/project2/cmake/backends/tvmcg.cmake +10 -0
  329. resources/platforms/zephyr/project2/cmake/backends/tvmllvm.cmake +8 -0
  330. resources/platforms/zephyr/project2/cmake/backends/tvmrt.cmake +8 -0
  331. resources/platforms/zephyr/project2/cmake/extras.cmake +9 -0
  332. resources/platforms/zephyr/project2/cmake/features/auto_vectorize_gcc.cmake +65 -0
  333. resources/platforms/zephyr/project2/cmake/features/auto_vectorize_llvm.cmake +20 -0
  334. resources/platforms/zephyr/project2/cmake/features/cmsisnn.cmake +86 -0
  335. resources/platforms/zephyr/project2/cmake/features/muriscvnn.cmake +87 -0
  336. resources/platforms/zephyr/project2/cmake/frameworks/tflm.cmake +1 -0
  337. resources/platforms/zephyr/project2/cmake/frameworks/tflm_mlif.cmake +8 -0
  338. resources/platforms/zephyr/project2/cmake/frameworks/tvm.cmake +1 -0
  339. resources/platforms/zephyr/project2/cmake/frameworks/tvm_mlif.cmake +37 -0
  340. resources/platforms/zephyr/project2/default_data.c +8 -0
  341. resources/platforms/zephyr/project2/default_model_support/CMakeLists.txt +3 -0
  342. resources/platforms/zephyr/project2/default_model_support/process_input.c +17 -0
  343. resources/platforms/zephyr/project2/default_model_support/process_output.c +27 -0
  344. resources/platforms/zephyr/project2/lib/CMakeLists.txt +13 -0
  345. resources/platforms/zephyr/project2/lib/drivers/fake_input.c +10 -0
  346. resources/platforms/zephyr/project2/lib/drivers/fake_input.h +8 -0
  347. resources/platforms/zephyr/project2/lib/support/CMakeLists.txt +2 -0
  348. resources/platforms/zephyr/project2/lib/support/dummy.c +0 -0
  349. resources/platforms/zephyr/project2/lib/support/exit.h +8 -0
  350. resources/platforms/zephyr/project2/lib/support/printing.h +11 -0
  351. resources/platforms/zephyr/project2/lib/support/quantize.h +23 -0
  352. resources/platforms/zephyr/project2/lib/targets/corstone300.c +62 -0
  353. resources/platforms/zephyr/project2/lib/targets/default.c +2 -0
  354. resources/platforms/zephyr/project2/lib/targets/etiss_pulpino.c +112 -0
  355. resources/platforms/zephyr/project2/lib/targets/generic_riscv.c +112 -0
  356. resources/platforms/zephyr/project2/lib/targets/riscv_qemu.c +112 -0
  357. resources/platforms/zephyr/project2/lib/targets/target.h +2 -0
  358. resources/platforms/zephyr/project2/ml_interface.c +36 -0
  359. resources/platforms/zephyr/project2/ml_interface.h +47 -0
  360. resources/platforms/zephyr/project2/ml_interface_tflm.cc +22 -0
  361. resources/platforms/zephyr/project2/ml_interface_tvm.c +22 -0
  362. resources/platforms/zephyr/project2/prj.conf +13 -0
  363. resources/platforms/zephyr/project2/sample.yaml +19 -0
  364. resources/platforms/zephyr/project2/settings.json +6 -0
  365. resources/platforms/zephyr/project2/src/main.c +35 -0
  366. resources/pycharm/.run/README.md +73 -0
  367. resources/pycharm/.run/step1_ init env.run.xml +24 -0
  368. resources/pycharm/.run/step2_ setup.run.xml +25 -0
  369. resources/pycharm/.run/step3_ run resnet on pulpxpulpissimo.run.xml +25 -0
  370. resources/templates/default.yml.j2 +258 -0
  371. resources/templates/dev.yml.j2 +212 -0
  372. resources/templates/minimal.yml.j2 +234 -0
  373. resources/templates/phi.yml.j2 +282 -0
  374. resources/templates/pulp.yml.j2 +267 -0
  375. resources/templates/research.yml.j2 +237 -0
  376. resources/templates/tumeda.yml.j2 +239 -0
mlonmcu/cli/compile.py ADDED
@@ -0,0 +1,87 @@
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
+ """Command line subcommand for the run process."""
20
+
21
+ from mlonmcu.cli.common import kickoff_runs
22
+ from mlonmcu.cli.build import (
23
+ handle as handle_build,
24
+ add_build_options,
25
+ )
26
+ from mlonmcu.context.context import MlonMcuContext
27
+ from mlonmcu.session.run import RunStage
28
+ from mlonmcu.platform.lookup import get_platforms_targets
29
+ from .helper.parse import extract_target_names, extract_platform_names, extract_config_and_feature_names
30
+
31
+
32
+ def add_compile_options(parser):
33
+ add_build_options(parser)
34
+ # compile_parser = parser.add_argument_group("compile options")
35
+
36
+
37
+ def get_parser(subparsers):
38
+ """ "Define and return a subparser for the compile subcommand."""
39
+ parser = subparsers.add_parser("compile", description="Compile model using ML on MCU flow.")
40
+ parser.set_defaults(flow_func=handle)
41
+ add_compile_options(parser)
42
+ return parser
43
+
44
+
45
+ def _handle(args, context):
46
+ handle_build(args, ctx=context)
47
+ targets = extract_target_names(args, context=context) # This will eventually be ignored below
48
+ platforms = extract_platform_names(args, context=context)
49
+
50
+ new_config, _, _, _ = extract_config_and_feature_names(args, context=context)
51
+ platform_targets = get_platforms_targets(context, config=new_config) # This will slow?
52
+
53
+ assert len(context.sessions) > 0 # TODO: automatically request session if no active one is available
54
+ session = context.sessions[-1]
55
+ new_runs = []
56
+ for run in session.runs:
57
+ if run.target is None:
58
+ # assert run.compile_platform is None
59
+ targets_ = targets
60
+ else:
61
+ targets_ = [None]
62
+ for target_name in targets_:
63
+ new_run = run.copy()
64
+ if target_name is not None:
65
+ platform_name = None
66
+ for platform in platforms:
67
+ candidates = platform_targets[platform]
68
+ if target_name in candidates:
69
+ platform_name = platform
70
+ new_run.add_platform_by_name(platform_name, context=context)
71
+ new_run.add_target_by_name(target_name, context=context)
72
+ new_runs.append(new_run)
73
+ session.runs = new_runs
74
+
75
+
76
+ def check_args(context, args):
77
+ # print("CHECK ARGS")
78
+ pass
79
+
80
+
81
+ def handle(args, ctx=None):
82
+ if ctx:
83
+ _handle(args, ctx)
84
+ else:
85
+ with MlonMcuContext(path=args.home, deps_lock="read") as context:
86
+ _handle(args, context)
87
+ kickoff_runs(args, RunStage.COMPILE, context)
mlonmcu/cli/env.py ADDED
@@ -0,0 +1,68 @@
1
+ #
2
+ # Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
3
+ #
4
+ # This file is part of MLonMCU.
5
+ # See https://github.com/tum-ei-eda/mlonmcu.git for further info.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ """Command line subcommand for manaing environments."""
20
+
21
+ import configparser
22
+
23
+ from mlonmcu.environment.config import get_environments_file
24
+
25
+
26
+ def get_parser(subparsers):
27
+ """ "Define and return a subparser for the env subcommand."""
28
+ parser = subparsers.add_parser("env", description="List ML on MCU environments.")
29
+ parser.set_defaults(func=handle)
30
+ return parser
31
+
32
+
33
+ class EnvironmentHint:
34
+ def __init__(self, name, path, created_at=None):
35
+ self.name = name
36
+ self.path = path
37
+ self.created_at = created_at
38
+
39
+
40
+ def lookup_user_environments(file):
41
+ config = configparser.ConfigParser()
42
+ config.read(file)
43
+ hints = []
44
+ for env_name in config.sections():
45
+ env = config[env_name]
46
+ assert "path" in env
47
+ path = env["path"]
48
+ created_at = None
49
+ if "created" in env:
50
+ created_at = env["created"]
51
+ hint = EnvironmentHint(env_name, path, created_at=created_at)
52
+ hints.append(hint)
53
+ return hints
54
+
55
+
56
+ def handle(args):
57
+ envs_file = get_environments_file()
58
+ print(f"Looking for user environments config file: {envs_file}")
59
+ envs = lookup_user_environments(envs_file)
60
+ count = len(envs)
61
+ if not envs or count == 0:
62
+ print("No mlonmcu environments were found for the current user. You can create a new one using `mlonmcu init`")
63
+ else:
64
+ print(f"Found {count} mlonmcu environment(s):")
65
+ for env in envs:
66
+ print(f" - {env.name} ({env.path})")
67
+
68
+ print("Point the environment variable MLONMCU_HOME to a environment directory to get started")
mlonmcu/cli/export.py ADDED
@@ -0,0 +1,93 @@
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
+ """Command line subcommand for exporting session and runs."""
20
+ from mlonmcu.context.context import MlonMcuContext
21
+
22
+ from mlonmcu.cli.common import (
23
+ add_common_options,
24
+ add_context_options,
25
+ )
26
+
27
+
28
+ def add_export_options(parser):
29
+ export_parser = parser.add_argument_group("export options")
30
+ export_parser.add_argument(
31
+ "destination",
32
+ nargs="?",
33
+ default="exported.zip",
34
+ help="Path to the output directory or archive (default: %(default)s)",
35
+ )
36
+ export_parser.add_argument(
37
+ "-f",
38
+ "--force",
39
+ default=False,
40
+ action="store_true",
41
+ help="Overwrite files if the destination already exists (DANGEROUS)",
42
+ )
43
+ export_parser.add_argument(
44
+ "-l",
45
+ "--list",
46
+ default=False,
47
+ action="store_true",
48
+ help="Print a summary of all available sessions and runs",
49
+ )
50
+ export_parser.add_argument(
51
+ "-s",
52
+ "--session",
53
+ metavar="SESSION",
54
+ type=int,
55
+ nargs="?",
56
+ default=None,
57
+ const=-1,
58
+ action="append",
59
+ help="Which session(s) should be exported (default: latest session id)",
60
+ )
61
+ export_parser.add_argument(
62
+ "-r",
63
+ "--run",
64
+ metavar="RUN",
65
+ type=int,
66
+ nargs="?",
67
+ default=None,
68
+ const=-1,
69
+ action="append",
70
+ help="Which run(s) should be exported (default: all runs of the selected session/latest run id)",
71
+ )
72
+
73
+
74
+ def get_parser(subparsers):
75
+ """ "Define and return a subparser for the cleanup subcommand."""
76
+ parser = subparsers.add_parser("export", description="Export session/run artifacts to a directory/archive.")
77
+ parser.set_defaults(func=handle)
78
+ add_common_options(parser)
79
+ add_context_options(parser)
80
+ add_export_options(parser)
81
+ return parser
82
+
83
+
84
+ def handle(args):
85
+ with MlonMcuContext(path=args.home, deps_lock="read") as context:
86
+ if args.list:
87
+ context.print_summary(sessions=True, runs=True, labels=True)
88
+ return 0
89
+ dest = args.destination
90
+ interactive = not args.force
91
+ sids = args.session
92
+ rids = args.run
93
+ context.export(dest, session_ids=sids, run_ids=rids, interactive=interactive)
mlonmcu/cli/flow.py ADDED
@@ -0,0 +1,67 @@
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
+ """Command line subcommand for invoking the mlonmcu flow."""
20
+
21
+ import sys
22
+
23
+ from mlonmcu.context.context import MlonMcuContext
24
+ import mlonmcu.platform.lookup
25
+ import mlonmcu.cli.load as load
26
+ import mlonmcu.cli.tune as tune
27
+ import mlonmcu.cli.build as build
28
+ import mlonmcu.cli.compile as compile_ # compile is a builtin name
29
+ import mlonmcu.cli.run as run
30
+ from mlonmcu.cli.common import add_flow_options, add_common_options, add_context_options
31
+
32
+
33
+ def get_parser(subparsers, parent=None):
34
+ """ "Define and return a subparser for the flow subcommand."""
35
+ parser = subparsers.add_parser(
36
+ "flow",
37
+ description="Invoke ML on MCU flow",
38
+ parents=[parent] if parent else [],
39
+ add_help=(parent is None),
40
+ )
41
+ parser.set_defaults(func=handle)
42
+ add_common_options(parser)
43
+ add_context_options(parser)
44
+ add_flow_options(parser)
45
+ subparsers = parser.add_subparsers(dest="subcommand2") # this line changed
46
+ load.get_parser(subparsers)
47
+ tune.get_parser(subparsers)
48
+ build.get_parser(subparsers)
49
+ compile_.get_parser(subparsers)
50
+ run.get_parser(subparsers)
51
+
52
+
53
+ def handle_list_targets(args):
54
+ with MlonMcuContext(path=args.home, deps_lock="read") as context:
55
+ mlonmcu.platform.lookup.print_summary(context=context)
56
+
57
+
58
+ def handle(args):
59
+ """Callback function which will be called to process the flow subcommand"""
60
+ if args.list_targets:
61
+ handle_list_targets(args)
62
+ else:
63
+ if hasattr(args, "flow_func"):
64
+ args.flow_func(args)
65
+ else:
66
+ print("Invalid command. Check 'mlonmcu flow --help' for the available subcommands!")
67
+ sys.exit(1)
@@ -0,0 +1,18 @@
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
+ #
@@ -0,0 +1,25 @@
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
+ def filter_arg(arg):
22
+ """TODO"""
23
+ if not arg:
24
+ return []
25
+ return list(filter(None, arg.split(",")))
@@ -0,0 +1,159 @@
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
+ def parse_var(s):
22
+ """
23
+ Parse a key, value pair, separated by '='
24
+ That's the reverse of ShellArgs.
25
+
26
+ On the command line (argparse) a declaration will typically look like:
27
+ foo=hello
28
+ or
29
+ foo="hello world"
30
+ """
31
+ items = s.split("=")
32
+ key = items[0].strip() # we remove blanks around keys, as is logical
33
+ if len(key) == 0 or len(items) <= 1 or "=" not in s:
34
+ raise RuntimeError(f"The argument {s} is not a key-value pair")
35
+ if len(items) > 1:
36
+ # rejoin the rest:
37
+ value = "=".join(items[1:])
38
+ return (key, value)
39
+
40
+
41
+ def parse_vars(items): # TODO: this needs to be used in other subcommands as well?
42
+ """
43
+ Parse a series of key-value pairs and return a dictionary
44
+ """
45
+ d = {}
46
+
47
+ if items:
48
+ for item in items:
49
+ if len(item) > 0:
50
+ key, value = parse_var(item)
51
+ d[key] = value
52
+ return d
53
+
54
+
55
+ def extract_feature_names(args):
56
+ if args.feature:
57
+ features = args.feature
58
+ else:
59
+ features = []
60
+ if hasattr(args, "feature_gen") and args.feature_gen:
61
+ gen = []
62
+ for x in args.feature_gen:
63
+ if "_" in x:
64
+ assert len(x) == 1
65
+ gen.append([])
66
+ else:
67
+ gen.append(x)
68
+ else:
69
+ gen = [[]]
70
+ return features, gen
71
+
72
+
73
+ def extract_config(args):
74
+ if args.config:
75
+ configs = sum(args.config, [])
76
+ configs = parse_vars(configs)
77
+ else:
78
+ configs = {}
79
+ if hasattr(args, "config_gen") and args.config_gen:
80
+ gen = []
81
+ for x in args.config_gen:
82
+ if "_" in x:
83
+ assert len(x) == 1
84
+ gen.append({})
85
+ else:
86
+ c = parse_vars(x)
87
+ gen.append(c)
88
+ else:
89
+ gen = [{}]
90
+
91
+ return configs, gen
92
+
93
+
94
+ def extract_config_and_feature_names(args, context=None):
95
+ # TODO: get features from context?
96
+ feature_names, feature_gen = extract_feature_names(args)
97
+ config, config_gen = extract_config(args)
98
+ return config, feature_names, config_gen, feature_gen
99
+
100
+
101
+ def extract_frontend_names(args, context=None):
102
+ frontend_names = args.frontend
103
+ names = []
104
+ if isinstance(frontend_names, list) and len(frontend_names) > 0:
105
+ names = frontend_names
106
+ elif isinstance(frontend_names, str):
107
+ names = [frontend_names]
108
+ else:
109
+ # No need to specify a default, because we just use the provided order in the environment.yml
110
+ assert frontend_names is None, "TODO"
111
+ assert context is not None, "Need context to resolve default frontends"
112
+ all_frontend_names = context.environment.lookup_frontend_configs(names_only=True)
113
+ names.extend(all_frontend_names)
114
+ return names
115
+
116
+
117
+ def extract_postprocess_names(args, context=None):
118
+ return list(dict.fromkeys(args.postprocess)) if args.postprocess is not None else []
119
+
120
+
121
+ def extract_backend_names(args, context=None):
122
+ if isinstance(args.backend, list) and len(args.backend) > 0:
123
+ backends = args.backend
124
+ elif isinstance(args.backend, str):
125
+ backends = [args.backend]
126
+ else:
127
+ assert args.backend is None, "TODO"
128
+ assert context is not None
129
+ frameworks = context.environment.get_default_frameworks()
130
+ backends = []
131
+ for framework in frameworks:
132
+ framework_backends = context.environment.get_default_backends(framework)
133
+ backends.extend(framework_backends)
134
+ return backends
135
+
136
+
137
+ def extract_target_names(args, context=None):
138
+ if isinstance(args.target, list) and len(args.target) > 0:
139
+ targets = args.target
140
+ elif isinstance(args.target, str):
141
+ targets = [args.target]
142
+ else:
143
+ assert args.target is None, "TODO"
144
+ # assert context is not None
145
+ if context is None:
146
+ return [None]
147
+ targets = context.environment.get_default_targets()
148
+ return targets
149
+
150
+
151
+ def extract_platform_names(args, context=None):
152
+ if args.platform:
153
+ platforms = [x[0] for x in args.platform]
154
+ else:
155
+ assert args.platform is None
156
+ if context is None:
157
+ return [None]
158
+ platforms = context.environment.lookup_platform_configs(names_only=True)
159
+ return platforms
mlonmcu/cli/init.py ADDED
@@ -0,0 +1,130 @@
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
+ """Command line subcommand for initializing a mlonmcu environment."""
20
+
21
+ import os
22
+
23
+ from mlonmcu.environment.templates import get_template_names
24
+ from mlonmcu.environment.config import get_environments_dir, DEFAULTS
25
+ from mlonmcu.environment.init import initialize_environment
26
+ from .helper.parse import extract_config
27
+
28
+
29
+ def add_init_options(parser):
30
+ init_parser = parser.add_argument_group("init options")
31
+ init_parser.add_argument(
32
+ "-n",
33
+ "--name",
34
+ metavar="NAME",
35
+ nargs=1,
36
+ type=str,
37
+ default="",
38
+ help="Environment name (default: %(default)s)",
39
+ )
40
+ init_parser.add_argument(
41
+ "-t",
42
+ "--template",
43
+ metavar="TEMPLATE",
44
+ nargs=1,
45
+ type=str,
46
+ # choices=get_template_names(),
47
+ default=DEFAULTS["template"],
48
+ help="Environment template name or path (default: %(default)s, available: "
49
+ + ", ".join(get_template_names())
50
+ + ")",
51
+ )
52
+ init_parser.add_argument(
53
+ "DIR",
54
+ nargs="?",
55
+ type=str,
56
+ default=get_environments_dir(),
57
+ help="Environment directory (default: " + os.path.join(get_environments_dir(), "{NAME}") + ")",
58
+ )
59
+ init_parser.add_argument(
60
+ "--non-interactive",
61
+ dest="non_interactive",
62
+ action="store_true",
63
+ help="Do not ask questions interactively",
64
+ )
65
+ init_parser.add_argument(
66
+ "--venv",
67
+ default=None,
68
+ action="store_true",
69
+ help="Create virtual python environment",
70
+ )
71
+ init_parser.add_argument(
72
+ "--clone-models",
73
+ dest="clone_models",
74
+ default=None,
75
+ action="store_true",
76
+ help="Clone models directory into environment",
77
+ )
78
+ init_parser.add_argument(
79
+ "--register",
80
+ default=None,
81
+ action="store_true",
82
+ help="Add environment to the list of environment for the current user",
83
+ )
84
+ init_parser.add_argument(
85
+ "--allow-exists",
86
+ dest="allow_exists",
87
+ default=None,
88
+ action="store_true",
89
+ help="Allow overwriting an existing environment directory",
90
+ )
91
+ init_parser.add_argument(
92
+ "-c",
93
+ "--config",
94
+ metavar="KEY=VALUE",
95
+ nargs="+",
96
+ action="append",
97
+ help=(
98
+ "Set a number of key-value pairs "
99
+ "(do not put spaces before or after the = sign). "
100
+ "If a value contains spaces, you should define "
101
+ "it with double quotes: "
102
+ 'foo="this is a sentence". Note that '
103
+ "values are always treated as strings."
104
+ ),
105
+ )
106
+
107
+
108
+ def get_parser(subparsers):
109
+ """ "Define and return a subparser for the init subcommand."""
110
+ parser = subparsers.add_parser("init", description="Initialize ML on MCU environment.")
111
+ parser.set_defaults(func=handle)
112
+ add_init_options(parser)
113
+ return parser
114
+
115
+
116
+ def handle(args):
117
+ """Callback function which will be called to process the init subcommand"""
118
+ name = args.name[0] if isinstance(args.name, list) else args.name
119
+ config, _ = extract_config(args)
120
+ initialize_environment(
121
+ args.DIR,
122
+ name,
123
+ create_venv=args.venv,
124
+ interactive=not args.non_interactive,
125
+ clone_models=args.clone_models,
126
+ register=args.register,
127
+ template=args.template[0] if isinstance(args.template, list) else args.template,
128
+ allow_exists=args.allow_exists,
129
+ config=config,
130
+ )