Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[microTVM] AOT Demo #8075

Merged
merged 20 commits into from May 28, 2021
Merged
Expand Up @@ -10,8 +10,9 @@ find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(microtvm_zephyr_runtime)

set(CMAKE_VERBOSE_MAKEFILE ON)
file(GLOB TVM_SOURCES ${CMAKE_SOURCE_DIR}/__tvm*.c)
target_sources(app PRIVATE src/main.c ${TVM_SOURCES})

target_sources(app PRIVATE src/zephyr_uart.c)
target_sources(app PRIVATE src/main.c)

foreach(tvm_lib ${TVM_LIBS})
string(LENGTH ${tvm_lib} tvm_lib_length)
Expand Down
20 changes: 20 additions & 0 deletions apps/microtvm/zephyr/aot_demo/README.md
@@ -0,0 +1,20 @@
<!--- 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. -->

This directory contains a Zephyr-based ahead of time (AOT) "demo" runtime environment that
pulls together the microTVM runtime dependencies into a single application
that can run TVM on a microTVM device without the need to a host.
31 changes: 31 additions & 0 deletions apps/microtvm/zephyr/aot_demo/boards/nrf5340dk_nrf5340_cpuapp.conf
@@ -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.
#
# This file is specific to the nRF5340 DK board.

# For intrinsics used by generated optimized operators.
CONFIG_CMSIS_DSP=y

# For AOT runtime which requires lots of function call.
CONFIG_MAIN_STACK_SIZE=2000

# For random number generation.
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

# For debugging.
CONFIG_LED=y
25 changes: 25 additions & 0 deletions apps/microtvm/zephyr/aot_demo/boards/qemu_x86.conf
@@ -0,0 +1,25 @@
# 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.

# This file is specific to the QEMU-emulated microTVM board.

# For TVMPlatformGenerateRandom(). Remember, these values do not need to be truly random.
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_TIMER_RANDOM_GENERATOR=y

# Default stack size is 1k, this is required for debug mode.
CONFIG_MAIN_STACK_SIZE=2000
mehrdadh marked this conversation as resolved.
Show resolved Hide resolved
62 changes: 62 additions & 0 deletions apps/microtvm/zephyr/aot_demo/crt/crt_config.h
@@ -0,0 +1,62 @@
/*
* 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_config.h.template
* \brief Template for CRT configuration, to be modified on each target.
*/
#ifndef TVM_RUNTIME_CRT_CONFIG_H_
#define TVM_RUNTIME_CRT_CONFIG_H_

#include <tvm/runtime/crt/logging.h>

/*! Log level of the CRT runtime */
#define TVM_CRT_LOG_LEVEL TVM_CRT_LOG_LEVEL_DEBUG

/*! Maximum supported dimension in NDArray */
#define TVM_CRT_MAX_NDIM 6

/*! Maximum supported arguments in generated functions */
#define TVM_CRT_MAX_ARGS 10

/*! Size of the global function registry, in bytes. */
#define TVM_CRT_GLOBAL_FUNC_REGISTRY_SIZE_BYTES 200

/*! Maximum number of registered modules. */
#define TVM_CRT_MAX_REGISTERED_MODULES 2

/*! Maximum packet size, in bytes, including the length header. */
#define TVM_CRT_MAX_PACKET_SIZE_BYTES (1 * 1024)

/*! Maximum supported string length in dltype, e.g. "int8", "int16", "float32" */
#define TVM_CRT_MAX_STRLEN_DLTYPE 10

/*! Maximum supported string length in function names */
#define TVM_CRT_MAX_STRLEN_FUNCTION_NAME 80

/*! \brief Maximum length of a PackedFunc function name. */
#define TVM_CRT_MAX_FUNCTION_NAME_LENGTH_BYTES 30

/*! \brief Log2 of the page size (bytes) for a virtual memory page. */
#define TVM_CRT_PAGE_BITS 10 // 1 kB

/*! \brief Number of pages on device. */
#define TVM_CRT_MAX_PAGES 300

#endif // TVM_RUNTIME_CRT_CONFIG_H_
50 changes: 50 additions & 0 deletions apps/microtvm/zephyr/aot_demo/include/zephyr_uart.h
@@ -0,0 +1,50 @@
/*
mehrdadh marked this conversation as resolved.
Show resolved Hide resolved
* 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_AOT_DEMO_INCLUDE_ZEPHYR_UART_H_
#define TVM_APPS_MICROTVM_ZEPHYR_AOT_DEMO_INCLUDE_ZEPHYR_UART_H_

#include <stdint.h>

// Used to read data from the UART.

/*!
* \brief Read Uart Rx buffer.
* \param data Pointer to read data.
* \param data_size_bytes Read request size in bytes.
*
* \return Number of data read in bytes.
*/
uint32_t TVMPlatformUartRxRead(uint8_t* data, uint32_t data_size_bytes);

/*!
* \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.
*/
void TVMPlatformUARTInit();

#endif /* TVM_APPS_MICROTVM_ZEPHYR_AOT_DEMO_INCLUDE_ZEPHYR_UART_H_ */
1 change: 1 addition & 0 deletions apps/microtvm/zephyr/aot_demo/qemu-hack