text: !function(n,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.paddlejsWebglBackend=o():n.paddlejsWebglBackend=o()}(self,(function(){return(()=>{"use strict";var n={968:(n,o,e)=>{e.r(o),e.d(o,{GLHelper:()=>h,glInstance:()=>on,webgl_types:()=>i});var t={};e.r(t),e.d(t,{hardSigmoid:()=>X,leakyRelu:()=>U,pow:()=>G,prelu:()=>I,relu6:()=>D,scale:()=>B,scaleWidthBias:()=>k,sigmoid:()=>M,sqrt:()=>N,transferFromNHWCtoNCHW:()=>L});var r={};e.r(r),e.d(r,{getPixelsFromTexturePos:()=>z,getSamplerCode:()=>K,getTensorPosFromArrayIndex:()=>Y,getValueFromTensorPos:()=>j,getValueFromTensorPosPacked:()=>H,getValueFromTensorPosPacking:()=>W,moveTexture2PosToReal:()=>q});var i={};e.r(i);var a,s={opRegistry:{ops:{}},backend:"",backendInstance:null};(a=function(){var n;if("undefined"!=typeof window)n=window;else if(void 0!==e.g)n=e.g;else{if("undefined"==typeof self)throw new Error("Could not find a global object");n=self}return n}()).GLOBALS||(a.GLOBALS=s),s=a.GLOBALS;const u=function(){function n(){}return n.set=function(o,e){n.ENV||(n.ENV=new n),n.ENV[o]=e},n.get=function(o){return n.ENV||(n.ENV=new n),n.ENV[o]},n}();var l,f;!function(n){n[n.VS_SHADER=0]="VS_SHADER",n[n.FS_SHADER=1]="FS_SHADER"}(l||(l={})),function(n){n[n.FLOAT_VEC2=35664]="FLOAT_VEC2",n[n.FLOAT_VEC3=35665]="FLOAT_VEC3",n[n.FLOAT_VEC4=35666]="FLOAT_VEC4",n[n.INT_VEC2=35667]="INT_VEC2",n[n.INT_VEC3=35668]="INT_VEC3",n[n.INT_VEC4=35669]="INT_VEC4",n[n.BOOL=35670]="BOOL",n[n.BOOL_VEC2=35671]="BOOL_VEC2",n[n.BOOL_VEC3=35672]="BOOL_VEC3",n[n.BOOL_VEC4=35673]="BOOL_VEC4",n[n.FLOAT_MAT2=35674]="FLOAT_MAT2",n[n.FLOAT_MAT3=35675]="FLOAT_MAT3",n[n.FLOAT_MAT4=35676]="FLOAT_MAT4",n[n.SAMPLER_2D=35677]="SAMPLER_2D",n[n.SAMPLER_CUBE=35678]="SAMPLER_CUBE",n[n.FLOAT=5126]="FLOAT",n[n.INT=5124]="INT"}(f||(f={}));var c,g=function(n,o,e){this.size=n,this.type=o,this.location=e},_=function(n,o,e){this.size=n,this.type=o,this.location=e},h=function(){function n(){}return n.getWebglVersion=function(){return u.get("webglVersion")},n.createCanvas=function(){return document.createElement("canvas")},n.setWebglVersion=function(n){u.set("webglVersion",n)},n.setWebGLRenderingContext=function(n){return this.gl?this.gl:(this.gl=n,n)},n.getWebGLRenderingContext=function(){if(this.gl)return this.gl;var n=this.createCanvas();n.addEventListener("webglcontextlost",(function(n){throw n.preventDefault(),Error("webgl context is lost~")}),!1);var o=n.getContext("webgl2",this.WEBGL_ATTRIBUTES);return o?u.set("webglVersion",2):(u.set("webglVersion",1),o=n.getContext("webgl",this.WEBGL_ATTRIBUTES)||n.getContext("experimental-webgl",this.WEBGL_ATTRIBUTES)),o},n.printStates=function(n){console.log("1. isBlendEnable = "+n.isEnabled(n.BLEND)),console.log("2. isCullFaceEnable = "+n.isEnabled(n.CULL_FACE)),console.log("3. isDepthTestEnable = "+n.isEnabled(n.DEPTH_TEST)),console.log("4. isDitherEnable = "+n.isEnabled(n.DITHER)),console.log("5. isPolygonOffsetFillEnable = "+n.isEnabled(n.POLYGON_OFFSET_FILL)),console.log("6. isSampleAlphtToCoverageEnable = "+n.isEnabled(n.SAMPLE_ALPHA_TO_COVERAGE)),console.log("7. isSampleCoverageEnable = "+n.isEnabled(n.SAMPLE_COVERAGE)),console.log("8. isScissorTestEnable = "+n.isEnabled(n.SCISSOR_TEST)),console.log("9. isStencilTestEnable = "+n.isEnabled(n.STENCIL_TEST))},n.printWebGLInfo=function(n){console.log("renderer = "+n.getParameter(n.RENDERER)),console.log("version = "+n.getParameter(n.VERSION)),console.log("vendor = "+n.getParameter(n.VENDOR)),console.log("glsl version = "+n.getParameter(n.SHADING_LANGUAGE_VERSION))},n.printWebGLTextureInfo=function(n){console.log("MAX_COMBINED_TEXTURE_IMAGE_UNITS = ",n.getParameter(n.MAX_COMBINED_TEXTURE_IMAGE_UNITS)),console.log("MAX_TEXTURE_IMAGE_UNITS = ",n.getParameter(n.MAX_TEXTURE_IMAGE_UNITS)),console.log("MAX_TEXTURE_SIZE = ",n.getParameter(n.MAX_TEXTURE_SIZE)),console.log("MAX_CUBE_MAP_TEXTURE_SIZE = ",n.getParameter(n.MAX_CUBE_MAP_TEXTURE_SIZE))},n.triggerContextLostEvent=function(n){var o=n.getExtension("WEBGL_lose_context");null!==o&&o.loseContext()},n.checkGLError=function(n){var o=n.getError();return 0!==o&&(console.log("WebGL Error NO: ",o),!0)},n.setDefaultState=function(n){n.clearColor(0,0,0,0),n.clearDepth(1),n.enable(n.DEPTH_TEST),n.enable(n.CULL_FACE),n.enable(n.SCISSOR_TEST)},n.setViewport=function(n,o){n.viewport(o[0],o[1],o[2],o[3])},n.initShader=function(n,o,e){var t=this.createShader(n,o);return this.compileShader(n,e,t),t},n.createShader=function(n,o){var e;if(null===(e=o===l.VS_SHADER?n.createShader(n.VERTEX_SHADER):n.createShader(n.FRAGMENT_SHADER)))throw new Error("WebGLShader创建失败！");return e},n.compileShader=function(n,o,e){return n.shaderSource(e,o),n.compileShader(e),!1!==n.getShaderParameter(e,n.COMPILE_STATUS)||(console.error(n.getShaderInfoLog(e)),n.deleteShader(e),!1)},n.createProgram=function(n){var o=n.createProgram();if(null===o)throw new Error("WebGLProgram创建失败！");return o},n.linkProgram=function(n,o,e,t,r,i){return void 0===r&&(r=null),void 0===i&&(i=null),n.attachShader(o,e),n.attachShader(o,t),null!==r&&r(n,o),n.linkProgram(o),!1===n.getProgramParameter(o,n.LINK_STATUS)?(console.error(n.getProgramInfoLog(o)),n.deleteShader(e),n.deleteShader(t),n.deleteProgram(o),!1):(n.validateProgram(o),!1===n.getProgramParameter(o,n.VALIDATE_STATUS)?(console.error(n.getProgramInfoLog(o)),n.deleteShader(e),n.deleteShader(t),n.deleteProgram(o),!1):(null!==i&&i(n,o),!0))},n.getProgramActiveAttribs=function(n,o,e){for(var t=n.getProgramParameter(o,n.ACTIVE_ATTRIBUTES),r=0;r<t;r++){var i=n.getActiveAttrib(o,r);i&&(e[i.name]=new _(i.size,i.type,n.getAttribLocation(o,i.name)))}},n.getProgramAtciveUniforms=function(n,o,e){for(var t=n.getProgramParameter(o,n.ACTIVE_UNIFORMS),r=0;r<t;r++){var i=n.getActiveUniform(o,r);if(i){var a=n.getUniformLocation(o,i.name);null!==a&&(e[i.name]=new g(i.size,i.type,a))}}},n.createBuffer=function(n){var o=n.createBuffer();if(null===o)throw new Error("WebGLBuffer创建失败！");return o},n.getColorBufferData=function(n){var o=new Uint8Array(n.drawingBufferWidth*n.drawingBufferHeight*4);return n.readPixels(0,0,n.drawingBufferWidth,n.drawingBufferHeight,n.RGBA,n.UNSIGNED_BYTE,o),o},n.WEBGL_ATTRIBUTES={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0},n.gl=null,n}();!function(n){n[n.GL_REPEAT=0]="GL_REPEAT",n[n.GL_MIRRORED_REPEAT=1]="GL_MIRRORED_REPEAT",n[n.GL_CLAMP_TO_EDGE=2]="GL_CLAMP_TO_EDGE"}(c||(c={}));var p=function(){function n(){}return n.getTextureConfig=function(n){var o,e,t,r,i,a=n,s=!0,l=!0;return 2===u.get("webglVersion")?(o=a.getExtension("EXT_color_buffer_float"),t=null,r=a.R32F,e=a.RED,i=a.RGBA32F):(r=a.RGBA,e=a.RGBA,i=a.RGBA,o=a.getExtension("OES_texture_float"),t=a.getExtension("OES_texture_half_float"),s=this.isDownloadFloatTextureEnabled(a,i),l=this.isFloatTextureReadPixelsEnabledMethod(a,1)),{textureFloat:o,textureHalfFloat:t,internalFormat:r,textureFormat:e,downloadInternalFormat:i,frameBufferSupportFloat:s,isFloatTextureReadPixelsEnabled:l}},n.isFloatTextureReadPixelsEnabledMethod=function(n,o){var e=n;if(0===o)return!1;if(1===o){if(null==e.getExtension("OES_texture_float"))return!1}else if(null==e.getExtension("EXT_color_buffer_float")||null==e.getExtension("EXT_color_buffer_half_float"))return!1;var t=e.createFramebuffer(),r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r);var i=2===o?e.RGBA32F:e.RGBA;e.texImage2D(e.TEXTURE_2D,0,i,1,1,0,e.RGBA,e.getExtension("OES_texture_half_float").HALF_FLOAT_OES,null),e.bindFramebuffer(e.FRAMEBUFFER,t),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0);var a=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;e.readPixels(0,0,1,1,e.RGBA,e.FLOAT,new Float32Array(4));var s=e.getError()===e.NO_ERROR;return a&&s},n.isDownloadFloatTextureEnabled=function(n,o){var e=n.createTexture();n.bindTexture(n.TEXTURE_2D,e),n.texImage2D(n.TEXTURE_2D,0,o,1,1,0,n.RGBA,n.FLOAT,null);var t=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,t),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,e,0);var r=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;return n.bindTexture(n.TEXTURE_2D,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.deleteTexture(e),n.deleteFramebuffer(t),r},n.initTexture=function(n,o,e){var t=this.getTextureConfig(n),r=n.createTexture();if(n.activeTexture(n["TEXTURE"+o]),n.bindTexture(n.TEXTURE_2D,r),e)if(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),2===u.get("webglVersion"))n.texImage2D(n.TEXTURE_2D,0,t.internalFormat,e.width_texture,e.height_texture,0,t.textureFormat,n.FLOAT,e.data);else{for(var i=new Float32Array(e.width_texture*e.height_texture*4),a=0;a<e.data.length;a++)i[4*a]=e.data[a],i[4*a+1]=0,i[4*a+2]=0,i[4*a+3]=0;n.texImage2D(n.TEXTURE_2D,0,n.RGBA,e.width_texture,e.height_texture,0,n.RGBA,n.FLOAT,i)}return r},n.genOutputTexture=function(n,o,e,t){var r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,o.downloadInternalFormat,e.width_texture,e.height_texture,0,n.RGBA,t?o.isFloatTextureReadPixelsEnabled?o.frameBufferSupportFloat?n.FLOAT:o.textureHalfFloat.HALF_FLOAT_OES:n.UNSIGNED_BYTE:o.frameBufferSupportFloat?n.FLOAT:o.textureHalfFloat.HALF_FLOAT_OES,null),n.bindTexture(n.TEXTURE_2D,null),r},n}(),d=["\n    precision highp float;\n    precision highp int;\n\n    attribute vec4 position;\n    varying vec2 vCoord;\n\n    void main() {\n        vCoord.x = (position.x + 1.0) / 2.0;\n        vCoord.y = (position.y + 1.0) / 2.0;\n        gl_Position = position;\n    }\n    ","#version 300 es\n    in vec4 position;\n    out vec2 vCoord;\n\n    void main() {\n        vCoord.x = (position.x + 1.0) / 2.0;\n        vCoord.y = (position.y + 1.0) / 2.0;\n        gl_Position = position;\n    }\n    "],P=new Float32Array([-1,1,0,1,-1,-1,0,0,1,1,1,1,1,-1,1,0]);const m={mainFunc:function(n,o){var e=n.origin,t=n.filter,r=n.out,i=o.groups,a=void 0===i?1:i,s=o.strides,u=void 0===s?[]:s,l=o.paddings,f=void 0===l?[]:l,c=o.dilations,g=void 0===c?[]:c,_=o.fuse_relu,h=o.filter_nearest_vec4,p=o.filter_remainder_vec4,d=u[0],P=void 0===d?1:d,m=u[1],v=void 0===m?1:m,x=f[0],T=void 0===x?0:x,F=f[1],E=void 0===F?0:F,b=g[0],y=void 0===b?1:b,V=g[1],w=void 0===V?1:V;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        int x = oPos.a;\n        int c = oPos.g;\n        int y = oPos.b;\n        int b = oPos.r;\n        float res = 0.0;\n\n        // 获取output的坐标\n        int oTensorChannel = (c / ("+r.channel+" / "+a+")) * "+t.channel+";\n        int oy = y * "+P+" - "+T+";\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                oy += "+y+";\n                continue;\n            }\n            int ox = x * "+v+" - "+E+";\n            for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    ox += "+w+";\n                    continue;\n                }\n                // channel计算\n                for (int j = 0; j < "+h+"; j += 4) {\n                    vec4 fValues = vec4(\n                        getValueFromTensorPos_filter(c, j, fy, fx),\n                        getValueFromTensorPos_filter(c, j + 1, fy, fx),\n                        getValueFromTensorPos_filter(c, j + 2, fy, fx),\n                        getValueFromTensorPos_filter(c, j + 3, fy, fx)\n                    );\n\n                    vec4 oValues = vec4(\n                        getValueFromTensorPos_origin(b, oTensorChannel + j, oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + j + 1, oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + j + 2, oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + j + 3, oy, ox)\n                      );\n\n                    res += dot(fValues, oValues);\n                }\n\n                if ("+p+" == 1) {\n                    res += dot(\n                        getValueFromTensorPos_filter(c, "+h+", fy, fx),\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+", oy, ox));\n                } else if ("+p+" == 2) {\n                    vec2 fValues = vec2(\n                        getValueFromTensorPos_filter(c, "+h+", fy, fx),\n                        getValueFromTensorPos_filter(c, "+h+" + 1, fy, fx)\n                    );\n                    vec2 oValues = vec2(\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+", oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+" + 1, oy, ox)\n                      );\n                    res += dot(fValues, oValues);\n                } else if ("+p+" == 3) {\n                    vec3 fValues = vec3(\n                        getValueFromTensorPos_filter(c, "+h+", fy, fx),\n                        getValueFromTensorPos_filter(c, "+h+" + 1, fy, fx),\n                        getValueFromTensorPos_filter(c, "+h+" + 2, fy, fx)\n                    );\n                    vec3 oValues = vec3(\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+", oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+" + 1, oy, ox),\n                        getValueFromTensorPos_origin(b, oTensorChannel + "+h+" + 2, oy, ox)\n                    );\n                    res += dot(fValues, oValues);\n                }\n\n                ox += "+w+";\n            }\n            oy += "+y+";\n        }\n\n        float bi = getValueFromTensorPos_bias(0, 0, 0, c);\n        res += bi;\n        if ("+_+") {\n            res = max(0.0, res);\n        }\n\n        setOutput(res);\n    }\n    "},params:["strides","paddings","dilations","groups","filter_nearest_vec4","filter_remainder_vec4"],textureFuncConf:{filter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"],bias:["getValueFromTensorPos"]},behaviors:["adaptPaddings","isApplySeparableConv","batchComputeConv2d","processBias"]};function v(n,o){for(var e=o[0],t=o[1],r=o[2],i=o[3],a=r*i,s=t*r*i,u=[],l=0;l<e;l++)for(var f=0;f<i;f++)for(var c=0;c<t;c++)for(var g=0;g<r;g++)u.push(n[l*s+c*a+g*i+f]);return u}function x(n){for(var o=n.length,e=function(){for(var n=0,o=0,e=arguments.length;o<e;o++)n+=arguments[o].length;var t=Array(n),r=0;for(o=0;o<e;o++)for(var i=arguments[o],a=0,s=i.length;a<s;a++,r++)t[r]=i[a];return t}(n),t=[];o>1;)e.splice(0,1),t.push(e.reduce((function(n,o){return n*o}))),o--;return t}function T(n,o){var e=n[0],t=n[1],r=n[2],i=n[3];if(1===e&&1===t)return[[1,1,r],3,[i],1,[r,i]];var a=n.slice(0,o),s=n.slice(o);return[a,a.length,s,s.length,[a.reduce((function(n,o){return n*o})),s.reduce((function(n,o){return n*o}))]]}function F(n,o,e){if(1===e)return"\n            int getTensorPosFromArrayIndex_"+n+"(int n) {\n                return int(mod(float(n), float("+o[0]+")));\n            }\n        ";var t=x(o);return t.push(1),"\n    ivec"+e+" shapeVec_"+n+" = ivec"+e+"("+t.join(", ")+");\n    ivec"+e+" getTensorPosFromArrayIndex_"+n+"(int n) {\n        ivec"+e+" pos;\n        pos[0] = n / shapeVec_"+n+"[0];\n        for (int i = 1; i < "+e+"; i++) {\n            n = int(mod(float(n), float(shapeVec_"+n+"[i - 1])));\n            pos[i] = n / shapeVec_"+n+"[i];\n        }\n        return pos;\n    }\n    "}function E(n){return 1===n?"int":"ivec"+n}function b(n){var o=n.total_shape,e=n.channel,t=n.height_shape,r=n.width_shape;return[o/e/t/r,e,t,r]}var y={relu:["transToPrelu"],relu6:["transToRelu6"],leaky_relu:["transToLeakyrelu"],transToLeakyrelu:["transToLeakyrelu"],scale:["transToScale"],sigmoid:["transToSigmoid"],hard_sigmoid:["transToHardSigmoid"],pow:["transToPow"]};function V(n,o){var e=o.multi_value,t=void 0===e?1:e,r=o.bias_value,i=void 0===r?0:r;return"\n    // start函数\n    void main(void) {\n        // 输出数据\n        float o = getPixelsFromTexturePos_origin(vCoord).r;\n        float res = "+o.active_function+"(o, float("+t+"), float("+i+"));\n        setOutput(res);\n    }\n    "}function w(n){return{mainFunc:V,params:["multi_value","bias_value","active_function"],textureFuncConf:{origin:["getPixelsFromTexturePos"]},behaviors:y[n]}}const A={mainFunc:function(n,o){var e=o.axes,t=Array.isArray(e)?e:[e],r=[0,1,2,3].filter((function(n){return n>=t.length}));return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float o = 0.0;\n        o = getValueFromTensorPos_origin("+[0,1,2,3].map((function(n){return t.indexOf(n)>-1?0:"oPos["+r.splice(0,1)+"]"})).join(",")+");\n        setOutput(float(o));\n    }\n    "},params:["axes"],textureFuncConf:{origin:["getValueFromTensorPos"]}};var C={arg_max:{mainFunc:function(n,o){var e=n.origin,t=o.axis,r=void 0===t?-1:t,i=o.flatten,a=e.total_shape,s=e.height_shape,u=e.width_shape,l=e.channel,f=e.length_unformatted_shape,c=a/(u*s*l),g=r<0?3:4-f+r,_=[c,l,s,u][g];return"\n\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        float o = 0.0;\n        int pos = 0;\n        if ("+!i+") {\n            if ("+g+" == 1) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, 0, oPos.b, oPos.a);\n                for (int index = 0; index < "+_+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, index, oPos.b, oPos.a);\n                    if (o > tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n            else if ("+g+" == 2) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, oPos.b, 0, oPos.a);\n                for (int index = 0; index < "+_+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, oPos.b, index, oPos.a);\n                    if (o > tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n            else if ("+g+" == 3) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, oPos.b, oPos.a, 0);\n                for (int index = 0; index < "+_+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, oPos.b, oPos.a, index);\n                    if (o > tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n            else {\n                float tmp = getValueFromTensorPos_origin(0, oPos.g, oPos.b, oPos.a);\n                for (int index = 0; index < "+_+"; index++) {\n                    o = getValueFromTensorPos_origin(index, oPos.g, oPos.b, oPos.a);\n                    if (o > tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n        }\n        else {\n            int index = 0;\n            float tmp = getValueFromTensorPos_origin(0, 0, 0, 0);\n            for (int n = 0; n < "+c+"; n++) {\n                for (int c = 0; c < "+l+"; c++) {\n                    for (int h = 0; h < "+s+"; h++) {\n                        for (int w = 0; w < "+u+"; w++) {\n                            o = getValueFromTensorPos_origin(n, c, h, w);\n                            if (o > tmp) {\n                                tmp = o;\n                                pos = index;\n                            }\n                            index++;\n                        }\n                    }\n                }\n            }\n        }\n        setOutput(float(pos));\n    }"},params:["axis","flatten"],textureFuncConf:{origin:["getValueFromTensorPos"]}},arg_min:{mainFunc:function(n,o){for(var e=n.origin,t=o.axis,r=void 0===t?-1:t,i=o.flatten,a=e.total_shape,s=e.height_shape,u=e.width_shape,l=e.channel,f=a/(u*s*l),c=[f,l,s,u],g=0,_=0;_<4&&!(c[_]>1);_++)g++;var h=r<0?4-g+r:r,p=c[h=g+h];return"\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        float o = 0.0;\n        int pos = 0;\n        if ("+!i+") {\n            if ("+h+" == 1) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, 0, oPos.b, oPos.a);\n                for (int index = 0; index < "+p+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, index, oPos.b, oPos.a);\n                    if (o < tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n            else if ("+h+" == 2) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, oPos.b, 0, oPos.a);\n                for (int index = 0; index < "+p+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, oPos.b, index, oPos.a);\n                    if (o < tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n            else if ("+h+" == 3) {\n                float tmp = getValueFromTensorPos_origin(oPos.g, oPos.b, oPos.a, 0);\n                for (int index = 0; index < "+p+"; index++) {\n                    o = getValueFromTensorPos_origin(oPos.g, oPos.b, oPos.a, index);\n                    if (o < tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }     \n            }\n            else {\n                float tmp = getValueFromTensorPos_origin(0, oPos.g, oPos.b, oPos.a);\n                for (int index = 0; index < "+p+"; index++) {\n                    o = getValueFromTensorPos_origin(index, oPos.g, oPos.b, oPos.a);\n                    if (o < tmp) {\n                        tmp = o;\n                        pos = index;\n                    }\n                }\n            }\n        }\n        else {\n            int index = 0;\n            float tmp = getValueFromTensorPos_origin(0, 0, 0, 0);\n            for (int n = 0; n < "+f+"; n++) {\n                for (int c = 0; c < "+l+"; c++) {\n                    for (int h = 0; h < "+s+"; h++) {\n                        for (int w = 0; w < "+u+"; w++) {\n                            o = getValueFromTensorPos_origin(n, c, h, w);\n                            if (o < tmp) {\n                                tmp = o;\n                                pos = index;\n                            }\n                            index++;\n                        }\n                    }\n                }\n            }\n        }\n        setOutput(float(pos));\n    }"},params:["axis","flatten"],textureFuncConf:{origin:["getValueFromTensorPos"]}},conv2d:m,conv2d_packing:{mainFunc:function(n,o){var e=n.origin,t=n.filter,r=n.out,i=o.groups,a=void 0===i?1:i,s=o.strides,u=void 0===s?[]:s,l=o.paddings,f=void 0===l?[]:l,c=o.dilations,g=void 0===c?[]:c,_=o.fuse_relu,h=u[0],p=void 0===h?1:h,d=u[1],P=void 0===d?1:d,m=f[0],v=void 0===m?0:m,x=f[1],T=void 0===x?0:x,F=g[0],E=void 0===F?1:F,b=g[1],y=void 0===b?1:b;return"\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        int x = oPos.a;\n        int c = oPos.g;\n        int y = oPos.b;\n        int b = oPos.r;\n        vec4 res = vec4(0.0, 0.0, 0.0, 0.0);\n\n        int oy = y * "+p+" - "+v+";\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                oy += "+E+";\n                continue;\n            }\n            int ox = x * "+P+" - "+T+";\n            for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    ox += "+y+";\n                    continue;\n                }\n                // channel计算\n                for (int j = 0; j < "+t.channel+"; j += 1) {\n                    int c0 = (c / ("+r.channel+" * 4 / "+a+")) * "+t.channel+" + j;\n                    vec4 fValue = getValueFromTensorPosPacking_filter(c * 4, j, fy, fx);\n                    vec4 oValue = getValueFromTensorPosPacking_origin(b, c0, oy, ox);\n\n                    for (int packed_index = 0; packed_index < 4; packed_index++) {\n                        if (packed_index == 0) {\n                            res.r += dot(fValue, oValue);\n                        } else if (packed_index == 1) {\n                            int c1 = ((c + 1) / ("+r.channel+" * 4 / "+a+")) * "+t.channel+" + j;\n                            oValue = getValueFromTensorPosPacking_origin(b, c1, oy, ox);\n                            fValue = getValueFromTensorPosPacking_filter(c * 4 + 1, j, fy, fx);\n                            res.g += dot(fValue, oValue);\n                        } else if (packed_index == 2) {\n                            int c2 = ((c + 2) / ("+r.channel+" * 4 / "+a+")) * "+t.channel+" + j;\n                            oValue = getValueFromTensorPosPacking_origin(b, c2, oy, ox);\n                            fValue = getValueFromTensorPosPacking_filter(c * 4 + 2, j, fy, fx);\n                            res.b += dot(fValue, oValue);\n                        } else if (packed_index == 3) {\n                            int c3 = ((c + 3) / ("+r.channel+" * 4 / "+a+")) * "+t.channel+" + j;\n                            oValue = getValueFromTensorPosPacking_origin(b, c3, oy, ox);\n                            fValue = getValueFromTensorPosPacking_filter(c * 4 + 3, j, fy, fx);\n                            res.a += dot(fValue, oValue);\n                        }\n                    }\n                }\n                ox += "+y+";\n            }\n            oy += "+E+";\n        }\n\n        res += getValueFromTensorPosPacking_bias(0, c, 0, 0);\n        if ("+_+") {\n            res.r = max(0.0, res.r);\n            res.g = max(0.0, res.g);\n            res.b = max(0.0, res.b);\n            res.a = max(0.0, res.a);\n        }\n        setPackedOutput(res);\n    }\n    "},params:["strides","paddings","dilations","groups"],textureFuncConf:{filter:["getValueFromTensorPosPacking"],origin:["getValueFromTensorPosPacking"],bias:["getValueFromTensorPosPacking"]},behaviors:["adaptPaddings","isApplySeparableConv","batchComputeConv2d","processBias"]},conv2d_transpose:{mainFunc:function(n,o){var e=n.origin,t=n.filter,r=n.out,i=o.groups,a=void 0===i?1:i,s=o.strides,u=void 0===s?[]:s,l=o.paddings,f=void 0===l?[]:l,c=o.dilations,g=void 0===c?[]:c,_=u[0],h=void 0===_?1:_,p=u[1],d=void 0===p?1:p,P=f[0],m=void 0===P?0:P,v=f[1],x=void 0===v?0:v;x=t.height_shape-x-1,m=t.width_shape-m-1;var T=g[0],F=void 0===T?1:T,E=g[1],b=void 0===E?1:E;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        int x = oPos.a;\n        int c = oPos.g;\n        int y = oPos.b;\n        int b = oPos.r;\n        float res = 0.0;\n        int temp_x = 0;\n        int temp_y = 0;\n        float o = 0.0;\n        float f = 0.0;\n\n        // 获取output的坐标\n        int oTensorChannel = int(c * "+a+" / "+r.channel+") * "+e.channel+";\n        int oy = y - "+x+";\n        const int groupLen = int("+e.channel+" / "+a+");\n        int groupIndex = int(c / groupLen);\n\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n            if (oy < 0) {\n                oy += "+F+";\n                continue;\n            }\n            int ox = x - "+m+";\n            for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n\n                if (ox < 0) {\n                    ox += "+b+";\n                    continue;\n                }\n                // channel计算\n                for (int j = 0; j < groupLen; j++) {\n                    int curIndex = j + b * groupLen;\n                    if (int(mod(float(ox), float("+d+"))) == 0 && int(mod(float(oy), float("+h+"))) == 0) {\n                        temp_x = int(floor(float(ox) / float("+d+")));\n                        temp_y = int(floor(float(oy) / float("+h+")));\n                        if (temp_x < "+e.width_shape+" && temp_y < "+e.height_shape+") {\n                            o = getValueFromTensorPos_origin(b, curIndex , temp_y, temp_x);\n                            f = getValueFromTensorPos_filter(\n                                curIndex,\n                                int(c / "+a+"),\n                                "+t.height_shape+"-1-fy,\n                                "+t.width_shape+"-1-fx\n                            );\n                            res += f * o;\n                        }\n                    }\n                }\n                ox += "+b+";\n            }\n            oy += "+F+";\n        }\n        setOutput(float(res));\n    }\n"},params:["strides","paddings","dilations","groups"],textureFuncConf:{filter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]},behaviors:["adaptPaddings","isApplySeparableConv","batchComputeConv2d","processBias"]},depthwise_conv2d:m,conv2d_depthwise:{mainFunc:function(n,o){var e=n.origin,t=n.filter,r=o.strides,i=void 0===r?[]:r,a=o.paddings,s=void 0===a?[]:a,u=o.dilations,l=void 0===u?[]:u,f=o.fuse_relu,c=i[0],g=void 0===c?1:c,_=i[1],h=void 0===_?1:_,p=s[0],d=void 0===p?0:p,P=s[1],m=void 0===P?0:P,v=l[0],x=void 0===v?1:v,T=l[1],F=void 0===T?1:T;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        int x = oPos.a;\n        int c = oPos.g;\n        int y = oPos.b;\n        int b = oPos.r;\n        float res = 0.0;\n        int top = y * "+g+" - "+d+";\n        int left = x * "+h+" - "+m+";\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n          int oy = top + fy * "+x+";\n          if (oy >= "+e.height_shape+") {\n              break;\n          }\n          if (oy < 0) {\n            continue;\n          }\n          for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n            int ox = left + fx * "+F+";\n            if (ox >= "+e.width_shape+") {\n                break;\n            }\n            if (ox < 0) {\n                continue;\n            }\n            // b默认是0\n            float f = getValueFromTensorPos_filter(c, 0, fy, fx);\n            float o = getValueFromTensorPos_origin(b, c, oy, ox);\n            res += f * o;\n          }\n        }\n        float bi = getValueFromTensorPos_bias(0, 0, 0, c);\n        res += bi;\n        if ("+f+") {\n            res = max(0.0, res);\n        }\n        setOutput(res);\n    }\n"},params:["strides","paddings","dilations","fuse_relu"],textureFuncConf:{filter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"],bias:["getValueFromTensorPos"]}},conv2d_elementwise_add:{mainFunc:function(n,o){var e=n.origin,t=n.filter,r=n.out,i=n.counter,a=o.active_function,s=o.groups,u=void 0===s?1:s,l=o.axis,f=o.strides,c=void 0===f?[]:f,g=o.paddings,_=void 0===g?[]:g,h=o.dilations,p=void 0===h?[]:h,d=o.multi_value,P=o.bias_value,m=c[0],v=void 0===m?1:m,x=c[1],T=void 0===x?1:x,F=_[0],E=void 0===F?0:F,b=_[1],y=void 0===b?0:b,V=p[0],w=void 0===V?1:V,A=p[1],C=void 0===A?1:A;return"\n    // start函数\n\n    float getValueFromCounter(int index) {\n        float xPos = float(index) / float("+i.width_shape+");\n        vec4 pixels = TEXTURE2D(texture_counter, vec2(xPos, 0.5));\n        return pixels.r;\n    }\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n\n        int x = oPos.a;\n        int c = oPos.g;\n        int y = oPos.b;\n        int b = oPos.r;\n        int addAxis = oPos["+l+"];\n        float res = getValueFromCounter(addAxis);\n\n        // 获取output的坐标\n        int oTensorChannel = (c / ("+r.channel+" / "+u+")) * "+t.channel+";\n        int oy = y * "+v+" - "+E+";\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                oy += "+w+";\n                continue;\n            }\n            int ox = x * "+T+" - "+y+";\n            for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    ox += "+C+";\n                    continue;\n                }\n                // channel计算\n                for (int j = 0; j < "+t.channel+"; j++) {\n                    float f = getValueFromTensorPos_filter(c, j, fy, fx);\n                    float o = getValueFromTensorPos_origin(b, oTensorChannel + j, oy, ox);\n                    res += f * o;\n                }\n                ox += "+C+";\n            }\n            oy += "+w+";\n        }\n        setOutput("+a+"(res,  "+d+",  "+P+"));\n    }\n"},params:["active_function","groups","axis","strides","paddings","dilations","multi_value","bias_value"],textureFuncConf:{filter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"],counter:["getValueFromTensorPos"]},behaviors:["mergeAttrs","checkIsMerge","setActiveFunc"]},pool2d:{mainFunc:function(n,o){var e=n.origin,t=o.strides,r=void 0===t?[]:t,i=o.paddings,a=void 0===i?[]:i,s=o.pooling_type,u=o.ksize,l=r[0],f=void 0===l?1:l,c=r[1],g=void 0===c?1:c,_=a[0],h=void 0===_?0:_,p=a[1],d=void 0===p?0:p,P=u[0];return"\n    // start函数\n    void main(void) {\n        float res = 0.0;\n        // 获取output的坐标\n        ivec4 out_pos = getOutputTensorPos();\n        // X、Y方向的移动步长\n        int count_pool = 0;\n        int oy_base = out_pos[2] * "+f+" - "+h+";\n        int ox_base = out_pos[3] * "+g+" - "+d+";\n        for (int fy = 0; fy < "+u[1]+"; fy++) {\n            int oy = oy_base + fy;\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                continue;\n            }\n            for (int fx = 0; fx < "+P+"; fx++) {\n                int ox = ox_base + fx;\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    continue;\n                }\n                // origin数据\n                float curr = getValueFromTensorPos_origin(out_pos[0], out_pos[1], oy, ox);\n                if ("+s+" == 1) {\n                    if (curr > res) {\n                        res = curr;\n                    }\n                } else {\n                    res += curr;\n                    // 在平均池化模式忽略填充值(exclusive默认为true）\n                    count_pool++;\n                }\n            }\n        }\n        if ("+s+" != 1) {\n            res = res / float(count_pool);\n        }\n        setOutput(res);\n    }\n    "},params:["strides","paddings","pooling_type","ksize"],textureFuncConf:{origin:["getValueFromTensorPos"]},behaviors:["isMax","setPacked","isGlobalPooling"]},pool2d_max:{mainFunc:function(n,o){var e=n.origin,t=o.strides,r=void 0===t?[]:t,i=o.paddings,a=void 0===i?[]:i,s=o.ksize,u=r[0],l=void 0===u?1:u,f=r[1],c=void 0===f?1:f,g=a[0],_=void 0===g?0:g,h=a[1],p=void 0===h?0:h,d=s[0];return"\n    // start函数\n    void main(void) {\n        float res = -1. / 0.;\n        // 获取output的坐标\n        ivec4 out_pos = getOutputTensorPos();\n        int b = out_pos[0];\n        int c = out_pos[1];\n        int y = out_pos[2];\n        int x = out_pos[3];\n        // X、Y方向的移动步长\n        int oy_base = out_pos[2] * "+l+" - "+_+";\n        int ox_base = out_pos[3] * "+c+" - "+p+";\n        for (int fy = 0; fy < "+s[1]+"; fy++) {\n            int oy = oy_base + fy;\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                continue;\n            }\n            for (int fx = 0; fx < "+d+"; fx++) {\n                int ox = ox_base + fx;\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    continue;\n                }\n                // origin数据\n                float curr = getValueFromTensorPos_origin(out_pos[0], out_pos[1], oy, ox);\n                res = max(res, curr);\n            }\n        }\n        setOutput(res);\n    }\n    "},params:["strides","paddings","ksize"],textureFuncConf:{origin:["getValueFromTensorPos"]},behaviors:["isMax","setPacked","isGlobalPooling"]},pool2d_winograd:{mainFunc:function(n,o){var e=n.origin,t=n.pool,r=o.strides,i=void 0===r?[]:r,a=o.paddings,s=void 0===a?[]:a,u=o.type_pool,l=i[0],f=void 0===l?1:l,c=i[1],g=void 0===c?1:c,_=s[0],h=void 0===_?0:_,p=s[1];return"\n    // start函数\n    void main(void) {\n        float res = (-1.0 / exp(-20.0));\n        // 获取output的坐标\n        ivec4 out_pos = getOutputTensorPos();\n        // int b = out_pos[0];\n        // int c = out_pos[1];\n        // int y = out_pos[2];\n        // int x = out_pos[3];\n        // X、Y方向的移动步长\n        int count_pool = 0;\n        int oy_base = out_pos[2] * "+f+" - "+h+";\n        int ox_base = out_pos[3] * "+g+" - "+(void 0===p?0:p)+";\n\n        for (int fy = 0; fy < "+t.height_shape+"; fy++) {\n            int oy = oy_base + fy;\n            if (oy >= "+e.height_shape+") {\n                break;\n            }\n            if (oy < 0) {\n                continue;\n            }\n            for (int fx = 0; fx < "+t.width_shape+"; fx++) {\n                int ox = ox_base + fx;\n                if (ox >= "+e.width_shape+") {\n                    break;\n                }\n                if (ox < 0) {\n                    continue;\n                }\n                // origin数据\n                float curr = getValueFromTensorPosPacked_origin(out_pos[0], out_pos[1], oy, ox);\n                if ("+u+" == 1) {\n                    if (curr > res) {\n                        res = curr;\n                    }\n                } else {\n                    res += curr;\n                    // 在平均池化模式忽略填充值(exclusive默认为true）\n                    count_pool++;\n                }\n            }\n        }\n        if ("+u+" != 1) {\n            res = res / float(count_pool);\n        }\n        setOutput(res);\n    }\n    "},params:["strides","paddings","type_pool"],textureFuncConf:{origin:["getValueFromTensorPosPacked"]},behaviors:["isMax","setPacked","isGlobalPooling"]},elementwise_add:{mainFunc:function(n,o){var e=o.counterPos,t=o.Scale_y,r=void 0===t?1:t,i=o.Scale_x,a=void 0===i?1:i,s=o.Scale_out,u=void 0===s?1:s;return"\n    void main(void) {\n        // 输出数据\n        ivec4 oPos = getOutputTensorPos();\n        float o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n\n        float c = getValueFromTensorPos_counter("+e+");\n        float res = float("+u/r+") * c + float("+u/a+") * o;\n        setOutput(float(res));\n    }\n    "},params:["Scale_y","Scale_x","Scale_out","counterPos"],textureFuncConf:{counter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]},behaviors:["processAxis","genElementwiseCounterPos"]},elementwise_mul:{mainFunc:function(n,o){var e=n.counter,t=o.counterPos,r=o.Scale_y,i=void 0===r?1:r,a=o.Scale_x,s=void 0===a?1:a,u=o.Scale_out,l=void 0===u?1:u;return"\n    ivec4 formatNCHW(int n, int c, int h, int w) {\n        int newN = n;\n        int newC = c;\n        int newH = h;\n        int newW = w;\n\n        if (n >= "+e.height_texture/e.height_shape+") {\n            newN = int("+e.height_texture/e.height_shape+");\n        }\n        if (c >= "+e.channel+") {\n            newC = int("+(e.channel-1)+");\n        }\n        if (h >= "+e.height_shape+") {\n            newH = "+(e.height_shape-1)+";\n        }\n        if (w >= "+e.width_shape+") {\n            newW = "+(e.width_shape-1)+";\n        }\n        return ivec4(newN, newC, newH, newW);\n    }\n\n    // start函数\n    void main() {\n        // 输出数据\n        ivec4 oPos1 = getOutputTensorPos();\n        float o = getValueFromTensorPos_origin(oPos1.r, oPos1.g, oPos1.b, oPos1.a);\n        ivec4 oPos = formatNCHW(oPos1.r, oPos1.g, oPos1.b, oPos1.a);\n\n        float c = getValueFromTensorPos_counter("+t+");\n        float res = float("+l/s+") * o * float("+1/i+") * c;\n        setOutput(float(res));\n    }\n\n    "},params:["Scale_y","Scale_x","Scale_out","counterPos"],textureFuncConf:{counter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]},behaviors:["processAxis","genElementwiseCounterPos"]},elementwise_div:{mainFunc:function(n,o){var e=n.counter,t=o.counterPos,r=o.Scale_y,i=void 0===r?1:r,a=o.Scale_x,s=void 0===a?1:a,u=o.Scale_out,l=void 0===u?1:u;return"\n    ivec4 formatNCHW(int n, int c, int h, int w) {\n        int newN = n;\n        int newC = c;\n        int newH = h;\n        int newW = w;\n\n        if (n >= "+e.height_texture/e.height_shape+") {\n            newN = int("+e.height_texture/e.height_shape+");\n        }\n        if (c >= "+e.channel+") {\n            newC = int("+(e.channel-1)+");\n        }\n        if (h >= "+e.height_shape+") {\n            newH = "+(e.height_shape-1)+";\n        }\n        if (w >= "+e.width_shape+") {\n            newW = "+(e.width_shape-1)+";\n        }\n        return ivec4(newN, newC, newH, newW);\n    }\n\n    // start函数\n    void main() {\n        // 输出数据\n        ivec4 oPos1 = getOutputTensorPos();\n        float o = getValueFromTensorPos_origin(oPos1.r, oPos1.g, oPos1.b, oPos1.a);\n        ivec4 oPos = formatNCHW(oPos1.r, oPos1.g, oPos1.b, oPos1.a);\n\n        float c = getValueFromTensorPos_counter("+t+");\n        float res = float("+l+") * (float("+1/s+") * o / (float("+1/i+") * c));\n        setOutput(float(res));\n    }\n\n    "},params:["axis","Scale_y","Scale_x","Scale_out","counterPos"],textureFuncConf:{counter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]},behaviors:["processAxis","genElementwiseCounterPos"]},mul:{mainFunc:function(n,o){var e=n.origin,t=n.counter,r=o.x_num_col_dims,i=o.y_num_col_dims,a=b(e),s=b(t),u=T(a,r),l=u[0],f=u[1],c=u[2],g=u[3],_=u[4],h=T(s,i),p=h[0],d=h[1],P=h[2],m=h[3];return"\n    "+F("x1",l,f)+"\n    "+F("x2",c,g)+"\n    "+F("y1",p,d)+"\n    "+F("y2",P,m)+"\n\n    // start函数\n    void main(void) {\n        float res = 0.0;\n        // 获取output的坐标\n        ivec4 opos = getOutputTensorPos();\n        float temp = 0.0;\n\n        // output is 2D\n        int b = opos.b;\n        int a = opos.a;\n\n        "+E(f)+" x1 = getTensorPosFromArrayIndex_x1(b);\n        "+E(m)+" y2 = getTensorPosFromArrayIndex_y2(a);\n\n        for (int j = 0; j < "+_[1]+"; j++) {\n            "+E(g)+" x2 = getTensorPosFromArrayIndex_x2(j);\n            "+E(d)+" y1 = getTensorPosFromArrayIndex_y1(j);\n\n            ivec4 xPos = ivec4("+E(f)+"(x1), "+E(g)+"(x2));\n            ivec4 yPos = ivec4("+E(d)+"(y1), "+E(m)+"(y2));\n\n            float o = getValueFromTensorPos_origin(xPos.r, xPos.g, xPos.b, xPos.a);\n            float c = getValueFromTensorPos_counter(yPos.r, yPos.g, yPos.b, yPos.a);\n            res += c * o;\n        }\n\n        setOutput(res);\n    }\n    "},params:["x_num_col_dims","y_num_col_dims"],textureFuncConf:{counter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]}},matmul:{mainFunc:function(n,o){var e=n.origin,t=o.transpose_X,r=void 0!==t&&t,i=o.transpose_Y,a=void 0!==i&&i;return"\n    void main() {\n        float res = 0.0;\n        // 获取output的坐标\n        ivec4 out_pos = getOutputTensorPos();\n        ivec4 origin_pos = out_pos;\n        if ("+r+") {\n            origin_pos[3] = origin_pos[2];\n        }\n        ivec4 counter_pos = out_pos;\n        if ("+a+") {\n            counter_pos[2] = counter_pos[3];\n        }\n\n        for (int j = 0; j < "+(r?e.height_shape:e.width_shape)+"; j++) {\n            if ("+r+") {\n                origin_pos[2] = j;\n            }\n            else {\n                origin_pos[3] = j;\n            }\n            if ("+a+") {\n                counter_pos[3] = j;\n            }\n            else {\n                counter_pos[2] = j;\n            }\n            float o = getValueFromTensorPos_origin(origin_pos[0], origin_pos[1], origin_pos[2], origin_pos[3]);\n            float c = getValueFromTensorPos_counter(counter_pos[0], counter_pos[1], counter_pos[2], counter_pos[3]);\n            \n            res += c * o;\n        }\n        setOutput(res);\n    }\n    "},params:["transpose_X","transpose_Y"],textureFuncConf:{counter:["getValueFromTensorPos"],origin:["getValueFromTensorPos"]}},fc:{mainFunc:function(n,o){return"\n    // start函数\n    void main(void) {\n        float res = 0.0;\n        ivec4 out_pos = getOutputTensorPos();\n        float bias = getValueFromTensorPos_bias(out_pos.r, out_pos.g, out_pos.b, out_pos.a);\n\n        for (int j = 0; j < "+n.origin.width_shape+"; j++) {\n            float w = getValueFromTensorPos_weight(out_pos[0], out_pos[1], j, out_pos[3]);\n            float o = getValueFromTensorPos_origin(out_pos[0], out_pos[1], out_pos[2], j);\n            res += w * o;\n        }\n\n        res = res + bias;\n        setOutput(res);\n    }\n"},params:[],textureFuncConf:{weight:["getValueFromTensorPos"],origin:["getValueFromTensorPos"],bias:["getValueFromTensorPos"]},behaviors:["flattenShape"]},dropout:{mainFunc:function(n,o){return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float o = 0.0;\n        o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n        if ("+("downgrade_in_infer"===o.dropout_implementation)+") {\n            o = o * (1.0 - "+o.dropout_prob+");\n        }\n        setOutput(float(o));\n    }\n    "},params:["dropout_implementation","dropout_prob"],textureFuncConf:{origin:["getValueFromTensorPos"]},behaviors:["normalizeDim"]},concat:{mainFunc:function(n,o){var e=o.inputs_dim,t=o.dim;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float o = 0.0;\n        if (oPos["+t+"] > "+e+" - 1) {\n            oPos["+t+"] = oPos["+t+"] - "+e+";\n            o = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);\n        }\n        else {\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n        }\n        setOutput(float(o));\n    }\n    "},params:["inputs_dim","dim"],textureFuncConf:{origin:["getValueFromTensorPos"],counter:["getValueFromTensorPos"]},behaviors:["normalizeDim"]},concat_mul:{mainFunc:function(n,o){var e=o.dim,t=o.inputs_dim,r=o.append_num,i=o.fourth_num,a=void 0===i?0:i,s=o.fourInputs,u=t+r,l=t+r+a;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float o = 0.0;\n\n        if (oPos["+e+"] < "+t+") {\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n        }\n        else if (oPos["+e+"] < "+u+") {\n            oPos["+e+"] = oPos["+e+"] - "+t+";\n            o = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);\n        }\n        else {\n            "+(void 0!==s&&s?"\n            if (oPos["+e+"] < "+l+") {\n                oPos["+e+"] = oPos["+e+"] - "+u+";\n                o = getValueFromTensorPos_appender(oPos.r, oPos.g, oPos.b, oPos.a);\n            }\n            else {\n                oPos["+e+"] = oPos["+e+"] - "+l+";\n                o = getValueFromTensorPos_fourth(oPos.r, oPos.g, oPos.b, oPos.a);\n            }\n        ":"\n            oPos["+e+"] = oPos["+e+"] - "+u+";\n            o = getValueFromTensorPos_appender(oPos.r, oPos.g, oPos.b, oPos.a);\n        ")+"\n        }\n        setOutput(float(o));\n    }\n    "},params:["dim","inputs_dim","append_num","fourInputs","fourth_num"],textureFuncConf:{origin:["getValueFromTensorPos"],counter:["getValueFromTensorPos"],appender:["getValueFromTensorPos"],fourth:["getValueFromTensorPos"]},behaviors:["normalizeDim"]},split:{mainFunc:function(n,o){var e=n.out,t=o.target_length,r=o.num,i=o.dim;return"\n    // start函数\n    void main(void) {\n        int length = int("+t+" / "+r+");\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        //int sumVal = oPos.g\n            + oPos.a * "+e.channel+"\n            + oPos.b * "+e.channel+" * "+e.width_shape+"\n            + oPos.r * "+e.channel+" * "+e.width_shape+" * "+e.height_shape+";\n\n        oPos["+i+"] = oPos["+i+"] + layer_run_time * length;\n        float o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n        setOutput(float(o));\n    }\n    "},params:["target_length","num","dim"],textureFuncConf:{origin:["getValueFromTensorPos"]},behaviors:["normalizeDim"]},softmax:{mainFunc:function(n,o){var e=n.origin,t=o.axis,r=t;return(!t||t<0)&&(r=(t||-1)+4),"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        const int n = int("+e.total_shape+"/"+e.channel+"/"+e.height_shape+"/"+e.width_shape+");\n        float o = getValueFromTensorPos_origin(oPos[0], oPos[1], oPos[2], oPos[3]);\n        // 输出坐标转换为输入坐标\n        float total = 0.0;\n        float res = 0.0;\n        if ("+r+" == 0) {\n            for (int i = 0; i < n; i++){\n            float temp = getValueFromTensorPos_origin(i, oPos[1], oPos[2], oPos[3]);\n            total += exp(temp);\n            }\n            res = exp(o) / total;\n        }\n        else if ("+r+" == 1) {\n            for (int i = 0; i < "+e.channel+"; i++){\n            float temp = getValueFromTensorPos_origin(oPos[0], i, oPos[2], oPos[3]);\n            total += exp(temp);\n            }\n            res = exp(o) / total;\n        }\n        else if ("+r+" == 2) {\n            for (int i = 0; i < "+e.height_shape+"; i++){\n            float temp = getValueFromTensorPos_origin(oPos[0], oPos[1], i, oPos[3]);\n            total += exp(temp);\n            }\n            res = exp(o) / total;\n        }\n        else {\n            for (int i = 0; i < "+e.width_shape+"; i++){\n            float temp = getValueFromTensorPos_origin(oPos[0], oPos[1], oPos[2], i);\n            total += exp(temp);\n            }\n            res = exp(o) / total;\n        }\n        setOutput(res);\n    }\n    "},params:["axis"],textureFuncConf:{origin:["getValueFromTensorPos"]}},batchnorm:{mainFunc:function(n,o){var e=n.bias,t=n.scale,r=n.mean,i=n.variance,a=o.epsilon;return"\n    // start函数\n    void main(void) {\n        // 输出数据\n        ivec4 oPos = getOutputTensorPos();\n        float o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);\n\n        // 归一化数据\n        vec4 scale = getPixelsFromTexturePos_scale(vec2( float(oPos.g) / float("+t.width_texture+") + 0.00001, 0.0));\n        vec4 bias = getPixelsFromTexturePos_bias(vec2( float(oPos.g) / float("+e.width_texture+") + 0.00001, 0.0));\n        vec4 mean = getPixelsFromTexturePos_mean(vec2((float(oPos.g)) / float("+r.width_texture+")  + 0.00001, 0.0));\n        vec4 variance = getPixelsFromTexturePos_variance(\n            vec2((float(oPos.g)) / float("+i.width_texture+") + 0.00001,\n            0.0)\n        );\n\n        float x = (o - mean[0]) / sqrt(variance[0] + "+a+");\n        float res = scale[0] * x + bias[0];\n        setOutput(res);\n    }\n    "},params:["epsilon"],textureFuncConf:{origin:["getValueFromTensorPos"],scale:["getPixelsFromTexturePos"],bias:["getPixelsFromTexturePos"],mean:["getPixelsFromTexturePos"],variance:["getPixelsFromTexturePos"]}},reshape2:{mainFunc:function(n,o){var e=n.origin,t=n.out;return"\n    // start函数\n    void main(void) {\n        // 输出数据\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        int sumVal = oPos.a\n            + oPos.b * "+t.width_shape+"\n            + oPos.g * "+t.height_shape+" * "+t.width_shape+"\n            + oPos.r * "+t.channel+" * "+t.width_shape+" * "+t.height_shape+";\n        ivec4 new_oPos = transferFromNHWCtoNCHW(\n            sumVal,\n            "+e.channel+",\n            "+e.width_shape+",\n            "+e.height_shape+",\n            "+e.total_shape+"\n        );\n        float o = getValueFromTensorPos_origin(new_oPos.r, new_oPos.g, new_oPos.b, new_oPos.a);\n        setOutput(float(o));\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPos"]},commonFuncConf:["transferFromNHWCtoNCHW"]},bilinear_interp:{mainFunc:function(n,o){var e=n.out,t=n.origin,r=o.align_mode,i=void 0===r?1:r,a=o.align_corners,s=void 0===a||a;return"\n    // start函数\n\n    vec4 getData(float n, float scale, bool align_flag, int in_len) {\n        float m = align_flag ? ((n + 0.5) / scale - 0.5) : (n / scale);\n        int a1 = int(floor(m));\n        a1 = a1 > 0 ? a1 : 0;\n        int a2 = (a1 + 1) < (in_len - 1) ? (a1 + 1) : (in_len - 1);\n\n        float idx_src = (n + 0.5) / scale - 0.5;\n        idx_src = idx_src > 0.0 ? idx_src : 0.0;\n        float b1 = align_flag ? (idx_src - float(a1)) : (n / scale - float(a1));\n        float b2 = 1.0 - b1;\n        return vec4(float(a1), float(a2), b1, b2);\n    }\n\n    void main(void) {\n        // 输出数据\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        //int sumVal = oPos.g\n            + oPos.a * "+e.channel+"\n            + oPos.b * "+e.channel+" * "+e.width_shape+"\n            + oPos.r * "+e.channel+" * "+e.width_shape+" * "+e.height_shape+";\n\n\n        bool align_flag = "+i+" == 0 && !"+s+";\n\n        float scale_x = 0.0;\n        float scale_y = 0.0;\n        if ("+s+") {\n            scale_x = float("+e.width_shape+" - 1) / float("+t.width_shape+" - 1);\n            scale_y = float("+e.height_shape+" - 1) / float("+t.height_shape+" - 1);\n        }\n        else {\n            scale_x = float("+e.width_shape+") / float("+t.width_shape+");\n            scale_y = float("+e.height_shape+") / float("+t.height_shape+");\n        }\n\n        vec4 vx = getData(float(oPos.a), scale_x, align_flag, "+t.width_shape+");\n        vec4 vy = getData(float(oPos.b), scale_y, align_flag, "+t.height_shape+");\n\n        int x1 = int(vx.r);\n        int x2 = int(vx.g);\n        float x3 = vx.b;\n        float x4 = vx.a;\n        int y1 = int(vy.r);\n        int y2 = int(vy.g);\n        float y3 = vy.b;\n        float y4 = vy.a;\n\n        float value11 = getValueFromTensorPos_origin(oPos.r, oPos.g, y1, x1);\n        float value12 = getValueFromTensorPos_origin(oPos.r, oPos.g, y2, x1);\n        float value21 = getValueFromTensorPos_origin(oPos.r, oPos.g, y1, x2);\n        float value22 = getValueFromTensorPos_origin(oPos.r, oPos.g, y2, x2);\n        float value = x4 * y4 * value11 + x4 * y3 * value12 + x3 * y4 * value21 + x3 * y3 * value22;\n        setOutput(float(value));\n    }\n    "},params:["align_corners","align_mode"],textureFuncConf:{origin:["getValueFromTensorPos"]}},transpose2:{mainFunc:function(n,o){var e=n.origin,t=o.axis,r=e.length_unformatted_shape,i=t,a=i.length;if(a-r>0&&(a=(i=i.map((function(n){return n-1})).filter((function(n){return n>=0}))).length),a>4)throw Error("op transpoes2 axis length exceeds maximum length 4, get "+a);for(var s=new Array(a).fill(0),u=0;u<a;u++)s[i[u]]=u;var l=[];for(u=0;u<4;u++)l[u]=s[u]||0;var f=l[0],c=l[1],g=l[2];return"\n    // start函数\n    void main(void) {\n        // 输出数据\n        ivec4 oPos = getOutputTensorPos();\n\n        // 转置 坐标变换\n        float o = 0.0;\n        if ("+a+" == 1) {\n            o = getValueFromTensorPos_origin(oPos[0], oPos[1], oPos[2], oPos[3]);\n        }\n        else if ("+a+" == 2) {\n            o = getValueFromTensorPos_origin(\n                oPos[0], oPos[1],\n                oPos[(2 + "+f+") > 3 ? 3 : (2 + "+f+")],\n                oPos[(2 + "+c+") > 3 ? 3 : (2 + "+c+")]\n            );\n        }\n        else if ("+a+" == 3) {\n            o = getValueFromTensorPos_origin(\n                oPos[0],\n                oPos[(1 + "+f+") > 3 ? 3 : (1 + "+f+")],\n                oPos[(1 + "+c+") > 3 ? 3 : (1 + "+c+")],\n                oPos[(1 + "+g+") > 3 ? 3 : (1 + "+g+")]\n            );\n        }\n        else if ("+a+" == 4) {\n            o = getValueFromTensorPos_origin(\n                oPos["+f+"],\n                oPos["+c+"],\n                oPos["+g+"],\n                oPos["+l[3]+"]\n            );\n        }\n\n\n        setOutput(float(o));\n    }\n    "},params:["axis"],textureFuncConf:{origin:["getValueFromTensorPos"]}},unpacked_2_packed:{mainFunc:function(n,o){return"\n    // start函数\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        vec4 out4;\n        for (int i = 0; i < 4; i++) {\n            vec4 o = getValueFromTensorPosPacking_origin(oPos[0], oPos[1] * 4 + i, oPos[2], oPos[3]);\n            out4[i] = o[0];\n        }\n        setPackedOutput(out4);\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPosPacking"]}},packed_2_unpacked:{mainFunc:function(n,o){return"\n    // start函数\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        float res = 0.0;\n        int c1 = int(mod(float(oPos[1]), 4.0));\n        vec4 o = getValueFromTensorPosPacking_origin(oPos[0], oPos[1] / 4, oPos[2], oPos[3]);\n\n        if (c1 == 0) {\n            res = o.r;\n        } else if (c1 == 1) {\n            res = o.g;\n        } else if (c1 == 2) {\n            res = o.b;\n        } else if (c1 == 3) {\n            res = o.a;\n        }\n        setOutput(res);\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPosPacking"]}},unsqueeze2:{mainFunc:function(n,o){var e=n.origin,t=o.axes,r=e.length_unformatted_shape,i=Array.isArray(t)?t:[t],a=4-r-i.length,s=i.map((function(n){return n+a})),u=[0,1,2,3].filter((function(n){return-1===s.indexOf(n)})).map((function(n){return"oPos["+n+"]"})),l=Array.from(new Array(s.length),(function(){return"0"}));return u.splice.apply(u,function(){for(var n=0,o=0,e=arguments.length;o<e;o++)n+=arguments[o].length;var t=Array(n),r=0;for(o=0;o<e;o++)for(var i=arguments[o],a=0,s=i.length;a<s;a++,r++)t[r]=i[a];return t}([0,0],l)),"\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        float o = 0.0;\n        o = getValueFromTensorPos_origin("+u.join(",")+");\n        setOutput(float(o));\n    }\n    "},params:["axes"],textureFuncConf:{origin:["getValueFromTensorPos"]}},flatten_contiguous_range:{mainFunc:function(n,o){var e=n.origin,t=n.out;return"\n    void main() {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        int sumVal = oPos.a\n            + oPos.b * "+t.width_shape+"\n            + oPos.g * "+t.height_shape+" * "+t.width_shape+"\n            + oPos.r * "+t.channel+" * "+t.width_shape+" * "+t.height_shape+";\n        ivec4 new_oPos = transferFromNHWCtoNCHW(\n            sumVal,\n            "+e.channel+",\n            "+e.width_shape+",\n            "+e.height_shape+",\n            "+e.total_shape+"\n        );\n        float o = getValueFromTensorPos_origin(new_oPos.r, new_oPos.g, new_oPos.b, new_oPos.a);\n        setOutput(float(o));\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPos"]},commonFuncConf:["transferFromNHWCtoNCHW"]},greater_than:{mainFunc:function(n,o){return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float x = getValueFromTensorPos_input(oPos.r, oPos.g, oPos.b, oPos.a);\n        float y = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);\n\n        setOutput(bool(x >= y));\n    }\n    "},textureFuncConf:{origin:["getValueFromTensorPos"],counter:["getValueFromTensorPos"]}},reduce_sum:{mainFunc:function(n,o){return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float o = 0.0;\n        for (int i = 0; i < "+o.inputs_dim+"; i++) {\n            oPos["+o.dim+"] = i;\n            o += getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);;\n        }\n        setOutput(float(o));\n    }\n    "},params:["inputs_dim","dim"],textureFuncConf:{origin:["getValueFromTensorPos"]},behaviors:["normalizeDim"]},where:{mainFunc:function(n,o){return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        // 输出坐标转换为输入坐标\n        float x = getValueFromTensorPos_input(oPos.r, oPos.g, oPos.b, oPos.a);\n        float y = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);\n        float condition = getValueFromTensorPos_condition(oPos.r, oPos.g, oPos.b, oPos.a);\n        float o = 0.0;\n\n        if (bool(condition)) {\n            o = x;\n        }\n        else {\n            o = y;\n        }\n        setOutput(o);\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPos"],counter:["getValueFromTensorPos"],condition:["getValueFromTensorPos"]}},connect:{mainFunc:function(n,o){var e=n.origin,t=n.out,r=t.total_shape,i=t.width_shape,a=t.height_shape,s=t.channel;return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        float o = 0.0;\n        ivec4 co;\n        int sumVal = oPos.b * "+x([r/(i*a*s),s,a,i])[2]+" + oPos.a;\n        if (sumVal < "+e.total_shape+") {\n            // from origin\n            co = getTensorPosFromArrayIndex_origin(sumVal);\n            o = getValueFromTensorPos_origin(co.r, co.g, co.b, co.a);\n\n        }\n        else {\n            // from counter\n            co = getTensorPosFromArrayIndex_counter(sumVal - "+e.total_shape+");\n            o = getValueFromTensorPos_counter(co.r, co.g, co.b, co.a);\n        }\n        setOutput(float(o));\n    }\n    "},params:[],textureFuncConf:{origin:["getValueFromTensorPos","getTensorPosFromArrayIndex"],counter:["getValueFromTensorPos","getTensorPosFromArrayIndex"]}},prelu:w("prelu"),relu6:w("relu6"),leakyRelu:w("leakyRelu"),scale:w("scale"),sigmoid:w("sigmoid"),relu:w("relu"),hard_sigmoid:w("hard_sigmoid"),pow:w("pow"),sqrt:w("sqrt"),squeeze2:A,pad3d:{mainFunc:function(n,o){var e=n.origin,t=o.padding,r=o.mode,i=o.value,a=function(n){var o=n.total_shape,e=n.channel,t=n.height_shape,r=n.width_shape;return[o/e/t/r,e,t,r]}(e),s={reflect:"\n            int a;\n            int b;\n            if (oPos.a - "+t[0]+" < 0) {\n                a = "+t[0]+" - oPos.a;\n            }\n            else if (oPos.a - "+t[0]+" >= "+a[3]+") {\n                a = "+a[3]+" - (oPos.a - "+t[0]+" - "+a[3]+" + 1) - 1;\n            }\n            else {\n                a = oPos.a - "+t[0]+";\n            }\n            if (oPos.b - "+t[2]+" < 0) {\n                b = "+t[2]+" - oPos.b;\n            }\n            else if (oPos.b - "+t[2]+" >= "+a[2]+") {\n                b = "+a[2]+" - (oPos.b - "+t[2]+" - "+a[2]+" + 1) - 1;\n            }\n            else {\n                b = oPos.b - "+t[2]+";\n            }\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, b, a);\n        ",replicate:"\n            int a;\n            int b;\n            if (oPos.a - "+t[0]+" < 0) {\n                a = 0;\n            }\n            else if (oPos.a - "+t[0]+" >= "+a[3]+") {\n                a = "+a[3]+" - 1;\n            }\n            else {\n                a = oPos.a - "+t[0]+";\n            }\n            if (oPos.b - "+t[2]+" < 0) {\n                b = 0;\n            }\n            else if (oPos.b - "+t[2]+" >= "+a[2]+") {\n                b = "+a[2]+" - 1;\n            }\n            else {\n                b = oPos.b - "+t[2]+";\n            }\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, b, a);\n        ",circular:"\n            int a;\n            int b;\n            if (oPos.a - "+t[0]+" < 0) {\n                a = int(mod(float("+t[0]+" + oPos.a - 1), float("+a[3]+")));\n            }\n            else if (oPos.a - "+t[0]+" >= "+a[3]+") {\n                a = int(mod(float(oPos.a - "+t[0]+" - "+a[3]+"), float("+a[3]+")));\n            }\n            else {\n                a = oPos.a - "+t[0]+";\n            }\n            if (oPos.b - "+t[2]+" < 0) {\n                b = int(mod(float("+t[2]+" + oPos.b - 1), float("+a[2]+")));\n            }\n            else if (oPos.b - "+t[2]+" >= "+a[2]+") {\n                b = int(mod(float(oPos.b - "+t[2]+" - "+a[2]+"), float("+a[2]+")));\n            }\n            else {\n                b = oPos.b - "+t[2]+";\n            }\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, b, a);\n        ",constant:"",undefined:""};return"\n    // start函数\n    void main(void) {\n        ivec4 oPos = getOutputTensorPos();\n        float o = "+(i||"0.0")+";\n        if (oPos.a - "+t[0]+" >= 0\n            && oPos.b - "+t[2]+" >= 0\n            && oPos.a - "+t[0]+" < "+a[3]+"\n            && oPos.b - "+t[2]+" < "+a[2]+"\n        ) {\n            o = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b - "+t[2]+", oPos.a - "+t[0]+");\n        }\n        else {\n            "+s[r]+"\n        }\n        setOutput(float(o));\n    }\n    "},params:["padding","mode","value"],textureFuncConf:{origin:["getValueFromTensorPos"]}}},R=["length_shape","length_unformatted_shape","width_shape","height_shape","width_texture","height_texture","offset_x","offset_y","limit","channel","total_shape","numbers_shape"],O=["total_shape","width_shape","height_shape","width_texture","height_texture","channel","limit"],S={float:["multi_value","bias_value"],bool:["fuse_relu"]};const L="\nivec4 transferFromNHWCtoNCHW(\n    int sumVal,\n    const int channel,\n    const int width_shape,\n    const int height_shape,\n    const int total_shape) {\n\n    int n_origin = int(total_shape/(channel * width_shape * height_shape));\n    int new_a = int(mod(float(sumVal), float(width_shape)));\n    sumVal = int((sumVal - new_a) / width_shape);\n    int new_b = int(mod(float(sumVal), float(height_shape)));\n    sumVal = int((sumVal - new_b) / height_shape);\n    int new_g = int(mod(float(sumVal), float(channel)));\n    sumVal = int((sumVal - new_g) / channel);\n    int new_r = int(mod(float(sumVal), float(n_origin)));\n    return ivec4(new_r,new_g,new_b,new_a);\n}\n";var I="\nfloat prelu(float x, float p, float b) {\n    float result = x;\n    if (x < 0.0) {\n        result = x * p;\n    }\n\n    return result;\n}",D="\nfloat relu6(float x, float threshold, float b) {\n    float result = max(0.0, x);\n    result = min(result, threshold);\n    return result;\n}",U="\nfloat leakyRelu(float x, float p, float b) {\n    float result = 0.0\n    if (x > 0.0) {\n        result = x;\n    }\n    else {\n        result = p * x;\n    }\n    return result;\n}",B="\nfloat scale(float x, float p, float b) {\n    float result = p * x + b;\n    return result;\n}",k="\nfloat scaleWidthBias(float x, float p, float b) {\n    float result = p * (x + b);\n    return result;\n}",M="\nfloat sigmoid(float x, float y, float z) {\n    float result = 1.0 / (1.0 + exp(-x));\n    return result;\n}",X="\n    float hardSigmoid(float x, float slope, float offset) {\n        float result = max(0.0, min(1.0, slope * x + offset));\n        return result;\n    }\n",N="\n    float sqrt(float x, float slope, float offset) {\n        return sqrt(x);\n    }\n",G="\n    float pow(float x, float factor, float offset) {\n        return pow(x, factor);\n    }\n";function j(n,o){return o.limit?function(n,o){var e=o.width_shape,t=o.height_shape;return"\n    // 超限布局根据tensor坐标获取这个tensor位置的值\n    float getValueFromTensorPos_"+n+"(int r, int g, int b, int a) {\n        float pieceW = ceil(float("+e+") / 4.0);\n        int x = int(mod(float(a), pieceW));\n        int offsetY = 0;\n\n        if ((float(a) / pieceW) >= 3.0) {\n            offsetY = 3 * "+t+";\n        }\n        else if (float(a) / pieceW >= 2.0) {\n            offsetY = 2 * "+t+";\n        }\n        else if (float(a) >= pieceW) {\n            offsetY = "+t+";\n        }\n        vec4 pixels = TEXTURE2D(texture_"+n+",\n            vec2(\n                (float(x * "+o.channel+" + g) + 0.5) / float("+o.width_texture+"),\n                (float(r * 4 * "+t+" + b + offsetY) + 0.5) / float("+o.height_texture+")\n            )\n        );\n        return pixels.r;\n    }"}(n,o):function(n,o){var e=o.channel,t=o.height_shape;return"\n    // 根据tensor坐标获取这个tensor位置的值\n    float getValueFromTensorPos_"+n+"(int r, int g, int b, int a) {\n        vec4 pixels = TEXTURE2D(texture_"+n+",\n            vec2(\n                (float(a * "+e+" + g) + 0.5) / float("+o.width_texture+"),\n                (float(r * "+t+" + b) + 0.5) / float("+o.height_texture+")\n            )\n        );\n        // 只用了r通道\n        return pixels.r;\n    }"}(n,o)}function W(n,o){return o.limit?function(n,o){var e=o.width_shape,t=o.height_shape;return"\n    // 超限布局根据tensor坐标获取这个tensor位置的值\n    float getValueFromTensorPosPacking_"+n+"(int r, int g, int b, int a) {\n        float pieceW = ceil(float("+e+") / 4.0);\n        int x = int(mod(float(a), pieceW));\n        int offsetY = 0;\n\n        if ((float(a) / pieceW) >= 3.0) {\n            offsetY = 3 * "+t+";\n        }\n        else if (float(a) / pieceW >= 2.0) {\n            offsetY = 2 * "+t+";\n        }\n        else if (float(a) >= pieceW) {\n            offsetY = "+t+";\n        }\n        vec4 pixels = TEXTURE2D(texture_"+n+",\n            vec2(\n                (float(x * "+o.channel+" + g) + 0.5) / float("+o.width_texture+"),\n                (float(r * 4 * "+t+" + b + offsetY) + 0.5) / float("+o.height_texture+")\n            )\n        );\n        return pixels;\n    }"}(n,o):function(n,o){var e=o.channel,t=o.height_shape;return"\n    // 根据tensor坐标获取这个tensor位置的值\n    vec4 getValueFromTensorPosPacking_"+n+"(int r, int g, int b, int a) {\n        vec4 pixels = TEXTURE2D(texture_"+n+",\n            vec2(\n                (float(a * "+e+" + g) + 0.5) / float("+o.width_texture+"),\n                (float(r * "+t+" + b) + 0.5) / float("+o.height_texture+")\n            )\n        );\n        return pixels;\n    }"}(n,o)}function H(n,o){var e=o.offset_y;return"\n    // 超限布局根据tensor坐标获取这个tensor位置的值\n    float getValueFromTensorPosPacked_"+n+"(int r, int g, int b, int a) {\n        int y = b / 2;\n        int yOffset = int(mod(float(b), 2.0));\n        int x = a / 2;\n        int xOffset = int(mod(float(a), 2.0));\n        int height = "+o.height_shape+" + "+e+";\n        vec4 pixels = TEXTURE2D(\n            texture_"+n+",\n            vec2((float(x) + 0.5) / float("+o.width_texture+"),\n            (float(g * height / 2 + y) + 0.5) / float("+o.height_texture+"))\n        );\n        int index = 0;\n        if (xOffset == 0 && yOffset == 0) {\n            return pixels[0];\n        }\n        else if (xOffset == 1 && yOffset == 0) {\n            return pixels[1];\n        }\n        else if (xOffset == 0 && yOffset == 1) {\n            return pixels[2];\n        }\n        return pixels[3];\n    }"}function Y(n,o){var e=o.numbers_shape,t=o.length_shape;return 1===t?"\n            int getTensorPosFromArrayIndex_"+n+"(int n) {\n                return int(mod(float(n), float("+e[0]+")));\n            }\n        ":"\n    ivec"+t+" shapeVec_"+n+" = ivec"+t+"("+e.join(", ")+");\n    ivec"+t+" getTensorPosFromArrayIndex_"+n+"(int n) {\n        ivec"+t+" pos;\n        pos[0] = n / shapeVec_"+n+"[0];\n        for (int i = 1; i < "+t+"; i++) {\n            n = int(mod(float(n), float(shapeVec_"+n+"[i - 1])));\n            pos[i] = n / shapeVec_"+n+"[i];\n        }\n        return pos;\n    }\n    "}function z(n){return"\n    #define getPixelsFromTexturePos_"+n+"(pos) TEXTURE2D(texture_"+n+", pos)\n    "}function q(n,o){return"\n    vec2 moveTexture2PosToReal_"+n+"(vec2 v) {\n        vec2 v2;\n        v2.x = v.x * float("+o.width_texture+");\n        v2.y = v.y * float("+o.height_texture+");\n        return v2;\n    }\n    "}function K(n){return"uniform sampler2D texture_"+n+";"}const Z=function(){function n(n,o,e,t){var r=n;this.vShader=o;try{this.fShader=this.initShader(r,e,"fragment"),this.shape=t&&t.shape;var i=this.program=r.createProgram();r.attachShader(i,this.vShader),r.attachShader(i,this.fShader),r.linkProgram(i)}catch(n){console.error(n)}}return n.prototype.initShader=function(n,o,e){void 0===e&&(e="vertex");var t,r="vertex"===e?n.VERTEX_SHADER:n.FRAGMENT_SHADER;if("vertex"===e&&this.vShader)t=this.vShader;else if(t=n.createShader(r),"vertex"===e&&(this.vShader=t),n.shaderSource(t,o),n.compileShader(t),!n.getShaderParameter(t,n.COMPILE_STATUS))throw new Error("compile: "+n.getShaderInfoLog(t));return t},n.prototype.setProgram=function(n,o,e){n.useProgram(this.program),e||this.runVertexShader(n,o)},n.prototype.runVertexShader=function(n,o){var e=n.getAttribLocation(this.program,"position");n.enableVertexAttribArray(e),n.bindBuffer(n.ARRAY_BUFFER,o),n.vertexAttribPointer(e,2,n.FLOAT,!1,16,0)},n.Sampler="uSampler",n}();var Q,J=(Q=function(n,o){return(Q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(n[e]=o[e])})(n,o)},function(n,o){function e(){this.constructor=n}Q(n,o),n.prototype=null===o?Object.create(o):(e.prototype=o.prototype,new e)}),$=function(n,o,e,t){return new(e||(e=Promise))((function(r,i){function a(n){try{u(t.next(n))}catch(n){i(n)}}function s(n){try{u(t.throw(n))}catch(n){i(n)}}function u(n){var o;n.done?r(n.value):(o=n.value,o instanceof e?o:new e((function(n){n(o)}))).then(a,s)}u((t=t.apply(n,o||[])).next())}))},nn=function(n,o){var e,t,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,t&&(r=2&i[0]?t.return:i[0]?t.throw||((r=t.return)&&r.call(t),0):t.next)&&!(r=r.call(t,i[1])).done)return r;switch(t=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,t=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=o.call(n,a)}catch(n){i=[6,n],t=0}finally{e=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},on=new(function(n){function o(){var o=n.call(this)||this;return o.gl=h.getWebGLRenderingContext(),o.textureConf=p.getTextureConfig(o.gl),o.glVersion=h.getWebglVersion(),o.MAX_TEXTURE_SIZE=o.gl.getParameter(o.gl.MAX_TEXTURE_SIZE),o.cacheTextures={},o.uniformLocations={},o.texturesMap={},o.queryList=[],o.prevTexture=null,o.currentTexture=null,o.width_shape_out=1,o.height_shape_out=1,o.width_texture_out=1,o.height_texture_out=1,o.channel=0,o.total_shape=0,o}return J(o,n),o.prototype.init=function(){return $(this,void 0,void 0,(function(){var n;return nn(this,(function(o){return(n=this.gl).disable(n.DEPTH_TEST),n.disable(n.STENCIL_TEST),n.disable(n.BLEND),n.disable(n.DITHER),n.disable(n.POLYGON_OFFSET_FILL),n.disable(n.SAMPLE_COVERAGE),n.enable(n.SCISSOR_TEST),n.enable(n.CULL_FACE),n.cullFace(n.BACK),this.vertexBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexBuffer),n.bufferData(n.ARRAY_BUFFER,P,n.STATIC_DRAW),this.vShader=h.initShader(n,l.VS_SHADER,d[this.glVersion-1]),this.frameBuffer=n.createFramebuffer(),n.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer),this.pbo=n.createBuffer(),[2]}))}))},o.prototype.createProgram=function(n){var o=n.name,e=n.outTensor,i=n.inputTensors,a=n.shaderParams,s=n.runtime,l=n.isFinalOp,f=n.isPacked,c=function(n,o,e,i,a,s){void 0===s&&(s=!1);var l,f,c="";try{var g=function(n,o){return n.indexOf("conv2d-elementwise_add")>-1?"conv2d_elementwise_add":o?n+"_packing":n}(o,s),_=C[g],h=_.params,p=void 0===h?{}:h,d=_.mainFunc,P=_.textureFuncConf,m=void 0===P?{}:P,v=_.commonFuncConf,x=function(n,o,e){for(var t={},r={},i=[],a=0,s=n;a<s.length;a++){for(var u=s[a],l=u.name,f={},c=0,g=R;c<g.length;c++)void 0!==u[E=g[c]]&&(f[E]=u[E]);t[l]=f,i.push(l)}if(o)for(var _=0,h=o;_<h.length;_++)void 0!==e[E=h[_]]&&(r[E]=e[E]);for(var p=0,d=Object.keys(S);p<d.length;p++)for(var P=d[p],m=0,v=S[P];m<v.length;m++)void 0!==e[E=v[m]]&&(r[E]=P+"("+e[E]+")");for(var x={},T=0,F=O;T<F.length;T++){var E;void 0!==e[(E=F[T])+"_out"]&&(x[E]=e[E+"_out"])}return t.out=x,e.active_function&&(r.active_function=e.active_function),{textureParams:t,opParams:r,active_function:e.active_function}}(e,p,i),T=x.textureParams,F=x.opParams,E=x.active_function,b=function(n){var o=n.isFrameBufferSupportFloat,e=n.isFinalOp,t=n.isFloatTextureReadPixelsEnabled;return 2===u.get("webglVersion")?"   #version 300 es\n    #ifdef GL_FRAGMENT_PRECISION_HIGH\n        precision highp float;\n        precision highp int;\n    #else\n        precision mediump float;\n        precision mediump int;\n    #endif\n\n    // 顶点shader透传的材质坐标\n    in vec2 vCoord;\n    out vec4 outColor;\n    void setOutput(float result) {\n        outColor.r = result;\n    }\n    void setPackedOutput(vec4 result) {\n        outColor = result;\n    }\n":o?"   #ifdef GL_FRAGMENT_PRECISION_HIGH\n        precision highp float;\n        precision highp int;\n    #else\n        precision highp float;\n        precision highp int;\n    #endif\n        varying vec2 vCoord;\n        varying vec4 outColor;\n        void setOutput(float result) {\n            gl_FragColor.r = result;\n        }\n        void setPackedOutput(vec4 result) {\n            gl_FragColor = result;\n        }\n":e&&!t?"\nprecision highp float;\nprecision highp int;\n\nvarying vec2 vCoord;\nvarying vec4 outColor;\n\nconst float FLOAT_MAX = 1.70141184e38;\nconst float FLOAT_MIN = 1.17549435e-38;\n\n#define isnan(value) isnan_custom(value)\nbool isnan_custom(float val) {\n    return (val > 0. || val < 1. || val == 0.) ? false : true;\n}\n\nlowp vec4 encode_float(highp float v) {\n    if (isnan(v)) {\n      return vec4(255, 255, 255, 255);\n    }\n\n    highp float av = abs(v);\n\n    if(av < FLOAT_MIN) {\n      return vec4(0.0, 0.0, 0.0, 0.0);\n    } else if(v > FLOAT_MAX) {\n      return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n    } else if(v < -FLOAT_MAX) {\n      return vec4(0.0, 0.0,  128.0, 255.0) / 255.0;\n    }\n\n    highp vec4 c = vec4(0,0,0,0);\n\n    highp float e = floor(log2(av));\n    highp float m = exp2(fract(log2(av))) - 1.0;\n\n    c[2] = floor(128.0 * m);\n    m -= c[2] / 128.0;\n    c[1] = floor(32768.0 * m);\n    m -= c[1] / 32768.0;\n    c[0] = floor(8388608.0 * m);\n\n    highp float ebias = e + 127.0;\n    c[3] = floor(ebias / 2.0);\n    ebias -= c[3] * 2.0;\n    c[2] += floor(ebias) * 128.0;\n\n    c[3] += 128.0 * step(0.0, -v);\n\n    return c / 255.0;\n}\n\nvoid setOutput(float result) {\n        gl_FragColor = encode_float(result);\n}\n":"\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n    precision highp float;\n    precision highp int;\n#else\n    precision highp float;\n    precision highp int;\n#endif\n\n    #define isnan(value) isnan_custom(value)\n    bool isnan_custom(float val) {\n        return (val > 0. || val < 1. || val == 0.) ? false : true;\n    }\n\n    varying vec2 vCoord;\n    varying vec4 outColor;\n    void setOutput(float result) {\n        if(isnan(result)) {\n            gl_FragColor.r = 0.0;\n        }else {\n            gl_FragColor.r = result;\n        }\n    }\n\n    void setPackedOutput(vec4 result) {\n        gl_FragColor = result;\n    }\n"}(n),y=function(n,o,e){if(!n)return"";for(var t="",i="",a=0,s=Object.keys(n);a<s.length;a++){var u=s[a];if(o[u]){i+=K(u);for(var l=0,f=n[u];l<f.length;l++){var c=f[l];if(r[c])try{t+=r[c](u,o[u],e)}catch(n){console.error(n)}}}}return"\n    "+i+"\n    "+t+"\n    "}(m,T,F),V=function(n){return void 0===n?"":"\n        int layer_run_time = "+n+";\n    "}(a),w=function(n){var o,e,t,r;return"\n        \n    vec2 _2d_shape_texture_out = vec2(float("+n.width_texture+"), float("+n.height_texture+"));\n    \n        "+(n.limit?(e=(o=n).height_shape,t=o.width_shape,"\n    ivec4 getOutputTensorPos() {\n        // 获取原始长度\n        vec2 outCoord = vCoord.xy * _2d_shape_texture_out;\n        float offsetY = floor(outCoord.y / float("+e+"));\n        int x = int(outCoord.x / float("+(r=o.channel)+"));\n        if (mod(offsetY, 4.0) > 0.0) {\n            x += int(mod(offsetY, 4.0)) * int(ceil(float("+t+") / 4.0));\n        }\n        int y = int(mod(outCoord.y, float("+e+")));\n        int c = int(mod(outCoord.x, float("+r+")));\n        int b = int(outCoord.y / float(4 * "+e+"));\n        return ivec4(b, c, y, x);\n    }\n    "):function(n){var o=n.height_shape,e=n.channel;return"\n    ivec4 getOutputTensorPos() {\n        vec2 outCoord = vCoord.xy * _2d_shape_texture_out;\n        int x = int(outCoord.x / float("+e+"));\n        int c = int(mod(outCoord.x, float("+e+")));\n        int y = int(mod(outCoord.y, float("+o+")));\n        int b = int(outCoord.y / float("+o+"));\n        return ivec4(b, c, y, x);\n    }\n    "}(n))+"\n    "}(T.out),A=function(n){if(!n)return"";for(var o="",e=0,r=n;e<r.length;e++){var i=r[e];t[i]&&(o+=t[i])}return o}(v);l=c="   "+b+"\n            "+A+"\n            "+(E?t[E]:"")+"\n            "+y+"\n            "+V+"\n            "+w+"\n            "+d(T,F)+"\n        ",f=1===u.get("webglVersion")?"texture2D":"texture",c=l.replace(/\bTEXTURE2D\b/g,f)}catch(n){console.error(n)}return c}(this.textureConf,o,i,a,s,f),g=new Z(this.gl,this.vShader,c,e);g.fsCode=c;var _=p.genOutputTexture(this.gl,this.textureConf,e,l);return this.texturesMap[e.tensorId]=_,this.program=g,g},o.prototype.runProgram=function(n,o){var e=this,t=function(n,o){if(2===o){var e=n.getExtension("EXT_disjoint_timer_query_webgl2");if(!e)return;var t=n.createQuery();return n.beginQuery(e.TIME_ELAPSED_EXT,t),t}return null}(this.gl,this.glVersion),r=n.isPackedOp;n.program.forEach((function(t,i){var a=n.outputTensors[i],s=a.tensorId;e.setOutProps(a),e.attachFrameBuffer(s),t.setProgram(e.gl,e.vertexBuffer,o),e.program=t,e.render(n.inputTensors,n.iLayer,o,i,r,n.modelName)})),t&&(this.queryList.push({name:n.name,query:t,count:1}),t=function(n,o,e){if(2===o){var t=n.getExtension("EXT_disjoint_timer_query_webgl2");if(!t)return;n.endQuery(t.TIME_ELAPSED_EXT)}return e}(this.gl,this.glVersion,t))},o.prototype.read=function(){return $(this,void 0,void 0,(function(){var n,o,e,t,r,i,a;return nn(this,(function(s){switch(s.label){case 0:return n=this.createPBO(),[4,this.createAndWaitForFence()];case 1:return s.sent(),o=this.downloadFoat32TensorFromBuffer(n),e=this.program.shape,u.get("debug")&&u.get("shape")&&(e=u.get("shape")),t=e[0],r=e[1],i=e[2],a=e[3],[2,v(o,[t,i,a,r])]}}))}))},o.prototype.createPBO=function(){var n,o=this.textureConf;if(2===this.glVersion){var e=this.gl,t=this.pbo;e.bindBuffer(e.PIXEL_PACK_BUFFER,t);var r=16*this.width_texture_out*this.height_texture_out;return e.bufferData(e.PIXEL_PACK_BUFFER,r,e.STREAM_READ),e.readPixels(0,0,this.width_texture_out,this.height_texture_out,e.RGBA,e.FLOAT,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),t}var i=this.gl,a=i.FLOAT;return o.isFloatTextureReadPixelsEnabled?n=new Float32Array(this.width_texture_out*this.height_texture_out*4):(n=new Uint8Array(this.width_texture_out*this.height_texture_out*4),a=i.UNSIGNED_BYTE),i.readPixels(0,0,this.width_texture_out,this.height_texture_out,i.RGBA,a,n),o.isFloatTextureReadPixelsEnabled?n:new Float32Array(n.buffer)},o.prototype.createAndWaitForFence=function(){return $(this,void 0,void 0,(function(){var n,o,e,t,r=this;return nn(this,(function(i){return n=this.gl,o=null!=n.fenceSync,e=function(){return!0},o&&(t=n.fenceSync(n.SYNC_GPU_COMMANDS_COMPLETE,0),n.flush(),e=function(){var o=n.clientWaitSync(t,0,0);return o===n.ALREADY_SIGNALED||o===n.CONDITION_SATISFIED}),[2,new Promise((function(n){r.pollItem(e,n)}))]}))}))},o.prototype.pollItem=function(n,o){var e=function(){n()?o():setTimeout(e,1)};e()},o.prototype.downloadFoat32TensorFromBuffer=function(n){var o=this.gl,e=4*this.width_texture_out*this.height_texture_out;if(2===this.glVersion){var t=new Float32Array(e);o.bindBuffer(o.PIXEL_PACK_BUFFER,n),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,t),o.bindBuffer(o.PIXEL_PACK_BUFFER,null);for(var r=[],i=0;i<this.width_texture_out*this.height_texture_out;i++)r.push(t[4*i]);return r}var a=n,s=[];for(i=0;i<this.width_texture_out*this.height_texture_out;i++){var u=this.textureConf.isFloatTextureReadPixelsEnabled?4*i:i;s.push(a[u])}return s},o.prototype.setOutProps=function(n){var o=n.width_shape,e=void 0===o?1:o,t=n.height_shape,r=void 0===t?1:t,i=n.width_texture,a=void 0===i?1:i,s=n.height_texture,u=void 0===s?1:s,l=n.channel,f=void 0===l?0:l,c=n.total_shape,g=void 0===c?0:c;this.width_shape_out=e,this.height_shape_out=r,this.width_texture_out=a,this.height_texture_out=u,this.channel=f,this.total_shape=g},o.prototype.attachFrameBuffer=function(n){this.prevTexture=this.currentTexture,this.currentTexture=this.texturesMap[n];var o=this.gl;return o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,this.currentTexture,0),o.viewport(0,0,this.width_texture_out,this.height_texture_out),o.scissor(0,0,this.width_texture_out,this.height_texture_out),this.frameBuffer},o.prototype.render=function(n,o,e,t,r,i){void 0===n&&(n=[]),void 0===o&&(o=0),void 0===e&&(e=!1),void 0===r&&(r=!1);var a=this.gl,s=this,u=0;n.forEach((function(n){var l=s.getUniformLoc("texture_"+n.name,o,e,t,i);l&&(s.initTexture(u,n,o,e,r,i),a.uniform1i(l,u++))})),a.drawArrays(a.TRIANGLE_STRIP,0,4)},o.prototype.initTexture=function(n,o,e,t,r,i){var a,s=this.gl,u=this.textureConf,l=o.opts.type,f=i+"_";if(o.data?t&&(e>1||1===e&&!l.endsWith("_image"))?a=this.cacheTextures[f+e]["texture_"+l]:(a=s.createTexture(),this.cacheTextures[f+e]=this.cacheTextures[f+e]||{},this.cacheTextures[f+e]["texture_"+l]=a):a=this.texturesMap[o.opts.type],s.activeTexture(s["TEXTURE"+n]),s.bindTexture(s.TEXTURE_2D,a),o.data&&(!t||t&&1===e&&l.endsWith("_image")))if(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),2===this.glVersion){var c=r?s.RGBA16F:u.internalFormat,g=r?s.RGBA:u.textureFormat;s.texImage2D(s.TEXTURE_2D,0,c,o.width_texture,o.height_texture,0,g,s.FLOAT,o.data)}else{for(var _=new Float32Array(o.width_texture*o.height_texture*4),h=0;h<o.data.length;h++)r?_[h]=o.data[h]:(_[4*h]=o.data[h],_[4*h+1]=0,_[4*h+2]=0,_[4*h+3]=0);s.texImage2D(s.TEXTURE_2D,0,s.RGBA,o.width_texture,o.height_texture,0,s.RGBA,s.FLOAT,_)}},o.prototype.getUniformLoc=function(n,o,e,t,r){var i=r+"_";if(e)return this.uniformLocations[i+o][n+t];var a=this.gl.getUniformLocation(this.program.program,n);return this.uniformLocations[i+o]=this.uniformLocations[i+o]||{},this.uniformLocations[i+o][n+t]=a,a},o.prototype.dispose=function(){},o}((function(){})));!function(n,o,e){n&&(s.backend=n),o&&(s.backendInstance=o),e&&Object.keys(e).forEach((function(n){!function(n,o){var e=n.conf,t=n.params,r=n.main,i=n.main_packed,a=void 0===i?"":i,u=n.behaviors,l=void 0===u?[]:u,f=s.backend+"_"+o;s.opRegistry.ops[f]||(s.opRegistry.ops[f]={name:o,conf:e,params:t,main:r,main_packed:a,behaviors:l})}(e[n],n)}))}("webgl",on,C)}},o={};function e(t){if(o[t])return o[t].exports;var r=o[t]={exports:{}};return n[t](r,r.exports,e),r.exports}return e.d=(n,o)=>{for(var t in o)e.o(o,t)&&!e.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:o[t]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(n){if("object"==typeof window)return window}}(),e.o=(n,o)=>Object.prototype.hasOwnProperty.call(n,o),e.r=n=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e(968)})()}));