Browse Source

deepcopy image shader

tags/20200616
nihuini 6 years ago
parent
commit
ed7bca6de0
5 changed files with 102 additions and 0 deletions
  1. +29
    -0
      src/layer/vulkan/deepcopy_vulkan.cpp
  2. +1
    -0
      src/layer/vulkan/deepcopy_vulkan.h
  3. +24
    -0
      src/layer/vulkan/shader/deepcopy.comp
  4. +24
    -0
      src/layer/vulkan/shader/deepcopy_pack4.comp
  5. +24
    -0
      src/layer/vulkan/shader/deepcopy_pack8.comp

+ 29
- 0
src/layer/vulkan/deepcopy_vulkan.cpp View File

@@ -23,6 +23,7 @@ DEFINE_LAYER_CREATOR(DeepCopy_vulkan)
DeepCopy_vulkan::DeepCopy_vulkan()
{
support_vulkan = true;
support_image_storage = true;

pipeline_deepcopy = 0;
pipeline_deepcopy_pack4 = 0;
@@ -168,4 +169,32 @@ int DeepCopy_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkComput
return 0;
}

int DeepCopy_vulkan::forward(const VkImageMat& bottom_blob, VkImageMat& top_blob, VkCompute& cmd, const Option& opt) const
{
int elempack = bottom_blob.elempack;

top_blob.create_like(bottom_blob, opt.blob_vkallocator);
if (top_blob.empty())
return -100;

std::vector<VkImageMat> bindings(2);
bindings[0] = bottom_blob;
bindings[1] = top_blob;

std::vector<vk_constant_type> constants(5);
constants[0].i = bottom_blob.dims;
constants[1].i = bottom_blob.w;
constants[2].i = bottom_blob.h;
constants[3].i = bottom_blob.c;
constants[4].i = 0;//bottom_blob.cstep;

const Pipeline* pipeline = elempack == 8 ? pipeline_deepcopy_pack8
: elempack == 4 ? pipeline_deepcopy_pack4
: pipeline_deepcopy;

cmd.record_pipeline(pipeline, bindings, constants, top_blob);

return 0;
}

} // namespace ncnn

+ 1
- 0
src/layer/vulkan/deepcopy_vulkan.h View File

@@ -29,6 +29,7 @@ public:

using DeepCopy::forward;
virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
virtual int forward(const VkImageMat& bottom_blob, VkImageMat& top_blob, VkCompute& cmd, const Option& opt) const;

public:
Pipeline* pipeline_deepcopy;


+ 24
- 0
src/layer/vulkan/shader/deepcopy.comp View File

@@ -32,8 +32,17 @@ layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

#if NCNN_image_shader
layout (binding = 0) uniform unfp sampler1D bottom_blob_1d;
layout (binding = 0) uniform unfp sampler2D bottom_blob_2d;
layout (binding = 0) uniform unfp sampler3D bottom_blob_3d;
layout (binding = 1, imfmtc1) writeonly uniform unfp image1D top_blob_1d;
layout (binding = 1, imfmtc1) writeonly uniform unfp image2D top_blob_2d;
layout (binding = 1, imfmtc1) writeonly uniform unfp image3D top_blob_3d;
#else
layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; };
#endif

layout (push_constant) uniform parameter
{
@@ -53,7 +62,22 @@ void main()
if (gx >= psc(w) || gy >= psc(h) || gz >= psc(c))
return;

#if NCNN_image_shader
if (psc(dims) == 1)
{
image1d_cp1(top_blob_1d, gx, bottom_blob_1d, gx);
}
else if (psc(dims) == 2)
{
image2d_cp1(top_blob_2d, ivec2(gx, gy), bottom_blob_2d, ivec2(gx, gy));
}
else // if (psc(dims) == 3)
{
image3d_cp1(top_blob_3d, ivec3(gx, gy, gz), bottom_blob_3d, ivec3(gx, gy, gz));
}
#else
const int gi = gz * psc(cstep) + gy * psc(w) + gx;

buffer_cp1(top_blob_data, gi, bottom_blob_data, gi);
#endif
}

+ 24
- 0
src/layer/vulkan/shader/deepcopy_pack4.comp View File

@@ -32,8 +32,17 @@ layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

#if NCNN_image_shader
layout (binding = 0) uniform unfp sampler1D bottom_blob_1d;
layout (binding = 0) uniform unfp sampler2D bottom_blob_2d;
layout (binding = 0) uniform unfp sampler3D bottom_blob_3d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image1D top_blob_1d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image2D top_blob_2d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image3D top_blob_3d;
#else
layout (binding = 0) readonly buffer bottom_blob { sfpvec4 bottom_blob_data[]; };
layout (binding = 1) writeonly buffer top_blob { sfpvec4 top_blob_data[]; };
#endif

layout (push_constant) uniform parameter
{
@@ -53,7 +62,22 @@ void main()
if (gx >= psc(w) || gy >= psc(h) || gz >= psc(c))
return;

#if NCNN_image_shader
if (psc(dims) == 1)
{
image1d_cp4(top_blob_1d, gx, bottom_blob_1d, gx);
}
else if (psc(dims) == 2)
{
image2d_cp4(top_blob_2d, ivec2(gx, gy), bottom_blob_2d, ivec2(gx, gy));
}
else // if (psc(dims) == 3)
{
image3d_cp4(top_blob_3d, ivec3(gx, gy, gz), bottom_blob_3d, ivec3(gx, gy, gz));
}
#else
const int gi = gz * psc(cstep) + gy * psc(w) + gx;

buffer_cp4(top_blob_data, gi, bottom_blob_data, gi);
#endif
}

+ 24
- 0
src/layer/vulkan/shader/deepcopy_pack8.comp View File

@@ -33,8 +33,17 @@ layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

#if NCNN_image_shader
layout (binding = 0) uniform unfp sampler1D bottom_blob_1d;
layout (binding = 0) uniform unfp sampler2D bottom_blob_2d;
layout (binding = 0) uniform unfp sampler3D bottom_blob_3d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image1D top_blob_1d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image2D top_blob_2d;
layout (binding = 1, imfmtc4) writeonly uniform unfp image3D top_blob_3d;
#else
layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; };
layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };
#endif

layout (push_constant) uniform parameter
{
@@ -54,7 +63,22 @@ void main()
if (gx >= psc(w) || gy >= psc(h) || gz >= psc(c))
return;

#if NCNN_image_shader
if (psc(dims) == 1)
{
image1d_cp8(top_blob_1d, gx, bottom_blob_1d, gx);
}
else if (psc(dims) == 2)
{
image2d_cp8(top_blob_2d, ivec2(gx, gy), bottom_blob_2d, ivec2(gx, gy));
}
else // if (psc(dims) == 3)
{
image3d_cp8(top_blob_3d, ivec3(gx, gy, gz), bottom_blob_3d, ivec3(gx, gy, gz));
}
#else
const int gi = gz * psc(cstep) + gy * psc(w) + gx;

buffer_cp8(top_blob_data, gi, bottom_blob_data, gi);
#endif
}

Loading…
Cancel
Save