Browse Source

crop pack8 shader

tags/20200226
nihui 6 years ago
parent
commit
2b624686e6
3 changed files with 275 additions and 0 deletions
  1. +109
    -0
      src/layer/vulkan/shader/crop_pack4to8.comp
  2. +69
    -0
      src/layer/vulkan/shader/crop_pack8.comp
  3. +97
    -0
      src/layer/vulkan/shader/crop_pack8to4.comp

+ 109
- 0
src/layer/vulkan/shader/crop_pack4to8.comp View File

@@ -0,0 +1,109 @@
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

#version 450

#if NCNN_fp16_storage
#extension GL_EXT_shader_16bit_storage: require
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
#endif
#if NCNN_fp16_arithmetic
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
#endif

layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

#if NCNN_fp16_packed
layout (binding = 0) readonly buffer bottom_blob { sfpvec2 bottom_blob_data[]; };
#else
layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
#endif
layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };

layout (push_constant) uniform parameter
{
int dims;
int w;
int h;
int c;
int cstep;

int outdims;
int outw;
int outh;
int outc;
int outcstep;

int woffset;
int hoffset;
int coffset;
} p;

void main()
{
int gx = int(gl_GlobalInvocationID.x);
int gy = int(gl_GlobalInvocationID.y);
int gz = int(gl_GlobalInvocationID.z);

if (gx >= p.outw || gy >= p.outh || gz >= p.outc)
return;

int x = gx + p.woffset;
int y = gy + p.hoffset;
int z = gz * 8 + p.coffset;

ivec4 i4 = z * p.outh * p.outw + y * p.outw + x + ivec4(0, 1, 2, 3) * p.outh * p.outw;
ivec4 ii4 = i4 + 4 * p.outh * p.outw;;

int size = p.w * p.h;

ivec4 z4 = i4 / size;
ivec4 y4 = i4 % size / p.w;
ivec4 x4 = i4 % size % p.w;
ivec4 zz4 = ii4 / size;
ivec4 yy4 = ii4 % size / p.w;
ivec4 xx4 = ii4 % size % p.w;

#if NCNN_fp16_packed
ivec4 v_offset = ((z4 / 4) * p.cstep + y4 * p.w + x4) * 2 + (z4 % 4) / 2;
ivec4 lane2 = z4 % 2;
ivec4 vv_offset = ((zz4 / 4) * p.cstep + yy4 * p.w + xx4) * 2 + (zz4 % 4) / 2;
ivec4 lane4 = zz4 % 2;

afpvec2 vr = buffer_ld2(bottom_blob_data, v_offset.r);
afpvec2 vg = buffer_ld2(bottom_blob_data, v_offset.g);
afpvec2 vb = buffer_ld2(bottom_blob_data, v_offset.b);
afpvec2 va = buffer_ld2(bottom_blob_data, v_offset.a);

afpvec2 vvr = buffer_ld2(bottom_blob_data, vv_offset.r);
afpvec2 vvg = buffer_ld2(bottom_blob_data, vv_offset.g);
afpvec2 vvb = buffer_ld2(bottom_blob_data, vv_offset.b);
afpvec2 vva = buffer_ld2(bottom_blob_data, vv_offset.a);

afpvec8 v = afpvec8(vr[lane2.r], vg[lane2.g], vb[lane2.b], va[lane2.a], vvr[lane4.r], vvg[lane4.g], vvb[lane4.b], vva[lane4.a]);

int gi = gz * p.outcstep + gy * p.outw + gx;

buffer_st8(top_blob_data, gi, v);
#else
ivec4 v_offset = ((z4 / 4) * p.cstep + y4 * p.w + x4) * 4 + z4 % 4;
ivec4 vv_offset = ((zz4 / 4) * p.cstep + yy4 * p.w + xx4) * 4 + zz4 % 4;

int gi = gz * p.outcstep + gy * p.outw + gx;

buffer_cp1to8(top_blob_data, gi, bottom_blob_data, v_offset, vv_offset);
#endif
}

+ 69
- 0
src/layer/vulkan/shader/crop_pack8.comp View File

@@ -0,0 +1,69 @@
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

#version 450

#if NCNN_fp16_storage
#extension GL_EXT_shader_16bit_storage: require
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
#endif
#if NCNN_fp16_arithmetic
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
#endif

layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; };
layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };

layout (push_constant) uniform parameter
{
int dims;
int w;
int h;
int c;
int cstep;

int outdims;
int outw;
int outh;
int outc;
int outcstep;

int woffset;
int hoffset;
int coffset;
} p;

void main()
{
int gx = int(gl_GlobalInvocationID.x);
int gy = int(gl_GlobalInvocationID.y);
int gz = int(gl_GlobalInvocationID.z);

if (gx >= p.outw || gy >= p.outh || gz >= p.outc)
return;

const int gi = gz * p.outcstep + gy * p.outw + gx;

int x = gx + p.woffset;
int y = gy + p.hoffset;
int z = gz + p.coffset;

int v_offset = z * p.cstep + y * p.w + x;

buffer_cp8(top_blob_data, gi, bottom_blob_data, v_offset);
}

+ 97
- 0
src/layer/vulkan/shader/crop_pack8to4.comp View File

@@ -0,0 +1,97 @@
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

#version 450

#if NCNN_fp16_storage
#extension GL_EXT_shader_16bit_storage: require
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
#endif
#if NCNN_fp16_arithmetic
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
#endif

layout (local_size_x_id = 233) in;
layout (local_size_y_id = 234) in;
layout (local_size_z_id = 235) in;

#if NCNN_fp16_packed
layout (binding = 0) readonly buffer bottom_blob { sfpvec2 bottom_blob_data[]; };
#else
layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
#endif
layout (binding = 1) writeonly buffer top_blob { sfpvec4 top_blob_data[]; };

layout (push_constant) uniform parameter
{
int dims;
int w;
int h;
int c;
int cstep;

int outdims;
int outw;
int outh;
int outc;
int outcstep;

int woffset;
int hoffset;
int coffset;
} p;

void main()
{
int gx = int(gl_GlobalInvocationID.x);
int gy = int(gl_GlobalInvocationID.y);
int gz = int(gl_GlobalInvocationID.z);

if (gx >= p.outw || gy >= p.outh || gz >= p.outc)
return;

int x = gx + p.woffset;
int y = gy + p.hoffset;
int z = gz * 4 + p.coffset;

ivec4 i4 = z * p.outh * p.outw + y * p.outw + x + ivec4(0, 1, 2, 3) * p.outh * p.outw;

int size = p.w * p.h;

ivec4 z4 = i4 / size;
ivec4 y4 = i4 % size / p.w;
ivec4 x4 = i4 % size % p.w;

#if NCNN_fp16_packed
ivec4 v_offset = ((z4 / 8) * p.cstep + y4 * p.w + x4) * 4 + (z4 % 8) / 2;
ivec4 lane2 = z4 % 2;

afpvec2 vr = buffer_ld2(bottom_blob_data, v_offset.r);
afpvec2 vg = buffer_ld2(bottom_blob_data, v_offset.g);
afpvec2 vb = buffer_ld2(bottom_blob_data, v_offset.b);
afpvec2 va = buffer_ld2(bottom_blob_data, v_offset.a);

afpvec4 v = afpvec4(vr[lane2.r], vg[lane2.g], vb[lane2.b], va[lane2.a]);

int gi = gz * p.outcstep + gy * p.outw + gx;

buffer_st4(top_blob_data, gi, v);
#else
ivec4 v_offset = ((z4 / 8) * p.cstep + y4 * p.w + x4) * 8 + z4 % 8;

int gi = gz * p.outcstep + gy * p.outw + gx;

buffer_cp1to4(top_blob_data, gi, bottom_blob_data, v_offset);
#endif
}

Loading…
Cancel
Save