pc_win10_x64安装ncnn,并使用vulkan

只是简单记录,免得以后忘记

参考:

https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017

https://github.com/Tencent/ncnn/wiki/FAQ-ncnn-vulkan

https://github.com/Tencent/ncnn/wiki/vulkan-notes

 

编译器:vs2017

一、protobuf

1、下载protobuf https://github.com/google/protobuf/archive/v3.4.0.zip

2、使用vs2017编译器 Start → Programs → Visual Studio 2017 → Visual Studio Tools → x64 Native Tools Command Prompt for VS 2017

3、编译protobuf

> cd <protobuf-root-dir>

> mkdir build-vs2017

> cd build-vs2017

> cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake

> nmake

> nmake install

 

注意,此时编译的是Release版本,如需debug版本,需要将指令中的Release改为Debug

 

二、Vulkan

 

4、下载最新版本vulkan, https://vulkan.lunarg.com/sdk/home,目前最新版为 VulkanSDK-1.1.106.0-Installer.exe (465MB)

5、安装vulkan,并配置环境变量

Vulkan_INCLUDE_DIR  = C:\VulkanSDK\1.1.106.0\Include

Vulkan_LIBRARY  =  C:\VulkanSDK\1.1.106.0\Lib

VULKAN_SDK  =  C:\VulkanSDK\1.1.106.0

 

注意根据实际情况修改

 

6、更新intel显卡驱动到最新,在 我的电脑-属性-设备管理器-显示适配器  右键intel显卡然后更新 (这一步可能不需要)

7、安装vulkan_intel驱动,在https://downloadcenter.intel.com/zh-cn/product/80939/- 找到与本机相应的驱动

我的电脑使用的是 https://downloadcenter.intel.com/zh-cn/download/28816/Intel-Graphics-Windows-10-DCH-Drivers?product=80939   igfx_win10_100.6890.exe

安装vulkan_NVIDIA驱动 https://developer.nvidia.com/vulkan-driver

注意:调用vulkan需要 安装vulkan SDK,与显卡对应的vulkan驱动

 

三、ncnn

8、下载ncnn,我是从20190605的master下载的包

9,编译ncnn

> cd <ncnn-root-dir>

> mkdir -p build-vs2017

> cd build-vs2017

 

# cmake option NCNN_VULKAN for enabling vulkan

> cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=<protobuf-root-dir>/build-vs2017/install/include -DProtobuf_LIBRARIES=<protobuf-root-dir>/build-vs2017/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=<protobuf-root-dir>/build-vs2017/install/bin/protoc.exe -DNCNN_VULKAN=OFF ..

 

> nmake

> nmake install

 

注意,如果需要编译debug版本,需要将指令中的Release改为Debug,libprotobuf.lib改为libprotobufd.lib

如果要支持vulkan,需要将-DNCNN_VULKAN=OFF改为ON

 

四、在vs中使用ncnn与vulkan

 

此时ncnn与vulkan都编译,可以直接使用.lib、.h、.dll

10、使用vs工程调用vulkan,需要配置包含目录、库目录、链接器,分别指向vulkan安装时的Vulkan_INCLUDE_DIR、Vulkan_LIBRARY 、VULKAN_SDK 

11、配置ncnn的包含目录、库目录、链接器

12、开启vulkan

// initialize when app starts

ncnn::create_gpu_instance();// line1

 

// enable vulkan compute feature before loading

ncnn::Net net;

net.opt.use_vulkan_compute = 1;// line2

 

// deinitialize when app exits

ncnn::destroy_gpu_instance();// line3

 

13、指定使用某个GPU

// get gpu count

int gpu_count = ncnn::get_gpu_count();

 

ncnn::VulkanDevice vkdev; // use default gpu

ncnn::VulkanDevice vkdev(0); // use device-0

ncnn::VulkanDevice vkdev(1); // use device-1

 

// set specified vulkan device before loading param and model

net.set_vulkan_device(&vkdev);

 

 

经测试,处理某图像任务时,各设备速度为 cpu-i7-870 = 3.5ms/张,GPU-GTX1060 = 0.77ms/张 ,GPU-Intel-630 = 2.44ms/张

 

-----------END-----------

感谢nihui大神,感谢ncnn各位贡献者

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值