From b8c3051bad5d817a71ef560f5809b83d5e2698c6 Mon Sep 17 00:00:00 2001 From: Michael Vigovsky Date: Thu, 29 Jun 2023 20:05:05 +0300 Subject: [PATCH] Don't silently ignore errors in VkCompute::submit_and_wait --- src/gpu.cpp | 10 ++++++---- src/net.cpp | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/gpu.cpp b/src/gpu.cpp index a09a5f74453..c743d42c90b 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -1878,9 +1878,7 @@ int VulkanDevicePrivate::create_dummy_buffer_image() cmd.record_dummy_readonly(dummy_image_readonly); #endif - cmd.submit_and_wait(); - - return 0; + return cmd.submit_and_wait(); } void VulkanDevicePrivate::destroy_dummy_buffer_image() @@ -2289,7 +2287,11 @@ VulkanDevice::VulkanDevice(int device_index) } } - d->create_dummy_buffer_image(); + int cret = d->create_dummy_buffer_image(); + if (cret != 0) + { + NCNN_LOGE("VulkanDevice create_dummy_buffer_image failed %d", cret); + } d->pipeline_cache = new PipelineCache(this); diff --git a/src/net.cpp b/src/net.cpp index de4b7fa6608..8d4e234f75c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -162,9 +162,7 @@ int NetPrivate::upload_model() } } - cmd.submit_and_wait(); - - return 0; + return cmd.submit_and_wait(); } #endif // NCNN_VULKAN @@ -288,9 +286,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector& blob_mats, std: } } + int ret; if (cmd_submit_and_wait) { - cmd.submit_and_wait(); + ret = cmd.submit_and_wait(); #if NCNN_BENCHMARK std::vector results(layer_index * 2); @@ -308,9 +307,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector& blob_mats, std: #endif // NCNN_BENCHMARK cmd.reset(); + if (ret != 0) + return ret; } - int ret; if (layer->support_vulkan) { #if NCNN_BENCHMARK @@ -505,9 +505,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector& blob_mats, std: } } + int ret; if (cmd_submit_and_wait) { - cmd.submit_and_wait(); + ret = cmd.submit_and_wait(); #if NCNN_BENCHMARK std::vector results(layer_index * 2); @@ -525,9 +526,11 @@ int NetPrivate::forward_layer(int layer_index, std::vector& blob_mats, std: #endif // NCNN_BENCHMARK cmd.reset(); + + if (ret != 0) + return ret; } - int ret; if (layer->support_vulkan && !image_allocation_failed) { #if NCNN_BENCHMARK @@ -1827,9 +1830,9 @@ int Net::load_model(const DataReader& dr) } #if NCNN_VULKAN - if (opt.use_vulkan_compute) + if (ret == 0 && opt.use_vulkan_compute) { - d->upload_model(); + ret = d->upload_model(); } #endif // NCNN_VULKAN @@ -2506,11 +2509,11 @@ int Extractor::extract(int blob_index, Mat& feat, int type) VkImageMat feat_gpu; ret = extract(blob_index, feat_gpu, cmd); - if (d->blob_mats[blob_index].dims == 0 && feat_gpu.dims != 0) + if (ret == 0 && d->blob_mats[blob_index].dims == 0 && feat_gpu.dims != 0) { cmd.record_download(feat_gpu, d->blob_mats[blob_index], d->opt); - cmd.submit_and_wait(); + ret = cmd.submit_and_wait(); #if NCNN_BENCHMARK std::vector results(d->net->layers().size() * 2); @@ -2533,11 +2536,11 @@ int Extractor::extract(int blob_index, Mat& feat, int type) VkMat feat_gpu; ret = extract(blob_index, feat_gpu, cmd); - if (d->blob_mats[blob_index].dims == 0 && feat_gpu.dims != 0) + if (ret == 0 && d->blob_mats[blob_index].dims == 0 && feat_gpu.dims != 0) { cmd.record_download(feat_gpu, d->blob_mats[blob_index], d->opt); - cmd.submit_and_wait(); + ret = cmd.submit_and_wait(); #if NCNN_BENCHMARK std::vector results(d->net->layers().size() * 2);