guberti commented on code in PR #13885: URL: https://github.com/apache/tvm/pull/13885#discussion_r1100668301
########## apps/microtvm/zephyr/template_project/microtvm_api_server.py: ########## @@ -658,13 +673,31 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec API_SERVER_DIR / "crt_config" / "crt_config.h", crt_config_dir / "crt_config.h" ) - # Populate src/ + # Populate src and include Review Comment: nit: ```suggestion # Populate `src` and `include` directories ``` ########## apps/microtvm/arduino/template_project/src/example_project/project.ino: ########## @@ -17,10 +17,10 @@ * under the License. */ -#include "src/model.h" +#include "src/standalone_crt/include/tvm/runtime/crt/platform.h" void setup() { - TVMInitialize(); + TVMPlatformInitialize(); Review Comment: I like this approach of being very high level. I know we haven't focused a whole lot on usability, but being able to call one function and set up the whole thing is really nice. ########## apps/microtvm/arduino/template_project/src/example_project/platform.c: ########## @@ -77,14 +88,19 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) { return kTvmErrorNoError; } -tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* buffer, size_t num_bytes) { +// Fill a buffer with random data. +__attribute__((weak)) tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* buffer, size_t num_bytes) { Review Comment: I'm a fan of these being weak - I think allowing the user to change the implementation is worth the increased complexity. ########## apps/microtvm/zephyr/template_project/microtvm_api_server.py: ########## @@ -658,13 +673,31 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec API_SERVER_DIR / "crt_config" / "crt_config.h", crt_config_dir / "crt_config.h" ) - # Populate src/ + # Populate src and include src_dir = project_dir / "src" - if project_type != "host_driven" or self._is_fvp(zephyr_board, use_fvp): - shutil.copytree(API_SERVER_DIR / "src" / project_type, src_dir) - else: - src_dir.mkdir() - shutil.copy2(API_SERVER_DIR / "src" / project_type / "main.c", src_dir) + src_dir.mkdir() + include_dir = project_dir / "include" / "tvm" + include_dir.mkdir(parents=True) + src_project_type_dir = API_SERVER_DIR / "src" / project_type + for file in os.listdir(src_project_type_dir): + file = pathlib.Path(src_project_type_dir / file) + if file.is_file(): + if file.suffix in [".cc", ".c"]: + shutil.copy2(file, src_dir) + elif file.suffix in [".h"]: + shutil.copy2(file, include_dir) + + if self._is_fvp(zephyr_board, use_fvp): + for file in os.listdir(src_project_type_dir / "fvp"): + file = pathlib.Path(src_project_type_dir / "fvp" / file) + if file.is_file(): + if file.suffix in [".cc", ".c"]: + shutil.copy2(file, src_dir) + elif file.suffix in [".h"]: + shutil.copy2(file, include_dir) Review Comment: nit: can we abstract this logic into a function to prevent duplicate code with the above if statement? ########## apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc: ########## @@ -19,44 +19,189 @@ #include "api/submitter_implemented.h" +#include <string.h> +#include <tvm/runtime/crt/logging.h> #include <tvm/runtime/crt/platform.h> #include <unistd.h> #include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/uart.h> #include <zephyr/kernel.h> +#include <zephyr/sys/ring_buffer.h> #include "api/internally_implemented.h" -#include "tvmruntime.h" -#include "zephyr_uart.h" +#include "crt_config.h" +#include "tvm/output_data.h" +#include "tvmgen_default.h" + +// ############################################################### +// Model +// ############################################################### +#define MODEL_KWS 1 +#define MODEL_VWW 2 +#define MODEL_AD 3 +#define MODEL_IC 4 static void* g_input_data; -#if TARGET_MODEL == 3 // AD +// TODO: use name instead of number directly Review Comment: nit: WDYM here? `#if TARGET_MODEL == MODEL_AD` seems fine. ########## apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc: ########## @@ -19,44 +19,189 @@ #include "api/submitter_implemented.h" +#include <string.h> +#include <tvm/runtime/crt/logging.h> #include <tvm/runtime/crt/platform.h> #include <unistd.h> #include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/uart.h> #include <zephyr/kernel.h> +#include <zephyr/sys/ring_buffer.h> #include "api/internally_implemented.h" -#include "tvmruntime.h" -#include "zephyr_uart.h" +#include "crt_config.h" +#include "tvm/output_data.h" +#include "tvmgen_default.h" + +// ############################################################### +// Model +// ############################################################### +#define MODEL_KWS 1 Review Comment: Defining these constants is a really nice improvement! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org