mehrdadh commented on code in PR #13885:
URL: https://github.com/apache/tvm/pull/13885#discussion_r1096386580
##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -413,6 +418,9 @@ def _create_prj_conf(
"CONFIG_UART_INTERRUPT_DRIVEN=y\n"
"\n"
)
+ if config_led and not self._is_qemu(board, False):
Review Comment:
added
##########
apps/microtvm/zephyr/template_project/src/host_driven/platform.h:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef TVM_APPS_MICROTVM_ZEPHYR_HOST_DRIVEN_PLATFORM_H_
+#define TVM_APPS_MICROTVM_ZEPHYR_HOST_DRIVEN_PLATFORM_H_
+
+#include <zephyr/drivers/gpio.h>
+
+#ifdef CONFIG_LED
Review Comment:
this file is removed since no longer needed.
##########
apps/microtvm/zephyr/template_project/src/aot_standalone_demo/platform.c:
##########
@@ -16,19 +16,64 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include "zephyr_uart.h"
+#include "tvm/platform.h"
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <zephyr/drivers/uart.h>
+#include <zephyr/sys/reboot.h>
#include <zephyr/sys/ring_buffer.h>
#include "crt_config.h"
+#include "dlpack/dlpack.h"
+#include "tvm/runtime/crt/error_codes.h"
+#include "tvmgen_default.h"
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.
RING_BUF_DECLARE(uart_rx_rbuf, RING_BUF_SIZE_BYTES);
+void TVMLogf(const char* msg, ...) {
Review Comment:
it is removed from this file, so no longer needed.
##########
apps/microtvm/arduino/template_project/src/example_project/platform.c:
##########
@@ -45,16 +46,18 @@ void TVMPlatformAbort(tvm_crt_error_t error) {
}
}
-void TVMLogf(const char* msg, ...) {}
-
+// Called by TVM when memory allocation is required.
tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev,
void** out_ptr) {
return StackMemoryManager_Allocate(&app_workspace, num_bytes, out_ptr);
}
+// Called by TVM to free an allocated memory.
tvm_crt_error_t TVMPlatformMemoryFree(void* ptr, DLDevice dev) {
return StackMemoryManager_Free(&app_workspace, ptr);
}
+void TVMLogf(const char* msg, ...) {}
Review Comment:
added
##########
apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc:
##########
@@ -162,3 +172,33 @@ int8_t QuantizeFloatToInt8(float value, float scale, int
zero_point) {
}
return (int8_t)(result);
}
+
+// UART read.
+char TVMPlatformUartRxRead() {
Review Comment:
file is restructured, now all of them are with weak attribute.
##########
apps/microtvm/zephyr/template_project/src/host_driven/platform.h:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef TVM_APPS_MICROTVM_ZEPHYR_HOST_DRIVEN_PLATFORM_H_
+#define TVM_APPS_MICROTVM_ZEPHYR_HOST_DRIVEN_PLATFORM_H_
+
+#include <zephyr/drivers/gpio.h>
+
+#ifdef CONFIG_LED
+#define LED0_NODE DT_ALIAS(led0)
+// #define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
+// #define LED0_PIN DT_GPIO_PIN(LED0_NODE, gpios)
+// #define LED0_FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
+// static const struct device* led0_pin;
Review Comment:
this file is removed since no longer needed.
##########
apps/microtvm/zephyr/template_project/src/aot_standalone_demo/platform.h:
##########
@@ -17,12 +17,13 @@
* under the License.
*/
-#ifndef TVM_APPS_MICROTVM_ZEPHYR_AOT_STANDALONE_DEMO_ZEPHYR_UART_H_
-#define TVM_APPS_MICROTVM_ZEPHYR_AOT_STANDALONE_DEMO_ZEPHYR_UART_H_
+#ifndef TVM_APPS_MICROTVM_ZEPHYR_AOT_STANDALONE_DEMO_PLATFORM_H_
+#define TVM_APPS_MICROTVM_ZEPHYR_AOT_STANDALONE_DEMO_PLATFORM_H_
#include <stdint.h>
+#include <tvm/runtime/crt/stack_allocator.h>
-// Used to read data from the UART.
+extern tvm_workspace_t app_workspace;
Review Comment:
wdym?
##########
apps/microtvm/zephyr/template_project/src/host_driven/main.c:
##########
@@ -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);
Review Comment:
done
##########
src/runtime/crt/host/platform-template.h:
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/runtime/crt/host/platform-template.h
+ * \brief Template for CRT platform configuration.
+ */
+#ifndef TVM_RUNTIME_CRT_HOST_PLATFORM_TEMPLATE_H_
+#define TVM_RUNTIME_CRT_HOST_PLATFORM_TEMPLATE_H_
+
+#include <tvm/runtime/crt/page_allocator.h>
+
+MemoryManagerInterface* memory_manager;
+
Review Comment:
file is removed. I added all the functions that could be implemented in the
platform-template.c
##########
apps/microtvm/zephyr/template_project/src/host_driven/platform.c:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "tvm/platform.h"
+
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/reboot.h>
+
+#include "dlpack/dlpack.h"
+#include "tvm/runtime/crt/error_codes.h"
+
+// Heap for use by TVMPlatformMemoryAllocate.
+K_HEAP_DEFINE(tvm_heap, HEAP_SIZE_BYTES);
+
+// 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 vsnprintk(out_buf, out_buf_size_bytes, fmt, args);
+}
+
+// Called by TVM when an internal invariant is violated, and execution cannot
continue.
+__attribute__((weak)) void TVMPlatformAbort(tvm_crt_error_t error) {
+ TVMLogf("TVMError: 0x%x", error);
Review Comment:
I think in host_driven version it's part of the RPC server library that is
linked. I didn't add this, just moved the function to platform.c
##########
apps/microtvm/arduino/template_project/src/example_project/platform.c:
##########
@@ -45,16 +46,18 @@ void TVMPlatformAbort(tvm_crt_error_t error) {
}
}
-void TVMLogf(const char* msg, ...) {}
-
+// Called by TVM when memory allocation is required.
tvm_crt_error_t TVMPlatformMemoryAllocate(size_t num_bytes, DLDevice dev,
void** out_ptr) {
return StackMemoryManager_Allocate(&app_workspace, num_bytes, out_ptr);
}
+// Called by TVM to free an allocated memory.
Review Comment:
done
##########
apps/microtvm/arduino/template_project/src/host_driven/platform.c:
##########
@@ -21,27 +21,32 @@
#include "standalone_crt/include/tvm/runtime/crt/error_codes.h"
#include "stdarg.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 vsnprintf(out_buf, out_buf_size_bytes, fmt, args);
+}
+
+// Called by TVM when an internal invariant is violated, and execution cannot
continue.
// Blink code for debugging purposes
Review Comment:
done
##########
apps/microtvm/zephyr/template_project/src/aot_standalone_demo/platform.c:
##########
@@ -16,19 +16,64 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include "zephyr_uart.h"
+#include "tvm/platform.h"
+
+#include <assert.h>
Review Comment:
was added by mistake, removed it
##########
apps/microtvm/zephyr/template_project/src/aot_standalone_demo/platform.c:
##########
@@ -16,19 +16,64 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include "zephyr_uart.h"
+#include "tvm/platform.h"
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <zephyr/drivers/uart.h>
+#include <zephyr/sys/reboot.h>
#include <zephyr/sys/ring_buffer.h>
#include "crt_config.h"
+#include "dlpack/dlpack.h"
+#include "tvm/runtime/crt/error_codes.h"
+#include "tvmgen_default.h"
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.
RING_BUF_DECLARE(uart_rx_rbuf, RING_BUF_SIZE_BYTES);
+void TVMLogf(const char* msg, ...) {
+ char buffer[256];
+ int size;
+ va_list args;
+ va_start(args, msg);
+ size = vsprintf(buffer, msg, args);
+ va_end(args);
+ TVMPlatformWriteSerial(buffer, (uint32_t)size);
+}
+
+// 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 vsnprintk(out_buf, out_buf_size_bytes, fmt, args);
+}
+
+// Called by TVM when an internal invariant is violated, and execution cannot
continue.
+__attribute__((weak)) void TVMPlatformAbort(tvm_crt_error_t error) {
+ TVMLogf("TVMPlatformAbort: %08x\n", error);
+ sys_reboot(SYS_REBOOT_COLD);
+ for (;;)
+ ;
Review Comment:
I'm not sure how does it work, I rather make this change when we test it on
a physical board
##########
apps/microtvm/arduino/template_project/src/example_project/platform.c:
##########
@@ -28,6 +28,7 @@ static uint8_t g_aot_memory[WORKSPACE_SIZE]
__attribute__((aligned(TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES)));
tvm_workspace_t app_workspace;
+// Called by TVM when an internal invariant is violated, and execution cannot
continue.
// Blink code for debugging purposes
void TVMPlatformAbort(tvm_crt_error_t error) {
Review Comment:
done.
##########
apps/microtvm/zephyr/template_project/src/mlperftiny/platform.h:
##########
@@ -59,4 +62,24 @@ void TVMInfer(void* input_ptr);
*/
int8_t QuantizeFloatToInt8(float value, float scale, int zero_point);
-#endif /* APPS_MICROTVM_ZEPHYR_TEMPLATE_PROJECT_SRC_MLPERFTINY_TVMRUNTIME_H_ */
+/*!
+ * \brief Read Uart Rx buffer.
+ */
+char TVMPlatformUartRxRead();
+
+/*!
+ * \brief Write data in serial.
+ * \param data Pointer to data to write.
+ * \param size Size of data in bytes.
+ *
+ * \return Number of write in bytes.
+ */
+uint32_t TVMPlatformWriteSerial(const char* data, uint32_t size);
+
+/*!
+ * \brief Initialize Uart.
Review Comment:
file is removed
--
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]