|
| 1 | +cmake_policy(SET CMP0069 NEW) # suppress cmake warning about IPO |
| 2 | + |
| 3 | +set(RTVM_SOURCES |
| 4 | + main.cc |
| 5 | + tvm_runner.cc |
| 6 | + ../../3rdparty/cnpy/cnpy.cpp |
| 7 | +) |
| 8 | +set(TVM_RUNNER_SOURCES |
| 9 | + tvm_runner.cc |
| 10 | + ../../3rdparty/cnpy/cnpy.cpp |
| 11 | +) |
| 12 | + |
| 13 | +set(RTVM_LINKER_LIBS "") |
| 14 | + |
| 15 | +if(WIN32) |
| 16 | + list(APPEND RTVM_SOURCES win32_process.cc) |
| 17 | + list(APPEND TVM_RUNNER_SOURCES win32_process.cc) |
| 18 | +endif() |
| 19 | + |
| 20 | +# Set output to same directory as the other TVM libs |
| 21 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 22 | +add_executable(rtvm ${RTVM_SOURCES}) |
| 23 | +add_library(tvm_runner_objs OBJECT ${TVM_RUNNER_SOURCES}) |
| 24 | +add_library(tvm_runner SHARED $<TARGET_OBJECTS:tvm_runner_objs>) |
| 25 | + |
| 26 | +include(CheckIPOSupported) |
| 27 | +check_ipo_supported(RESULT result OUTPUT output) |
| 28 | +if(result) |
| 29 | + set_property(TARGET rtvm PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) |
| 30 | +endif() |
| 31 | + |
| 32 | +if(WIN32) |
| 33 | + target_compile_definitions(rtvm PUBLIC -DNOMINMAX) |
| 34 | +endif() |
| 35 | + |
| 36 | +if (OS) |
| 37 | + if (OS STREQUAL "Linux") |
| 38 | + set_property(TARGET rtvm PROPERTY LINK_FLAGS -lpthread) |
| 39 | + set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -lpthread) |
| 40 | + endif() |
| 41 | +endif() |
| 42 | + |
| 43 | +if(USE_OPENCL) |
| 44 | + if (ANDROID_ABI) |
| 45 | + if(DEFINED ENV{ANDROID_NDK_MAJOR}) |
| 46 | + if($ENV{ANDROID_NDK_MAJOR} VERSION_LESS "23") |
| 47 | + set_property(TARGET rtvm PROPERTY LINK_FLAGS -fuse-ld=gold) |
| 48 | + set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -fuse-ld=gold) |
| 49 | + endif() |
| 50 | + endif() |
| 51 | + endif() |
| 52 | +endif() |
| 53 | + |
| 54 | +target_include_directories( |
| 55 | + rtvm |
| 56 | + PUBLIC "../../include" |
| 57 | + PUBLIC "../../3rdparty/cnpy" |
| 58 | + PUBLIC DLPACK_PATH |
| 59 | + PUBLIC DMLC_PATH |
| 60 | +) |
| 61 | + |
| 62 | +if (BUILD_FOR_ANDROID AND USE_HEXAGON) |
| 63 | + get_hexagon_sdk_property("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}" |
| 64 | + DSPRPC_LIB DSPRPC_LIB_DIRS |
| 65 | + ) |
| 66 | + if(DSPRPC_LIB_DIRS) |
| 67 | + link_directories(${DSPRPC_LIB_DIRS}) |
| 68 | + else() |
| 69 | + message(WARNING "Could not locate some Hexagon SDK components") |
| 70 | + endif() |
| 71 | + list(APPEND RTVM_LINKER_LIBS cdsprpc log) |
| 72 | +endif() |
| 73 | + |
| 74 | +if(USE_ETHOSN) |
| 75 | + if (ETHOSN_RUNTIME_LIBRARY) |
| 76 | + list(APPEND RTVM_LINKER_LIBS ${ETHOSN_RUNTIME_LIBRARY}) |
| 77 | + else() |
| 78 | + message(WARNING "Could not locate Arm(R) Ethos(TM)-N runtime library components") |
| 79 | + endif() |
| 80 | +endif() |
| 81 | + |
| 82 | +if(BUILD_STATIC_RUNTIME) |
| 83 | + list(APPEND RTVM_LINKER_LIBS -Wl,--whole-archive tvm_runtime -Wl,--no-whole-archive z) |
| 84 | +else() |
| 85 | + list(APPEND RTVM_LINKER_LIBS tvm_runtime z) |
| 86 | +endif() |
| 87 | + |
| 88 | +target_link_libraries(rtvm ${RTVM_LINKER_LIBS}) |
| 89 | + |
| 90 | +# Build tvm_runner as a exportable lib |
| 91 | +target_include_directories( |
| 92 | + tvm_runner_objs |
| 93 | + PUBLIC "../../include" |
| 94 | + PUBLIC "../../3rdparty/cnpy" |
| 95 | + PUBLIC DLPACK_PATH |
| 96 | + PUBLIC DMLC_PATH |
| 97 | +) |
| 98 | +target_link_libraries(tvm_runner ${RTVM_LINKER_LIBS}) |
0 commit comments