Merge pull request #12703 from wzw-intel:vkcom
authorWuZhiwen <zhiwen.wu@intel.com>
Mon, 29 Oct 2018 14:51:26 +0000 (14:51 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 29 Oct 2018 14:51:26 +0000 (17:51 +0300)
commit6e3ea8b49db4c750f3ea0ae5080ccca3a3af6a58
tree98f0871251d80233b73c9023d2bd0ca835eea7aa
parent220b278575e59cb11dc5f9994f5ce1644a3a39cb
Merge pull request #12703 from wzw-intel:vkcom

* dnn: Add a Vulkan based backend

This commit adds a new backend "DNN_BACKEND_VKCOM" and a
new target "DNN_TARGET_VULKAN". VKCOM means vulkan based
computation library.

This backend uses Vulkan API and SPIR-V shaders to do
the inference computation for layers. The layer types
that implemented in DNN_BACKEND_VKCOM include:
Conv, Concat, ReLU, LRN, PriorBox, Softmax, MaxPooling,
AvePooling, Permute

This is just a beginning work for Vulkan in OpenCV DNN,
more layer types will be supported and performance
tuning is on the way.

Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com>
* dnn/vulkan: Add FindVulkan.cmake to detect Vulkan SDK

In order to build dnn with Vulkan support, need installing
Vulkan SDK and setting environment variable "VULKAN_SDK" and
add "-DWITH_VULKAN=ON" to cmake command.

You can download Vulkan SDK from:
https://vulkan.lunarg.com/sdk/home#linux

For how to install, see
https://vulkan.lunarg.com/doc/sdk/latest/linux/getting_started.html
https://vulkan.lunarg.com/doc/sdk/latest/windows/getting_started.html
https://vulkan.lunarg.com/doc/sdk/latest/mac/getting_started.html
respectively for linux, windows and mac.

To run the vulkan backend, also need installing mesa driver.
On Ubuntu, use this command 'sudo apt-get install mesa-vulkan-drivers'

To test, use command '$BUILD_DIR/bin/opencv_test_dnn --gtest_filter=*VkCom*'

Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com>
* dnn/Vulkan: dynamically load Vulkan runtime

No compile-time dependency on Vulkan library.
If Vulkan runtime is unavailable, fallback to CPU path.

Use environment "OPENCL_VULKAN_RUNTIME" to specify path to your
own vulkan runtime library.

Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com>
* dnn/Vulkan: Add a python script to compile GLSL shaders to SPIR-V shaders

The SPIR-V shaders are in format of text-based 32-bit hexadecimal
numbers, and inserted into .cpp files as unsigned int32 array.

* dnn/Vulkan: Put Vulkan headers into 3rdparty directory and some other fixes

Vulkan header files are copied from
https://github.com/KhronosGroup/Vulkan-Docs/tree/master/include/vulkan
to 3rdparty/include

Fix the Copyright declaration issue.

Refine OpenCVDetectVulkan.cmake

* dnn/Vulkan: Add vulkan backend tests into existing ones.

Also fixed some test failures.

- Don't use bool variable as uniform for shader
- Fix dispathed group number beyond max issue
- Bypass "group > 1" convolution. This should be support in future.

* dnn/Vulkan: Fix multiple initialization in one thread.
89 files changed:
3rdparty/include/vulkan/vk_platform.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_android.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_core.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_fuchsia.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_ios.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_macos.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_mir.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_vi.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_wayland.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_win32.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_xcb.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_xlib.h [new file with mode: 0644]
3rdparty/include/vulkan/vulkan_xlib_xrandr.h [new file with mode: 0644]
CMakeLists.txt
cmake/FindVulkan.cmake [new file with mode: 0644]
cmake/OpenCVDetectVulkan.cmake [new file with mode: 0644]
cmake/checks/vulkan.cpp [new file with mode: 0644]
cmake/templates/cvconfig.h.in
modules/dnn/include/opencv2/dnn/dnn.hpp
modules/dnn/src/dnn.cpp
modules/dnn/src/layers/concat_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
modules/dnn/src/layers/elementwise_layers.cpp
modules/dnn/src/layers/lrn_layer.cpp
modules/dnn/src/layers/permute_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
modules/dnn/src/layers/prior_box_layer.cpp
modules/dnn/src/layers/softmax_layer.cpp
modules/dnn/src/op_vkcom.cpp [new file with mode: 0644]
modules/dnn/src/op_vkcom.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/buffer.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_base.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_concat.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_conv.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_lrn.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_permute.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_pool.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_prior_box.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_relu.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/op_softmax.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/tensor.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/include/vkcom.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/avg_pool.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/avg_pool_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/concat.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/concat_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/conv.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/conv_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/dw_conv.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/dw_conv_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/lrn.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/lrn_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/max_pool.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/max_pool_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/permute.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/permute_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/prior_box.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/prior_box_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/relu.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/relu_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/softmax.comp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/softmax_spv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/shader/spirv_generator.py [new file with mode: 0644]
modules/dnn/src/vkcom/shader/spv_shader.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/buffer.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/common.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/context.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/internal.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/internal.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_base.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_concat.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_conv.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_lrn.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_permute.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_pool.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_prior_box.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_relu.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/op_softmax.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/tensor.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/src/vkcom.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/vulkan/function_list.inl [new file with mode: 0644]
modules/dnn/src/vkcom/vulkan/vk_functions.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/vulkan/vk_functions.hpp [new file with mode: 0644]
modules/dnn/src/vkcom/vulkan/vk_loader.cpp [new file with mode: 0644]
modules/dnn/src/vkcom/vulkan/vk_loader.hpp [new file with mode: 0644]
modules/dnn/test/test_backends.cpp
modules/dnn/test/test_common.hpp
modules/dnn/test/test_misc.cpp