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
@@ -0,0 +1,49 @@
1
+ /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_
17
+ #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_
18
+
19
+ #include <stdint.h>
20
+ // #include "tensorflow/lite/c/common.h"
21
+ // #include "tensorflow/lite/micro/micro_error_reporter.h"
22
+
23
+ // This is an abstraction around an audio source like a microphone, and is
24
+ // expected to return 16-bit PCM sample data for a given point in time. The
25
+ // sample data itself should be used as quickly as possible by the caller, since
26
+ // to allow memory optimizations there are no guarantees that the samples won't
27
+ // be overwritten by new data in the future. In practice, implementations should
28
+ // ensure that there's a reasonable time allowed for clients to access the data
29
+ // before any reuse.
30
+ // The reference implementation can have no platform-specific dependencies, so
31
+ // it just returns an array filled with zeros. For real applications, you should
32
+ // ensure there's a specialized implementation that accesses hardware APIs.
33
+ // TfLiteStatus GetAudioSamples(tflite::ErrorReporter* error_reporter,
34
+ // int start_ms, int duration_ms,
35
+ // int* audio_samples_size, int16_t** audio_samples);
36
+ int GetAudioSamples(int start_ms, int duration_ms,
37
+ int* audio_samples_size, int16_t** audio_samples);
38
+
39
+ // Returns the time that audio data was last captured in milliseconds. There's
40
+ // no contract about what time zero represents, the accuracy, or the granularity
41
+ // of the result. Subsequent calls will generally not return a lower value, but
42
+ // even that's not guaranteed if there's an overflow wraparound.
43
+ // The reference implementation of this function just returns a constantly
44
+ // incrementing value for each call, since it would need a non-portable platform
45
+ // call to access time information. For real applications, you'll need to write
46
+ // your own platform-specific implementation.
47
+ int32_t LatestAudioTimestamp();
48
+
49
+ #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_
@@ -0,0 +1,53 @@
1
+ /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #include <stdio.h>
17
+ #include "command_responder.h"
18
+ #include "driver/gpio.h"
19
+ #include "pins.h"
20
+ #include "string.h"
21
+
22
+ // The default implementation writes out the name of the recognized command
23
+ // to the error console. Real applications will want to take some custom
24
+ // action instead, and should implement their own versions of this function.
25
+ // void RespondToCommand(tflite::ErrorReporter* error_reporter,
26
+ // int32_t current_time, const char* found_command,
27
+ // uint8_t score, bool is_new_command) {
28
+ void RespondToCommand(int32_t current_time, const char* found_command,
29
+ uint8_t score, bool is_new_command) {
30
+ if (is_new_command) {
31
+ // TF_LITE_REPORT_ERROR(error_reporter, "Heard %s (%d) @%dms", found_command,
32
+ // score, current_time);
33
+ printf("Heard %s (%d) @%dms\n", found_command,
34
+ score, current_time);
35
+ if (strcmp(found_command, "silence") == 0) {
36
+ gpio_set_level(GPIO_LED_RED, 0);
37
+ gpio_set_level(GPIO_LED_GREEN, 0);
38
+ gpio_set_level(GPIO_LED_BLUE, 0);
39
+ } else if (strcmp(found_command, "unknown") == 0) {
40
+ gpio_set_level(GPIO_LED_RED, 0);
41
+ gpio_set_level(GPIO_LED_GREEN, 0);
42
+ gpio_set_level(GPIO_LED_BLUE, 1);
43
+ } else if (strcmp(found_command, "up") == 0) {
44
+ gpio_set_level(GPIO_LED_RED, 0);
45
+ gpio_set_level(GPIO_LED_GREEN, 1);
46
+ gpio_set_level(GPIO_LED_BLUE, 0);
47
+ } else if (strcmp(found_command, "down") == 0) {
48
+ gpio_set_level(GPIO_LED_RED, 1);
49
+ gpio_set_level(GPIO_LED_GREEN, 0);
50
+ gpio_set_level(GPIO_LED_BLUE, 0);
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,35 @@
1
+ /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ // Provides an interface to take an action based on an audio command.
17
+
18
+ #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_
19
+ #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_
20
+
21
+ #include <stdint.h>
22
+ // #include "tensorflow/lite/c/common.h"
23
+ // #include "tensorflow/lite/micro/micro_error_reporter.h"
24
+
25
+ // Called every time the results of an audio recognition run are available. The
26
+ // human-readable name of any recognized command is in the `found_command`
27
+ // argument, `score` has the numerical confidence, and `is_new_command` is set
28
+ // if the previous command was different to this one.
29
+ // void RespondToCommand(tflite::ErrorReporter* error_reporter,
30
+ // int32_t current_time, const char* found_command,
31
+ // uint8_t score, bool is_new_command);
32
+ void RespondToCommand(int32_t current_time, const char* found_command,
33
+ uint8_t score, bool is_new_command);
34
+
35
+ #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_
@@ -0,0 +1,132 @@
1
+ /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #include <stdio.h>
17
+ #include "feature_provider.h"
18
+
19
+ #include "audio_provider.h"
20
+ #include "micro_features_generator.h"
21
+ #include "micro_model_settings.h"
22
+
23
+ FeatureProvider::FeatureProvider(int feature_size, int8_t* feature_data)
24
+ : feature_size_(feature_size),
25
+ feature_data_(feature_data),
26
+ is_first_run_(true) {
27
+ // Initialize the feature data to default values.
28
+ for (int n = 0; n < feature_size_; ++n) {
29
+ feature_data_[n] = 0;
30
+ }
31
+ }
32
+
33
+ FeatureProvider::~FeatureProvider() {}
34
+
35
+ // TfLiteStatus FeatureProvider::PopulateFeatureData(
36
+ // tflite::ErrorReporter* error_reporter, int32_t last_time_in_ms,
37
+ // int32_t time_in_ms, int* how_many_new_slices) {
38
+ int FeatureProvider::PopulateFeatureData(
39
+ int32_t last_time_in_ms,
40
+ int32_t time_in_ms, int* how_many_new_slices) {
41
+ if (feature_size_ != kFeatureElementCount) {
42
+ printf("Requested feature_data_ size %d doesn't match %d\n",
43
+ feature_size_, kFeatureElementCount);
44
+ return -1;
45
+ }
46
+
47
+ // Quantize the time into steps as long as each window stride, so we can
48
+ // figure out which audio data we need to fetch.
49
+ const int last_step = (last_time_in_ms / kFeatureSliceStrideMs);
50
+ const int current_step = (time_in_ms / kFeatureSliceStrideMs);
51
+
52
+ int slices_needed = current_step - last_step;
53
+ // If this is the first call, make sure we don't use any cached information.
54
+ if (is_first_run_) {
55
+ int init_status = InitializeMicroFeatures();
56
+ if (init_status != 0) {
57
+ return init_status;
58
+ }
59
+ is_first_run_ = false;
60
+ slices_needed = kFeatureSliceCount;
61
+ }
62
+ if (slices_needed > kFeatureSliceCount) {
63
+ slices_needed = kFeatureSliceCount;
64
+ }
65
+ *how_many_new_slices = slices_needed;
66
+
67
+ const int slices_to_keep = kFeatureSliceCount - slices_needed;
68
+ const int slices_to_drop = kFeatureSliceCount - slices_to_keep;
69
+ // If we can avoid recalculating some slices, just move the existing data
70
+ // up in the spectrogram, to perform something like this:
71
+ // last time = 80ms current time = 120ms
72
+ // +-----------+ +-----------+
73
+ // | data@20ms | --> | data@60ms |
74
+ // +-----------+ -- +-----------+
75
+ // | data@40ms | -- --> | data@80ms |
76
+ // +-----------+ -- -- +-----------+
77
+ // | data@60ms | -- -- | <empty> |
78
+ // +-----------+ -- +-----------+
79
+ // | data@80ms | -- | <empty> |
80
+ // +-----------+ +-----------+
81
+ if (slices_to_keep > 0) {
82
+ for (int dest_slice = 0; dest_slice < slices_to_keep; ++dest_slice) {
83
+ int8_t* dest_slice_data =
84
+ feature_data_ + (dest_slice * kFeatureSliceSize);
85
+ const int src_slice = dest_slice + slices_to_drop;
86
+ const int8_t* src_slice_data =
87
+ feature_data_ + (src_slice * kFeatureSliceSize);
88
+ for (int i = 0; i < kFeatureSliceSize; ++i) {
89
+ dest_slice_data[i] = src_slice_data[i];
90
+ }
91
+ }
92
+ }
93
+ // Any slices that need to be filled in with feature data have their
94
+ // appropriate audio data pulled, and features calculated for that slice.
95
+ if (slices_needed > 0) {
96
+ for (int new_slice = slices_to_keep; new_slice < kFeatureSliceCount;
97
+ ++new_slice) {
98
+ const int new_step = (current_step - kFeatureSliceCount + 1) + new_slice;
99
+ const int32_t slice_start_ms = (new_step * kFeatureSliceStrideMs);
100
+ int16_t* audio_samples = nullptr;
101
+ int audio_samples_size = 0;
102
+ // TODO(petewarden): Fix bug that leads to non-zero slice_start_ms
103
+ // GetAudioSamples(error_reporter, (slice_start_ms > 0 ? slice_start_ms : 0),
104
+ // kFeatureSliceDurationMs, &audio_samples_size,
105
+ // &audio_samples);
106
+ GetAudioSamples((slice_start_ms > 0 ? slice_start_ms : 0),
107
+ kFeatureSliceDurationMs, &audio_samples_size,
108
+ &audio_samples);
109
+ if (audio_samples_size < kMaxAudioSampleSize) {
110
+ // TF_LITE_REPORT_ERROR(error_reporter,
111
+ // "Audio data size %d too small, want %d",
112
+ // audio_samples_size, kMaxAudioSampleSize);
113
+ printf("Audio data size %d too small, want %d\n",
114
+ audio_samples_size, kMaxAudioSampleSize);
115
+ // return kTfLiteError;
116
+ return -1;
117
+ }
118
+ int8_t* new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize);
119
+ size_t num_samples_read;
120
+ // TfLiteStatus generate_status = GenerateMicroFeatures(
121
+ // error_reporter, audio_samples, audio_samples_size, kFeatureSliceSize,
122
+ // new_slice_data, &num_samples_read);
123
+ int generate_status = GenerateMicroFeatures(
124
+ audio_samples, audio_samples_size, kFeatureSliceSize,
125
+ new_slice_data, &num_samples_read);
126
+ if (generate_status != 0) {
127
+ return generate_status;
128
+ }
129
+ }
130
+ }
131
+ return 0;
132
+ }
@@ -0,0 +1,145 @@
1
+ /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #include <stdio.h>
17
+ #include "feature_provider.h"
18
+
19
+ #include "freertos/FreeRTOS.h"
20
+ #include "freertos/task.h"
21
+ #include "audio_provider.h"
22
+ #include "micro_features_generator.h"
23
+ #include "micro_model_settings.h"
24
+
25
+ FeatureProvider::FeatureProvider(int feature_size, int8_t* feature_data)
26
+ : feature_size_(feature_size),
27
+ feature_data_(feature_data),
28
+ is_first_run_(true) {
29
+ // Initialize the feature data to default values.
30
+ for (int n = 0; n < feature_size_; ++n) {
31
+ feature_data_[n] = 0;
32
+ }
33
+ }
34
+
35
+ FeatureProvider::~FeatureProvider() {}
36
+
37
+ // TfLiteStatus FeatureProvider::PopulateFeatureData(
38
+ // tflite::ErrorReporter* error_reporter, int32_t last_time_in_ms,
39
+ // int32_t time_in_ms, int* how_many_new_slices) {
40
+ int FeatureProvider::PopulateFeatureData(
41
+ int32_t last_time_in_ms,
42
+ int32_t time_in_ms, int* how_many_new_slices) {
43
+ uint32_t startA = xTaskGetTickCount();
44
+ if (feature_size_ != kFeatureElementCount) {
45
+ printf("Requested feature_data_ size %d doesn't match %d\n",
46
+ feature_size_, kFeatureElementCount);
47
+ uint32_t endA = xTaskGetTickCount();
48
+ printf("ticks(PopulateFeatureData1)=%lu\n", endA-startA);
49
+ return -1;
50
+ }
51
+
52
+ // Quantize the time into steps as long as each window stride, so we can
53
+ // figure out which audio data we need to fetch.
54
+ const int last_step = (last_time_in_ms / kFeatureSliceStrideMs);
55
+ const int current_step = (time_in_ms / kFeatureSliceStrideMs);
56
+
57
+ int slices_needed = current_step - last_step;
58
+ // If this is the first call, make sure we don't use any cached information.
59
+ if (is_first_run_) {
60
+ int init_status = InitializeMicroFeatures();
61
+ if (init_status != 0) {
62
+ uint32_t endA = xTaskGetTickCount();
63
+ printf("ticks(PopulateFeatureData2)=%lu\n", endA-startA);
64
+ return init_status;
65
+ }
66
+ is_first_run_ = false;
67
+ slices_needed = kFeatureSliceCount;
68
+ }
69
+ if (slices_needed > kFeatureSliceCount) {
70
+ slices_needed = kFeatureSliceCount;
71
+ }
72
+ *how_many_new_slices = slices_needed;
73
+
74
+ const int slices_to_keep = kFeatureSliceCount - slices_needed;
75
+ const int slices_to_drop = kFeatureSliceCount - slices_to_keep;
76
+ // If we can avoid recalculating some slices, just move the existing data
77
+ // up in the spectrogram, to perform something like this:
78
+ // last time = 80ms current time = 120ms
79
+ // +-----------+ +-----------+
80
+ // | data@20ms | --> | data@60ms |
81
+ // +-----------+ -- +-----------+
82
+ // | data@40ms | -- --> | data@80ms |
83
+ // +-----------+ -- -- +-----------+
84
+ // | data@60ms | -- -- | <empty> |
85
+ // +-----------+ -- +-----------+
86
+ // | data@80ms | -- | <empty> |
87
+ // +-----------+ +-----------+
88
+ if (slices_to_keep > 0) {
89
+ for (int dest_slice = 0; dest_slice < slices_to_keep; ++dest_slice) {
90
+ int8_t* dest_slice_data =
91
+ feature_data_ + (dest_slice * kFeatureSliceSize);
92
+ const int src_slice = dest_slice + slices_to_drop;
93
+ const int8_t* src_slice_data =
94
+ feature_data_ + (src_slice * kFeatureSliceSize);
95
+ for (int i = 0; i < kFeatureSliceSize; ++i) {
96
+ dest_slice_data[i] = src_slice_data[i];
97
+ }
98
+ }
99
+ }
100
+ // Any slices that need to be filled in with feature data have their
101
+ // appropriate audio data pulled, and features calculated for that slice.
102
+ if (slices_needed > 0) {
103
+ for (int new_slice = slices_to_keep; new_slice < kFeatureSliceCount;
104
+ ++new_slice) {
105
+ const int new_step = (current_step - kFeatureSliceCount + 1) + new_slice;
106
+ const int32_t slice_start_ms = (new_step * kFeatureSliceStrideMs);
107
+ int16_t* audio_samples = nullptr;
108
+ int audio_samples_size = 0;
109
+ // TODO(petewarden): Fix bug that leads to non-zero slice_start_ms
110
+ // GetAudioSamples(error_reporter, (slice_start_ms > 0 ? slice_start_ms : 0),
111
+ // kFeatureSliceDurationMs, &audio_samples_size,
112
+ // &audio_samples);
113
+ GetAudioSamples((slice_start_ms > 0 ? slice_start_ms : 0),
114
+ kFeatureSliceDurationMs, &audio_samples_size,
115
+ &audio_samples);
116
+ if (audio_samples_size < kMaxAudioSampleSize) {
117
+ // TF_LITE_REPORT_ERROR(error_reporter,
118
+ // "Audio data size %d too small, want %d",
119
+ // audio_samples_size, kMaxAudioSampleSize);
120
+ printf("Audio data size %d too small, want %d\n",
121
+ audio_samples_size, kMaxAudioSampleSize);
122
+ // return kTfLiteError;
123
+ uint32_t endA = xTaskGetTickCount();
124
+ printf("ticks(PopulateFeatureData3)=%lu\n", endA-startA);
125
+ return -1;
126
+ }
127
+ int8_t* new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize);
128
+ size_t num_samples_read;
129
+ // TfLiteStatus generate_status = GenerateMicroFeatures(
130
+ // error_reporter, audio_samples, audio_samples_size, kFeatureSliceSize,
131
+ // new_slice_data, &num_samples_read);
132
+ int generate_status = GenerateMicroFeatures(
133
+ audio_samples, audio_samples_size, kFeatureSliceSize,
134
+ new_slice_data, &num_samples_read);
135
+ if (generate_status != 0) {
136
+ uint32_t endA = xTaskGetTickCount();
137
+ printf("ticks(PopulateFeatureData4)=%lu\n", endA-startA);
138
+ return generate_status;
139
+ }
140
+ }
141
+ }
142
+ uint32_t endA = xTaskGetTickCount();
143
+ printf("ticks(PopulateFeatureData)=%lu\n", endA-startA);
144
+ return 0;
145
+ }
@@ -0,0 +1,55 @@
1
+ /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_
17
+ #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_
18
+
19
+ #include <stdint.h>
20
+ // #include "tensorflow/lite/c/common.h"
21
+ // #include "tensorflow/lite/micro/micro_error_reporter.h"
22
+
23
+ // Binds itself to an area of memory intended to hold the input features for an
24
+ // audio-recognition neural network model, and fills that data area with the
25
+ // features representing the current audio input, for example from a microphone.
26
+ // The audio features themselves are a two-dimensional array, made up of
27
+ // horizontal slices representing the frequencies at one point in time, stacked
28
+ // on top of each other to form a spectrogram showing how those frequencies
29
+ // changed over time.
30
+ class FeatureProvider {
31
+ public:
32
+ // Create the provider, and bind it to an area of memory. This memory should
33
+ // remain accessible for the lifetime of the provider object, since subsequent
34
+ // calls will fill it with feature data. The provider does no memory
35
+ // management of this data.
36
+ FeatureProvider(int feature_size, int8_t* feature_data);
37
+ ~FeatureProvider();
38
+
39
+ // Fills the feature data with information from audio inputs, and returns how
40
+ // many feature slices were updated.
41
+ // TfLiteStatus PopulateFeatureData(tflite::ErrorReporter* error_reporter,
42
+ // int32_t last_time_in_ms, int32_t time_in_ms,
43
+ // int* how_many_new_slices);
44
+ int PopulateFeatureData(int32_t last_time_in_ms, int32_t time_in_ms,
45
+ int* how_many_new_slices);
46
+
47
+ private:
48
+ int feature_size_;
49
+ int8_t* feature_data_;
50
+ // Make sure we don't try to use cached information if this is the first call
51
+ // into the provider.
52
+ bool is_first_run_;
53
+ };
54
+
55
+ #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2003-2010 Mark Borgerding
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,168 @@
1
+ #ifndef _KISS_FFT_GUTS_H
2
+ #define _KISS_FFT_GUTS_H
3
+
4
+ /*
5
+ Copyright (c) 2003-2010, Mark Borgerding
6
+
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
10
+
11
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13
+ * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
+ */
17
+
18
+ /* kiss_fft.h
19
+ defines kiss_fft_scalar as either short or a float type
20
+ and defines
21
+ typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
22
+ #include "kiss_fft.h"
23
+ #include <limits.h>
24
+
25
+ #define MAXFACTORS 32
26
+ /* e.g. an fft of length 128 has 4 factors
27
+ as far as kissfft is concerned
28
+ 4*4*4*2
29
+ */
30
+
31
+ struct kiss_fft_state{
32
+ int nfft;
33
+ int inverse;
34
+ int factors[2*MAXFACTORS];
35
+ kiss_fft_cpx twiddles[1];
36
+ };
37
+
38
+ /*
39
+ Explanation of macros dealing with complex math:
40
+
41
+ C_MUL(m,a,b) : m = a*b
42
+ C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
43
+ C_SUB( res, a,b) : res = a - b
44
+ C_SUBFROM( res , a) : res -= a
45
+ C_ADDTO( res , a) : res += a
46
+ * */
47
+ #ifdef FIXED_POINT
48
+ #if (FIXED_POINT==32)
49
+ # define FRACBITS 31
50
+ # define SAMPPROD int64_t
51
+ #define SAMP_MAX 2147483647
52
+ #else
53
+ # define FRACBITS 15
54
+ # define SAMPPROD int32_t
55
+ #define SAMP_MAX 32767
56
+ #endif
57
+
58
+ #define SAMP_MIN -SAMP_MAX
59
+
60
+ #if defined(CHECK_OVERFLOW)
61
+ # define CHECK_OVERFLOW_OP(a,op,b) \
62
+ if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \
63
+ fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); }
64
+ #endif
65
+
66
+
67
+ # define smul(a,b) ( (SAMPPROD)(a)*(b) )
68
+ # define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
69
+
70
+ # define S_MUL(a,b) sround( smul(a,b) )
71
+
72
+ # define C_MUL(m,a,b) \
73
+ do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
74
+ (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
75
+
76
+ # define DIVSCALAR(x,k) \
77
+ (x) = sround( smul( x, SAMP_MAX/k ) )
78
+
79
+ # define C_FIXDIV(c,div) \
80
+ do { DIVSCALAR( (c).r , div); \
81
+ DIVSCALAR( (c).i , div); }while (0)
82
+
83
+ # define C_MULBYSCALAR( c, s ) \
84
+ do{ (c).r = sround( smul( (c).r , s ) ) ;\
85
+ (c).i = sround( smul( (c).i , s ) ) ; }while(0)
86
+
87
+ #else /* not FIXED_POINT*/
88
+
89
+ # define S_MUL(a,b) ( (a)*(b) )
90
+ #define C_MUL(m,a,b) \
91
+ do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
92
+ (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
93
+ # define C_FIXDIV(c,div) /* NOOP */
94
+ # define C_MULBYSCALAR( c, s ) \
95
+ do{ (c).r *= (s);\
96
+ (c).i *= (s); }while(0)
97
+ #endif
98
+
99
+ #ifndef CHECK_OVERFLOW_OP
100
+ # define CHECK_OVERFLOW_OP(a,op,b) /* noop */
101
+ #endif
102
+
103
+ #define C_ADD( res, a,b)\
104
+ do { \
105
+ CHECK_OVERFLOW_OP((a).r,+,(b).r)\
106
+ CHECK_OVERFLOW_OP((a).i,+,(b).i)\
107
+ (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
108
+ }while(0)
109
+ #define C_SUB( res, a,b)\
110
+ do { \
111
+ CHECK_OVERFLOW_OP((a).r,-,(b).r)\
112
+ CHECK_OVERFLOW_OP((a).i,-,(b).i)\
113
+ (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
114
+ }while(0)
115
+ #define C_ADDTO( res , a)\
116
+ do { \
117
+ CHECK_OVERFLOW_OP((res).r,+,(a).r)\
118
+ CHECK_OVERFLOW_OP((res).i,+,(a).i)\
119
+ (res).r += (a).r; (res).i += (a).i;\
120
+ }while(0)
121
+
122
+ #define C_SUBFROM( res , a)\
123
+ do {\
124
+ CHECK_OVERFLOW_OP((res).r,-,(a).r)\
125
+ CHECK_OVERFLOW_OP((res).i,-,(a).i)\
126
+ (res).r -= (a).r; (res).i -= (a).i; \
127
+ }while(0)
128
+
129
+
130
+ #ifdef FIXED_POINT
131
+ # define KISS_FFT_COS(phase) floor(.5+SAMP_MAX * cos (phase))
132
+ # define KISS_FFT_SIN(phase) floor(.5+SAMP_MAX * sin (phase))
133
+ # define HALF_OF(x) ((x)>>1)
134
+ #elif defined(USE_SIMD)
135
+ # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
136
+ # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
137
+ # define HALF_OF(x) ((x)*_mm_set1_ps(.5))
138
+ #else
139
+ # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
140
+ # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
141
+ # define HALF_OF(x) ((x)*(kiss_fft_scalar).5)
142
+ #endif
143
+
144
+ #define kf_cexp(x,phase) \
145
+ do{ \
146
+ (x)->r = KISS_FFT_COS(phase);\
147
+ (x)->i = KISS_FFT_SIN(phase);\
148
+ }while(0)
149
+
150
+
151
+ /* a debugging function */
152
+ #define pcpx(c)\
153
+ fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
154
+
155
+
156
+ #ifdef KISS_FFT_USE_ALLOCA
157
+ // define this to allow use of alloca instead of malloc for temporary buffers
158
+ // Temporary buffers are used in two case:
159
+ // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
160
+ // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform.
161
+ #include <alloca.h>
162
+ #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
163
+ #define KISS_FFT_TMP_FREE(ptr)
164
+ #else
165
+ #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes)
166
+ #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr)
167
+ #endif
168
+ #endif // _KISS_FFT_GUTS_H