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

µTVM RPC server and Part 1 of AutoTVM compilation infrastructure #6334

Merged
merged 66 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
2e5923c
initial commit of RPC server
areusch Aug 19, 2020
a453f67
add session tests
areusch Aug 21, 2020
4353dd4
add python compilation infra
areusch Aug 22, 2020
2818ff9
rm illegal file names
areusch Aug 22, 2020
438d5a9
fix lint
areusch Aug 22, 2020
d9c92d8
git-clang-format
areusch Aug 22, 2020
b0163a2
pylint
areusch Aug 25, 2020
112f551
make work again
areusch Aug 25, 2020
33b0e81
asf header
areusch Aug 25, 2020
11f4156
git-clang-format
areusch Aug 25, 2020
716e3c4
Merge remote-tracking branch 'tvm/master' into utvm-rpc-server-merge
areusch Aug 25, 2020
97581ac
cppdocs
areusch Aug 25, 2020
144e7ec
stop using list(TRANSFORM ...) in cmake
areusch Aug 26, 2020
675e5fd
split session start packet into start init and start reply
areusch Aug 26, 2020
4f4b808
remove debug messages, fix tests
areusch Aug 26, 2020
726b699
git-clang-format
areusch Aug 26, 2020
9278407
add terminate session message and test reset flow
areusch Aug 27, 2020
451f447
git-clang-format
areusch Aug 27, 2020
a0d8ed5
pylint
areusch Aug 27, 2020
0dff0a0
fix path dependencies when using make
areusch Aug 27, 2020
abb6cf5
fix test building on linux
areusch Aug 27, 2020
cc448a1
git-clang-format
areusch Aug 27, 2020
9777728
add missing file
areusch Aug 27, 2020
11feb64
git-clang-format
areusch Aug 27, 2020
51a1888
fix type pun error
areusch Aug 28, 2020
ec43c72
rm old micro runtime test
areusch Aug 28, 2020
06288ee
fix posix_popen_server test
areusch Aug 28, 2020
973ab58
retrigger CI
areusch Aug 31, 2020
27e6aa1
Merge remote-tracking branch 'origin/master' into utvm-rpc-server-merge
areusch Aug 31, 2020
52e38b1
can't repro segfault, retrigger
areusch Aug 31, 2020
97abd7c
Merge remote-tracking branch 'origin/master' into utvm-rpc-server-merge
areusch Sep 1, 2020
dc139f8
patch GIL fix
areusch Sep 2, 2020
3131804
use better cmake/makefile rules
areusch Sep 2, 2020
0e2574e
fixup bundle_deploy, unify crt_config.h, TVMInitializeRuntime
areusch Sep 2, 2020
dcb3fb5
fix build warnings
areusch Sep 2, 2020
e256cd9
deprecate building crt in source tree, adjust bundle_deploy makefile
areusch Sep 2, 2020
4c5e662
git-clang-format
areusch Sep 2, 2020
805d69e
Merge remote-tracking branch 'origin/master' into utvm-rpc-server-merge
areusch Sep 2, 2020
0358eca
enable MICRO on i386, fix missing #include
areusch Sep 2, 2020
093abab
add -fPIC to host crt builds
areusch Sep 2, 2020
c5941ee
move MISRA-C test to cpp_unittest.
areusch Sep 3, 2020
f803ba8
retrigger CI
areusch Sep 3, 2020
975dab4
use proper --runtime= in target, don't double-generate mod wrapper
areusch Sep 3, 2020
569d78a
disable DEBUG mode on test_crt workspace
areusch Sep 3, 2020
a3c0fae
allow using local graph runtime with all-rpc contexts, fix micro_tflite
areusch Sep 3, 2020
799de5f
try to address relocation failure on ci-gpu
areusch Sep 3, 2020
22fb6cd
lint
areusch Sep 3, 2020
1c12a51
more lint
areusch Sep 3, 2020
aea5d3b
set all target_link_libraries to PRIVATE
areusch Sep 4, 2020
bc84b1e
add utvm_rpc_common library to micro TVM build logic
areusch Sep 4, 2020
c882735
address comments
areusch Sep 8, 2020
fce40ac
git-clang-format
areusch Sep 8, 2020
c20fa92
crttests pass
areusch Sep 8, 2020
b3fbf26
git-clang-format
areusch Sep 8, 2020
9b5d89a
try to fix regression
areusch Sep 9, 2020
4371f09
verbose makefile, for CI
areusch Sep 9, 2020
0fde646
try adding more deps
areusch Sep 9, 2020
fd3d4f7
retrigger CI
areusch Sep 10, 2020
73ce7ac
Merge remote-tracking branch 'origin/master' into utvm-rpc-server-merge
areusch Sep 10, 2020
573be23
fix bad merge
areusch Sep 10, 2020
8a441d3
merge in Target() change
areusch Sep 10, 2020
e6cde35
Merge remote-tracking branch 'origin/master' into utvm-rpc-server-merge
areusch Sep 12, 2020
3fc9f1e
fix bad merge, delete more stuff
areusch Sep 12, 2020
78993f4
delete moar things!
areusch Sep 12, 2020
1b24904
fixing more bad merge
areusch Sep 12, 2020
d32f42d
address tqchen comments, add unit test for graph runtime
areusch Sep 14, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2013 Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
* integrated circuit in a product or a software update for such product, must reproduce
* the above copyright notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary or object form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include "crc16.h"

#include <stdlib.h>

uint16_t crc16_compute(uint8_t const* p_data, uint32_t size, uint16_t const* p_crc) {
uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc;

for (uint32_t i = 0; i < size; i++) {
crc = (uint8_t)(crc >> 8) | (crc << 8);
crc ^= p_data[i];
crc ^= (uint8_t)(crc & 0xFF) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xFF) << 4) << 1;
}

return crc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2013 Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
* integrated circuit in a product or a software update for such product, must reproduce
* the above copyright notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary or object form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

/** @file
*
* @defgroup crc_compute CRC compute
* @{
* @ingroup hci_transport
*
* @brief This module implements CRC-16-CCITT (polynomial 0x1021) with 0xFFFF initial value.
* The data can be passed in multiple blocks.
*/

#ifndef CRC16_H__
#define CRC16_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/**@brief Function for calculating CRC-16 in blocks.
*
* Feed each consecutive data block into this function, along with the current value of p_crc as
* returned by the previous call of this function. The first call of this function should pass NULL
* as the initial value of the crc in p_crc.
*
* @param[in] p_data The input data block for computation.
* @param[in] size The size of the input data block in bytes.
* @param[in] p_crc The previous calculated CRC-16 value or NULL if first call.
*
* @return The updated CRC-16 value, based on the input supplied.
*/
uint16_t crc16_compute(uint8_t const* p_data, uint32_t size, uint16_t const* p_crc);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // CRC16_H__

/** @} */
26 changes: 16 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
tvm_option(USE_RTTI "Build with RTTI" ON)
tvm_option(USE_MSVC_MT "Build with MT" OFF)
tvm_option(USE_MICRO "Build with Micro" OFF)
tvm_option(USE_MICRO "Build with Micro TVM support" OFF)
tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
tvm_option(HIDE_PRIVATE_SYMBOLS "Compile with -fvisibility=hidden." OFF)
tvm_option(USE_TF_TVMDSOOP "Build with TensorFlow TVMDSOOp" OFF)
Expand Down Expand Up @@ -77,7 +77,6 @@ tvm_option(USE_TARGET_ONNX "Build with ONNX Codegen support" OFF)
tvm_option(USE_ARM_COMPUTE_LIB "Build with Arm Compute Library" OFF)
tvm_option(USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME "Build with Arm Compute Library graph runtime" OFF)


# include directories
include_directories(${CMAKE_INCLUDE_PATH})
include_directories("include")
Expand Down Expand Up @@ -403,12 +402,12 @@ if(USE_THREADS AND NOT BUILD_FOR_HEXAGON)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(tvm Threads::Threads)
target_link_libraries(tvm_runtime Threads::Threads)
target_link_libraries(tvm PUBLIC Threads::Threads)
target_link_libraries(tvm_runtime PUBLIC Threads::Threads)
endif()

target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm PRIVATE ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_runtime PRIVATE ${TVM_RUNTIME_LINKER_LIBS})

# Related headers
target_include_directories(
Expand All @@ -417,20 +416,27 @@ target_include_directories(
target_include_directories(
tvm_objs
PUBLIC "topi/include")
set(CRC16_INCLUDE_PATH "3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16")
target_include_directorieS(
tvm_objs
PRIVATE "${CRC16_INCLUDE_PATH}")
target_include_directorieS(
tvm_runtime_objs
PRIVATE "${CRC16_INCLUDE_PATH}")

set(TVM_TEST_LIBRARY_NAME tvm)
if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_library(tvm_allvisible SHARED $<TARGET_OBJECTS:tvm_objs>)
target_include_directories(tvm_allvisible PUBLIC "$<TARGET_PROPERTY:tvm,INCLUDE_DIRECTORIES>")
target_link_libraries(tvm_allvisible PUBLIC "$<TARGET_PROPERTY:tvm,LINK_LIBRARIES>")
target_link_libraries(tvm_allvisible PRIVATE "$<TARGET_PROPERTY:tvm,LINK_LIBRARIES>")
set(TVM_TEST_LIBRARY_NAME tvm_allvisible)

set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL")
set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL")
# Note: 'target_link_options' with 'PRIVATE' keyword would be cleaner
# but it's not available until CMake 3.13. Switch to 'target_link_options'
# once minimum CMake version is bumped up to 3.13 or above.
target_link_libraries(tvm ${HIDE_SYMBOLS_LINKER_FLAGS})
target_link_libraries(tvm_runtime ${HIDE_SYMBOLS_LINKER_FLAGS})
target_link_libraries(tvm PRIVATE ${HIDE_SYMBOLS_LINKER_FLAGS})
target_link_libraries(tvm_runtime PRIVATE ${HIDE_SYMBOLS_LINKER_FLAGS})
endif()

# Tests
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Apache Software Foundation License 2.0
3rdparty/bfloat16/bfloat16.cc
3rdparty/dlpack
3rdparty/dmlc-core
3rdparty/mbed-os


BSD 2-clause License
Expand Down
18 changes: 11 additions & 7 deletions apps/bundle_deploy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

# Setup build environment
TVM_ROOT=$(shell cd ../..; pwd)
CRT_ROOT ?= ../../src/runtime/crt
CRT_ROOT ?= ../../build/standalone_crt
ifeq ($(shell ls -lhd $(CRT_ROOT)),)
$(error "CRT not found. Ensure you have built the standalone_crt target and try again")
endif

ENABLE_TVM_PLATFORM_ABORT_BACKTRACE ?= 1

Expand Down Expand Up @@ -57,6 +60,7 @@ $(else)
QUIET ?= @
$(endif)

CRT_SRCS = $(shell find $(CRT_ROOT))

demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/bundle.so $(build_dir)/graph_cpp.json $(build_dir)/graph_c.json $(build_dir)/params_cpp.bin $(build_dir)/params_c.bin $(build_dir)/cat.bin
$(QUIET)TVM_NUM_THREADS=1 $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/graph_cpp.json $(build_dir)/params_cpp.bin $(build_dir)/cat.bin
Expand All @@ -72,10 +76,10 @@ demo_static: $(build_dir)/demo_static $(build_dir)/cat.bin
test_static: $(build_dir)/test_static $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin
$(QUIET)TVM_NUM_THREADS=1 $(build_dir)/test_static $(build_dir)/test_data_c.bin $(build_dir)/test_output_c.bin $(build_dir)/test_graph_c.json $(build_dir)/test_params_c.bin

$(build_dir)/crt/graph_runtime/libgraph_runtime.a:
$(build_dir)/crt/libgraph_runtime.a: $(CRT_SRCS)
$(QUIET)cd $(CRT_ROOT) && make QUIET= BUILD_DIR=$(abspath $(build_dir))/crt CRT_CONFIG=$(abspath crt_config/crt_config.h) "EXTRA_CFLAGS=$(PKG_COMPILE_OPTS)" graph_runtime

$(build_dir)/crt/common/libcommon.a:
$(build_dir)/crt/libcommon.a: $(CRT_SRCS)
$(QUIET)cd $(CRT_ROOT) && make QUIET= BUILD_DIR=$(abspath $(build_dir))/crt CRT_CONFIG=$(abspath crt_config/crt_config.h) "EXTRA_CFLAGS=$(PKG_COMPILE_OPTS)" common

$(build_dir)/demo_dynamic: demo.cc
Expand All @@ -86,11 +90,11 @@ $(build_dir)/test_dynamic: test.cc ${build_dir}/test_graph_c.json ${build_dir}/t
$(QUIET)mkdir -p $(@D)
$(QUIET)g++ $(PKG_CXXFLAGS) -o $@ test.cc $(BACKTRACE_OBJS) $(BACKTRACE_LDFLAGS)

$(build_dir)/demo_static: demo_static.c ${build_dir}/bundle_static.o ${build_dir}/model_c.o ${build_dir}/crt/graph_runtime/libgraph_runtime.a ${build_dir}/crt/common/libcommon.a $(BACKTRACE_OBJS)
$(build_dir)/demo_static: demo_static.c ${build_dir}/bundle_static.o ${build_dir}/model_c.o ${build_dir}/crt/libgraph_runtime.a ${build_dir}/crt/libcommon.a ${build_dir}/graph_c.json.c ${build_dir}/params_c.bin.c $(BACKTRACE_OBJS)
$(QUIET)mkdir -p $(@D)
$(QUIET)gcc $(PKG_CFLAGS) -o $@ $^ $(BACKTRACE_CFLAGS)

$(build_dir)/test_static: test_static.c ${build_dir}/bundle_static.o ${build_dir}/test_model_c.o ${build_dir}/crt/graph_runtime/libgraph_runtime.a ${build_dir}/crt/common/libcommon.a $(BACKTRACE_OBJS)
$(build_dir)/test_static: test_static.c ${build_dir}/bundle_static.o ${build_dir}/test_model_c.o ${build_dir}/crt/libgraph_runtime.a ${build_dir}/crt/libcommon.a $(BACKTRACE_OBJS)
$(QUIET)mkdir -p $(@D)
$(QUIET)gcc $(PKG_CFLAGS) -o $@ $^ $(BACKTRACE_LDFLAGS)

Expand Down Expand Up @@ -124,15 +128,15 @@ $(build_dir)/bundle.so: bundle.cc runtime.cc $(build_dir)/model_cpp.o
$(QUIET)mkdir -p $(@D)
$(QUIET)g++ -shared $(PKG_CXXFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS)

$(build_dir)/bundle_c.so: bundle.c $(build_dir)/model_c.o ${build_dir}/crt/graph_runtime/libgraph_runtime.a ${build_dir}/crt/common/libcommon.a $(BACKTRACE_OBJS)
$(build_dir)/bundle_c.so: bundle.c $(build_dir)/model_c.o ${build_dir}/crt/libgraph_runtime.a ${build_dir}/crt/libcommon.a $(BACKTRACE_OBJS)
$(QUIET)mkdir -p $(@D)
$(QUIET)gcc -shared $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS) $(BACKTRACE_LDFLAGS) $(BACKTRACE_CFLAGS)

$(build_dir)/test_bundle.so: bundle.cc runtime.cc $(build_dir)/test_model_cpp.o
$(QUIET)mkdir -p $(@D)
$(QUIET)g++ -shared $(PKG_CXXFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS)

$(build_dir)/test_bundle_c.so: bundle.c $(build_dir)/test_model_c.o ${build_dir}/crt/graph_runtime/libgraph_runtime.a ${build_dir}/crt/common/libcommon.a $(BACKTRACE_OBJS)
$(build_dir)/test_bundle_c.so: bundle.c $(build_dir)/test_model_c.o ${build_dir}/crt/libgraph_runtime.a ${build_dir}/crt/libcommon.a $(BACKTRACE_OBJS)
$(QUIET)mkdir -p $(@D)
$(QUIET)gcc -shared $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS) $(BACKTRACE_LDFLAGS) $(BACKTRACE_CFLAGS)

Expand Down
17 changes: 15 additions & 2 deletions apps/bundle_deploy/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <tvm/runtime/c_runtime_api.h>
Expand All @@ -28,6 +29,11 @@
#include "backtrace.h"
#endif

#define CRT_MEMORY_NUM_PAGES 16384
#define CRT_MEMORY_PAGE_SIZE_LOG2 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making this as part of crt_config.h ?

Copy link
Contributor Author

@areusch areusch Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so actually i'm going the other way with this PR--saying that the backing memory for the memory allocator needs to be allocated by the caller. we can put these into crt_config.h, but I'm not sure what the benefit is after this change--the total memory is now passed in to memory.c as an argument.

the reason for this is that an embedded project might want to e.g. pin the memory to some particular RAM on the device. that would need integration with a linker script, so we defer allocating the backing memory to project-specific code.


static uint8_t g_crt_memory[CRT_MEMORY_NUM_PAGES * (1 << CRT_MEMORY_PAGE_SIZE_LOG2)];

/*! \brief macro to do C API call */
#define TVM_CCALL(func) \
do { \
Expand Down Expand Up @@ -56,7 +62,7 @@ TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
ctx.device_id = device_id;

// declare pointers
TVM_CCALL(TVMInitializeRuntime());
TVM_CCALL(TVMInitializeRuntime(g_crt_memory, sizeof(g_crt_memory), CRT_MEMORY_PAGE_SIZE_LOG2));
TVMPackedFunc pf;
TVMArgs args = TVMArgs_Create(NULL, NULL, 0);
TVM_CCALL(TVMPackedFunc_InitGlobalFunc(&pf, "runtime.SystemLib", &args));
Expand Down Expand Up @@ -90,7 +96,14 @@ TVM_DLL void tvm_runtime_get_output(void* runtime, int32_t index, DLTensor* tens
TVMGraphRuntime_GetOutput(graph_runtime, index, tensor);
}

void __attribute__((noreturn)) TVMPlatformAbort(int error_code) {
void TVMLogf(const char* msg, ...) {
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
}

void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t error_code) {
fprintf(stderr, "TVMPlatformAbort: %d\n", error_code);
#ifdef ENABLE_TVM_ABORT_BACKTRACE
tvm_platform_abort_backtrace();
Expand Down
17 changes: 15 additions & 2 deletions apps/bundle_deploy/bundle_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <tvm/runtime/crt/crt.h>
Expand All @@ -29,6 +30,11 @@
#endif
#include "bundle.h"

#define CRT_MEMORY_NUM_PAGES 16384
#define CRT_MEMORY_PAGE_SIZE_LOG2 10

static uint8_t g_crt_memory[CRT_MEMORY_NUM_PAGES * (1 << CRT_MEMORY_PAGE_SIZE_LOG2)];

/*! \brief macro to do C API call */
#define TVM_CCALL(func) \
do { \
Expand Down Expand Up @@ -56,7 +62,7 @@ TVM_DLL void* tvm_runtime_create(const char* json_data, const char* params_data,
ctx.device_id = device_id;

// get pointers
TVM_CCALL(TVMInitializeRuntime());
TVM_CCALL(TVMInitializeRuntime(g_crt_memory, sizeof(g_crt_memory), CRT_MEMORY_PAGE_SIZE_LOG2));
TVMPackedFunc pf;
TVMArgs args = TVMArgs_Create(NULL, NULL, 0);
TVM_CCALL(TVMPackedFunc_InitGlobalFunc(&pf, "runtime.SystemLib", &args));
Expand Down Expand Up @@ -91,7 +97,14 @@ TVM_DLL void tvm_runtime_get_output(void* runtime, int32_t index, DLTensor* tens
TVMGraphRuntime_GetOutput(graph_runtime, index, tensor);
}

void __attribute__((noreturn)) TVMPlatformAbort(int error_code) {
void TVMLogf(const char* msg, ...) {
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
}

void __attribute__((noreturn)) TVMPlatformAbort(tvm_crt_error_t error_code) {
fprintf(stderr, "TVMPlatformAbort: %d\n", error_code);
#ifdef ENABLE_TVM_PLATFORM_ABORT_BACKTRACE
tvm_platform_abort_backtrace();
Expand Down
Loading