概述
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)
解决1(失败)
添加环境变量配置:
##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,但还是失败
解决2(成功)
这个解决1中的并没有注释-- 后续可以测试一下,注释过后有没有影响
在CMakeLists.txt中添加:
set(Vulkan_LIBRARY /home/fwq/softs/1.2.182.0/x86_64/lib)文章来源:https://www.toymoban.com/news/detail-818355.html
set(Vulkan_INCLUDE_DIR /home/fwq/softs/1.2.182.0/x86_64/include)文章来源地址https://www.toymoban.com/news/detail-818355.html
完整导入ncnn的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(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点自动发
到了这里,关于ncnn - ubuntu调用vulkan加速ncnn是的CMakeLists.txt和bashrc配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!