main.es6 1.7 KB
Newer Older
W
wangqun 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/* eslint-disable */
/**
 * @file 主函数
 * @author chenhaoze
 */
export default `
    // start函数
    void main(void) {
        ivec4 oPos = getOutputTensorPosLIMIT_OUT();
        int x = oPos.a;
        int c = oPos.g;
        int y = oPos.b;
13
        int b = oPos.r;
W
wangqun 已提交
14
        float res = 0.0;
W
wangqun 已提交
15 16 17 18
        int temp_x = 0;
        int temp_y = 0;
        float o = 0.0;
        float f = 0.0;
19
        
W
wangqun 已提交
20
        // 获取output的坐标
W
wangqun 已提交
21
        int oTensorChannel = int(c * groups / channel_out) * channel_origin;
22
        int oy = y - padTop;
W
wangqun 已提交
23 24 25 26 27
        for (int fy = 0; fy < height_shape_filter; fy++) {
            if (oy < 0) {
                oy += dilation_v;
                continue;
            }
28
            int ox = x - padLeft;
W
wangqun 已提交
29
            for (int fx = 0; fx < width_shape_filter; fx++) {
W
wangqun 已提交
30

W
wangqun 已提交
31 32 33 34 35
                if (ox < 0) {
                    ox += dilation_h;
                    continue;
                }
                // channel计算
W
wangqun 已提交
36
                for (int j = 0; j < channel_origin; j++) {
37
                	if (int(mod(float(ox), float(stride_h))) == 0 && int(mod(float(oy), float(stride_v))) == 0) {
W
wangqun 已提交
38 39 40 41
						temp_x = int(floor(float(ox) / float(stride_h)));
						temp_y = int(floor(float(oy) / float(stride_v)));
                        if (temp_x < width_shape_origin && temp_y < height_shape_origin){
						    o = getValueFromTensorPosLIMIT_ORIGIN_origin(b, j, temp_y, temp_x);
42
                            f = getValueFromTensorPosLIMIT_FILTER_filter(j, c, height_shape_filter-1-fy, width_shape_filter-1-fx);
W
wangqun 已提交
43 44
                            res += f * o;
                        }
W
wangqun 已提交
45 46 47 48 49 50
					}
                }
                ox += dilation_h;
            }
            oy += dilation_v;
        }
W
wangqun 已提交
51
        setOutput(float(res));
W
wangqun 已提交
52 53
    }
`;