本文主要是介绍ncnn - ubuntu调用vulkan加速ncnn是的CMakeLists.txt和bashrc配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
概述
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) (foundversion "")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_64export Vulkan_LIBRARY=/home/fwq/softs/1.2.182.0/x86_64/libexport Vulkan_INCLUDE_DIR=/home/fwq/softs/1.2.182.0/x86_64/includeexport vulkan_BIN=/home/fwq/softs/1.2.182.0/x86_64/binexport 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)
set(Vulkan_INCLUDE_DIR /home/fwq/softs/1.2.182.0/x86_64/include)
完整导入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配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!