-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Hexagon] Add RPC Mechanism for Hexagon #9631
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
Changes from all commits
6f2eec9
87d8bec
cea8757
b16c8b0
076619f
299a378
4656232
e57c7aa
aa61967
461df6a
28db608
f87f51d
31fda2b
a7ee1a9
532bf1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # 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. | ||
|
|
||
| cmake_minimum_required(VERSION 3.2) | ||
| include(ExternalProject) | ||
| project(HexagonRPCSkel C CXX) | ||
|
|
||
| set(TVM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") | ||
| set(TVM_SRC_DIR "${TVM_SOURCE_DIR}/src") | ||
|
|
||
|
|
||
| include("${TVM_SOURCE_DIR}/cmake/modules/HexagonSDK.cmake") | ||
|
|
||
| find_hexagon_sdk_root("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}") | ||
|
|
||
| include_directories(SYSTEM ${HEXAGON_SDK_INCLUDES} ${HEXAGON_REMOTE_ROOT}) | ||
|
|
||
| set(HEXAGON_RPC_H "hexagon_rpc.h") | ||
| set(HEXAGON_RPC_SKEL_C "hexagon_rpc_skel.c") | ||
| set(HEXAGON_RPC_STUB_C "hexagon_rpc_stub.c") | ||
|
|
||
| include_directories( | ||
| "${TVM_SOURCE_DIR}/include" | ||
| "${TVM_SOURCE_DIR}/3rdparty/dlpack/include" | ||
| "${TVM_SOURCE_DIR}/3rdparty/dmlc-core/include" | ||
| ) | ||
|
|
||
| set(QAIC_EXE "${HEXAGON_QAIC_EXE}") | ||
| foreach(INCDIR IN LISTS HEXAGON_SDK_INCLUDES HEXAGON_REMOTE_ROOT) | ||
| list(APPEND QAIC_FLAGS "-I${INCDIR}") | ||
| endforeach() | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${HEXAGON_RPC_SKEL_C} ${HEXAGON_RPC_H} | ||
| COMMAND ${QAIC_EXE} ${QAIC_FLAGS} "${TVM_SRC_DIR}/runtime/hexagon/rpc/hexagon_rpc.idl" | ||
| MAIN_DEPENDENCY "${TVM_SRC_DIR}/runtime/hexagon/rpc/hexagon_rpc.idl" | ||
| ) | ||
|
|
||
| include_directories(SYSTEM | ||
| ${HEXAGON_QURT_INCLUDES} | ||
| ${CMAKE_CURRENT_BINARY_DIR} # Output of qaic will go here | ||
| ) | ||
|
|
||
| link_directories(${HEXAGON_QURT_LIBS}) | ||
|
|
||
| add_definitions(-D_MACH_I32=int) | ||
| add_definitions(-DDMLC_CXX11_THREAD_LOCAL=0) | ||
| add_definitions(-DDMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>) | ||
|
|
||
| # Extra compile flags (both C and C++). | ||
| set(EXTRA_COMP_FLAGS | ||
| "-O3" | ||
| "-m${USE_HEXAGON_ARCH}" | ||
| ) | ||
| string(REGEX REPLACE ";" " " EXTRA_COMP_FLAGS_STR "${EXTRA_COMP_FLAGS}") | ||
| set(CMAKE_C_FLAGS "${EXTRA_COMP_FLAGS_STR} ${CMAKE_C_FLAGS}") | ||
| set(CMAKE_CXX_FLAGS "${EXTRA_COMP_FLAGS_STR} ${CMAKE_CXX_FLAGS}") | ||
|
|
||
| set(SKEL_SRCS | ||
| "${TVM_SRC_DIR}/runtime/hexagon/rpc/hexagon/rpc_server.cc" | ||
| ) | ||
|
|
||
| set(MINRPC_SRCS | ||
| "${TVM_SRC_DIR}/runtime/minrpc/minrpc_server.h" | ||
| "${TVM_SRC_DIR}/runtime/minrpc/rpc_reference.h" | ||
| ) | ||
|
|
||
| set(TVM_RPC_SRC | ||
| "${TVM_SRC_DIR}/runtime/rpc/rpc_module.cc" | ||
| "${TVM_SRC_DIR}/runtime/rpc/rpc_endpoint.cc" | ||
| "${TVM_SRC_DIR}/runtime/rpc/rpc_session.cc" | ||
| "${TVM_SRC_DIR}/runtime/rpc/rpc_local_session.cc" | ||
| ) | ||
|
|
||
| add_library(hexagon_rpc_skel SHARED | ||
| "${HEXAGON_RPC_H}" | ||
| "${HEXAGON_RPC_SKEL_C}" | ||
| "${SKEL_SRCS}" | ||
| "${MINRPC_SRCS}" | ||
| "${TVM_RPC_SRC}" | ||
| ) | ||
|
|
||
| ExternalProject_Add(static_hexagon_tvm_runtime | ||
| SOURCE_DIR "${TVM_SOURCE_DIR}" | ||
| BUILD_COMMAND $(MAKE) runtime | ||
| CMAKE_ARGS | ||
| "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" | ||
| "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" | ||
| "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" | ||
| "-DCMAKE_CXX_STANDARD=14" | ||
| "-DUSE_LIBBACKTRACE=OFF" | ||
| "-DUSE_LLVM=OFF" | ||
| "-DUSE_RPC=OFF" | ||
| "-DBUILD_STATIC_RUNTIME=ON" | ||
| "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" | ||
| INSTALL_COMMAND "" | ||
| BUILD_ALWAYS ON | ||
| ) | ||
| ExternalProject_Get_Property(static_hexagon_tvm_runtime BINARY_DIR) | ||
|
|
||
| add_dependencies(hexagon_rpc_skel static_hexagon_tvm_runtime) | ||
| add_library(h_tvm_runtime STATIC IMPORTED) | ||
| set_target_properties(h_tvm_runtime PROPERTIES IMPORTED_LOCATION "${BINARY_DIR}/libtvm_runtime.a") | ||
|
|
||
| target_link_libraries(hexagon_rpc_skel -Wl,--whole-archive h_tvm_runtime -Wl,--no-whole-archive) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,6 @@ if(BUILD_FOR_HEXAGON) | |
| include_directories(SYSTEM ${HEXAGON_SDK_INCLUDES} ${HEXAGON_QURT_INCLUDES}) | ||
| endif() | ||
|
|
||
|
|
||
| if (NOT USE_HEXAGON_SDK STREQUAL "" AND | ||
| NOT USE_HEXAGON_SDK STREQUAL "/path/to/sdk") | ||
| set(HEXAGON_SDK_PATH_DEFINED ${USE_HEXAGON_SDK}) | ||
|
|
@@ -73,10 +72,12 @@ endif() | |
| # e.g. when compiling the TVM runtime for Hexagon. | ||
| if (NOT BUILD_FOR_HEXAGON AND NOT BUILD_FOR_ANDROID) | ||
| if(USE_HEXAGON_LAUNCHER STREQUAL "OFF" AND | ||
| USE_HEXAGON_PROXY_RPC STREQUAL "OFF") | ||
| USE_HEXAGON_PROXY_RPC STREQUAL "OFF" AND NOT USE_HEXAGON_RPC) | ||
| if(USE_HEXAGON_DEVICE STREQUAL "OFF") | ||
| list(APPEND COMPILER_SRCS src/target/opt/build_hexagon_off.cc) | ||
| return() | ||
| if (NOT USE_HEXAGON_RPC) | ||
| return() | ||
| endif() | ||
| elseif(NOT USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}" AND | ||
| NOT USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}") | ||
| set(ERROR_MSG | ||
|
|
@@ -202,6 +203,103 @@ if(USE_HEXAGON_PROXY_RPC STREQUAL "ON") | |
| set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${RPC_BINARY_DIR}") | ||
| endif() | ||
|
|
||
| if(USE_HEXAGON_RPC) | ||
| if(DEFINED USE_ANDROID_TOOLCHAIN) | ||
| if(NOT DEFINED ANDROID_PLATFORM) | ||
| message(SEND_ERROR "Please set ANDROID_PLATFORM " | ||
| "when providing an Android cmake toolchain.") | ||
| endif() | ||
| if(NOT DEFINED ANDROID_ABI) | ||
| message(SEND_ERROR "Please set ANDROID_ABI " | ||
| "when providing an Android cmake toolchain.") | ||
| endif() | ||
| else() | ||
| message(SEND_ERROR "Please set USE_ANDROID_TOOLCHAIN to build the android " | ||
| "RPC server for Hexagon.") | ||
| endif() | ||
|
|
||
| if(NOT DEFINED USE_HEXAGON_SDK) | ||
| message(SEND_ERROR "Please set USE_HEXAGON_SDK to build the android " | ||
| "RPC server for Hexagon RPC.") | ||
| endif() | ||
| if(NOT DEFINED USE_HEXAGON_ARCH) | ||
| message(SEND_ERROR "Please set USE_HEXAGON_ARCH to build the android " | ||
| "RPC server for Hexagon RPC.") | ||
| endif() | ||
| find_hexagon_sdk_root("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}") | ||
|
|
||
| set(HEXAGON_RPC_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/hexagon_rpc") | ||
| file(MAKE_DIRECTORY ${HEXAGON_RPC_OUTPUT}) | ||
|
|
||
| # Android Part | ||
| ExternalProject_Add(android_runtime_rpc | ||
| SOURCE_DIR "${CMAKE_SOURCE_DIR}" | ||
| BUILD_COMMAND $(MAKE) runtime tvm_rpc | ||
| CMAKE_ARGS | ||
| "-DCMAKE_TOOLCHAIN_FILE=${USE_ANDROID_TOOLCHAIN}" | ||
| "-DUSE_ANDROID_TOOLCHAIN=${USE_ANDROID_TOOLCHAIN}" | ||
| "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" | ||
| "-DANDROID_ABI=${ANDROID_ABI}" | ||
| "-DCMAKE_CXX_STANDARD=14" | ||
| "-DUSE_LIBBACKTRACE=OFF" | ||
| "-DUSE_LLVM=OFF" | ||
| "-DUSE_RPC=ON" | ||
| "-DUSE_CPP_RPC=ON" | ||
| "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" | ||
| "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" | ||
| "-DCMAKE_VERBOSE_MAKEFILE=ON" | ||
| INSTALL_COMMAND "" | ||
| BUILD_ALWAYS ON | ||
| ) | ||
| ExternalProject_Get_Property(android_runtime_rpc BINARY_DIR) | ||
| ExternalProject_Add_Step(android_runtime_rpc copy_binary_runtime | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
| ${BINARY_DIR}/libtvm_runtime.so | ||
| ${HEXAGON_RPC_OUTPUT}/libtvm_runtime.so | ||
| DEPENDEES install | ||
| ) | ||
| ExternalProject_Add_Step(android_runtime_rpc copy_binary_rpc | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
| ${BINARY_DIR}/tvm_rpc | ||
| ${HEXAGON_RPC_OUTPUT}/tvm_rpc_android | ||
| DEPENDEES install | ||
| ) | ||
|
|
||
| if("${USE_HEXAGON_TOOLCHAIN}" STREQUAL "") | ||
| message(SEND_ERROR "Please set USE_HEXAGON_TOOLCHAIN to build the hexagon " | ||
| "RPC SKEL.") | ||
| endif() | ||
| find_hexagon_toolchain() | ||
| message(STATUS "HEXAGON_TOOLCHAIN: ${HEXAGON_TOOLCHAIN}") | ||
|
|
||
| # Hexagon Part | ||
| ExternalProject_Add(hexagon_rpc_skel | ||
| SOURCE_DIR "${CMAKE_SOURCE_DIR}/cmake/libs/hexagon_rpc_skel" | ||
| INSTALL_DIR "${LAUNCHER_BINARY_DIR}" | ||
| CMAKE_ARGS | ||
| "-DCMAKE_C_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang" | ||
| "-DCMAKE_CXX_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang++" | ||
| "-DFASTRPC_LIBS=SKEL" | ||
| "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" | ||
| "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" | ||
| INSTALL_COMMAND "" | ||
| BUILD_ALWAYS ON | ||
| ) | ||
| ExternalProject_Get_Property(hexagon_rpc_skel BINARY_DIR) | ||
| ExternalProject_Add_Step(hexagon_rpc_skel copy_hexagon_skel | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
| ${BINARY_DIR}/libhexagon_rpc_skel.so | ||
| ${HEXAGON_RPC_OUTPUT}/libhexagon_rpc_skel.so | ||
| DEPENDEES install | ||
| ) | ||
|
|
||
| # copy android_bash template file | ||
| configure_file("${CMAKE_SOURCE_DIR}/src/runtime/hexagon/rpc/android_bash.sh.template" | ||
| ${HEXAGON_RPC_OUTPUT} COPYONLY) | ||
|
|
||
| set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${HEXAGON_RPC_OUTPUT}") | ||
| endif() | ||
|
|
||
| if(USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}") | ||
| find_hexagon_toolchain() | ||
| message(STATUS "Hexagon toolchain: ${HEXAGON_TOOLCHAIN}") | ||
|
|
@@ -227,6 +325,7 @@ elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}") | |
| ${HEXAGON_RPCMEM_ROOT}/inc | ||
| ${HEXAGON_REMOTE_ROOT} | ||
| ) | ||
|
|
||
| list(APPEND TVM_RUNTIME_LINKER_LIBS "dl") | ||
| if(BUILD_FOR_ANDROID) | ||
| # Hexagon runtime uses __android_log_print, which is in liblog. | ||
|
|
@@ -241,10 +340,39 @@ if (USE_HEXAGON_DEVICE STREQUAL "${PICK_NONE}") | |
| elseif(BUILD_FOR_ANDROID AND HEXAGON_SDK_PATH_DEFINED) | ||
| list(APPEND RUNTIME_HEXAGON_SRCS src/runtime/hexagon/proxy_rpc/device_api.cc) | ||
| else() | ||
| file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/host/*.cc) | ||
| file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/host/*.cc) | ||
| endif() | ||
| else() | ||
| file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/android/*.cc) | ||
| endif() | ||
|
|
||
| if(USE_HEXAGON_RPC) | ||
| file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/host/*.cc) | ||
| endif() | ||
|
|
||
| if(USE_HEXAGON_SDK AND BUILD_FOR_ANDROID) | ||
| find_hexagon_sdk_root("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}") | ||
| include_directories(SYSTEM ${HEXAGON_SDK_INCLUDES} ${HEXAGON_REMOTE_ROOT}) | ||
|
|
||
| set(QAIC_EXE "${HEXAGON_QAIC_EXE}") | ||
| foreach(INCDIR IN LISTS HEXAGON_SDK_INCLUDES HEXAGON_REMOTE_ROOT) | ||
| list(APPEND QAIC_FLAGS "-I${INCDIR}") | ||
| endforeach() | ||
|
|
||
| set(HEXAGON_RPC_DIR "${CMAKE_SOURCE_DIR}/src/runtime/hexagon/rpc") | ||
| set(RPC_IDL "hexagon_rpc.idl") | ||
| set(RPC_H "hexagon_rpc.h") | ||
| set(RPC_STUB_C "hexagon_rpc_stub.c") | ||
|
|
||
| add_custom_command( | ||
| OUTPUT "${HEXAGON_RPC_DIR}/${RPC_STUB_C}" "${HEXAGON_RPC_DIR}/${RPC_H}" | ||
| COMMAND ${QAIC_EXE} ${QAIC_FLAGS} "${HEXAGON_RPC_DIR}/${RPC_IDL}" -o ${HEXAGON_RPC_DIR} | ||
| MAIN_DEPENDENCY "${HEXAGON_RPC_DIR}/${RPC_IDL}" | ||
| ) | ||
| file(GLOB HEXAGON_RPC_CPP "${HEXAGON_RPC_DIR}/android/*.cc") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will unconditionally add all files from that directory to the runtime target. If
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kparzysz-quic thanks for pointing out. This could break if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kparzysz-quic happy to hear your suggestion on this. thanks! |
||
| set(HEXAGON_RPC_STUB_C "${HEXAGON_RPC_DIR}/${RPC_STUB_C}") | ||
| endif() | ||
|
|
||
| list(APPEND RUNTIME_SRCS ${RUNTIME_HEXAGON_SRCS} ${RUNTIME_HEXAGON_SIM_SRCS} | ||
| ${RUNTIME_HEXAGON_DEVICE_SRCS} ${RUNTIME_HEXAGON_COMMON_SRCS}) | ||
| ${RUNTIME_HEXAGON_DEVICE_SRCS} ${HEXAGON_RPC_CPP} ${HEXAGON_RPC_STUB_C} | ||
| ${RUNTIME_HEXAGON_COMMON_SRCS}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # 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. | ||
| """Hexagon APIs.""" |
Uh oh!
There was an error while loading. Please reload this page.