[microTVM] Refactor required external functions in CRT to platform-template.c#13885
[microTVM] Refactor required external functions in CRT to platform-template.c#13885mehrdadh merged 27 commits intoapache:mainfrom
Conversation
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
93fba20 to
7e7df14
Compare
| #include <tvm/runtime/crt/stack_allocator.h> | ||
|
|
||
| // Used to read data from the UART. | ||
| extern tvm_workspace_t app_workspace; |
There was a problem hiding this comment.
do we need to place the prototypes of the functions defined in platform.c here?
| @@ -110,17 +103,6 @@ size_t TVMPlatformFormatMessage(char* out_buf, size_t out_buf_size_bytes, const | |||
| return vsnprintk(out_buf, out_buf_size_bytes, fmt, args); | |||
There was a problem hiding this comment.
Move this function to platform.c?
mkatanbaf
left a comment
There was a problem hiding this comment.
LGTM, just left a few minor comments.
|
|
||
| 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) { |
There was a problem hiding this comment.
how come these are weak? if you miss implementing one, could you accidentally link the default and then wind up with two implementations?
There was a problem hiding this comment.
The idea here is that platform.c has one implementation of these functions which is added by default to the project. But in case the user wants to change the implementation, they could reimplement it in their main.c
That's why it is defined as weak.
There was a problem hiding this comment.
I'm a fan of these being weak - I think allowing the user to change the implementation is worth the increased complexity.
| g_microtvm_timer_running = 1; | ||
| return kTvmErrorNoError; | ||
| // Initialize UART | ||
| void UARTInit() { |
There was a problem hiding this comment.
use consistent caps (UART vs Uart; i prefer Uart because the string parses easier)
| void main(void) { | ||
| UARTInit(); | ||
| TVMPlatformInitialize(); | ||
| g_cmd_buf_ind = 0; |
There was a problem hiding this comment.
initialize the Uart after you are ready to receive stuff
There was a problem hiding this comment.
UartInit initialize both transmit and receive
There was a problem hiding this comment.
I guess what @areusch means here (and correct me if I'm wrong) is to init Uart once the platform (including memory, rpc for example) is initialized. Otherwise, the received data might drop or even cause errors (by trying to write into memory spaces that are not allocated yet)
There was a problem hiding this comment.
That makes sense. I changed the order.
guberti
left a comment
There was a problem hiding this comment.
Left a few nits, but looks good to me!
|
|
||
| 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) { |
There was a problem hiding this comment.
I'm a fan of these being weak - I think allowing the user to change the implementation is worth the increased complexity.
| // ############################################################### | ||
| // Model | ||
| // ############################################################### | ||
| #define MODEL_KWS 1 |
There was a problem hiding this comment.
Defining these constants is a really nice improvement!
dae1733 to
c132e9b
Compare
c132e9b to
ab944ab
Compare
This PR refactors all the necessary functions for a CRT project into
platform-template.cfile. Using this PR the content of CRT template project is as follow:The content of platform-template.c is as follows. This file shows the minimum implementation that is required for using a microTVM generated MLF file in a different environment.
Using the same idea, various project types for Zephyr and Arduino was refactored.
In addition, these templates files are also added along with
crt_config-template.h(which was accidentally removed in #13812) to generated model library format (MLF). Here is the updated structure of a MLF file: