forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencv#21036 from fengyuentau:timvx_backend_support
dnn: TIM-VX NPU backend support * Add TimVX NPU backend for DNN module. * use official branch from tim-vx repo; fix detecting viv sdk Co-authored-by: fytao <[email protected]>
- Loading branch information
1 parent
9390c56
commit 7b582b7
Showing
37 changed files
with
2,982 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
set(TIMVX_COMMIT_HASH "1d9c7ab941b3d8d9c4d28d80058402725731e3d6") | ||
set(OCV_TIMVX_DIR "${OpenCV_BINARY_DIR}/3rdparty/libtim-vx") | ||
set(OCV_TIMVX_SOURCE_PATH "${OCV_TIMVX_DIR}/TIM-VX-${TIMVX_COMMIT_HASH}") | ||
|
||
# Download TIM-VX source code | ||
if(EXISTS "${OCV_TIMVX_SOURCE_PATH}") | ||
message(STATUS "TIM-VX: Use cache of TIM-VX source code at ${OCV_TIMVX_SOURCE_PATH}") | ||
set(TIMVX_FOUND ON) | ||
else() | ||
set(OCV_TIMVX_FILENAME "${TIMVX_COMMIT_HASH}.zip") | ||
set(OCV_TIMVX_URL "https://github.com/VeriSilicon/TIM-VX/archive/") | ||
set(timvx_zip_md5sum 92619cc4498014ac7a09834d5e33ebd5) | ||
|
||
ocv_download(FILENAME ${OCV_TIMVX_FILENAME} | ||
HASH ${timvx_zip_md5sum} | ||
URL "${OCV_TIMVX_URL}" | ||
DESTINATION_DIR "${OCV_TIMVX_DIR}" | ||
ID "TIM-VX" | ||
STATUS res | ||
UNPACK RELATIVE_URL) | ||
if(res) | ||
set(TIMVX_FOUND ON) | ||
message(STATUS "TIM-VX: Source code downloaded at ${OCV_TIMVX_SOURCE_PATH}.") | ||
else() | ||
set(TIMVX_FOUND OFF) | ||
message(STATUS "TIM-VX: Failed to download source code from github. Turning off TIMVX_FOUND") | ||
return() | ||
endif() | ||
endif() | ||
|
||
# set VIVANTE SDK especially for x86_64 which comes along with TIM-VX source code | ||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) | ||
set(VIVANTE_SDK_DIR "${OCV_TIMVX_SOURCE_PATH}/prebuilt-sdk/x86_64_linux") | ||
message(STATUS "TIM-VX: Build from source using prebuilt x86_64 VIVANTE SDK.") | ||
endif() | ||
|
||
# Verify if requested VIVANTE SDK libraries are all found | ||
find_vivante_sdk_libs(missing ${VIVANTE_SDK_DIR}) | ||
if(missing) | ||
message(STATUS "TIM-VX: Failed to find ${missing} in ${VIVANTE_SDK_DIR}/lib. Turning off TIMVX_VIV_FOUND") | ||
set(TIMVX_VIV_FOUND OFF) | ||
else() | ||
message(STATUS "TIM-VX: dependent VIVANTE SDK libraries are found at ${VIVANTE_SDK_DIR}/lib.") | ||
set(TIMVX_VIV_FOUND ON) | ||
endif() | ||
|
||
if(TIMVX_VIV_FOUND) | ||
# vars used by TIM-VX CMake scripts | ||
set(EXTERNAL_VIV_SDK "${VIVANTE_SDK_DIR}" CACHE INTERNAL "" FORCE) | ||
set(VIV_SDK_DRIVER_PREFIX "lib" CACHE INTERNAL "" FORCE) | ||
endif() | ||
|
||
if(TIMVX_FOUND AND TIMVX_VIV_FOUND) | ||
set(BUILD_TIMVX ON) | ||
else() | ||
return() | ||
endif() | ||
|
||
if(BUILD_TIMVX) | ||
set(HAVE_TIMVX 1) | ||
|
||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wstrict-prototypes -Wundef -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wstrict-aliasing -Wunused-but-set-variable -Wmaybe-uninitialized -Wshadow -Wsuggest-override -Wswitch) | ||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-parameter -Wstrict-prototypes -Wundef -Wsign-compare -Wunused-but-set-variable -Wshadow -Wsuggest-override -Wmissing-declarations -Wswitch) | ||
|
||
set(TIMVX_INC_DIR "${OCV_TIMVX_SOURCE_PATH}/include" CACHE INTERNAL "TIM-VX include directory") | ||
if(EXISTS "${OCV_TIMVX_SOURCE_PATH}/CMakeLists.txt") | ||
add_subdirectory("${OCV_TIMVX_SOURCE_PATH}" "${OCV_TIMVX_DIR}/build") | ||
else() | ||
message(WARNING "TIM-VX: Missing 'CMakeLists.txt' in the source code: ${OCV_TIMVX_SOURCE_PATH}") | ||
endif() | ||
ocv_install_target(tim-vx EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) | ||
set(TIMVX_LIB "tim-vx") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
set(TIMVX_INSTALL_DIR "" CACHE PATH "Path to libtim-vx installation") | ||
set(VIVANTE_SDK_DIR "" CACHE PATH "Path to VIVANTE SDK needed by TIM-VX.") | ||
set(VIVANTE_SDK_LIB_CANDIDATES "OpenVX;VSC;GAL;ArchModelSw;NNArchPerf" CACHE STRING "VIVANTE SDK library candidates") | ||
|
||
# Ensure VIVANTE SDK library candidates are present in given search path | ||
function(find_vivante_sdk_libs _viv_notfound _viv_search_path) | ||
foreach(one ${VIVANTE_SDK_LIB_CANDIDATES}) | ||
#NO_DEFAULT_PATH is used to ensure VIVANTE SDK libs are from one only source | ||
find_library(VIV_${one}_LIB ${one} PATHS "${_viv_search_path}/lib" NO_DEFAULT_PATH) | ||
if(NOT VIV_${one}_LIB) | ||
list(APPEND _viv_notfound_list ${one}) | ||
endif() | ||
endforeach() | ||
set(${_viv_notfound} ${_viv_notfound_list} PARENT_SCOPE) | ||
endfunction() | ||
# Default value for VIVANTE_SDK_DIR: /usr | ||
if(NOT VIVANTE_SDK_DIR) | ||
set(VIVANTE_SDK_DIR "/usr") | ||
endif() | ||
# Environment variable VIVANTE_SDK_DIR overrides the one in this script | ||
if(DEFINED ENV{VIVANTE_SDK_DIR}) | ||
set(VIVANTE_SDK_DIR $ENV{VIVANTE_SDK_DIR}) | ||
message(STATUS "TIM-VX: Load VIVANTE_SDK_DIR from system environment: ${VIVANTE_SDK_DIR}") | ||
endif() | ||
|
||
|
||
# Compile with pre-installed TIM-VX; Or compile together with TIM-VX from source | ||
if(TIMVX_INSTALL_DIR AND NOT BUILD_TIMVX) | ||
message(STATUS "TIM-VX: Use binaries at ${TIMVX_INSTALL_DIR}") | ||
set(BUILD_TIMVX OFF) | ||
|
||
set(TIMVX_INC_DIR "${TIMVX_INSTALL_DIR}/include" CACHE INTERNAL "TIM-VX include directory") | ||
find_library(TIMVX_LIB "tim-vx" PATHS "${TIMVX_INSTALL_DIR}/lib") | ||
if(TIMVX_LIB) | ||
set(TIMVX_FOUND ON) | ||
else() | ||
set(TIMVX_FOUND OFF) | ||
endif() | ||
|
||
# Verify if requested VIVANTE SDK libraries are all found | ||
find_vivante_sdk_libs(missing ${VIVANTE_SDK_DIR}) | ||
if(missing) | ||
message(STATUS "TIM-VX: Failed to find ${missing} in ${VIVANTE_SDK_DIR}/lib. Turning off TIMVX_VIV_FOUND") | ||
set(TIMVX_VIV_FOUND OFF) | ||
else() | ||
message(STATUS "TIM-VX: dependent VIVANTE SDK libraries are found at ${VIVANTE_SDK_DIR}/lib.") | ||
set(TIMVX_VIV_FOUND ON) | ||
endif() | ||
else() | ||
message(STATUS "TIM-VX: Build from source") | ||
include("${OpenCV_SOURCE_DIR}/3rdparty/libtim-vx/tim-vx.cmake") | ||
endif() | ||
|
||
if(TIMVX_FOUND AND TIMVX_VIV_FOUND) | ||
set(HAVE_TIMVX 1) | ||
|
||
message(STATUS "TIM-VX: Found TIM-VX includes: ${TIMVX_INC_DIR}") | ||
message(STATUS "TIM-VX: Found TIM-VX library: ${TIMVX_LIB}") | ||
set(TIMVX_LIBRARY ${TIMVX_LIB}) | ||
set(TIMVX_INCLUDE_DIR ${TIMVX_INC_DIR}) | ||
|
||
message(STATUS "TIM-VX: Found VIVANTE SDK libraries: ${VIVANTE_SDK_DIR}/lib") | ||
link_directories(${VIVANTE_SDK_DIR}/lib) | ||
endif() | ||
|
||
MARK_AS_ADVANCED( | ||
TIMVX_INC_DIR | ||
TIMVX_LIB | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.