Browse Source

one codepath for unified and discrete device

tags/20190320
nihuini 7 years ago
parent
commit
d3a11eb6c9
2 changed files with 19 additions and 45 deletions
  1. +6
    -0
      src/command.cpp
  2. +13
    -45
      src/net.cpp

+ 6
- 0
src/command.cpp View File

@@ -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)


+ 13
- 45
src/net.cpp View File

@@ -1308,17 +1308,10 @@ int Net::forward_layer(int layer_index, std::vector<Mat>& 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<Mat>& 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<Mat>& 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<Mat>& 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<Mat>& 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<Mat>& 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];


Loading…
Cancel
Save