mehrdadh opened a new pull request, #13885:
URL: https://github.com/apache/tvm/pull/13885

   This PR refactors all the necessary function fors a CRT project into 
`platform-template.c`/`platfrom-template.h` files. Using this PR the content of 
CRT template project is as follow:
   ```
   .
   ├── include
   │   ├── crt_config-template.h
   │   └── platform-template.h
   ├── Makefile.template
   ├── microtvm_api_server.py
   └── src
       ├── main.cc
       └── platform-template.c
   ```
   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. 
   ```
   #include <stdarg.h>
   #include <stdint.h>
   #include <stdio.h>
   #include <stdlib.h>
   
   #include "dlpack/dlpack.h"
   #include "tvm/platform.h"
   #include "tvm/runtime/crt/error_codes.h"
   
   // Called by TVM when a message needs to be formatted.
   __attribute__((weak)) size_t TVMPlatformFormatMessage(char* out_buf, size_t 
out_buf_size_bytes,
                                                         const char* fmt, 
va_list args) {
     return vsprintf(out_buf, fmt, args);
   }
   
   // Called by TVM when an internal invariant is violated, and execution 
cannot continue.
   __attribute__((weak)) void TVMPlatformAbort(tvm_crt_error_t error_code) { 
exit(1); }
   
   // Called by TVM when memory allocation is required.
   __attribute__((weak)) tvm_crt_error_t TVMPlatformMemoryAllocate(size_t 
num_bytes, DLDevice dev,
                                                                   void** 
out_ptr) {
     return memory_manager->Allocate(memory_manager, num_bytes, dev, out_ptr);
   }
   
   // Called by TVM to free an allocated memory.
   __attribute__((weak)) tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, 
DLDevice dev) {
     return memory_manager->Free(memory_manager, ptr, dev);
   }
   ```
   Using the same idea, various project types for Zephyr was refactored.
   
   In addition. these templates files are also added along with 
`crt_config-template.h` (which was accidentally removed in #13812) to model 
library format. Here is the updated structure of a MLF file:
   ```
   .
   ├── codegen
   │   └── host
   ├── metadata.json
   ├── parameters
   │   └── default.params
   ├── runtime
   │   ├── include
   │   ├── Makefile
   │   └── src
   ├── src
   │   └── default.relay
   └── templates
       ├── crt_config-template.h
       ├── platform-template.c
       └── platform-template.h
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to