Skip to content

Commit

Permalink
Don't silently ignore errors in VkCompute::submit_and_wait (#4828)
Browse files Browse the repository at this point in the history
  • Loading branch information
Upliner authored Jul 11, 2023
1 parent 810bfba commit e8645e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
10 changes: 6 additions & 4 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);

Expand Down
29 changes: 16 additions & 13 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ int NetPrivate::upload_model()
}
}

cmd.submit_and_wait();

return 0;
return cmd.submit_and_wait();
}
#endif // NCNN_VULKAN

Expand Down Expand Up @@ -288,9 +286,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std:
}
}

int ret;
if (cmd_submit_and_wait)
{
cmd.submit_and_wait();
ret = cmd.submit_and_wait();

#if NCNN_BENCHMARK
std::vector<uint64_t> results(layer_index * 2);
Expand All @@ -308,9 +307,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std:
#endif // NCNN_BENCHMARK

cmd.reset();
if (ret != 0)
return ret;
}

int ret;
if (layer->support_vulkan)
{
#if NCNN_BENCHMARK
Expand Down Expand Up @@ -505,9 +505,10 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std:
}
}

int ret;
if (cmd_submit_and_wait)
{
cmd.submit_and_wait();
ret = cmd.submit_and_wait();

#if NCNN_BENCHMARK
std::vector<uint64_t> results(layer_index * 2);
Expand All @@ -525,9 +526,11 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& 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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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<uint64_t> results(d->net->layers().size() * 2);
Expand All @@ -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<uint64_t> results(d->net->layers().size() * 2);
Expand Down

0 comments on commit e8645e9

Please sign in to comment.