|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +cmake_minimum_required(VERSION 3.2) |
| 19 | +project(HexagonAndroidRPC C CXX) |
| 20 | + |
| 21 | +include("${CMAKE_CURRENT_SOURCE_DIR}/../HexagonRPC.cmake") |
| 22 | + |
| 23 | +add_custom_command( |
| 24 | + OUTPUT ${HEXAGON_PROXY_RPC_STUB_C} ${HEXAGON_PROXY_RPC_H} |
| 25 | + COMMAND ${QAIC_EXE} ${QAIC_FLAGS} "${HEXAGON_PROXY_RPC_SRC}/${HEXAGON_PROXY_RPC_IDL}" |
| 26 | + MAIN_DEPENDENCY "${HEXAGON_PROXY_RPC_SRC}/${HEXAGON_PROXY_RPC_IDL}" |
| 27 | +) |
| 28 | + |
| 29 | +include_directories(SYSTEM |
| 30 | + "${HEXAGON_SDK_INCLUDES}" |
| 31 | + "${HEXAGON_RPCMEM_ROOT}/inc" |
| 32 | + "${CMAKE_CURRENT_BINARY_DIR}" # Output of qaic will go here |
| 33 | +) |
| 34 | + |
| 35 | +link_directories(${HEXAGON_REMOTE_ROOT}) |
| 36 | + |
| 37 | +add_definitions(-DDMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>) |
| 38 | + |
| 39 | +set(TVM_RPC_ENV_SOURCES |
| 40 | + ${HEXAGON_PROXY_RPC_SRC}/rpc_env.cc |
| 41 | +) |
| 42 | + |
| 43 | +add_library(rpc_env SHARED |
| 44 | + ${TVM_RPC_ENV_SOURCES} |
| 45 | + ${HEXAGON_PROXY_RPC_H} |
| 46 | + ${HEXAGON_PROXY_RPC_STUB_C} |
| 47 | +) |
| 48 | + |
| 49 | +ExternalProject_Add(android_tvm_runtime |
| 50 | + SOURCE_DIR "${TVM_SOURCE_DIR}" |
| 51 | + BUILD_COMMAND $(MAKE) runtime |
| 52 | + CMAKE_ARGS |
| 53 | + "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" |
| 54 | + "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" |
| 55 | + "-DANDROID_ABI=${ANDROID_ABI}" |
| 56 | + "-DCMAKE_CXX_STANDARD=14" |
| 57 | + "-DUSE_LIBBACKTRACE=OFF" |
| 58 | + "-DUSE_LLVM=OFF" |
| 59 | + "-DUSE_RPC=ON" |
| 60 | + "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" |
| 61 | + "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" |
| 62 | + INSTALL_COMMAND "" |
| 63 | + BUILD_ALWAYS ON |
| 64 | +) |
| 65 | +ExternalProject_Get_Property(android_tvm_runtime BINARY_DIR) |
| 66 | +ExternalProject_Add_Step(android_tvm_runtime copy_binaries |
| 67 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 68 | + ${BINARY_DIR}/libtvm_runtime.so |
| 69 | + ${CMAKE_CURRENT_BINARY_DIR} |
| 70 | + DEPENDEES install |
| 71 | +) |
| 72 | + |
| 73 | +add_dependencies(rpc_env android_tvm_runtime) |
| 74 | +add_library(a_tvm_runtime SHARED IMPORTED) |
| 75 | +set_target_properties(a_tvm_runtime PROPERTIES IMPORTED_LOCATION "${BINARY_DIR}/libtvm_runtime.so") |
| 76 | + |
| 77 | +target_link_libraries(rpc_env cdsprpc log a_tvm_runtime) |
| 78 | + |
| 79 | +# TVM CPP RPC build |
| 80 | +set(TVM_RPC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../cpp_rpc") |
| 81 | + |
| 82 | + |
| 83 | +set(TVM_RPC_SOURCES |
| 84 | + ${TVM_RPC_DIR}/main.cc |
| 85 | + ${TVM_RPC_DIR}/rpc_server.cc |
| 86 | +) |
| 87 | + |
| 88 | +# Set output to same directory as the other TVM libs |
| 89 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 90 | +add_executable(tvm_rpc ${TVM_RPC_SOURCES}) |
| 91 | + |
| 92 | + |
| 93 | +target_include_directories( |
| 94 | + tvm_rpc |
| 95 | + PUBLIC "${TVM_RPC_DIR}../../include" |
| 96 | + PUBLIC "${TVM_RPC_DIR}../../3rdparty/dlpack" |
| 97 | + PUBLIC "${TVM_RPC_DIR}../../3rdparty/dmlc-core" |
| 98 | +) |
| 99 | + |
| 100 | +add_dependencies(rpc_env android_tvm_runtime) |
| 101 | +target_link_libraries(rpc_env a_tvm_runtime) |
| 102 | + |
| 103 | +add_dependencies(tvm_rpc android_tvm_runtime rpc_env) |
| 104 | +target_link_libraries(tvm_rpc a_tvm_runtime rpc_env) |
0 commit comments