20
20
21
21
#define op(X, A, B) ${OPERATOR}
22
22
23
- #include "indexing_utils_u16 .h"
23
+ #include "indexing_utils .h"
24
24
25
25
layout (std430) buffer ;
26
26
@@ -43,35 +43,34 @@ layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
43
43
* output at a single output location.
44
44
*/
45
45
void main() {
46
- // x divided up by batch size is used to determine 3d position
47
- // y divided up by batch size is used to determine 3d position
46
+ // x and y are divided by batch size to determine 3d position
48
47
// since work size is calculated by x * ((y + B_Y - 1) / B_Y) * z
49
- const ivec2 out_limits_xy_scaled = ivec2 (out_limits.xy + ivec2 (BATCH_SIZE_X, BATCH_SIZE_Y) - 1 ) / ivec2 (BATCH_SIZE_X, BATCH_SIZE_Y);
48
+ const ivec2 out_limits_xy_scaled = (out_limits.xy + ivec2 (BATCH_SIZE_X, BATCH_SIZE_Y) - 1 ) / ivec2 (BATCH_SIZE_X, BATCH_SIZE_Y);
50
49
51
- u16vec3 pos = idx_to_u16pos_x_wise (gl_GlobalInvocationID.x, out_limits_xy_scaled.x, out_limits_xy_scaled.y);
50
+ ivec3 pos = idx_to_ipos_x_wise (gl_GlobalInvocationID.x, out_limits_xy_scaled.x, out_limits_xy_scaled.y);
52
51
53
52
// scale pos.xy by batch sizes, because that's the top pixel to be processed
54
- pos.x *= uint16_t( BATCH_SIZE_X) ;
55
- pos.y *= uint16_t( BATCH_SIZE_Y) ;
53
+ pos.x *= BATCH_SIZE_X;
54
+ pos.y *= BATCH_SIZE_Y;
56
55
57
56
// do not process if top pixel does not fit within the output range
58
- if (any (greaterThanEqual (u16vec3( pos.x, pos.y, pos.z) , out_limits))) {
57
+ if (any (greaterThanEqual (pos, out_limits))) {
59
58
return ;
60
59
}
61
60
62
61
// Compute the index of the top-left element of the overlay region. Negative
63
62
// indices indicate that the top-left element is in a region added by padding.
64
- const u16vec2 ipos = pos.xy * u16vec2( stride) - u16vec2( padding) ;
63
+ const ivec2 ipos = pos.xy * stride - padding;
65
64
66
65
// Compute the start and end of the input indices to load. Padding is assumed
67
66
// to be constant 0 padding, so any reads from the padding region is skipped.
68
- const u16vec2 start = ipos;
69
- const u16vec2 end = ipos + u16vec2( overlay_region.xy) ;
67
+ const ivec2 start = ipos;
68
+ const ivec2 end = ipos + overlay_region.xy;
70
69
71
70
// sum outputs
72
71
VEC4_T sum[BATCH_SIZE_Y][BATCH_SIZE_X];
73
72
74
- sum[0 ][0 ] = texelFetch(t_bias, u16vec2 (pos.z, 0 ), 0 );
73
+ sum[0 ][0 ] = texelFetch(t_bias, ivec2 (pos.z, 0 ), 0 );
75
74
for (int y = 0 ; y < BATCH_SIZE_Y; y++ ) {
76
75
for (int x = 0 ; x < BATCH_SIZE_X; x++ ) {
77
76
sum[y][x] = sum[0 ][0 ];
@@ -84,39 +83,39 @@ void main() {
84
83
// array to store kernel data of previous y
85
84
VEC4_T prev_kernel_line[TILE_SIZE];
86
85
87
- uint16_t kx = uint16_t( 0 ) ;
88
- for (uint16_t y = start.y, i = uint16_t( 0 ) ; i < uint16_t( TILE_SIZE + BATCH_SIZE_Y - 1 ) ; y += uint16_t( dilation.y) , i++ ) {
89
- for (uint16_t x = start.x, j = uint16_t( 0 ) ; j < uint16_t( TILE_SIZE + BATCH_SIZE_X - 1 ) ; x += uint16_t( dilation.x) , j++ ) {
90
- in_texels[int (j) ] = texelFetch(t_in, u16vec3 (x, y, pos.z), 0 );
86
+ int kx = 0 ;
87
+ for (int y = start.y, i = 0 ; i < TILE_SIZE + BATCH_SIZE_Y - 1 ; y += dilation.y, i++ ) {
88
+ for (int x = start.x, j = 0 ; j < TILE_SIZE + BATCH_SIZE_X - 1 ; x += dilation.x, j++ ) {
89
+ in_texels[j ] = texelFetch(t_in, ivec3 (x, y, pos.z), 0 );
91
90
}
92
91
93
92
// from 2nd iteration onwards accumulate dot product in 2nd sum
94
93
// based on kernel line data fetched in previous iteration and input texel from this iteration
95
- if (i > uint16_t( 0 ) ) {
96
- for (uint16_t s = uint16_t( 0 ); s < uint16_t(BATCH_SIZE_X); s ++ ) {
97
- for (uint16_t j = uint16_t( 0 ); j < uint16_t(TILE_SIZE); j ++ ) {
98
- sum[1 ][int (s) ] = fma(in_texels[int (j + s) ], prev_kernel_line[int (j) ], sum[1 ][int (s) ]);
94
+ if (i > 0 ) {
95
+ for (int j = 0 ; j < TILE_SIZE; j ++ ) {
96
+ for (int s = 0 ; s < BATCH_SIZE_X; s ++ ) {
97
+ sum[1 ][s ] = fma(in_texels[j + s ], prev_kernel_line[j ], sum[1 ][s ]);
99
98
}
100
99
}
101
100
}
102
101
103
102
// accumulate dot product in 1st sum only until tile size
104
- if (i < uint16_t (TILE_SIZE)) {
105
- for (uint16_t j = uint16_t( 0 ) ; j < uint16_t( TILE_SIZE) ; j++ , kx++ ) {
106
- prev_kernel_line[int (j) ] = texelFetch(t_kernel, u16vec2 (kx, pos.z), 0 );
107
- for (uint16_t s = uint16_t( 0 ) ; s < uint16_t( BATCH_SIZE_X) ; s++ ) {
108
- sum[0 ][int (s) ] = fma(in_texels[int (j + s) ], prev_kernel_line[int (j) ], sum[0 ][int (s) ]);
103
+ if (i < int (TILE_SIZE)) {
104
+ for (int j = 0 ; j < TILE_SIZE; j++ , kx++ ) {
105
+ prev_kernel_line[j ] = texelFetch(t_kernel, ivec2 (kx, pos.z), 0 );
106
+ for (int s = 0 ; s < BATCH_SIZE_X; s++ ) {
107
+ sum[0 ][s ] = fma(in_texels[j + s ], prev_kernel_line[j ], sum[0 ][s ]);
109
108
}
110
109
}
111
110
}
112
111
}
113
112
114
- for (int i = 0 ; i < BATCH_SIZE_Y; i ++ ) {
115
- for (int j = 0 ; j < BATCH_SIZE_X; j ++ ) {
116
- if (any (greaterThanEqual (u16vec3 (pos.x + j , pos.y + i , pos.z), out_limits))) {
113
+ for (int y = 0 ; y < BATCH_SIZE_Y; y ++ ) {
114
+ for (int x = 0 ; x < BATCH_SIZE_X; x ++ ) {
115
+ if (any (greaterThanEqual (ivec3 (pos.x + x , pos.y + y , pos.z), out_limits))) {
117
116
continue ;
118
117
}
119
- imageStore(t_out, u16vec3 (pos.x + j , pos.y + i , pos.z), op(sum[i][j ], out_min, out_max));
118
+ imageStore(t_out, ivec3 (pos.x + x , pos.y + y , pos.z), op(sum[y][x ], out_min, out_max));
120
119
}
121
120
}
122
121
}
0 commit comments