diff --git a/src/command.cpp b/src/command.cpp index ba1d7a074..3aacef64f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -183,6 +183,9 @@ VkCompute::~VkCompute() void VkCompute::record_upload(const VkMat& m) { + if (m.allocator->mappable) + return; + record_prepare_transfer_barrier(m); if (vkdev->info.support_VK_KHR_push_descriptor) @@ -200,6 +203,9 @@ void VkCompute::record_upload(const VkMat& m) void VkCompute::record_download(const VkMat& m) { + if (m.allocator->mappable) + return; + record_prepare_transfer_barrier(m); if (vkdev->info.support_VK_KHR_push_descriptor) diff --git a/src/net.cpp b/src/net.cpp index d46237645..5da55951c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1308,17 +1308,10 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector VkMat& bottom_blob = blob_mats_gpu[bottom_blob_index]; bottom_blob.create_like(bottom_blob_cpu_packed, opt.blob_vkallocator, opt.staging_vkallocator); - if (!bottom_blob.allocator->mappable) - { - bottom_blob.prepare_staging_buffer(); - } - + bottom_blob.prepare_staging_buffer(); bottom_blob.upload(bottom_blob_cpu_packed); - if (!bottom_blob.allocator->mappable) - { - cmd.record_upload(bottom_blob); - } + cmd.record_upload(bottom_blob); // fprintf(stderr, "upload %d %d %d %d %lu %d\n", bottom_blob.total() * bottom_blob.elemsize, bottom_blob.w, bottom_blob.h, bottom_blob.c, bottom_blob.elemsize, bottom_blob.packing); } @@ -1415,17 +1408,10 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector VkMat& bottom_blob = blob_mats_gpu[bottom_blob_index]; bottom_blob.create_like(bottom_blob_cpu_packed, opt.blob_vkallocator, opt.staging_vkallocator); - if (!bottom_blob.allocator->mappable) - { - bottom_blob.prepare_staging_buffer(); - } - + bottom_blob.prepare_staging_buffer(); bottom_blob.upload(bottom_blob_cpu_packed); - if (!bottom_blob.allocator->mappable) - { - cmd.record_upload(bottom_blob); - } + cmd.record_upload(bottom_blob); // fprintf(stderr, "upload %d %d %d %d %lu %d\n", bottom_blob.total() * bottom_blob.elemsize, bottom_blob.w, bottom_blob.h, bottom_blob.c, bottom_blob.elemsize, bottom_blob.packing); } @@ -1535,11 +1521,8 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector // download VkMat& bottom_blob = blob_mats_gpu[bottom_blob_index]; - if (!bottom_blob.allocator->mappable) - { - bottom_blob.prepare_staging_buffer(); - cmd.record_download(bottom_blob); - } + bottom_blob.prepare_staging_buffer(); + cmd.record_download(bottom_blob); cmd.submit(); @@ -1551,10 +1534,7 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector bottom_blob_cpu_packed.create_like(bottom_blob, opt.blob_allocator); bottom_blob.download(bottom_blob_cpu_packed); - if (!bottom_blob.allocator->mappable) - { - bottom_blob.discard_staging_buffer(); - } + bottom_blob.discard_staging_buffer(); Mat& bottom_blob_cpu = blob_mats[bottom_blob_index]; convert_packing(bottom_blob_cpu_packed, bottom_blob_cpu, 1); @@ -1625,11 +1605,8 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector // download VkMat& bottom_blob = blob_mats_gpu[bottom_blob_index]; - if (!bottom_blob.allocator->mappable) - { - bottom_blob.prepare_staging_buffer(); - cmd.record_download(bottom_blob); - } + bottom_blob.prepare_staging_buffer(); + cmd.record_download(bottom_blob); } } } @@ -1655,10 +1632,7 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector bottom_blob_cpu_packed.create_like(bottom_blob, opt.blob_allocator); bottom_blob.download(bottom_blob_cpu_packed); - if (!bottom_blob.allocator->mappable) - { - bottom_blob.discard_staging_buffer(); - } + bottom_blob.discard_staging_buffer(); // TODO use gpu packing Mat& bottom_blob_cpu = blob_mats[bottom_blob_index]; @@ -1847,11 +1821,8 @@ int Extractor::extract(int blob_index, Mat& feat) if (blob_mats[blob_index].dims == 0 && feat_gpu.dims != 0) { // download - if (!feat_gpu.allocator->mappable) - { - feat_gpu.prepare_staging_buffer(); - cmd.record_download(feat_gpu); - } + feat_gpu.prepare_staging_buffer(); + cmd.record_download(feat_gpu); cmd.submit(); @@ -1861,10 +1832,7 @@ int Extractor::extract(int blob_index, Mat& feat) feat_cpu_packed.create_like(feat_gpu, opt.blob_allocator); feat_gpu.download(feat_cpu_packed); - if (!feat_gpu.allocator->mappable) - { - feat_gpu.discard_staging_buffer(); - } + feat_gpu.discard_staging_buffer(); // TODO use gpu packing Mat& feat_cpu = blob_mats[blob_index];