ncnn

Форк
0
/
innerproduct_reduce_sum8_pack8.comp 
102 строки · 2.9 Кб
1
// Tencent is pleased to support the open source community by making ncnn available.
2
//
3
// Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
4
//
5
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
7
//
8
// https://opensource.org/licenses/BSD-3-Clause
9
//
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
14

15
#version 450
16

17
#if NCNN_fp16_storage
18
#extension GL_EXT_shader_16bit_storage: require
19
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
20
#endif
21
#if NCNN_fp16_arithmetic
22
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
23
#endif
24

25
#extension GL_GOOGLE_include_directive: enable
26
#include "vulkan_activation.comp"
27

28
layout (constant_id = 0) const int bias_term = 0;
29
layout (constant_id = 1) const int activation_type = 0;
30
layout (constant_id = 2) const float activation_param_0 = 0;
31
layout (constant_id = 3) const float activation_param_1 = 0;
32

33
#define shape_constant_id_offset 4
34
layout (constant_id = shape_constant_id_offset + 0) const int w = 0;
35
layout (constant_id = shape_constant_id_offset + 1) const int h = 0;
36

37
layout (constant_id = shape_constant_id_offset + 2) const int outw = 0;
38

39
#if NCNN_image_shader
40
layout (binding = 0) uniform unfp sampler3D bottom_blob;
41
layout (binding = 1, imfmtc4) writeonly uniform unfp image3D top_blob;
42
layout (binding = 2) uniform unfp sampler3D bias_blob;
43
#else
44
layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; };
45
layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };
46
layout (binding = 2) readonly buffer bias_blob { sfpvec8 bias_data[]; };
47
#endif
48

49
layout (push_constant) uniform parameter
50
{
51
    int w;
52
    int h;
53

54
    int outw;
55
} p;
56

57
void main()
58
{
59
    int gx = int(gl_GlobalInvocationID.x);
60
    int gy = int(gl_GlobalInvocationID.y);
61
    int gz = int(gl_GlobalInvocationID.z);
62

63
    if (gx >= psc(outw) || gy >= 1 || gz >= 1)
64
        return;
65

66
    afpvec8 sum;
67

68
    if (bias_term == 1)
69
    {
70
#if NCNN_image_shader
71
        sum = image3d_ld8(bias_blob, ivec3(gx, 0, 0));
72
#else
73
        sum = buffer_ld8(bias_data, gx);
74
#endif
75
    }
76
    else
77
    {
78
        sum = afpvec8(afpvec4(0.f), afpvec4(0.f));
79
    }
80

81
#if NCNN_image_shader
82
    for (int i = 0; i < psc(w); i++)
83
    {
84
        sum += image3d_ld8(bottom_blob, ivec3(i, gx, 0));
85
    }
86
#else
87
    int v_offset = gx * psc(w);
88

89
    for (int i = 0; i < psc(w); i++)
90
    {
91
        sum += buffer_ld8(bottom_blob_data, v_offset + i);
92
    }
93
#endif
94

95
    sum = activation_afpvec8(sum, activation_type, activation_param_0, activation_param_1);
96

97
#if NCNN_image_shader
98
    image3d_st8(top_blob, ivec3(gx, 0, 0), sum);
99
#else
100
    buffer_st8(top_blob_data, gx, sum);
101
#endif
102
}
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.