Skip to content

Commit 9a4a50b

Browse files
committed
Merge branch 'main' into hexagon/aot_demo
2 parents 92cad6e + d9fac4f commit 9a4a50b

187 files changed

Lines changed: 6917 additions & 1201 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ We do encourage everyone to work anything they are interested in.
6464
- [Christopher Sidebottom](https://github.com/Mousius): @Mousius - arm, ethos-u, relay
6565
- [Junru Shao](https://github.com/junrushao1994) (PMC): @junrushao1994 - relay, compiler
6666
- [Haichen Shen](https://github.com/icemelon) (PMC): @icemelon - relay, topi
67+
- [Chris Sullivan](https://github.com/csullivan): @csullivan - amd backend
6768
- [Siva Rama Krishna Reddy](https://github.com/srkreddy1238): @srkreddy1238 - frontends, golang
6869
- [Zhixun Tan](https://github.com/phisiart): @phisiart - opengl, web
6970
- [Andrew Tulloch](https://github.com/ajtulloch): @ajtulloch - topi, compiler, runtime

Jenkinsfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ci_wasm = "tlcpack/ci-wasm:v0.71"
5252
ci_i386 = "tlcpack/ci-i386:v0.74"
5353
ci_qemu = "tlcpack/ci-qemu:v0.10"
5454
ci_arm = "tlcpack/ci-arm:v0.07"
55+
ci_hexagon = "tlcpack/ci-hexagon:v0.01"
5556
// <--- End of regex-scanned config.
5657

5758
// Parameters to allow overriding (in Jenkins UI), the images
@@ -381,6 +382,34 @@ stage('Build') {
381382
} else {
382383
Utils.markStageSkippedForConditional('BUILD: QEMU')
383384
}
385+
},
386+
'BUILD: Hexagon': {
387+
if (!skip_ci && is_docs_only_build != 1) {
388+
node('CPU') {
389+
ws(per_exec_ws('tvm/build-hexagon')) {
390+
init_git()
391+
sh (
392+
script: "${docker_run} ${ci_hexagon} ./tests/scripts/task_config_build_hexagon.sh",
393+
label: 'Create Hexagon cmake config',
394+
)
395+
try {
396+
make(ci_hexagon, 'build', '-j2')
397+
sh (
398+
script: "${docker_run} ${ci_hexagon} ./tests/scripts/task_build_hexagon_api.sh",
399+
label: 'Build Hexagon API',
400+
)
401+
sh (
402+
script: "${docker_run} ${ci_hexagon} ./tests/scripts/task_python_hexagon.sh",
403+
label: 'Run Hexagon tests',
404+
)
405+
} finally {
406+
junit 'build/pytest-results/*.xml'
407+
}
408+
}
409+
}
410+
} else {
411+
Utils.markStageSkippedForConditional('BUILD: Hexagon')
412+
}
384413
}
385414
}
386415

apps/hexagon_api/CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ else()
2323
endif()
2424
file(MAKE_DIRECTORY ${HEXAGON_API_BINARY_DIR})
2525

26+
# Build X86 binaries:
27+
# - tvm_rpc_x86
28+
29+
ExternalProject_Add(x86_tvm_runtime_rpc
30+
SOURCE_DIR "${TVM_SOURCE_DIR}"
31+
BUILD_COMMAND $(MAKE) runtime tvm_rpc
32+
CMAKE_ARGS
33+
"-DUSE_HEXAGON_TOOLCHAIN=${USE_HEXAGON_TOOLCHAIN}"
34+
"-DCMAKE_CXX_STANDARD=14"
35+
"-DUSE_LIBBACKTRACE=OFF"
36+
"-DUSE_RPC=ON"
37+
"-DUSE_CPP_RPC=ON"
38+
"-DUSE_HEXAGON_RPC=ON"
39+
"-DBUILD_STATIC_RUNTIME=ON"
40+
INSTALL_COMMAND ""
41+
BUILD_ALWAYS ON
42+
)
43+
ExternalProject_Get_Property(x86_tvm_runtime_rpc BINARY_DIR)
44+
ExternalProject_Add_Step(x86_tvm_runtime_rpc copy_rpc_server
45+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
46+
${BINARY_DIR}/tvm_rpc
47+
${HEXAGON_API_BINARY_DIR}/tvm_rpc_x86
48+
DEPENDEES install
49+
)
50+
2651
# Build Android binaries:
2752
# - libtvm_runtime.so
2853
# - tvm_rpc_android
@@ -38,7 +63,6 @@ ExternalProject_Add(android_tvm_runtime_rpc
3863
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
3964
"-DCMAKE_CXX_STANDARD=14"
4065
"-DUSE_LIBBACKTRACE=OFF"
41-
"-DUSE_LLVM=OFF"
4266
"-DUSE_RPC=ON"
4367
"-DUSE_CPP_RPC=ON"
4468
"-DUSE_HEXAGON_RPC=ON"
@@ -66,7 +90,7 @@ ExternalProject_Add_Step(android_tvm_runtime_rpc copy_rpc_server
6690

6791
ExternalProject_Add(hexagon_tvm_runtime_rpc
6892
SOURCE_DIR "${TVM_SOURCE_DIR}"
69-
BUILD_COMMAND $(MAKE) runtime
93+
BUILD_COMMAND $(MAKE) runtime hexagon_rpc_sim
7094
CMAKE_ARGS
7195
"-DCMAKE_C_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang"
7296
"-DCMAKE_CXX_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang++"
@@ -84,6 +108,7 @@ ExternalProject_Add_Step(hexagon_tvm_runtime_rpc copy_binaries
84108
COMMAND ${CMAKE_COMMAND} -E copy_if_different
85109
${BINARY_DIR}/libtvm_runtime.a
86110
${BINARY_DIR}/libhexagon_rpc_skel.so
111+
${BINARY_DIR}/libhexagon_rpc_sim.so
87112
${HEXAGON_API_BINARY_DIR}
88113
DEPENDEES install
89114
)

apps/microtvm/arduino/template_project/src/example_project/model.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* buffer, size_t num_bytes) {
8686
void TVMInitialize() { StackMemoryManager_Init(&app_workspace, g_aot_memory, WORKSPACE_SIZE); }
8787

8888
void TVMExecute(void* input_data, void* output_data) {
89-
int ret_val = tvmgen_default_run_model(input_data, output_data);
89+
int ret_val = tvmgen_default___tvm_main__(input_data, output_data);
9090
if (ret_val != 0) {
9191
TVMPlatformAbort(kTvmErrorPlatformCheckFailure);
9292
}

apps/microtvm/zephyr/template_project/microtvm_api_server.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import collections.abc
2121
import enum
2222
import fcntl
23+
import json
2324
import logging
2425
import os
2526
import os.path
@@ -35,7 +36,7 @@
3536
import tempfile
3637
import threading
3738
import time
38-
import json
39+
import usb
3940

4041
import serial
4142
import serial.tools.list_ports
@@ -179,8 +180,6 @@ def openocd_serial(options):
179180
if "openocd_serial" in options:
180181
return options["openocd_serial"]
181182

182-
import usb # pylint: disable=import-outside-toplevel
183-
184183
find_kw = BOARD_USB_FIND_KW[CMAKE_CACHE["BOARD"]]
185184
boards = usb.core.find(find_all=True, **find_kw)
186185
serials = []
@@ -588,6 +587,13 @@ def _set_nonblock(fd):
588587

589588

590589
class ZephyrSerialTransport:
590+
591+
NRF5340_VENDOR_ID = 0x1366
592+
593+
# NRF5340_DK v1.0.0 uses VCOM2
594+
# NRF5340_DK v2.0.0 uses VCOM1
595+
NRF5340_DK_BOARD_VCOM_BY_PRODUCT_ID = {0x1055: "VCOM2", 0x1051: "VCOM1"}
596+
591597
@classmethod
592598
def _lookup_baud_rate(cls, options):
593599
# TODO(mehrdadh): remove this hack once dtlib.py is a standalone project
@@ -625,7 +631,17 @@ def _find_nrf_serial_port(cls, options):
625631
parts = line.split()
626632
ports_by_vcom[parts[2]] = parts[1]
627633

628-
return ports_by_vcom["VCOM2"]
634+
nrf_board = usb.core.find(idVendor=cls.NRF5340_VENDOR_ID)
635+
636+
if nrf_board == None:
637+
raise Exception("_find_nrf_serial_port: unable to find NRF5340DK")
638+
639+
if nrf_board.idProduct in cls.NRF5340_DK_BOARD_VCOM_BY_PRODUCT_ID:
640+
vcom_port = cls.NRF5340_DK_BOARD_VCOM_BY_PRODUCT_ID[nrf_board.idProduct]
641+
else:
642+
raise Exception("_find_nrf_serial_port: unable to find known NRF5340DK product ID")
643+
644+
return ports_by_vcom[vcom_port]
629645

630646
@classmethod
631647
def _find_openocd_serial_port(cls, options):

apps/microtvm/zephyr_cmsisnn/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern float output_storage[12];
3434

3535
extern const size_t output_len;
3636

37-
static uint8_t g_crt_workspace[TVMGEN_DEFAULT_WORKSPACE_SIZE + 512];
37+
static uint8_t g_crt_workspace[TVMGEN_DEFAULT_WORKSPACE_SIZE];
3838
tvm_workspace_t app_workspace;
3939

4040
void TVMLogf(const char* msg, ...) {

cmake/modules/Hexagon.cmake

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ endif()
7878
#
7979
# USE_HEXAGON_RPC:
8080
# - When building for Hexagon, this will build the Hexagon endpoint of the
81-
# RPC server: the FastRPC skel library (with TVM runtime built into it).
81+
# RPC server: the FastRPC skel library (with TVM runtime built into it),
82+
# and the standalone RPC server for simulator.
8283
# - When building for Android, this will build the (intermediary) RPC server,
8384
# including the "stub" code for the FastRPC implementation of the RPC
8485
# channel.
86+
# - When building for x86, this will build the host-side code that instan-
87+
# tiates the simulator.
8588

8689
if(NOT BUILD_FOR_HEXAGON AND NOT BUILD_FOR_ANDROID)
8790
set(BUILD_FOR_HOST TRUE)
@@ -116,6 +119,15 @@ function(add_android_paths)
116119
link_directories(${HEXAGON_REMOTE_ROOT})
117120
endfunction()
118121

122+
function(add_hexagon_wrapper_paths)
123+
if(NOT DEFINED HEXAGON_TOOLCHAIN)
124+
message(FATAL_ERROR "This function must be called after find_hexagon_toolchain")
125+
endif()
126+
include_directories(SYSTEM
127+
"${HEXAGON_TOOLCHAIN}/include/iss"
128+
)
129+
link_directories("${HEXAGON_TOOLCHAIN}/lib/iss")
130+
endfunction()
119131

120132
# Common sources for TVM runtime with Hexagon support
121133
file_glob_append(RUNTIME_HEXAGON_COMMON_SRCS
@@ -148,12 +160,11 @@ if(USE_HEXAGON_DEVICE)
148160
invalid_device_value_for("host")
149161
endif()
150162
find_hexagon_toolchain()
163+
add_hexagon_wrapper_paths()
151164
file_glob_append(RUNTIME_HEXAGON_SRCS
152165
"${TVMRT_SOURCE_DIR}/hexagon/android/*.cc"
153166
"${TVMRT_SOURCE_DIR}/hexagon/android/sim/*.cc"
154167
)
155-
include_directories(SYSTEM "${HEXAGON_TOOLCHAIN}/include/iss")
156-
link_directories("${HEXAGON_TOOLCHAIN}/lib/iss")
157168
list(APPEND TVM_RUNTIME_LINKER_LIBS "-lwrapper")
158169

159170
ExternalProject_Add(sim_dev
@@ -245,6 +256,23 @@ if(USE_HEXAGON_RPC)
245256
target_include_directories(hexagon_rpc_skel
246257
SYSTEM PRIVATE "${TVMRT_SOURCE_DIR}/hexagon/rpc"
247258
)
259+
# Add the simulator-specific RPC code into a shared library to be
260+
# executed via run_main_on_sim.
261+
add_library(hexagon_rpc_sim SHARED
262+
"${TVMRT_SOURCE_DIR}/hexagon/rpc/simulator/rpc_server.cc"
263+
)
264+
target_link_libraries(hexagon_rpc_sim
265+
-Wl,--whole-archive tvm_runtime -Wl,--no-whole-archive
266+
)
267+
268+
elseif(BUILD_FOR_HOST)
269+
find_hexagon_toolchain()
270+
add_hexagon_wrapper_paths()
271+
file_glob_append(RUNTIME_HEXAGON_SRCS
272+
"${TVMRT_SOURCE_DIR}/hexagon/host/*.cc"
273+
"${TVMRT_SOURCE_DIR}/hexagon/rpc/simulator/session.cc"
274+
)
275+
list(APPEND TVM_RUNTIME_LINKER_LIBS "-lwrapper")
248276
endif()
249277
endif() # USE_HEXAGON_RPC
250278

cmake/utils/FindEthosN.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ macro(find_ethosn use_ethosn)
5858
PATHS ${__ethosn_stack}/lib)
5959
find_library(ETHOSN_COMPILER_LIBRARY NAMES EthosNSupport)
6060

61-
set(ETHOSN_PACKAGE_VERSION "0.1.1")
61+
list(GET ETHOSN_INCLUDE_DIRS 0 filename)
62+
set(filename "${filename}/ethosn_support_library/Support.hpp")
63+
file(READ ${filename} ETHOSN_SUPPORT_H)
64+
string(REGEX MATCH "VERSION_MAJOR ([0-9]*)" _ ${ETHOSN_SUPPORT_H})
65+
set(ver_major ${CMAKE_MATCH_1})
66+
string(REGEX MATCH "VERSION_MINOR ([0-9]*)" _ ${ETHOSN_SUPPORT_H})
67+
set(ver_minor ${CMAKE_MATCH_1})
68+
string(REGEX MATCH "VERSION_PATCH ([0-9]*)" _ ${ETHOSN_SUPPORT_H})
69+
set(ver_patch ${CMAKE_MATCH_1})
70+
set(ETHOSN_PACKAGE_VERSION "${ver_major}.${ver_minor}.${ver_patch}")
6271
set(ETHOSN_DEFINITIONS -DETHOSN_API_VERSION=${USE_ETHOSN_API_VERSION})
6372

6473
# Runtime hardware support. Driver library also needed for

docker/install/ubuntu_install_boost.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ cleanup() {
2424

2525
trap cleanup 0
2626

27-
curl -O https://boostorg.jfrog.io/artifactory/main/release/1.67.0/source/boost_1_67_0.tar.gz
28-
BOOST_HASH=cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
27+
curl -LO https://boostorg.jfrog.io/artifactory/main/release/1.67.0/source/boost_1_67_0.tar.gz
28+
BOOST_HASH=8c247e040303a97895cee9c9407ef205e2c3ab09f0b8320997835ad6221dff23a87231629498ccfd0acca473f74e9ec27b8bd774707b062228df1e5f72d44c92
2929
echo "$BOOST_HASH" boost_1_67_0.tar.gz | sha512sum -c
3030
tar -xf boost_1_67_0.tar.gz
3131

include/tvm/ir/module.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,44 @@
4040
#include <vector>
4141

4242
namespace tvm {
43+
/*!
44+
* \brief Describes one parameter that should be linked into the generated module.
45+
*
46+
* When parameters are to be linked in with generated code (i.e. on target_host-compatible
47+
* backends), Relay attaches instances of this object to a global TIR function. Code-generators
48+
* use the information contained in this node to include the parameter data in the generated
49+
* module.
50+
*/
51+
class LinkedParamNode : public Object {
52+
public:
53+
/*! \brief Unique numeric identifier used by runtimes to lookup this parameter. */
54+
int64_t id;
55+
56+
/*! \brief Parameter data which should get linked into the final module. */
57+
::tvm::runtime::NDArray param;
58+
59+
void VisitAttrs(tvm::AttrVisitor* v) {
60+
v->Visit("id", &id);
61+
v->Visit("param", &param);
62+
}
63+
64+
static constexpr const char* _type_key = "tir.LinkedParam";
65+
TVM_DECLARE_FINAL_OBJECT_INFO(LinkedParamNode, Object);
66+
};
67+
68+
/*!
69+
* \brief Managed reference to LinkedParamNode.
70+
*/
71+
class LinkedParam : public ObjectRef {
72+
public:
73+
TVM_DLL LinkedParam(int64_t id, tvm::runtime::NDArray param);
74+
75+
TVM_DEFINE_OBJECT_REF_METHODS(LinkedParam, ObjectRef, LinkedParamNode);
76+
TVM_DEFINE_OBJECT_REF_COW_METHOD(LinkedParamNode);
77+
};
78+
4379
class IRModule;
80+
4481
/*!
4582
* \brief IRModule that holds functions and type definitions.
4683
*
@@ -504,6 +541,11 @@ constexpr const char* kRuntime = "runtime";
504541
*/
505542
constexpr const char* kWorkspaceMemoryPools = "workspace_memory_pools";
506543

544+
/*
545+
* \brief Module attribute for tir constants
546+
*/
547+
constexpr const char* kConstantsArray = "Constants";
548+
507549
} // namespace attr
508550
} // namespace tvm
509551
#endif // TVM_IR_MODULE_H_

0 commit comments

Comments
 (0)