2021-05-10 23:06:04 +08:00
|
|
|
message("src/tim/vx")
|
|
|
|
|
|
|
|
|
|
set(TARGET_NAME "tim-vx")
|
|
|
|
|
|
|
|
|
|
aux_source_directory(./vx VX_SRC)
|
|
|
|
|
aux_source_directory(./vx/ops OPS_SRC)
|
|
|
|
|
|
2022-03-28 09:42:19 +08:00
|
|
|
if(NOT ${TIM_VX_ENABLE_CUSTOM_OP})
|
|
|
|
|
list(REMOVE_ITEM OPS_SRC "./vx/ops/custom_base.cc")
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-10-12 10:44:49 +08:00
|
|
|
set(${TARGET_NAME}_SRCS)
|
2023-06-26 09:14:42 +08:00
|
|
|
set(LITE_INC_DIRS)
|
|
|
|
|
set(LITE_EXTERNAL_LIBS)
|
2021-10-12 10:44:49 +08:00
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
2021-05-10 23:06:04 +08:00
|
|
|
${VX_SRC}
|
2023-03-28 09:51:23 +08:00
|
|
|
${OPS_SRC})
|
2021-03-01 14:50:43 +08:00
|
|
|
|
2021-12-15 22:23:32 +08:00
|
|
|
if(${TIM_VX_USE_EXTERNAL_OVXLIB})
|
|
|
|
|
find_library(OVXLIB_LIB NAMES "ovxlib")
|
|
|
|
|
message(STATUS "Using external OVXLIB from ${OVXLIB_LIB}")
|
|
|
|
|
add_library(tim_internal SHARED IMPORTED)
|
|
|
|
|
set_target_properties(tim_internal PROPERTIES IMPORTED_LOCATION ${OVXLIB_LIB})
|
|
|
|
|
target_link_libraries(tim_internal INTERFACE ${OVXDRV_LIBRARIES})
|
|
|
|
|
else()
|
|
|
|
|
include(vx/internal/tim_internal.cmake)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-06-10 17:02:13 +08:00
|
|
|
if(${TIM_VX_USE_EXTERNAL_OVXLIB})
|
|
|
|
|
if(NOT OVXLIB_INC)
|
|
|
|
|
message(FATAL_ERROR "Set OVXLIB_INC if using external OVXLIB (TIM_VX_USE_EXTERNAL_OVXLIB)")
|
|
|
|
|
endif()
|
|
|
|
|
set(OVXLIB_INCLUDE_DIR ${OVXLIB_INC})
|
|
|
|
|
else()
|
|
|
|
|
set(OVXLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/tim/vx/internal/include")
|
2023-04-18 22:19:16 +08:00
|
|
|
list(APPEND OVXLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/tim/vx/internal/src")
|
2021-06-10 17:02:13 +08:00
|
|
|
endif()
|
|
|
|
|
message(STATUS "OVXLIB include directory: ${OVXLIB_INCLUDE_DIR}")
|
2021-05-10 23:06:04 +08:00
|
|
|
|
2021-05-17 13:04:45 +08:00
|
|
|
if(TIM_VX_ENABLE_LAYOUT_INFER)
|
2021-05-11 09:46:46 +08:00
|
|
|
aux_source_directory(./transform LAYOUT_INFER_FRAMEWORK_SRCS)
|
|
|
|
|
aux_source_directory(./transform/ops LAYOUT_INFER_OP_SRCS)
|
2021-05-10 23:06:04 +08:00
|
|
|
|
2021-10-12 10:44:49 +08:00
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
2021-05-10 23:06:04 +08:00
|
|
|
${LAYOUT_INFER_FRAMEWORK_SRCS}
|
2023-03-28 09:51:23 +08:00
|
|
|
${LAYOUT_INFER_OP_SRCS})
|
2021-05-10 23:06:04 +08:00
|
|
|
endif()
|
|
|
|
|
|
2022-04-06 13:05:38 +08:00
|
|
|
if(TIM_VX_ENABLE_PLATFORM)
|
2023-03-28 09:51:23 +08:00
|
|
|
message(STATUS "Using platform")
|
2022-04-06 13:05:38 +08:00
|
|
|
aux_source_directory(./vx/platform PLATFORM_SRC)
|
|
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
2023-03-28 09:51:23 +08:00
|
|
|
${PLATFORM_SRC})
|
|
|
|
|
|
|
|
|
|
if(${TIM_VX_ENABLE_PLATFORM_LITE})
|
|
|
|
|
message(STATUS "Using lite paltform")
|
|
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/vx/platform/lite/lite_native.cc)
|
|
|
|
|
if(NOT VIP_LITE_SDK)
|
|
|
|
|
message(FATAL_ERROR "Please set VIP_LITE_SDK when using lite platform(TIM_VX_ENABLE_PLATFORM_LITE)")
|
|
|
|
|
endif()
|
2023-06-26 09:14:42 +08:00
|
|
|
list(APPEND LITE_EXTERNAL_LIBS
|
2023-03-28 09:51:23 +08:00
|
|
|
${VIP_LITE_SDK}/drivers/libNBGlinker.so
|
|
|
|
|
${VIP_LITE_SDK}/drivers/libVIPlite.so)
|
2023-06-26 09:14:42 +08:00
|
|
|
list(APPEND LITE_INC_DIRS ${VIP_LITE_SDK}/include)
|
2023-03-28 09:51:23 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(TIM_VX_ENABLE_GRPC)
|
|
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/vx/platform/grpc/grpc_platform_client.cc"
|
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/vx/platform/grpc/grpc_remote.cc")
|
|
|
|
|
|
|
|
|
|
# Proto file
|
|
|
|
|
get_filename_component(gp_proto "${CMAKE_CURRENT_SOURCE_DIR}/vx/platform/grpc/grpc_platform.proto" ABSOLUTE)
|
|
|
|
|
get_filename_component(gp_proto_path "${gp_proto}" PATH)
|
|
|
|
|
|
|
|
|
|
# Generate sources
|
|
|
|
|
set(gp_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpc_platform.pb.cc")
|
|
|
|
|
set(gp_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpc_platform.pb.h")
|
|
|
|
|
set(gp_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpc_platform.grpc.pb.cc")
|
|
|
|
|
set(gp_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpc_platform.grpc.pb.h")
|
|
|
|
|
add_custom_command(
|
|
|
|
|
OUTPUT "${gp_proto_srcs}" "${gp_proto_hdrs}" "${gp_grpc_srcs}" "${gp_grpc_hdrs}"
|
|
|
|
|
COMMAND ${PROTOBUF_PROTOC}
|
|
|
|
|
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
|
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
|
-I "${gp_proto_path}"
|
|
|
|
|
--plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN_EXECUTABLE}"
|
|
|
|
|
"${gp_proto}"
|
|
|
|
|
DEPENDS "${gp_proto}")
|
|
|
|
|
|
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
|
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
|
|
|
|
${gp_grpc_srcs}
|
|
|
|
|
${gp_grpc_hdrs}
|
|
|
|
|
${gp_proto_srcs}
|
|
|
|
|
${gp_proto_hdrs})
|
|
|
|
|
endif()
|
2022-04-06 13:05:38 +08:00
|
|
|
endif()
|
|
|
|
|
|
2021-10-12 10:44:49 +08:00
|
|
|
foreach(src_file ${${TARGET_NAME}_SRCS})
|
2021-05-14 14:00:22 +08:00
|
|
|
if(${src_file} MATCHES ".*_test\.cc")
|
2021-10-12 10:44:49 +08:00
|
|
|
list(REMOVE_ITEM ${TARGET_NAME}_SRCS ${src_file})
|
|
|
|
|
list(APPEND ${TARGET_NAME}_TEST_SRCS ${src_file})
|
2021-05-14 14:00:22 +08:00
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2023-06-26 09:14:42 +08:00
|
|
|
list(APPEND LITE_INC_DIRS
|
2021-10-12 10:44:49 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/include
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/vx
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/transform
|
|
|
|
|
${OVXLIB_INCLUDE_DIR}
|
2023-03-28 09:51:23 +08:00
|
|
|
${OVXDRV_INCLUDE_DIRS})
|
2021-10-12 10:44:49 +08:00
|
|
|
|
2021-11-10 20:05:31 +08:00
|
|
|
if(${TIM_VX_ENABLE_VIPLITE})
|
|
|
|
|
aux_source_directory(./lite LITE_SRC)
|
|
|
|
|
list(APPEND ${TARGET_NAME}_SRCS
|
|
|
|
|
${LITE_SRC})
|
2023-06-26 09:14:42 +08:00
|
|
|
list(APPEND LITE_EXTERNAL_LIBS ${VIPLITE_DRV_LIBRARIES})
|
|
|
|
|
list(APPEND LITE_INC_DIRS
|
2021-11-10 20:05:31 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lite
|
2023-03-28 09:51:23 +08:00
|
|
|
${VIPLITE_DRV_INCLUDE_DIR})
|
2021-11-10 20:05:31 +08:00
|
|
|
endif()
|
2023-06-26 09:14:42 +08:00
|
|
|
include_directories(${LITE_INC_DIRS})
|
2022-09-01 18:56:49 +08:00
|
|
|
# convert op list as compile flags so that we can implement compile compatable easier
|
|
|
|
|
if(${TIM_VX_USE_EXTERNAL_OVXLIB})
|
|
|
|
|
file(STRINGS "${OVXLIB_INC}/interface/ops.def" ops_file_content)
|
2023-05-23 14:28:47 +08:00
|
|
|
file(STRINGS "${OVXLIB_INC}/custom/custom_ops.def" custom_ops_file_content)
|
2022-09-01 18:56:49 +08:00
|
|
|
else()
|
|
|
|
|
file(STRINGS "./vx/internal/include/interface/ops.def" ops_file_content)
|
2023-05-23 14:28:47 +08:00
|
|
|
file(STRINGS "./vx/internal/include/custom/custom_ops.def" custom_ops_file_content)
|
2022-09-01 18:56:49 +08:00
|
|
|
endif()
|
|
|
|
|
string(LENGTH "/*; Add new ops to the end.;*_/" comment_len)
|
|
|
|
|
string(SUBSTRING "${ops_file_content}" ${comment_len} -1 op_list_only)
|
|
|
|
|
string(REGEX REPLACE "DEF_OP\\(" "-DVSI_FEAT_OP_" op_list_tmp ${op_list_only})
|
|
|
|
|
string(REGEX REPLACE "\\)" " " op_as_flags ${op_list_tmp})
|
|
|
|
|
|
2023-05-23 14:28:47 +08:00
|
|
|
string(LENGTH "/*; Add custom ops to the end.;*_/" custom_comment_len)
|
|
|
|
|
string(SUBSTRING "${custom_ops_file_content}" ${custom_comment_len} -1 custom_op_list_only)
|
|
|
|
|
string(REGEX REPLACE "DEF_OP\\(" "-DVSI_FEAT_OP_" custom_op_list_tmp ${custom_op_list_only})
|
|
|
|
|
string(REGEX REPLACE "\\)" " " custom_op_as_flags ${custom_op_list_tmp})
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${op_as_flags} ${custom_op_as_flags}")
|
2022-09-01 18:56:49 +08:00
|
|
|
|
2021-11-10 20:05:31 +08:00
|
|
|
add_library(${TARGET_NAME} ${${TARGET_NAME}_SRCS})
|
2023-06-26 09:14:42 +08:00
|
|
|
target_include_directories(${TARGET_NAME} PRIVATE ${LITE_INC_DIRS})
|
2021-11-10 20:05:31 +08:00
|
|
|
target_link_libraries(${TARGET_NAME} PUBLIC
|
2023-06-26 09:14:42 +08:00
|
|
|
-Wl,--no-whole-archive ${OVXDRV_LIBRARIES} ${LITE_EXTERNAL_LIBS})
|
2021-11-10 20:05:31 +08:00
|
|
|
|
2023-04-19 21:31:25 +08:00
|
|
|
if(${TIM_VX_ENABLE_TENSOR_CACHE})
|
2023-05-05 23:38:39 +08:00
|
|
|
add_dependencies(${TARGET_NAME} crypto)
|
|
|
|
|
target_link_libraries(${TARGET_NAME} PUBLIC crypto)
|
2023-04-19 21:31:25 +08:00
|
|
|
endif()
|
|
|
|
|
|
2021-12-15 22:23:32 +08:00
|
|
|
if(${TIM_VX_USE_EXTERNAL_OVXLIB})
|
|
|
|
|
#-Wl,--whole-archive should not applied to external library, but only for shared library
|
2023-03-28 09:51:23 +08:00
|
|
|
target_link_libraries(${TARGET_NAME} PUBLIC tim_internal)
|
2021-12-15 22:23:32 +08:00
|
|
|
endif()
|
2021-05-10 23:06:04 +08:00
|
|
|
|
2023-03-28 09:51:23 +08:00
|
|
|
if(TIM_VX_ENABLE_PLATFORM AND TIM_VX_ENABLE_GRPC)
|
|
|
|
|
target_link_libraries(${TARGET_NAME} PUBLIC
|
|
|
|
|
${GRPCPP_REFLECTION}
|
|
|
|
|
${GRPC_GRPCPP}
|
|
|
|
|
${PROTOBUF_LIBPROTOBUF})
|
|
|
|
|
|
|
|
|
|
add_executable(grpc_platform_server
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/vx/platform/grpc/grpc_platform_server.cc)
|
|
|
|
|
target_link_libraries(grpc_platform_server -Wl,--whole-archive ${TARGET_NAME})
|
|
|
|
|
install(TARGETS grpc_platform_server grpc_platform_server
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
|
|
|
|
|
endif()
|
|
|
|
|
if(NOT CMAKE_INSTALL_LIBDIR)
|
2021-12-15 22:23:32 +08:00
|
|
|
set(CMAKE_INSTALL_LIBDIR "lib")
|
2021-11-24 15:18:29 +08:00
|
|
|
endif()
|
|
|
|
|
|
2023-03-28 09:51:23 +08:00
|
|
|
# Install
|
2021-12-15 22:23:32 +08:00
|
|
|
install(TARGETS ${TARGET_NAME} ${TARGET_NAME}
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
|
2023-06-26 09:14:42 +08:00
|
|
|
|
2023-05-23 14:28:47 +08:00
|
|
|
if(TIM_VX_ENABLE_TENSOR_CACHE)
|
2023-07-06 09:30:24 +08:00
|
|
|
file(GLOB OPENSSL_H ${openssl-cmake_BINARY_DIR}/usr/local/include/openssl/*.h)
|
2023-05-23 14:28:47 +08:00
|
|
|
install(
|
2023-07-06 09:30:24 +08:00
|
|
|
FILES ${OPENSSL_H}
|
2023-05-23 14:28:47 +08:00
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/openssl)
|
|
|
|
|
endif()
|
2023-03-28 09:51:23 +08:00
|
|
|
install(
|
|
|
|
|
FILES
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/builtin_op.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/compile_option.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/context.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/graph.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/operation.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/ops.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/tensor.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/types.h
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim/vx)
|
|
|
|
|
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/vx/ops
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim/vx)
|
|
|
|
|
|
|
|
|
|
if(TIM_VX_ENABLE_VIPLITE)
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/lite
|
2022-02-21 10:20:38 +08:00
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim)
|
2023-03-28 09:51:23 +08:00
|
|
|
endif()
|
2021-05-10 23:06:04 +08:00
|
|
|
|
2023-03-28 09:51:23 +08:00
|
|
|
if(TIM_VX_ENABLE_LAYOUT_INFER)
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/transform
|
2022-02-21 10:20:38 +08:00
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim)
|
2023-03-28 09:51:23 +08:00
|
|
|
endif()
|
2021-11-10 20:05:31 +08:00
|
|
|
|
2023-03-28 09:51:23 +08:00
|
|
|
if(TIM_VX_ENABLE_PLATFORM)
|
|
|
|
|
install(
|
|
|
|
|
FILES
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/platform/platform.h
|
|
|
|
|
${CMAKE_SOURCE_DIR}/include/tim/vx/platform/native.h
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim/vx/platform)
|
|
|
|
|
if(TIM_VX_ENABLE_PLATFORM_LITE)
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/vx/platform/lite
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim/vx/platform)
|
|
|
|
|
endif()
|
|
|
|
|
if(TIM_VX_ENABLE_GRPC)
|
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/vx/platform/grpc
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/tim/vx/platform)
|
|
|
|
|
endif()
|
2021-05-17 13:04:45 +08:00
|
|
|
endif()
|
|
|
|
|
|
2021-10-12 10:44:49 +08:00
|
|
|
if(TIM_VX_ENABLE_TEST)
|
2021-05-17 13:04:45 +08:00
|
|
|
include(GoogleTest)
|
|
|
|
|
|
2023-07-19 18:40:48 +08:00
|
|
|
if(TIM_VX_ENABLE_API_TRACE)
|
|
|
|
|
add_definitions("-DENABLE_API_TRACE")
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-10-12 10:44:49 +08:00
|
|
|
add_executable(unit_test ${${TARGET_NAME}_TEST_SRCS})
|
2023-03-28 09:51:23 +08:00
|
|
|
target_link_libraries(unit_test PRIVATE
|
|
|
|
|
-Wl,--whole-archive ${TARGET_NAME}
|
|
|
|
|
-Wl,--no-whole-archive gtest gtest_main gmock gmock_main ${OVXDRV_LIBRARIES})
|
2021-10-12 10:44:49 +08:00
|
|
|
target_include_directories(unit_test PRIVATE
|
|
|
|
|
${PROJECT_SOURCE_DIR}/include
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/vx
|
2022-03-09 12:10:08 +08:00
|
|
|
${OVXLIB_INCLUDE_DIR}
|
2023-07-19 18:40:48 +08:00
|
|
|
${LITE_INC_DIRS}
|
|
|
|
|
${PROJECT_SOURCE_DIR}
|
|
|
|
|
)
|
2021-05-17 13:04:45 +08:00
|
|
|
|
2021-12-15 22:23:32 +08:00
|
|
|
install(TARGETS unit_test DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
|
2021-05-11 13:44:32 +08:00
|
|
|
endif()
|
2021-03-01 14:50:43 +08:00
|
|
|
|
|
|
|
|
add_subdirectory("utils")
|