Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ We do encourage everyone to work anything they are interested in.
- [Trevor Morris](https://github.com/trevor-m): @trevor-m - byoc, compiler
- [Leandro Nunes](https://github.com/leandron): @leandron - tvmc
- [Krzysztof Parzyszek](https://github.com/kparzysz-quic): @kparzysz-quic - hexagon, llvm
- [Andrew Reusch](https://github.com/areusch): @areusch - runtime, µTVM
- [Andrew Reusch](https://github.com/areusch): @areusch - runtime, microTVM
- [Jared Roesch](https://github.com/jroesch) (PMC): @jroesch - relay
- [Siju Samuel](https://github.com/siju-samuel): @siju-samuel - frontends
- [Junru Shao](https://github.com/junrushao1994) @junrushao1994 - relay, compiler
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ v0.7 brings many major features. The community works together to refactor the in
* Intial Hexagon support
* Bring your own codegen (BYOC) support

The community also continues to bring high quality improvements to the existing modules including, but not limited to: better frontend coverage, performance, quantization, uTVM and dynamic shape support.
The community also continues to bring high quality improvements to the existing modules including, but not limited to: better frontend coverage, performance, quantization, microTVM and dynamic shape support.

## New Features
### Automatic Scheduling (Experimental)
Expand Down
32 changes: 16 additions & 16 deletions apps/microtvm/zephyr/aot_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,52 +83,52 @@ void timer_expiry_function(struct k_timer* timer_id) { return; }

#define MILLIS_TIL_EXPIRY 200
#define TIME_TIL_EXPIRY (K_MSEC(MILLIS_TIL_EXPIRY))
struct k_timer g_utvm_timer;
uint32_t g_utvm_start_time;
int g_utvm_timer_running = 0;
struct k_timer g_microtvm_timer;
uint32_t g_microtvm_start_time;
int g_microtvm_timer_running = 0;

// Called to start system timer.
tvm_crt_error_t TVMPlatformTimerStart() {
if (g_utvm_timer_running) {
if (g_microtvm_timer_running) {
TVMLogf("timer already running");
return kTvmErrorPlatformTimerBadState;
}

k_timer_start(&g_utvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
g_utvm_start_time = k_cycle_get_32();
g_utvm_timer_running = 1;
k_timer_start(&g_microtvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
g_microtvm_start_time = k_cycle_get_32();
g_microtvm_timer_running = 1;
return kTvmErrorNoError;
}

// Called to stop system timer.
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
if (!g_utvm_timer_running) {
if (!g_microtvm_timer_running) {
TVMLogf("timer not running");
return kTvmErrorSystemErrorMask | 2;
}

uint32_t stop_time = k_cycle_get_32();

// compute how long the work took
uint32_t cycles_spent = stop_time - g_utvm_start_time;
if (stop_time < g_utvm_start_time) {
uint32_t cycles_spent = stop_time - g_microtvm_start_time;
if (stop_time < g_microtvm_start_time) {
// we rolled over *at least* once, so correct the rollover it was *only*
// once, because we might still use this result
cycles_spent = ~((uint32_t)0) - (g_utvm_start_time - stop_time);
cycles_spent = ~((uint32_t)0) - (g_microtvm_start_time - stop_time);
}

uint32_t ns_spent = (uint32_t)k_cyc_to_ns_floor64(cycles_spent);
double hw_clock_res_us = ns_spent / 1000.0;

// need to grab time remaining *before* stopping. when stopped, this function
// always returns 0.
int32_t time_remaining_ms = k_timer_remaining_get(&g_utvm_timer);
k_timer_stop(&g_utvm_timer);
int32_t time_remaining_ms = k_timer_remaining_get(&g_microtvm_timer);
k_timer_stop(&g_microtvm_timer);
// check *after* stopping to prevent extra expiries on the happy path
if (time_remaining_ms < 0) {
return kTvmErrorSystemErrorMask | 3;
}
uint32_t num_expiries = k_timer_status_get(&g_utvm_timer);
uint32_t num_expiries = k_timer_status_get(&g_microtvm_timer);
uint32_t timer_res_ms = ((num_expiries * MILLIS_TIL_EXPIRY) + time_remaining_ms);
double approx_num_cycles =
(double)k_ticks_to_cyc_floor32(1) * (double)k_ms_to_ticks_ceil32(timer_res_ms);
Expand All @@ -140,7 +140,7 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
*elapsed_time_seconds = hw_clock_res_us / 1e6;
}

g_utvm_timer_running = 0;
g_microtvm_timer_running = 0;
return kTvmErrorNoError;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ void main(void) {
g_cmd_buf_ind = 0;
memset((char*)cmd_buf, 0, sizeof(cmd_buf));
TVMPlatformUARTInit();
k_timer_init(&g_utvm_timer, NULL, NULL);
k_timer_init(&g_microtvm_timer, NULL, NULL);
// Wake up host side.
TVMPlatformWriteSerial(g_wakeup_sequence, sizeof(g_wakeup_sequence));

Expand Down
8 changes: 4 additions & 4 deletions apps/microtvm/zephyr/aot_demo/src/zephyr_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "crt_config.h"

static const struct device* g_utvm_uart;
static const struct device* g_microtvm_uart;
#define RING_BUF_SIZE_BYTES (TVM_CRT_MAX_PACKET_SIZE_BYTES + 100)

// Ring buffer used to store data read from the UART on rx interrupt.
Expand Down Expand Up @@ -68,14 +68,14 @@ uint32_t TVMPlatformUartRxRead(uint8_t* data, uint32_t data_size_bytes) {

uint32_t TVMPlatformWriteSerial(const char* data, uint32_t size) {
for (uint32_t i = 0; i < size; i++) {
uart_poll_out(g_utvm_uart, data[i]);
uart_poll_out(g_microtvm_uart, data[i]);
}
return size;
}

// Initialize UART
void TVMPlatformUARTInit() {
// Claim console device.
g_utvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
uart_rx_init(&uart_rx_rbuf, g_utvm_uart);
g_microtvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
uart_rx_init(&uart_rx_rbuf, g_microtvm_uart);
}
38 changes: 19 additions & 19 deletions apps/microtvm/zephyr/host_driven/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <sys/printk.h>
#include <sys/ring_buffer.h>
#include <tvm/runtime/crt/logging.h>
#include <tvm/runtime/crt/utvm_rpc_server.h>
#include <tvm/runtime/crt/microtvm_rpc_server.h>
#include <unistd.h>
#include <zephyr.h>

Expand Down Expand Up @@ -146,30 +146,30 @@ tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) {

#define MILLIS_TIL_EXPIRY 200
#define TIME_TIL_EXPIRY (K_MSEC(MILLIS_TIL_EXPIRY))
K_TIMER_DEFINE(g_utvm_timer, /* expiry func */ NULL, /* stop func */ NULL);
K_TIMER_DEFINE(g_microtvm_timer, /* expiry func */ NULL, /* stop func */ NULL);

uint32_t g_utvm_start_time;
int g_utvm_timer_running = 0;
uint32_t g_microtvm_start_time;
int g_microtvm_timer_running = 0;

// Called to start system timer.
tvm_crt_error_t TVMPlatformTimerStart() {
if (g_utvm_timer_running) {
if (g_microtvm_timer_running) {
TVMLogf("timer already running");
return kTvmErrorPlatformTimerBadState;
}

#ifdef CONFIG_LED
gpio_pin_set(led0_pin, LED0_PIN, 1);
#endif
k_timer_start(&g_utvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
g_utvm_start_time = k_cycle_get_32();
g_utvm_timer_running = 1;
k_timer_start(&g_microtvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
g_microtvm_start_time = k_cycle_get_32();
g_microtvm_timer_running = 1;
return kTvmErrorNoError;
}

// Called to stop system timer.
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
if (!g_utvm_timer_running) {
if (!g_microtvm_timer_running) {
TVMLogf("timer not running");
return kTvmErrorSystemErrorMask | 2;
}
Expand All @@ -180,26 +180,26 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
#endif

// compute how long the work took
uint32_t cycles_spent = stop_time - g_utvm_start_time;
if (stop_time < g_utvm_start_time) {
uint32_t cycles_spent = stop_time - g_microtvm_start_time;
if (stop_time < g_microtvm_start_time) {
// we rolled over *at least* once, so correct the rollover it was *only*
// once, because we might still use this result
cycles_spent = ~((uint32_t)0) - (g_utvm_start_time - stop_time);
cycles_spent = ~((uint32_t)0) - (g_microtvm_start_time - stop_time);
}

uint32_t ns_spent = (uint32_t)k_cyc_to_ns_floor64(cycles_spent);
double hw_clock_res_us = ns_spent / 1000.0;

// need to grab time remaining *before* stopping. when stopped, this function
// always returns 0.
int32_t time_remaining_ms = k_timer_remaining_get(&g_utvm_timer);
k_timer_stop(&g_utvm_timer);
int32_t time_remaining_ms = k_timer_remaining_get(&g_microtvm_timer);
k_timer_stop(&g_microtvm_timer);
// check *after* stopping to prevent extra expiries on the happy path
if (time_remaining_ms < 0) {
TVMLogf("negative time remaining");
return kTvmErrorSystemErrorMask | 3;
}
uint32_t num_expiries = k_timer_status_get(&g_utvm_timer);
uint32_t num_expiries = k_timer_status_get(&g_microtvm_timer);
uint32_t timer_res_ms = ((num_expiries * MILLIS_TIL_EXPIRY) + time_remaining_ms);
double approx_num_cycles =
(double)k_ticks_to_cyc_floor32(1) * (double)k_ms_to_ticks_ceil32(timer_res_ms);
Expand All @@ -211,7 +211,7 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
*elapsed_time_seconds = hw_clock_res_us / 1e6;
}

g_utvm_timer_running = 0;
g_microtvm_timer_running = 0;
return kTvmErrorNoError;
}

Expand Down Expand Up @@ -285,14 +285,14 @@ void main(void) {
uart_rx_init(&uart_rx_rbuf, tvm_uart);

// Initialize microTVM RPC server, which will receive commands from the UART and execute them.
utvm_rpc_server_t server = UTvmRpcServerInit(write_serial, NULL);
microtvm_rpc_server_t server = MicroTVMRpcServerInit(write_serial, NULL);
TVMLogf("microTVM Zephyr runtime - running");
#ifdef CONFIG_LED
gpio_pin_set(led0_pin, LED0_PIN, 0);
#endif

// The main application loop. We continuously read commands from the UART
// and dispatch them to UTvmRpcServerLoop().
// and dispatch them to MicroTVMRpcServerLoop().
while (true) {
uint8_t* data;
unsigned int key = irq_lock();
Expand All @@ -302,7 +302,7 @@ void main(void) {
size_t bytes_remaining = bytes_read;
while (bytes_remaining > 0) {
// Pass the received bytes to the RPC server.
tvm_crt_error_t err = UTvmRpcServerLoop(server, &data, &bytes_remaining);
tvm_crt_error_t err = MicroTVMRpcServerLoop(server, &data, &bytes_remaining);
if (err != kTvmErrorNoError && err != kTvmErrorFramingShortPacket) {
TVMPlatformAbort(err);
}
Expand Down
10 changes: 5 additions & 5 deletions cmake/modules/StandaloneCrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if(USE_MICRO)
# Build an isolated build directory, separate from the TVM tree.
list(APPEND CRT_FILE_COPY_JOBS
"3rdparty/libcrc/include *.h -> include"
"3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/utvm_rpc_common"
"3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/microtvm_rpc_common"
"3rdparty/libcrc/tab gentab_ccitt.inc -> src/runtime/crt/tab"
"3rdparty/dlpack/include *.h -> include"
"3rdparty/dmlc-core/include *.h -> include"
Expand All @@ -49,8 +49,8 @@ if(USE_MICRO)
"src/runtime/crt/host crt_config.h -> template/host"
"src/runtime/crt/host *.cc -> template/host"
"src/runtime/crt/memory *.c -> src/runtime/crt/memory"
"src/runtime/crt/utvm_rpc_common *.cc -> src/runtime/crt/utvm_rpc_common"
"src/runtime/crt/utvm_rpc_server *.cc -> src/runtime/crt/utvm_rpc_server"
"src/runtime/crt/microtvm_rpc_common *.cc -> src/runtime/crt/microtvm_rpc_common"
"src/runtime/crt/microtvm_rpc_server *.cc -> src/runtime/crt/microtvm_rpc_server"
"src/runtime/minrpc *.h -> src/runtime/minrpc"
"src/support generic_arena.h -> src/support"
"src/runtime/crt crt_config-template.h -> template"
Expand Down Expand Up @@ -98,7 +98,7 @@ if(USE_MICRO)
set(make_quiet )
endif(${VERBOSE})

list(APPEND crt_libraries memory graph_executor aot_executor utvm_rpc_server utvm_rpc_common common) # NOTE: listed in link order.
list(APPEND crt_libraries memory graph_executor aot_executor microtvm_rpc_server microtvm_rpc_common common) # NOTE: listed in link order.
foreach(crt_lib_name IN LISTS crt_libraries)
list(APPEND crt_library_paths "host_standalone_crt/lib${crt_lib_name}.a")
endforeach()
Expand Down Expand Up @@ -166,7 +166,7 @@ if(USE_MICRO)

tvm_crt_define_targets()

set(TVM_CRT_LINKER_LIB host_standalone_crt_utvm_rpc_common)
set(TVM_CRT_LINKER_LIB host_standalone_crt_microtvm_rpc_common)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(APPEND TVM_RUNTIME_LINKER_LIBS -Wl,--whole-archive ${TVM_CRT_LINKER_LIB} -Wl,--no-whole-archive)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

/*!
* \file utvm_rpc_server.h
* \file microtvm_rpc_server.h
* \brief MicroTVM RPC Server
*/

#ifndef TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
#define TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
#ifndef TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_
#define TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_

#include <stdlib.h>
#include <sys/types.h>
Expand All @@ -40,14 +40,15 @@ extern "C" {
* \param num_bytes Number of bytes avaiable in data.
* \return The number of bytes written.
*/
typedef ssize_t (*utvm_rpc_channel_write_t)(void* context, const uint8_t* data, size_t num_bytes);
typedef ssize_t (*microtvm_rpc_channel_write_t)(void* context, const uint8_t* data,
size_t num_bytes);

/*! \brief Opaque pointer type to TVM RPC Server. */
typedef void* utvm_rpc_server_t;
typedef void* microtvm_rpc_server_t;

/*! \brief Initialize the TVM RPC Server.
*
* Call this on device startup before calling anyother utvm_rpc_server_ functions.
* Call this on device startup before calling anyother microtvm_rpc_server_ functions.
*
* \param write_func A callback function invoked by the TVM RPC Server to write data back to the
* host. Internally, the TVM RPC Server will block until all data in a reply
Expand All @@ -56,7 +57,8 @@ typedef void* utvm_rpc_server_t;
* \return A pointer to the TVM RPC Server. The pointer is allocated in the same memory space as
* the TVM workspace.
*/
utvm_rpc_server_t UTvmRpcServerInit(utvm_rpc_channel_write_t write_func, void* write_func_ctx);
microtvm_rpc_server_t MicroTVMRpcServerInit(microtvm_rpc_channel_write_t write_func,
void* write_func_ctx);

/*! \brief Do any tasks suitable for the main thread, and maybe process new incoming data.
*
Expand All @@ -67,11 +69,11 @@ utvm_rpc_server_t UTvmRpcServerInit(utvm_rpc_channel_write_t write_func, void* w
* updated to the number of unprocessed bytes remaining in `new_data` (usually 0).
* \return An error code indicating the outcome of the server main loop iteration.
*/
tvm_crt_error_t UTvmRpcServerLoop(utvm_rpc_server_t server, uint8_t** new_data,
size_t* new_data_size_bytes);
tvm_crt_error_t MicroTVMRpcServerLoop(microtvm_rpc_server_t server, uint8_t** new_data,
size_t* new_data_size_bytes);

#ifdef __cplusplus
}
#endif

#endif // TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
#endif // TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@
* under the License.
*/

#ifndef TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
#define TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
#ifndef TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_
#define TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_

#include <stddef.h>
#include <stdint.h>

#define TVM_MICRO_RUNTIME_API_API extern "C" __attribute__((visibility("default")))

TVM_MICRO_RUNTIME_API_API void* UTVMRuntimeCreate(const char* json, size_t json_len, void* module);
TVM_MICRO_RUNTIME_API_API void* MicroTVMRuntimeCreate(const char* json, size_t json_len,
void* module);

TVM_MICRO_RUNTIME_API_API void UTVMRuntimeDestroy(void* handle);
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeDestroy(void* handle);

TVM_MICRO_RUNTIME_API_API void UTVMRuntimeSetInput(void* handle, int index, void* tensor);
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeSetInput(void* handle, int index, void* tensor);

TVM_MICRO_RUNTIME_API_API void UTVMRuntimeRun(void* handle);
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeRun(void* handle);

TVM_MICRO_RUNTIME_API_API void UTVMRuntimeGetOutput(void* handle, int index, void* tensor);
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeGetOutput(void* handle, int index, void* tensor);

TVM_MICRO_RUNTIME_API_API void* UTVMRuntimeDSOModuleCreate(const char* so, size_t so_len);
TVM_MICRO_RUNTIME_API_API void* MicroTVMRuntimeDSOModuleCreate(const char* so, size_t so_len);

TVM_MICRO_RUNTIME_API_API void UTVMRuntimeDSOModuleDestroy(void* module);
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeDSOModuleDestroy(void* module);

#undef TVM_MICRO_RUNTIME_API_API

#endif // TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
#endif // TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_
2 changes: 1 addition & 1 deletion python/tvm/driver/tvmc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def add_compile_parser(subparsers):
choices=["so", "mlf"],
default="so",
help="output format. Use 'so' for shared object or 'mlf' for Model Library Format "
"(only for µTVM targets). Defaults to 'so'.",
"(only for microTVM targets). Defaults to 'so'.",
)
parser.add_argument(
"--pass-config",
Expand Down
Loading