ncnn使用vulkan来加速时,需要先安装vulkan,然后再使用vulkan来编译ncnn,最后才是使用编译好的ncnn来推理模型。。
这里的vulkan再Ubuntu中通常是直接解压安装,然后配置环境变量如下:
export VULKAN_SDK=/home/fwq/softs/1.2.182.0/x86_64
1.2.182.0 是我使用的vulkan版本。。
配置完上述路径后,source ~/.bashrc。
这时,编译ncnn 时 依赖 vulkan就成功通过了,但使用CMakeLists.txt 调用ncnn时报错:
CMake Error at /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Vulkan (missing: Vulkan_LIBRARY Vulkan_INCLUDE_DIR) (found
version "")
Call Stack (most recent call first):
/usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.23/Modules/FindVulkan.cmake:159 (find_package_handle_standard_args)
/home/fwq/ncnn/lib/cmake/ncnn/ncnnConfig.cmake:18 (find_package)
添加环境变量配置:
##vulkan
export VULKAN_SDK=/home/fwq/softs/1.2.182.0/x86_64
export Vulkan_LIBRARY=/home/fwq/softs/1.2.182.0/x86_64/lib
export Vulkan_INCLUDE_DIR=/home/fwq/softs/1.2.182.0/x86_64/include
export vulkan_BIN=/home/fwq/softs/1.2.182.0/x86_64/bin
export PATH=$PATH:$Vulkan_LIBRARY:$Vulkan_INCLUDE_DIR:$vulkan_BIN
然后重新导入CMakeLIsts.txt,但还是失败
这个解决1中的并没有注释-- 后续可以测试一下,注释过后有没有影响
在CMakeLists.txt中添加:
set(Vulkan_LIBRARY /home/fwq/softs/1.2.182.0/x86_64/lib)
set(Vulkan_INCLUDE_DIR /home/fwq/softs/1.2.182.0/x86_64/include)
set(Vulkan_LIBRARY /home/fwq/softs/1.2.182.0/x86_64/lib)
set(Vulkan_INCLUDE_DIR /home/fwq/softs/1.2.182.0/x86_64/include)set(ncnn_DIR "/home/fwq/ncnn/lib/cmake/ncnn")
set(ncnn_INCLUDE_DIRS /home/fwq/ncnn/include)
find_package(ncnn REQUIRED)
# 添加openmp的编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
link_directories(
${ncnn_INCLUDE_DIRS}
)
add_library(yolov5lite_ncnn SHARED ${yolov5lite_ncnn_cpp})
target_link_libraries(yolov5lite_ncnn
${OpenCV_LIBS}
ncnn
)
target_include_directories(yolov5lite_ncnn PUBLIC
${CMAKE_SOURCE_DIR}/3rdpart
${CMAKE_SOURCE_DIR}/3rdpart/ncnn_include
${CMAKE_CURRENT_LIST_DIR}/Export
${CMAKE_CURRENT_LIST_DIR}/Include
)张无门槛流量券(+1000曝光),0点自动发