You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

vulkan-driver-loader.md 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # ncnn vulkan driver loader
  2. ncnn turns on the ```NCNN_SIMPLEVK``` cmake option by default, when ```NCNN_VULKAN``` is enabled
  3. simplevk is ncnn's built-in vulkan loader. It provides vulkan function declarations and function entries that meet ncnn's needs. It allows the use and compilation of vulkan-related codes without relying on vulkan-sdk. It can dynamically load the vulkan runtime library at runtime or directly load the graphics card driver. vulkan driver. When distributing ncnn applications, it is not required that the target system has a vulkan driver.
  4. Usually you don't need to care about how simplevk loads the vulkan driver, because ncnn will automatically load and initialize when using vulkan related functions. It is sufficient to set the `Option` switch before loading the model.
  5. Typical code
  6. ```cpp
  7. ncnn::Net net;
  8. net.opt.use_vulkan_compute = true;
  9. net.load_param("model.param");
  10. net.load_param("model.bin");
  11. ```
  12. Using the in-house vulkan loader instead of the standard libvulkan has the following benefits
  13. - Can compile ncnn vulkan code without installing vulkan-sdk
  14. - Can deploy and distribute applications without libvulkan linkage
  15. - Can load external vulkan driver instead of system driver
  16. - Can directly load android hal module
  17. - Can directly load graphics card driver files via NCNN_VULKAN_DRIVER env
  18. - Able to actively search for graphics card driver files in the system and load them
  19. - Can compile android libraries supporting vulkan under the platform of android-api<24
  20. ## Create and manage gpu context
  21. ```cpp
  22. int create_gpu_instance(const char* driver_path = 0);
  23. void destroy_gpu_instance();
  24. VkInstance get_gpu_instance();
  25. ```
  26. ## Loading order
  27. ```
  28. If driver_path == 0
  29. 1a from env ```VK_ICD_FILENAMES```
  30. 1b from env ```NCNN_VULKAN_DRIVER```
  31. If driver_path != 0
  32. 1 from specified driver_path
  33. 2 from vulkan-1.dll / libvulkan.so / libvulkan.dylib in system
  34. 3 search driver by name nvoglv64.dll / amdvlk64.dll / libGLX_nvidia.so.0 .... and load it
  35. ```
  36. ## Load from system vulkan library or graphics driver
  37. This is the default behavior and it should work on most systems
  38. sample usage
  39. ```cpp
  40. int ret = create_gpu_instance();
  41. ```
  42. Load from system-installed libvulkan
  43. #### Windows
  44. vulkan-1.dll
  45. #### Linux Android
  46. libvulkan.so
  47. #### macOS iOS and other APPLE platforms
  48. Requires static meltvk driver linking and should always succeed
  49. If failed, it will try to find graphics driver object and load it
  50. #### Windows
  51. for 64bit applications. search in ```%SystemRoot%\System32\DriverStore\FileRepository```
  52. - nvoglv64.dll
  53. - amdvlk64.dll
  54. - igvk64.dll
  55. for 32bit applications. search in ```%SystemRoot%\System32\DriverStore\FileRepository```
  56. - nvoglv32.dll
  57. - amdvlk32.dll
  58. - igvk32.dll
  59. #### Linux
  60. `dlopen()` search for
  61. - libGLX_nvidia.so.0
  62. - libvulkan_radeon.so
  63. - libvulkan_intel.so
  64. - libMaliVulkan.so.1
  65. - libVK_IMG.so
  66. #### Android
  67. for 64bit applications
  68. - /vendor/lib64/hw/vulkan.adreno.so
  69. - /vendor/lib64/egl/libGLES_mali.so
  70. for 32bit applications
  71. - /vendor/lib/hw/vulkan.adreno.so
  72. - /vendor/lib/egl/libGLES_mali.so
  73. ## Load from driver_path
  74. for advanced developer
  75. sample usage
  76. ```cpp
  77. int ret = create_gpu_instance("libvulkan.so");
  78. int ret = create_gpu_instance("/usr/lib64/libvulkan_radeon.so");
  79. int ret = create_gpu_instance("/vendor/lib64/hw/vulkan.adreno.so");
  80. int ret = create_gpu_instance("/data/local/tmp/vulkan.ad07XX.so");
  81. ```
  82. ## Load from env VK_ICD_FILENAMES
  83. for debug purpose
  84. sample usage
  85. ```sh
  86. export VK_ICD_FILENAMES=./vk_swiftshader_icd.json
  87. export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json
  88. export VK_ICD_FILENAMES=/etc/vulkan/icd.d/nvidia_icd.json
  89. ```
  90. ## Load from env NCNN_VULKAN_DRIVER
  91. for debug purpose
  92. sample usage
  93. ```sh
  94. export NCNN_VULKAN_DRIVER=/data/local/tmp/vulkan.ad07XX.so
  95. ```