| @@ -20,7 +20,7 @@ | |||||
| namespace ncnn { | namespace ncnn { | ||||
| Command::Command(VulkanDevice* _vkdev, uint32_t _queue_index) : vkdev(_vkdev), queue_index(_queue_index) | |||||
| Command::Command(const VulkanDevice* _vkdev, uint32_t _queue_index) : vkdev(_vkdev), queue_index(_queue_index) | |||||
| { | { | ||||
| // get queue | // get queue | ||||
| vkGetDeviceQueue(vkdev->vkdevice(), queue_index, 0, &queue); | vkGetDeviceQueue(vkdev->vkdevice(), queue_index, 0, &queue); | ||||
| @@ -161,7 +161,7 @@ int Command::wait_fence() | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| VkCompute::VkCompute(VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.compute_queue_index) | |||||
| VkCompute::VkCompute(const VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.compute_queue_index) | |||||
| { | { | ||||
| if (vkdev->info.support_VK_KHR_push_descriptor) | if (vkdev->info.support_VK_KHR_push_descriptor) | ||||
| { | { | ||||
| @@ -701,7 +701,7 @@ void VkCompute::transfer_transfer_barrier(VkBuffer buffer, size_t offset, size_t | |||||
| vkCmdPipelineBarrier(command_buffer, srcStageMask, dstStageMask, 0, 0, 0, 1, &bufferBarrier, 0, 0); | vkCmdPipelineBarrier(command_buffer, srcStageMask, dstStageMask, 0, 0, 0, 1, &bufferBarrier, 0, 0); | ||||
| } | } | ||||
| VkTransfer::VkTransfer(VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.transfer_queue_index) | |||||
| VkTransfer::VkTransfer(const VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.transfer_queue_index) | |||||
| { | { | ||||
| buffer_offset_alignment = vkdev->info.buffer_offset_alignment; | buffer_offset_alignment = vkdev->info.buffer_offset_alignment; | ||||
| staging_data = 0; | staging_data = 0; | ||||
| @@ -29,7 +29,7 @@ namespace ncnn { | |||||
| class Command | class Command | ||||
| { | { | ||||
| public: | public: | ||||
| Command(VulkanDevice* vkdev, uint32_t queue_index); | |||||
| Command(const VulkanDevice* vkdev, uint32_t queue_index); | |||||
| ~Command(); | ~Command(); | ||||
| protected: | protected: | ||||
| @@ -43,7 +43,7 @@ protected: | |||||
| int wait_fence(); | int wait_fence(); | ||||
| protected: | protected: | ||||
| VulkanDevice* vkdev; | |||||
| const VulkanDevice* vkdev; | |||||
| uint32_t queue_index; | uint32_t queue_index; | ||||
| VkQueue queue; | VkQueue queue; | ||||
| @@ -57,7 +57,7 @@ protected: | |||||
| class VkCompute : public Command | class VkCompute : public Command | ||||
| { | { | ||||
| public: | public: | ||||
| VkCompute(VulkanDevice* vkdev); | |||||
| VkCompute(const VulkanDevice* vkdev); | |||||
| ~VkCompute(); | ~VkCompute(); | ||||
| void record_upload(const VkMat& m); | void record_upload(const VkMat& m); | ||||
| @@ -153,7 +153,7 @@ protected: | |||||
| class VkTransfer : public Command | class VkTransfer : public Command | ||||
| { | { | ||||
| public: | public: | ||||
| VkTransfer(VulkanDevice* vkdev); | |||||
| VkTransfer(const VulkanDevice* vkdev); | |||||
| ~VkTransfer(); | ~VkTransfer(); | ||||
| void record_upload(const Mat& src, VkMat& dst); | void record_upload(const Mat& src, VkMat& dst); | ||||
| @@ -30,7 +30,7 @@ Option::Option() | |||||
| workspace_allocator = 0; | workspace_allocator = 0; | ||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| vulkan_compute = true; | |||||
| vulkan_compute = false; | |||||
| blob_vkallocator = 0; | blob_vkallocator = 0; | ||||
| workspace_vkallocator = 0; | workspace_vkallocator = 0; | ||||
| staging_vkallocator = 0; | staging_vkallocator = 0; | ||||
| @@ -13,6 +13,7 @@ | |||||
| // specific language governing permissions and limitations under the License. | // specific language governing permissions and limitations under the License. | ||||
| #include "concat.h" | #include "concat.h" | ||||
| #include <algorithm> | |||||
| namespace ncnn { | namespace ncnn { | ||||
| @@ -44,6 +44,7 @@ Net::Net() | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| vkdev = 0; | vkdev = 0; | ||||
| vkdev_local = 0; | |||||
| weight_vkallocator = 0; | weight_vkallocator = 0; | ||||
| weight_staging_vkallocator = 0; | weight_staging_vkallocator = 0; | ||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -52,6 +53,10 @@ Net::Net() | |||||
| Net::~Net() | Net::~Net() | ||||
| { | { | ||||
| clear(); | clear(); | ||||
| #if NCNN_VULKAN | |||||
| delete vkdev_local; | |||||
| #endif // NCNN_VULKAN | |||||
| } | } | ||||
| #if NCNN_STRING | #if NCNN_STRING | ||||
| @@ -142,8 +147,10 @@ int Net::load_param(FILE* fp) | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| if (use_vulkan_compute && !vkdev) | if (use_vulkan_compute && !vkdev) | ||||
| { | { | ||||
| fprintf(stderr, "vulkan device not set, vulkan compute disabled\n"); | |||||
| use_vulkan_compute = false; | |||||
| // use default vulkan device | |||||
| if (!vkdev_local) | |||||
| vkdev_local = new VulkanDevice; | |||||
| vkdev = vkdev_local; | |||||
| } | } | ||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -311,8 +318,10 @@ int Net::load_param_mem(const char* _mem) | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| if (use_vulkan_compute && !vkdev) | if (use_vulkan_compute && !vkdev) | ||||
| { | { | ||||
| fprintf(stderr, "vulkan device not set, vulkan compute disabled\n"); | |||||
| use_vulkan_compute = false; | |||||
| // use default vulkan device | |||||
| if (!vkdev_local) | |||||
| vkdev_local = new VulkanDevice; | |||||
| vkdev = vkdev_local; | |||||
| } | } | ||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -483,8 +492,10 @@ int Net::load_param_bin(FILE* fp) | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| if (use_vulkan_compute && !vkdev) | if (use_vulkan_compute && !vkdev) | ||||
| { | { | ||||
| fprintf(stderr, "vulkan device not set, vulkan compute disabled\n"); | |||||
| use_vulkan_compute = false; | |||||
| // use default vulkan device | |||||
| if (!vkdev_local) | |||||
| vkdev_local = new VulkanDevice; | |||||
| vkdev = vkdev_local; | |||||
| } | } | ||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -720,8 +731,10 @@ int Net::load_param(const unsigned char* _mem) | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| if (use_vulkan_compute && !vkdev) | if (use_vulkan_compute && !vkdev) | ||||
| { | { | ||||
| fprintf(stderr, "vulkan device not set, vulkan compute disabled\n"); | |||||
| use_vulkan_compute = false; | |||||
| // use default vulkan device | |||||
| if (!vkdev_local) | |||||
| vkdev_local = new VulkanDevice; | |||||
| vkdev = vkdev_local; | |||||
| } | } | ||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -918,7 +931,7 @@ Extractor Net::create_extractor() const | |||||
| } | } | ||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| void Net::set_vulkan_device(VulkanDevice* _vkdev) | |||||
| void Net::set_vulkan_device(const VulkanDevice* _vkdev) | |||||
| { | { | ||||
| vkdev = _vkdev; | vkdev = _vkdev; | ||||
| } | } | ||||
| @@ -1592,6 +1605,8 @@ Extractor::Extractor(const Net* _net, int blob_count) : net(_net) | |||||
| opt = get_default_option(); | opt = get_default_option(); | ||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| opt.vulkan_compute = net->use_vulkan_compute; | |||||
| if (net->use_vulkan_compute) | if (net->use_vulkan_compute) | ||||
| { | { | ||||
| blob_mats_gpu.resize(blob_count); | blob_mats_gpu.resize(blob_count); | ||||
| @@ -106,7 +106,7 @@ public: | |||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| void set_vulkan_device(VulkanDevice* vkdev); | |||||
| void set_vulkan_device(const VulkanDevice* vkdev); | |||||
| #endif // NCNN_VULKAN | #endif // NCNN_VULKAN | ||||
| @@ -132,7 +132,8 @@ protected: | |||||
| std::vector<layer_registry_entry> custom_layer_registry; | std::vector<layer_registry_entry> custom_layer_registry; | ||||
| #if NCNN_VULKAN | #if NCNN_VULKAN | ||||
| VulkanDevice* vkdev; | |||||
| const VulkanDevice* vkdev; | |||||
| const VulkanDevice* vkdev_local; | |||||
| VkAllocator* weight_vkallocator; | VkAllocator* weight_vkallocator; | ||||
| VkAllocator* weight_staging_vkallocator; | VkAllocator* weight_staging_vkallocator; | ||||