From 13abc4e0ca916e59ca59e84cc2459ef4e9627f03 Mon Sep 17 00:00:00 2001 From: Mehrdad Hessar Date: Thu, 5 Jan 2023 10:50:21 -0800 Subject: [PATCH] address comments --- 3rdparty/mlperftiny/README.md | 2 +- .../zephyr/template_project/src/mlperftiny/README.md | 2 ++ .../zephyr/template_project/src/mlperftiny/main.cc | 1 + .../src/mlperftiny/submitter_implemented.cc | 10 ++++++++++ cmake/modules/Zephyr.cmake | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 apps/microtvm/zephyr/template_project/src/mlperftiny/README.md diff --git a/3rdparty/mlperftiny/README.md b/3rdparty/mlperftiny/README.md index 7707f7e58b7f..28938e90d744 100644 --- a/3rdparty/mlperftiny/README.md +++ b/3rdparty/mlperftiny/README.md @@ -1,2 +1,2 @@ # MLPerf™ Tiny Benchmark API -This directory includes API files to build a microTVM project that could be tested with EEMBC benchmark runner. API files are captured from [MLCommons/tiny repository](https://github.com/mlcommons/tiny). +This directory includes API files to build a microTVM project that could be tested with EEMBC benchmark runner. API files are captured from the [MLCommons/tiny repository](https://github.com/mlcommons/tiny). diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/README.md b/apps/microtvm/zephyr/template_project/src/mlperftiny/README.md new file mode 100644 index 000000000000..2b41c1cb6a6a --- /dev/null +++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/README.md @@ -0,0 +1,2 @@ +# MLPerf Tiny Project API +This directory includes source files to build a Zephyr microTVM project to use for benchmarking with EEMBC runner. This project has been tested with NUCLEO_L4R5ZI and NRF5340DK. diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/main.cc b/apps/microtvm/zephyr/template_project/src/mlperftiny/main.cc index 16d2de8fd715..4c91177062ad 100644 --- a/apps/microtvm/zephyr/template_project/src/mlperftiny/main.cc +++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/main.cc @@ -23,6 +23,7 @@ int main(int argc, char* argv[]) { #if NRF_BOARD == 1 // Set frequency to 128MHz for nrf5340dk_nrf534 by setting the clock divider to 0. + // 0x50005558 is the clock division reg address. uint32_t* clock_div = (uint32_t*)0x50005558; *clock_div = 0; #endif diff --git a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc index 86373425f4bf..84baee3072cd 100644 --- a/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc +++ b/apps/microtvm/zephyr/template_project/src/mlperftiny/submitter_implemented.cc @@ -41,10 +41,12 @@ static const gpio_pin_t g_gpio_pin = 6; #endif // Implement this method to prepare for inference and preprocess inputs. +// Modified from source void th_load_tensor() { #if TARGET_MODEL == 1 // KWS g_input_data = static_cast(ee_get_buffer_pointer()); #elif TARGET_MODEL == 2 // VWW + // Converting uint8 to int8 int8_t* temp_int = reinterpret_cast(ee_get_buffer_pointer()); for (size_t i = 0; i < MAX_DB_INPUT_SIZE; i++) { temp_int[i] -= 128; @@ -111,9 +113,11 @@ void th_results() { } // Implement this method with the logic to perform one inference cycle. +// Modified from source void th_infer() { TVMInfer(g_input_data); } /// \brief optional API. +// Modified from source void th_final_initialize(void) { TVMRuntimeInit(); } void th_pre() {} @@ -143,6 +147,8 @@ void* th_memcpy(void* dst, const void* src, size_t n) { return memcpy(dst, src, /* N.B.: Many embedded *printf SDKs do not support all format specifiers. */ int th_vprintf(const char* format, va_list ap) { return vprintf(format, ap); } + +// Modified from source void th_printf(const char* p_fmt, ...) { char buffer[128]; int size; @@ -153,8 +159,10 @@ void th_printf(const char* p_fmt, ...) { TVMPlatformWriteSerial(buffer, (size_t)size); } +// Modified from source char th_getchar() { return TVMPlatformUartRxRead(); } +// Modified from source void th_serialport_initialize(void) { #if EE_CFG_ENERGY_MODE == 1 && NRF_BOARD != 1 TVMPlatformUARTInit(9600); @@ -163,6 +171,7 @@ void th_serialport_initialize(void) { #endif } +// Modified from source void th_timestamp(void) { #if EE_CFG_ENERGY_MODE == 1 && NRF_BOARD != 1 /* USER CODE 1 BEGIN */ @@ -182,6 +191,7 @@ void th_timestamp(void) { #endif } +// Modified from source void th_timestamp_initialize(void) { /* USER CODE 1 BEGIN */ // Setting up BOTH perf and energy here diff --git a/cmake/modules/Zephyr.cmake b/cmake/modules/Zephyr.cmake index 72e2f3f1ed17..1f506f5132fd 100644 --- a/cmake/modules/Zephyr.cmake +++ b/cmake/modules/Zephyr.cmake @@ -27,7 +27,8 @@ if(USE_MICRO) "apps/microtvm/zephyr/template_project/src/aot_standalone_demo *.h -> zephyr/src/aot_standalone_demo" "apps/microtvm/zephyr/template_project/src/host_driven *.c -> zephyr/src/host_driven" "apps/microtvm/zephyr/template_project/src/host_driven *.h -> zephyr/src/host_driven" - "apps/microtvm/zephyr/template_project/src/mlperftiny * -> zephyr/src/mlperftiny" + "apps/microtvm/zephyr/template_project/src/mlperftiny *.cc -> zephyr/src/mlperftiny" + "apps/microtvm/zephyr/template_project/src/mlperftiny *.h -> zephyr/src/mlperftiny" "3rdparty/mlperftiny/api * -> zephyr/src/mlperftiny/api" "apps/microtvm/zephyr/template_project/fvp-hack * -> zephyr/fvp-hack" "apps/microtvm/zephyr/template_project/qemu-hack * -> zephyr/qemu-hack"