Skip to content

Commit 3cb838d

Browse files
authored
[microTVM] Refactor uTVM to microTVM (#8283)
* refactor * rename utvm_rpc_server.h * rename file * rename * rename file * rename * variables * directories * format * trigger * more refactor * one more * format
1 parent 8022513 commit 3cb838d

File tree

31 files changed

+154
-148
lines changed

31 files changed

+154
-148
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ We do encourage everyone to work anything they are interested in.
6363
- [Trevor Morris](https://github.com/trevor-m): @trevor-m - byoc, compiler
6464
- [Leandro Nunes](https://github.com/leandron): @leandron - tvmc
6565
- [Krzysztof Parzyszek](https://github.com/kparzysz-quic): @kparzysz-quic - hexagon, llvm
66-
- [Andrew Reusch](https://github.com/areusch): @areusch - runtime, µTVM
66+
- [Andrew Reusch](https://github.com/areusch): @areusch - runtime, microTVM
6767
- [Jared Roesch](https://github.com/jroesch) (PMC): @jroesch - relay
6868
- [Siju Samuel](https://github.com/siju-samuel): @siju-samuel - frontends
6969
- [Junru Shao](https://github.com/junrushao1994) @junrushao1994 - relay, compiler

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ v0.7 brings many major features. The community works together to refactor the in
3636
* Intial Hexagon support
3737
* Bring your own codegen (BYOC) support
3838

39-
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.
39+
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.
4040

4141
## New Features
4242
### Automatic Scheduling (Experimental)

apps/microtvm/zephyr/aot_demo/src/main.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,52 +83,52 @@ void timer_expiry_function(struct k_timer* timer_id) { return; }
8383

8484
#define MILLIS_TIL_EXPIRY 200
8585
#define TIME_TIL_EXPIRY (K_MSEC(MILLIS_TIL_EXPIRY))
86-
struct k_timer g_utvm_timer;
87-
uint32_t g_utvm_start_time;
88-
int g_utvm_timer_running = 0;
86+
struct k_timer g_microtvm_timer;
87+
uint32_t g_microtvm_start_time;
88+
int g_microtvm_timer_running = 0;
8989

9090
// Called to start system timer.
9191
tvm_crt_error_t TVMPlatformTimerStart() {
92-
if (g_utvm_timer_running) {
92+
if (g_microtvm_timer_running) {
9393
TVMLogf("timer already running");
9494
return kTvmErrorPlatformTimerBadState;
9595
}
9696

97-
k_timer_start(&g_utvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
98-
g_utvm_start_time = k_cycle_get_32();
99-
g_utvm_timer_running = 1;
97+
k_timer_start(&g_microtvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
98+
g_microtvm_start_time = k_cycle_get_32();
99+
g_microtvm_timer_running = 1;
100100
return kTvmErrorNoError;
101101
}
102102

103103
// Called to stop system timer.
104104
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
105-
if (!g_utvm_timer_running) {
105+
if (!g_microtvm_timer_running) {
106106
TVMLogf("timer not running");
107107
return kTvmErrorSystemErrorMask | 2;
108108
}
109109

110110
uint32_t stop_time = k_cycle_get_32();
111111

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

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

123123
// need to grab time remaining *before* stopping. when stopped, this function
124124
// always returns 0.
125-
int32_t time_remaining_ms = k_timer_remaining_get(&g_utvm_timer);
126-
k_timer_stop(&g_utvm_timer);
125+
int32_t time_remaining_ms = k_timer_remaining_get(&g_microtvm_timer);
126+
k_timer_stop(&g_microtvm_timer);
127127
// check *after* stopping to prevent extra expiries on the happy path
128128
if (time_remaining_ms < 0) {
129129
return kTvmErrorSystemErrorMask | 3;
130130
}
131-
uint32_t num_expiries = k_timer_status_get(&g_utvm_timer);
131+
uint32_t num_expiries = k_timer_status_get(&g_microtvm_timer);
132132
uint32_t timer_res_ms = ((num_expiries * MILLIS_TIL_EXPIRY) + time_remaining_ms);
133133
double approx_num_cycles =
134134
(double)k_ticks_to_cyc_floor32(1) * (double)k_ms_to_ticks_ceil32(timer_res_ms);
@@ -140,7 +140,7 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
140140
*elapsed_time_seconds = hw_clock_res_us / 1e6;
141141
}
142142

143-
g_utvm_timer_running = 0;
143+
g_microtvm_timer_running = 0;
144144
return kTvmErrorNoError;
145145
}
146146

@@ -172,7 +172,7 @@ void main(void) {
172172
g_cmd_buf_ind = 0;
173173
memset((char*)cmd_buf, 0, sizeof(cmd_buf));
174174
TVMPlatformUARTInit();
175-
k_timer_init(&g_utvm_timer, NULL, NULL);
175+
k_timer_init(&g_microtvm_timer, NULL, NULL);
176176
// Wake up host side.
177177
TVMPlatformWriteSerial(g_wakeup_sequence, sizeof(g_wakeup_sequence));
178178

apps/microtvm/zephyr/aot_demo/src/zephyr_uart.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "crt_config.h"
2525

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

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

6969
uint32_t TVMPlatformWriteSerial(const char* data, uint32_t size) {
7070
for (uint32_t i = 0; i < size; i++) {
71-
uart_poll_out(g_utvm_uart, data[i]);
71+
uart_poll_out(g_microtvm_uart, data[i]);
7272
}
7373
return size;
7474
}
7575

7676
// Initialize UART
7777
void TVMPlatformUARTInit() {
7878
// Claim console device.
79-
g_utvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
80-
uart_rx_init(&uart_rx_rbuf, g_utvm_uart);
79+
g_microtvm_uart = device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_console)));
80+
uart_rx_init(&uart_rx_rbuf, g_microtvm_uart);
8181
}

apps/microtvm/zephyr/host_driven/src/main.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <sys/printk.h>
4040
#include <sys/ring_buffer.h>
4141
#include <tvm/runtime/crt/logging.h>
42-
#include <tvm/runtime/crt/utvm_rpc_server.h>
42+
#include <tvm/runtime/crt/microtvm_rpc_server.h>
4343
#include <unistd.h>
4444
#include <zephyr.h>
4545

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

147147
#define MILLIS_TIL_EXPIRY 200
148148
#define TIME_TIL_EXPIRY (K_MSEC(MILLIS_TIL_EXPIRY))
149-
K_TIMER_DEFINE(g_utvm_timer, /* expiry func */ NULL, /* stop func */ NULL);
149+
K_TIMER_DEFINE(g_microtvm_timer, /* expiry func */ NULL, /* stop func */ NULL);
150150

151-
uint32_t g_utvm_start_time;
152-
int g_utvm_timer_running = 0;
151+
uint32_t g_microtvm_start_time;
152+
int g_microtvm_timer_running = 0;
153153

154154
// Called to start system timer.
155155
tvm_crt_error_t TVMPlatformTimerStart() {
156-
if (g_utvm_timer_running) {
156+
if (g_microtvm_timer_running) {
157157
TVMLogf("timer already running");
158158
return kTvmErrorPlatformTimerBadState;
159159
}
160160

161161
#ifdef CONFIG_LED
162162
gpio_pin_set(led0_pin, LED0_PIN, 1);
163163
#endif
164-
k_timer_start(&g_utvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
165-
g_utvm_start_time = k_cycle_get_32();
166-
g_utvm_timer_running = 1;
164+
k_timer_start(&g_microtvm_timer, TIME_TIL_EXPIRY, TIME_TIL_EXPIRY);
165+
g_microtvm_start_time = k_cycle_get_32();
166+
g_microtvm_timer_running = 1;
167167
return kTvmErrorNoError;
168168
}
169169

170170
// Called to stop system timer.
171171
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
172-
if (!g_utvm_timer_running) {
172+
if (!g_microtvm_timer_running) {
173173
TVMLogf("timer not running");
174174
return kTvmErrorSystemErrorMask | 2;
175175
}
@@ -180,26 +180,26 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
180180
#endif
181181

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

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

193193
// need to grab time remaining *before* stopping. when stopped, this function
194194
// always returns 0.
195-
int32_t time_remaining_ms = k_timer_remaining_get(&g_utvm_timer);
196-
k_timer_stop(&g_utvm_timer);
195+
int32_t time_remaining_ms = k_timer_remaining_get(&g_microtvm_timer);
196+
k_timer_stop(&g_microtvm_timer);
197197
// check *after* stopping to prevent extra expiries on the happy path
198198
if (time_remaining_ms < 0) {
199199
TVMLogf("negative time remaining");
200200
return kTvmErrorSystemErrorMask | 3;
201201
}
202-
uint32_t num_expiries = k_timer_status_get(&g_utvm_timer);
202+
uint32_t num_expiries = k_timer_status_get(&g_microtvm_timer);
203203
uint32_t timer_res_ms = ((num_expiries * MILLIS_TIL_EXPIRY) + time_remaining_ms);
204204
double approx_num_cycles =
205205
(double)k_ticks_to_cyc_floor32(1) * (double)k_ms_to_ticks_ceil32(timer_res_ms);
@@ -211,7 +211,7 @@ tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds) {
211211
*elapsed_time_seconds = hw_clock_res_us / 1e6;
212212
}
213213

214-
g_utvm_timer_running = 0;
214+
g_microtvm_timer_running = 0;
215215
return kTvmErrorNoError;
216216
}
217217

@@ -285,14 +285,14 @@ void main(void) {
285285
uart_rx_init(&uart_rx_rbuf, tvm_uart);
286286

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

294294
// The main application loop. We continuously read commands from the UART
295-
// and dispatch them to UTvmRpcServerLoop().
295+
// and dispatch them to MicroTVMRpcServerLoop().
296296
while (true) {
297297
uint8_t* data;
298298
unsigned int key = irq_lock();
@@ -302,7 +302,7 @@ void main(void) {
302302
size_t bytes_remaining = bytes_read;
303303
while (bytes_remaining > 0) {
304304
// Pass the received bytes to the RPC server.
305-
tvm_crt_error_t err = UTvmRpcServerLoop(server, &data, &bytes_remaining);
305+
tvm_crt_error_t err = MicroTVMRpcServerLoop(server, &data, &bytes_remaining);
306306
if (err != kTvmErrorNoError && err != kTvmErrorFramingShortPacket) {
307307
TVMPlatformAbort(err);
308308
}

cmake/modules/StandaloneCrt.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if(USE_MICRO)
3434
# Build an isolated build directory, separate from the TVM tree.
3535
list(APPEND CRT_FILE_COPY_JOBS
3636
"3rdparty/libcrc/include *.h -> include"
37-
"3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/utvm_rpc_common"
37+
"3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/microtvm_rpc_common"
3838
"3rdparty/libcrc/tab gentab_ccitt.inc -> src/runtime/crt/tab"
3939
"3rdparty/dlpack/include *.h -> include"
4040
"3rdparty/dmlc-core/include *.h -> include"
@@ -49,8 +49,8 @@ if(USE_MICRO)
4949
"src/runtime/crt/host crt_config.h -> template/host"
5050
"src/runtime/crt/host *.cc -> template/host"
5151
"src/runtime/crt/memory *.c -> src/runtime/crt/memory"
52-
"src/runtime/crt/utvm_rpc_common *.cc -> src/runtime/crt/utvm_rpc_common"
53-
"src/runtime/crt/utvm_rpc_server *.cc -> src/runtime/crt/utvm_rpc_server"
52+
"src/runtime/crt/microtvm_rpc_common *.cc -> src/runtime/crt/microtvm_rpc_common"
53+
"src/runtime/crt/microtvm_rpc_server *.cc -> src/runtime/crt/microtvm_rpc_server"
5454
"src/runtime/minrpc *.h -> src/runtime/minrpc"
5555
"src/support generic_arena.h -> src/support"
5656
"src/runtime/crt crt_config-template.h -> template"
@@ -98,7 +98,7 @@ if(USE_MICRO)
9898
set(make_quiet )
9999
endif(${VERBOSE})
100100

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

167167
tvm_crt_define_targets()
168168

169-
set(TVM_CRT_LINKER_LIB host_standalone_crt_utvm_rpc_common)
169+
set(TVM_CRT_LINKER_LIB host_standalone_crt_microtvm_rpc_common)
170170
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
171171
list(APPEND TVM_RUNTIME_LINKER_LIBS -Wl,--whole-archive ${TVM_CRT_LINKER_LIB} -Wl,--no-whole-archive)
172172
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")

include/tvm/runtime/crt/utvm_rpc_server.h renamed to include/tvm/runtime/crt/microtvm_rpc_server.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919

2020
/*!
21-
* \file utvm_rpc_server.h
21+
* \file microtvm_rpc_server.h
2222
* \brief MicroTVM RPC Server
2323
*/
2424

25-
#ifndef TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
26-
#define TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
25+
#ifndef TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_
26+
#define TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_
2727

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

4546
/*! \brief Opaque pointer type to TVM RPC Server. */
46-
typedef void* utvm_rpc_server_t;
47+
typedef void* microtvm_rpc_server_t;
4748

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

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

7375
#ifdef __cplusplus
7476
}
7577
#endif
7678

77-
#endif // TVM_RUNTIME_CRT_UTVM_RPC_SERVER_H_
79+
#endif // TVM_RUNTIME_CRT_MICROTVM_RPC_SERVER_H_

include/tvm/runtime/micro/standalone/utvm_runtime.h renamed to include/tvm/runtime/micro/standalone/microtvm_runtime.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@
1717
* under the License.
1818
*/
1919

20-
#ifndef TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
21-
#define TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
20+
#ifndef TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_
21+
#define TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_
2222

2323
#include <stddef.h>
2424
#include <stdint.h>
2525

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

28-
TVM_MICRO_RUNTIME_API_API void* UTVMRuntimeCreate(const char* json, size_t json_len, void* module);
28+
TVM_MICRO_RUNTIME_API_API void* MicroTVMRuntimeCreate(const char* json, size_t json_len,
29+
void* module);
2930

30-
TVM_MICRO_RUNTIME_API_API void UTVMRuntimeDestroy(void* handle);
31+
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeDestroy(void* handle);
3132

32-
TVM_MICRO_RUNTIME_API_API void UTVMRuntimeSetInput(void* handle, int index, void* tensor);
33+
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeSetInput(void* handle, int index, void* tensor);
3334

34-
TVM_MICRO_RUNTIME_API_API void UTVMRuntimeRun(void* handle);
35+
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeRun(void* handle);
3536

36-
TVM_MICRO_RUNTIME_API_API void UTVMRuntimeGetOutput(void* handle, int index, void* tensor);
37+
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeGetOutput(void* handle, int index, void* tensor);
3738

38-
TVM_MICRO_RUNTIME_API_API void* UTVMRuntimeDSOModuleCreate(const char* so, size_t so_len);
39+
TVM_MICRO_RUNTIME_API_API void* MicroTVMRuntimeDSOModuleCreate(const char* so, size_t so_len);
3940

40-
TVM_MICRO_RUNTIME_API_API void UTVMRuntimeDSOModuleDestroy(void* module);
41+
TVM_MICRO_RUNTIME_API_API void MicroTVMRuntimeDSOModuleDestroy(void* module);
4142

4243
#undef TVM_MICRO_RUNTIME_API_API
4344

44-
#endif // TVM_RUNTIME_MICRO_STANDALONE_UTVM_RUNTIME_H_
45+
#endif // TVM_RUNTIME_MICRO_STANDALONE_MICROTVM_RUNTIME_H_

python/tvm/driver/tvmc/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def add_compile_parser(subparsers):
8181
choices=["so", "mlf"],
8282
default="so",
8383
help="output format. Use 'so' for shared object or 'mlf' for Model Library Format "
84-
"(only for µTVM targets). Defaults to 'so'.",
84+
"(only for microTVM targets). Defaults to 'so'.",
8585
)
8686
parser.add_argument(
8787
"--pass-config",

0 commit comments

Comments
 (0)