diff --git "a/dist/ort.all.bundle.min.mjs" "b/dist/ort.all.bundle.min.mjs" new file mode 100755--- /dev/null +++ "b/dist/ort.all.bundle.min.mjs" @@ -0,0 +1,4663 @@ +/*! + * ONNX Runtime Web v1.23.0 + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ +var o3=Object.create;var wi=Object.defineProperty;var i3=Object.getOwnPropertyDescriptor;var a3=Object.getOwnPropertyNames;var s3=Object.getPrototypeOf,u3=Object.prototype.hasOwnProperty;var eu=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var H=(n,e)=>()=>(n&&(e=n(n=0)),e);var ge=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),zn=(n,e)=>{for(var r in e)wi(n,r,{get:e[r],enumerable:!0})},jg=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of a3(e))!u3.call(n,o)&&o!==r&&wi(n,o,{get:()=>e[o],enumerable:!(t=i3(e,o))||t.enumerable});return n};var Ne=(n,e,r)=>(r=n!=null?o3(s3(n)):{},jg(e||!n||!n.__esModule?wi(r,"default",{value:n,enumerable:!0}):r,n)),uo=n=>jg(wi({},"__esModule",{value:!0}),n);var xi,Mn,_n,l3,Gg,tu=H(()=>{xi=new Map,Mn=[],_n=(n,e,r)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let t=xi.get(n);if(t===void 0)xi.set(n,{backend:e,priority:r});else{if(t.priority>r)return;if(t.priority===r&&t.backend!==e)throw new Error(`cannot register backend "${n}" using priority ${r}`)}if(r>=0){let o=Mn.indexOf(n);o!==-1&&Mn.splice(o,1);for(let i=0;i{let e=xi.get(n);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init(n)),await e.initPromise,e.initialized=!0,e.backend}catch(t){return r||(e.error=`${t}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},Gg=async n=>{let e=n.executionProviders||[],r=e.map(d=>typeof d=="string"?d:d.name),t=r.length===0?Mn:r,o,i=[],a=new Set;for(let d of t){let h=await l3(d);typeof h=="string"?i.push({name:d,err:h}):(o||(o=h),o===h&&a.add(d))}if(!o)throw new Error(`no available backend found. ERR: ${i.map(d=>`[${d.name}] ${d.err}`).join(", ")}`);for(let{name:d,err:h}of i)r.includes(d)&&console.warn(`removing requested execution provider "${d}" from session options because it is not available: ${h}`);let l=e.filter(d=>a.has(typeof d=="string"?d:d.name));return[o,new Proxy(n,{get:(d,h)=>h==="executionProviders"?l:Reflect.get(d,h)})]}});var Ug=H(()=>{tu()});var Wg,Hg=H(()=>{Wg="1.23.0"});var qg,Mt,ru=H(()=>{Hg();qg="warning",Mt={wasm:{},webgl:{},webgpu:{},versions:{common:Wg},set logLevel(n){if(n!==void 0){if(typeof n!="string"||["verbose","info","warning","error","fatal"].indexOf(n)===-1)throw new Error(`Unsupported logging level: ${n}`);qg=n}},get logLevel(){return qg}};Object.defineProperty(Mt,"logLevel",{enumerable:!0})});var Ae,Kg=H(()=>{ru();Ae=Mt});var Xg,Jg,Zg=H(()=>{Xg=(n,e)=>{let r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=n.dims[3],r.height=n.dims[2];let t=r.getContext("2d");if(t!=null){let o,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=n.dims[2],i=n.dims[3]):(o=n.dims[3],i=n.dims[2]);let a=e?.format!==void 0?e.format:"RGB",l=e?.norm,d,h;l===void 0||l.mean===void 0?d=[255,255,255,255]:typeof l.mean=="number"?d=[l.mean,l.mean,l.mean,l.mean]:(d=[l.mean[0],l.mean[1],l.mean[2],0],l.mean[3]!==void 0&&(d[3]=l.mean[3])),l===void 0||l.bias===void 0?h=[0,0,0,0]:typeof l.bias=="number"?h=[l.bias,l.bias,l.bias,l.bias]:(h=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(h[3]=l.bias[3]));let g=i*o,_=0,w=g,x=g*2,T=-1;a==="RGBA"?(_=0,w=g,x=g*2,T=g*3):a==="RGB"?(_=0,w=g,x=g*2):a==="RBG"&&(_=0,x=g,w=g*2);for(let S=0;S{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),t;if(r!=null){let o,i,a;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=n.dims[2],i=n.dims[1],a=n.dims[3]):(o=n.dims[3],i=n.dims[2],a=n.dims[1]);let l=e!==void 0&&e.format!==void 0?e.format:"RGB",d=e?.norm,h,g;d===void 0||d.mean===void 0?h=[255,255,255,255]:typeof d.mean=="number"?h=[d.mean,d.mean,d.mean,d.mean]:(h=[d.mean[0],d.mean[1],d.mean[2],255],d.mean[3]!==void 0&&(h[3]=d.mean[3])),d===void 0||d.bias===void 0?g=[0,0,0,0]:typeof d.bias=="number"?g=[d.bias,d.bias,d.bias,d.bias]:(g=[d.bias[0],d.bias[1],d.bias[2],0],d.bias[3]!==void 0&&(g[3]=d.bias[3]));let _=i*o;if(e!==void 0&&(e.format!==void 0&&a===4&&e.format!=="RGBA"||a===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let w=4,x=0,T=1,S=2,P=3,A=0,O=_,E=_*2,L=-1;l==="RGBA"?(A=0,O=_,E=_*2,L=_*3):l==="RGB"?(A=0,O=_,E=_*2):l==="RBG"&&(A=0,E=_,O=_*2),t=r.createImageData(o,i);for(let z=0;z{Ti();nu=(n,e)=>{if(n===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:r,width:t}=e,o=e.norm??{mean:255,bias:0},i,a;typeof o.mean=="number"?i=[o.mean,o.mean,o.mean,o.mean]:i=[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],typeof o.bias=="number"?a=[o.bias,o.bias,o.bias,o.bias]:a=[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let l=e.format!==void 0?e.format:"RGBA",d=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",h=r*t,g=d==="RGBA"?new Float32Array(h*4):new Float32Array(h*3),_=4,w=0,x=1,T=2,S=3,P=0,A=h,O=h*2,E=-1;l==="RGB"&&(_=3,w=0,x=1,T=2,S=-1),d==="RGBA"?E=h*3:d==="RBG"?(P=0,O=h,A=h*2):d==="BGR"&&(O=0,A=h,P=h*2);for(let z=0;z{let r=typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement,t=typeof ImageData<"u"&&n instanceof ImageData,o=typeof ImageBitmap<"u"&&n instanceof ImageBitmap,i=typeof n=="string",a,l=e??{},d=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},h=g=>typeof HTMLCanvasElement<"u"&&g instanceof HTMLCanvasElement||g instanceof OffscreenCanvas?g.getContext("2d"):null;if(r){let g=d();g.width=n.width,g.height=n.height;let _=h(g);if(_!=null){let w=n.height,x=n.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(w=e.resizedHeight,x=e.resizedWidth),e!==void 0){if(l=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");l.tensorFormat="RGBA",l.height=w,l.width=x}else l.tensorFormat="RGBA",l.height=w,l.width=x;_.drawImage(n,0,0),a=_.getImageData(0,0,x,w).data}else throw new Error("Can not access image data")}else if(t){let g,_;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(g=e.resizedHeight,_=e.resizedWidth):(g=n.height,_=n.width),e!==void 0&&(l=e),l.format="RGBA",l.height=g,l.width=_,e!==void 0){let w=d();w.width=_,w.height=g;let x=h(w);if(x!=null)x.putImageData(n,0,0),a=x.getImageData(0,0,_,g).data;else throw new Error("Can not access image data")}else a=n.data}else if(o){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let g=d();g.width=n.width,g.height=n.height;let _=h(g);if(_!=null){let w=n.height,x=n.width;return _.drawImage(n,0,0,x,w),a=_.getImageData(0,0,x,w).data,l.height=w,l.width=x,nu(a,l)}else throw new Error("Can not access image data")}else{if(i)return new Promise((g,_)=>{let w=d(),x=h(w);if(!n||!x)return _();let T=new Image;T.crossOrigin="Anonymous",T.src=n,T.onload=()=>{w.width=T.width,w.height=T.height,x.drawImage(T,0,0,w.width,w.height);let S=x.getImageData(0,0,w.width,w.height);l.height=w.height,l.width=w.width,g(nu(S.data,l))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(a!==void 0)return nu(a,l);throw new Error("Input data provided is not supported - aborted tensor creation")},Yg=(n,e)=>{let{width:r,height:t,download:o,dispose:i}=e,a=[1,t,r,4];return new St({location:"texture",type:"float32",texture:n,dims:a,download:o,dispose:i})},eb=(n,e)=>{let{dataType:r,dims:t,download:o,dispose:i}=e;return new St({location:"gpu-buffer",type:r??"float32",gpuBuffer:n,dims:t,download:o,dispose:i})},tb=(n,e)=>{let{dataType:r,dims:t,download:o,dispose:i}=e;return new St({location:"ml-tensor",type:r??"float32",mlTensor:n,dims:t,download:o,dispose:i})},rb=(n,e,r)=>new St({location:"cpu-pinned",type:n,data:e,dims:r??[e.length]})});var Bn,No,ob,ib,ab=H(()=>{Bn=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),No=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),ob=!1,ib=()=>{if(!ob){ob=!0;let n=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,r=globalThis.Float16Array,t=typeof r<"u"&&r.from;n&&(Bn.set("int64",BigInt64Array),No.set(BigInt64Array,"int64")),e&&(Bn.set("uint64",BigUint64Array),No.set(BigUint64Array,"uint64")),t?(Bn.set("float16",r),No.set(r,"float16")):Bn.set("float16",Uint16Array)}}});var sb,ub,lb=H(()=>{Ti();sb=n=>{let e=1;for(let r=0;r{switch(n.location){case"cpu":return new St(n.type,n.data,e);case"cpu-pinned":return new St({location:"cpu-pinned",data:n.data,type:n.type,dims:e});case"texture":return new St({location:"texture",texture:n.texture,type:n.type,dims:e});case"gpu-buffer":return new St({location:"gpu-buffer",gpuBuffer:n.gpuBuffer,type:n.type,dims:e});case"ml-tensor":return new St({location:"ml-tensor",mlTensor:n.mlTensor,type:n.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${n.location} is not supported`)}}});var St,Ti=H(()=>{Zg();nb();ab();lb();St=class{constructor(e,r,t){ib();let o,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,o=e.type,i=e.dims,e.location){case"cpu-pinned":{let l=Bn.get(o);if(!l)throw new TypeError(`unsupported type "${o}" to create tensor from pinned buffer`);if(!(e.data instanceof l))throw new TypeError(`buffer should be of type ${l.name}`);this.cpuData=e.data;break}case"texture":{if(o!=="float32")throw new TypeError(`unsupported type "${o}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}case"ml-tensor":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint64"&&o!=="int8"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let l,d;if(typeof e=="string")if(o=e,d=t,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");l=r}else{let h=Bn.get(e);if(h===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&h===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${h.name} as data.`);e==="uint64"||e==="int64"?l=h.from(r,BigInt):l=h.from(r)}else if(r instanceof h)l=r;else if(r instanceof Uint8ClampedArray)if(e==="uint8")l=Uint8Array.from(r);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(e==="float16"&&r instanceof Uint16Array&&h!==Uint16Array)l=new globalThis.Float16Array(r.buffer,r.byteOffset,r.length);else throw new TypeError(`A ${o} tensor's data must be type of ${h}`)}else if(d=r,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let h=typeof e[0];if(h==="string")o="string",l=e;else if(h==="boolean")o="bool",l=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${h}.`)}else if(e instanceof Uint8ClampedArray)o="uint8",l=Uint8Array.from(e);else{let h=No.get(e.constructor);if(h===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);o=h,l=e}if(d===void 0)d=[l.length];else if(!Array.isArray(d))throw new TypeError("A tensor's dims must be a number array");i=d,this.cpuData=l,this.dataLocation="cpu"}let a=sb(i);if(this.cpuData&&a!==this.cpuData.length&&!((o==="uint4"||o==="int4")&&Math.ceil(a/2)===this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=o,this.dims=i,this.size=a}static async fromImage(e,r){return Qg(e,r)}static fromTexture(e,r){return Yg(e,r)}static fromGpuBuffer(e,r){return eb(e,r)}static fromMLTensor(e,r){return tb(e,r)}static fromPinnedBuffer(e,r,t){return rb(e,r,t)}toDataURL(e){return Xg(this,e)}toImageData(e){return Jg(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,e&&this.disposer&&(this.disposer(),this.disposer=void 0),r}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return ub(this,e)}}});var Bt,ou=H(()=>{Ti();Bt=St});var Ii,cb,Ft,Dt,iu=H(()=>{ru();Ii=(n,e)=>{(typeof Mt.trace>"u"?!Mt.wasm.trace:!Mt.trace)||console.timeStamp(`${n}::ORT::${e}`)},cb=(n,e)=>{let r=new Error().stack?.split(/\r\n|\r|\n/g)||[],t=!1;for(let o=0;o{(typeof Mt.trace>"u"?!Mt.wasm.trace:!Mt.trace)||cb("BEGIN",n)},Dt=n=>{(typeof Mt.trace>"u"?!Mt.wasm.trace:!Mt.trace)||cb("END",n)}});var Si,db=H(()=>{tu();ou();iu();Si=class n{constructor(e){this.handler=e}async run(e,r,t){Ft();let o={},i={};if(typeof e!="object"||e===null||e instanceof Bt||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof Bt)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let h of r){if(typeof h!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(h)===-1)throw new RangeError(`'fetches' contains invalid output name: ${h}.`);o[h]=null}if(typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else{let h=!1,g=Object.getOwnPropertyNames(r);for(let _ of this.outputNames)if(g.indexOf(_)!==-1){let w=r[_];(w===null||w instanceof Bt)&&(h=!0,a=!1,o[_]=w)}if(h){if(typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let h of this.inputNames)if(typeof e[h]>"u")throw new Error(`input '${h}' is missing in 'feeds'.`);if(a)for(let h of this.outputNames)o[h]=null;let l=await this.handler.run(e,o,i),d={};for(let h in l)if(Object.hasOwnProperty.call(l,h)){let g=l[h];g instanceof Bt?d[h]=g:d[h]=new Bt(g.type,g.data,g.dims)}return Dt(),d}async release(){return this.handler.dispose()}static async create(e,r,t,o){Ft();let i,a={};if(typeof e=="string"){if(i=e,typeof r=="object"&&r!==null)a=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,typeof r=="object"&&r!==null)a=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let g=e,_=0,w=e.byteLength;if(typeof r=="object"&&r!==null)a=r;else if(typeof r=="number"){if(_=r,!Number.isSafeInteger(_))throw new RangeError("'byteOffset' must be an integer.");if(_<0||_>=g.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${g.byteLength}).`);if(w=e.byteLength-_,typeof t=="number"){if(w=t,!Number.isSafeInteger(w))throw new RangeError("'byteLength' must be an integer.");if(w<=0||_+w>g.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${g.byteLength-_}].`);if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(typeof t<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(g,_,w)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[l,d]=await Gg(a),h=await l.createInferenceSessionHandler(i,d);return Dt(),new n(h)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}});var c3,pb=H(()=>{db();c3=Si});var fb=H(()=>{});var hb=H(()=>{});var mb=H(()=>{});var gb=H(()=>{});var au={};zn(au,{InferenceSession:()=>c3,TRACE:()=>Ii,TRACE_FUNC_BEGIN:()=>Ft,TRACE_FUNC_END:()=>Dt,Tensor:()=>Bt,env:()=>Ae,registerBackend:()=>_n});var At=H(()=>{Ug();Kg();pb();ou();fb();hb();iu();mb();gb()});function vn(n,e,r,t){if(e===void 0)return p3(n);if(r===void 0)$i(n,e,1);else if(typeof r=="number"&&t===void 0)$i(n,e,r);else if(typeof r=="string"&&t===void 0)$i(n,r,1,e);else if(typeof r=="string"&&typeof t=="number")$i(n,r,t,e);else throw new TypeError("input is valid")}function p3(n){return{verbose:vn.verbose.bind(null,n),info:vn.info.bind(null,n),warning:vn.warning.bind(null,n),error:vn.error.bind(null,n),fatal:vn.fatal.bind(null,n)}}function $i(n,e,r,t){let o=Lo[t||""]||Lo[""];yb[n]{"use strict";su=class{log(e,r,t){}},uu=class{log(e,r,t){console.log(`${this.color(e)} ${t?"\x1B[35m"+t+"\x1B[0m ":""}${r}`)}color(e){switch(e){case"verbose":return"\x1B[34;40mv\x1B[0m";case"info":return"\x1B[32mi\x1B[0m";case"warning":return"\x1B[30;43mw\x1B[0m";case"error":return"\x1B[31;40me\x1B[0m";case"fatal":return"\x1B[101mf\x1B[0m";default:throw new Error(`unsupported severity: ${e}`)}}},yb={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},d3={none:new su,console:new uu},_b={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1},Lo={"":_b};(d=>{function n(h,g){d("verbose",h,g)}d.verbose=n;function e(h,g){d("info",h,g)}d.info=e;function r(h,g){d("warning",h,g)}d.warning=r;function t(h,g){d("error",h,g)}d.error=t;function o(h,g){d("fatal",h,g)}d.fatal=o;function i(h){Lo={},a("",h||{})}d.reset=i;function a(h,g){if(h==="*")i(g);else{let _=Lo[h]||_b;Lo[h]={provider:g.provider||_.provider,minimalSeverity:g.minimalSeverity||_.minimalSeverity,logDateTime:g.logDateTime===void 0?_.logDateTime:g.logDateTime,logSourceLocation:g.logSourceLocation===void 0?_.logSourceLocation:g.logSourceLocation}}}d.set=a;function l(h){let g={};h.logLevel&&(g.minimalSeverity=h.logLevel),a("",g)}d.setWithEnv=l})(vn||={});Ye=vn,Oi=class{constructor(e,r,t,o,i,a){this.category=e;this.name=r;this.startTime=t;this.endCallback=o;this.timer=i;this.ctx=a}async end(){return this.endCallback(this)}async checkTimer(){if(this.ctx===void 0||this.timer===void 0)throw new Error("No webgl timer found");return this.ctx.endTimer(),this.ctx.waitForQueryAndGetTime(this.timer)}},Ci=class{constructor(e,r,t,o){this.category=e;this.name=r;this.startTime=t;this.endTime=o}},Pi=class{constructor(e,r,t){this._started=!1;this._flushPointer=0;this._started=!1,this._maxNumberEvents=e===void 0?1e4:e,this._flushBatchSize=r===void 0?10:r,this._flushIntervalInMilliseconds=t===void 0?5e3:t}static create(e){return e===void 0?new this:new this(e.maxNumberEvents,e.flushBatchSize,e.flushIntervalInMilliseconds)}start(){this._started=!0,this._timingEvents=[],this._flushTime=Ai(),this._flushPointer=0}stop(){for(this._started=!1;this._flushPointer{l.then(async g=>{i&&await i.end(),d(g)},async g=>{i&&await i.end(),h(g)})});if(!a&&i){let d=i.end();if(d&&typeof d.then=="function")return new Promise((h,g)=>{d.then(()=>{h(l)},_=>{g(_)})})}return l}begin(e,r,t){if(!this._started)throw new Error("profiler is not started yet");if(t===void 0){let o=Ai();return this.flush(o),new Oi(e,r,o,i=>this.endSync(i))}else{let o=t.beginTimer();return new Oi(e,r,0,async i=>this.end(i),o,t)}}async end(e){let r=await e.checkTimer();this._timingEvents.length=this._flushBatchSize||e-this._flushTime>=this._flushIntervalInMilliseconds){for(let r=this._flushPointer;this._flushPointerperformance.now():Date.now});function vb(n,e,r){for(let t of r){let o=t[0],i=t[1],a=t[2],l=t[3],d=t[4];if(n.opType===o){for(let h of e)if((h.domain===i||h.domain==="ai.onnx"&&i==="")&&f3(h.version,a))return{opImpl:l,opInit:d}}}throw new TypeError(`cannot resolve operator '${n.opType}' with opsets: ${e.map(t=>`${t.domain||"ai.onnx"} v${t.version}`).join(", ")}`)}function f3(n,e){if(e.endsWith("+")){let r=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(r)&&r<=n}else if(e.split("-").length===2){let r=e.split("-"),t=Number.parseInt(r[0],10),o=Number.parseInt(r[1],10);return!isNaN(t)&&!isNaN(o)&&t<=n&&n<=o}else return Number.parseInt(e,10)===n}var wb=H(()=>{"use strict"});var xb=ge(lu=>{"use strict";lu.__esModule=!0;var h3=function(){function n(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=n.EMPTY,e&&n.isGuid(e)&&(this.value=e)}return n.isGuid=function(e){var r=e.toString();return e&&(e instanceof n||n.validator.test(r))},n.create=function(){return new n([n.gen(2),n.gen(1),n.gen(1),n.gen(1),n.gen(3)].join("-"))},n.createEmpty=function(){return new n("emptyguid")},n.parse=function(e){return new n(e)},n.raw=function(){return[n.gen(2),n.gen(1),n.gen(1),n.gen(1),n.gen(3)].join("-")},n.gen=function(e){for(var r="",t=0;t>>=0,(o=0<=n&&n<256)&&(t=Sb[n],t)?t:(r=Xe(n,0,!0),o&&(Sb[n]=r),r)):(n|=0,(o=-128<=n&&n<128)&&(t=Ib[n],t)?t:(r=Xe(n,n<0?-1:0,!1),o&&(Ib[n]=r),r))}function qt(n,e){if(isNaN(n))return e?dn:nr;if(e){if(n<0)return dn;if(n>=Cb)return Db}else{if(n<=-Ab)return kt;if(n+1>=Ab)return Eb}return n<0?qt(-n,e).neg():Xe(n%co|0,n/co|0,e)}function Xe(n,e,r){return new ot(n,e,r)}function du(n,e,r){if(n.length===0)throw Error("empty string");if(typeof e=="number"?(r=e,e=!1):e=!!e,n==="NaN"||n==="Infinity"||n==="+Infinity"||n==="-Infinity")return e?dn:nr;if(r=r||10,r<2||360)throw Error("interior hyphen");if(t===0)return du(n.substring(1),e,r).neg();for(var o=qt(Ei(r,8)),i=nr,a=0;a{Ht=null;try{Ht=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}ot.prototype.__isLong__;Object.defineProperty(ot.prototype,"__isLong__",{value:!0});ot.isLong=Ot;Ib={},Sb={};ot.fromInt=Fn;ot.fromNumber=qt;ot.fromBits=Xe;Ei=Math.pow;ot.fromString=du;ot.fromValue=or;$b=65536,m3=1<<24,co=$b*$b,Cb=co*co,Ab=Cb/2,Ob=Fn(m3),nr=Fn(0);ot.ZERO=nr;dn=Fn(0,!0);ot.UZERO=dn;lo=Fn(1);ot.ONE=lo;Pb=Fn(1,!0);ot.UONE=Pb;cu=Fn(-1);ot.NEG_ONE=cu;Eb=Xe(-1,2147483647,!1);ot.MAX_VALUE=Eb;Db=Xe(-1,-1,!0);ot.MAX_UNSIGNED_VALUE=Db;kt=Xe(0,-2147483648,!1);ot.MIN_VALUE=kt;ie=ot.prototype;ie.toInt=function(){return this.unsigned?this.low>>>0:this.low};ie.toNumber=function(){return this.unsigned?(this.high>>>0)*co+(this.low>>>0):this.high*co+(this.low>>>0)};ie.toString=function(e){if(e=e||10,e<2||36>>0,g=h.toString(e);if(a=d,a.isZero())return g+l;for(;g.length<6;)g="0"+g;l=""+g+l}};ie.getHighBits=function(){return this.high};ie.getHighBitsUnsigned=function(){return this.high>>>0};ie.getLowBits=function(){return this.low};ie.getLowBitsUnsigned=function(){return this.low>>>0};ie.getNumBitsAbs=function(){if(this.isNegative())return this.eq(kt)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,r=31;r>0&&(e&1<=0};ie.isOdd=function(){return(this.low&1)===1};ie.isEven=function(){return(this.low&1)===0};ie.equals=function(e){return Ot(e)||(e=or(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};ie.eq=ie.equals;ie.notEquals=function(e){return!this.eq(e)};ie.neq=ie.notEquals;ie.ne=ie.notEquals;ie.lessThan=function(e){return this.comp(e)<0};ie.lt=ie.lessThan;ie.lessThanOrEqual=function(e){return this.comp(e)<=0};ie.lte=ie.lessThanOrEqual;ie.le=ie.lessThanOrEqual;ie.greaterThan=function(e){return this.comp(e)>0};ie.gt=ie.greaterThan;ie.greaterThanOrEqual=function(e){return this.comp(e)>=0};ie.gte=ie.greaterThanOrEqual;ie.ge=ie.greaterThanOrEqual;ie.compare=function(e){if(Ot(e)||(e=or(e)),this.eq(e))return 0;var r=this.isNegative(),t=e.isNegative();return r&&!t?-1:!r&&t?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1};ie.comp=ie.compare;ie.negate=function(){return!this.unsigned&&this.eq(kt)?kt:this.not().add(lo)};ie.neg=ie.negate;ie.add=function(e){Ot(e)||(e=or(e));var r=this.high>>>16,t=this.high&65535,o=this.low>>>16,i=this.low&65535,a=e.high>>>16,l=e.high&65535,d=e.low>>>16,h=e.low&65535,g=0,_=0,w=0,x=0;return x+=i+h,w+=x>>>16,x&=65535,w+=o+d,_+=w>>>16,w&=65535,_+=t+l,g+=_>>>16,_&=65535,g+=r+a,g&=65535,Xe(w<<16|x,g<<16|_,this.unsigned)};ie.subtract=function(e){return Ot(e)||(e=or(e)),this.add(e.neg())};ie.sub=ie.subtract;ie.multiply=function(e){if(this.isZero())return this;if(Ot(e)||(e=or(e)),Ht){var r=Ht.mul(this.low,this.high,e.low,e.high);return Xe(r,Ht.get_high(),this.unsigned)}if(e.isZero())return this.unsigned?dn:nr;if(this.eq(kt))return e.isOdd()?kt:nr;if(e.eq(kt))return this.isOdd()?kt:nr;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(Ob)&&e.lt(Ob))return qt(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,o=this.high&65535,i=this.low>>>16,a=this.low&65535,l=e.high>>>16,d=e.high&65535,h=e.low>>>16,g=e.low&65535,_=0,w=0,x=0,T=0;return T+=a*g,x+=T>>>16,T&=65535,x+=i*g,w+=x>>>16,x&=65535,x+=a*h,w+=x>>>16,x&=65535,w+=o*g,_+=w>>>16,w&=65535,w+=i*h,_+=w>>>16,w&=65535,w+=a*d,_+=w>>>16,w&=65535,_+=t*g+o*h+i*d+a*l,_&=65535,Xe(x<<16|T,_<<16|w,this.unsigned)};ie.mul=ie.multiply;ie.divide=function(e){if(Ot(e)||(e=or(e)),e.isZero())throw Error("division by zero");if(Ht){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var r=(this.unsigned?Ht.div_u:Ht.div_s)(this.low,this.high,e.low,e.high);return Xe(r,Ht.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?dn:nr;var t,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return dn;if(e.gt(this.shru(1)))return Pb;i=dn}else{if(this.eq(kt)){if(e.eq(lo)||e.eq(cu))return kt;if(e.eq(kt))return lo;var a=this.shr(1);return t=a.div(e).shl(1),t.eq(nr)?e.isNegative()?lo:cu:(o=this.sub(e.mul(t)),i=t.add(o.div(e)),i)}else if(e.eq(kt))return this.unsigned?dn:nr;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=nr}for(o=this;o.gte(e);){t=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var l=Math.ceil(Math.log(t)/Math.LN2),d=l<=48?1:Ei(2,l-48),h=qt(t),g=h.mul(e);g.isNegative()||g.gt(o);)t-=d,h=qt(t,this.unsigned),g=h.mul(e);h.isZero()&&(h=lo),i=i.add(h),o=o.sub(g)}return i};ie.div=ie.divide;ie.modulo=function(e){if(Ot(e)||(e=or(e)),Ht){var r=(this.unsigned?Ht.rem_u:Ht.rem_s)(this.low,this.high,e.low,e.high);return Xe(r,Ht.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};ie.mod=ie.modulo;ie.rem=ie.modulo;ie.not=function(){return Xe(~this.low,~this.high,this.unsigned)};ie.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32};ie.clz=ie.countLeadingZeros;ie.countTrailingZeros=function(){return this.low?Tb(this.low):Tb(this.high)+32};ie.ctz=ie.countTrailingZeros;ie.and=function(e){return Ot(e)||(e=or(e)),Xe(this.low&e.low,this.high&e.high,this.unsigned)};ie.or=function(e){return Ot(e)||(e=or(e)),Xe(this.low|e.low,this.high|e.high,this.unsigned)};ie.xor=function(e){return Ot(e)||(e=or(e)),Xe(this.low^e.low,this.high^e.high,this.unsigned)};ie.shiftLeft=function(e){return Ot(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?Xe(this.low<>>32-e,this.unsigned):Xe(0,this.low<>>e|this.high<<32-e,this.high>>e,this.unsigned):Xe(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};ie.shr=ie.shiftRight;ie.shiftRightUnsigned=function(e){return Ot(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?Xe(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):e===32?Xe(this.high,0,this.unsigned):Xe(this.high>>>e-32,0,this.unsigned)};ie.shru=ie.shiftRightUnsigned;ie.shr_u=ie.shiftRightUnsigned;ie.rotateLeft=function(e){var r;return Ot(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?Xe(this.high,this.low,this.unsigned):e<32?(r=32-e,Xe(this.low<>>r,this.high<>>r,this.unsigned)):(e-=32,r=32-e,Xe(this.high<>>r,this.low<>>r,this.unsigned))};ie.rotl=ie.rotateLeft;ie.rotateRight=function(e){var r;return Ot(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?Xe(this.high,this.low,this.unsigned):e<32?(r=32-e,Xe(this.high<>>e,this.low<>>e,this.unsigned)):(e-=32,r=32-e,Xe(this.low<>>e,this.high<>>e,this.unsigned))};ie.rotr=ie.rotateRight;ie.toSigned=function(){return this.unsigned?Xe(this.low,this.high,!1):this};ie.toUnsigned=function(){return this.unsigned?this:Xe(this.low,this.high,!0)};ie.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};ie.toBytesLE=function(){var e=this.high,r=this.low;return[r&255,r>>>8&255,r>>>16&255,r>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]};ie.toBytesBE=function(){var e=this.high,r=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,r>>>24,r>>>16&255,r>>>8&255,r&255]};ot.fromBytes=function(e,r,t){return t?ot.fromBytesLE(e,r):ot.fromBytesBE(e,r)};ot.fromBytesLE=function(e,r){return new ot(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,r)};ot.fromBytesBE=function(e,r){return new ot(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],r)};wn=ot});var fu=ge(Di=>{"use strict";Object.defineProperty(Di,"__esModule",{value:!0});Di.ArgType=void 0;var kb;(function(n){n[n.INPUT=0]="INPUT",n[n.OUTPUT=1]="OUTPUT"})(kb||(Di.ArgType=kb={}))});var Vn=ge(br=>{"use strict";Object.defineProperty(br,"__esModule",{value:!0});br.SIZE_PREFIX_LENGTH=br.FILE_IDENTIFIER_LENGTH=br.SIZEOF_INT=br.SIZEOF_SHORT=void 0;br.SIZEOF_SHORT=2;br.SIZEOF_INT=4;br.FILE_IDENTIFIER_LENGTH=4;br.SIZE_PREFIX_LENGTH=4});var hu=ge(Kt=>{"use strict";Object.defineProperty(Kt,"__esModule",{value:!0});Kt.isLittleEndian=Kt.float64=Kt.float32=Kt.int32=void 0;Kt.int32=new Int32Array(2);Kt.float32=new Float32Array(Kt.int32.buffer);Kt.float64=new Float64Array(Kt.int32.buffer);Kt.isLittleEndian=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1});var mu=ge(ki=>{"use strict";Object.defineProperty(ki,"__esModule",{value:!0});ki.Encoding=void 0;var Nb;(function(n){n[n.UTF8_BYTES=1]="UTF8_BYTES",n[n.UTF16_STRING=2]="UTF16_STRING"})(Nb||(ki.Encoding=Nb={}))});var bu=ge(Ni=>{"use strict";Object.defineProperty(Ni,"__esModule",{value:!0});Ni.ByteBuffer=void 0;var yr=Vn(),Nt=hu(),g3=mu(),gu=class n{constructor(e){this.bytes_=e,this.position_=0,this.text_decoder_=new TextDecoder}static allocate(e){return new n(new Uint8Array(e))}clear(){this.position_=0}bytes(){return this.bytes_}position(){return this.position_}setPosition(e){this.position_=e}capacity(){return this.bytes_.length}readInt8(e){return this.readUint8(e)<<24>>24}readUint8(e){return this.bytes_[e]}readInt16(e){return this.readUint16(e)<<16>>16}readUint16(e){return this.bytes_[e]|this.bytes_[e+1]<<8}readInt32(e){return this.bytes_[e]|this.bytes_[e+1]<<8|this.bytes_[e+2]<<16|this.bytes_[e+3]<<24}readUint32(e){return this.readInt32(e)>>>0}readInt64(e){return BigInt.asIntN(64,BigInt(this.readUint32(e))+(BigInt(this.readUint32(e+4))<>8}writeUint16(e,r){this.bytes_[e]=r,this.bytes_[e+1]=r>>8}writeInt32(e,r){this.bytes_[e]=r,this.bytes_[e+1]=r>>8,this.bytes_[e+2]=r>>16,this.bytes_[e+3]=r>>24}writeUint32(e,r){this.bytes_[e]=r,this.bytes_[e+1]=r>>8,this.bytes_[e+2]=r>>16,this.bytes_[e+3]=r>>24}writeInt64(e,r){this.writeInt32(e,Number(BigInt.asIntN(32,r))),this.writeInt32(e+4,Number(BigInt.asIntN(32,r>>BigInt(32))))}writeUint64(e,r){this.writeUint32(e,Number(BigInt.asUintN(32,r))),this.writeUint32(e+4,Number(BigInt.asUintN(32,r>>BigInt(32))))}writeFloat32(e,r){Nt.float32[0]=r,this.writeInt32(e,Nt.int32[0])}writeFloat64(e,r){Nt.float64[0]=r,this.writeInt32(e,Nt.int32[Nt.isLittleEndian?0:1]),this.writeInt32(e+4,Nt.int32[Nt.isLittleEndian?1:0])}getBufferIdentifier(){if(this.bytes_.length{"use strict";Object.defineProperty(Li,"__esModule",{value:!0});Li.Builder=void 0;var Lb=bu(),Vt=Vn(),yu=class n{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null,this.text_encoder=new TextEncoder;let r;e?r=e:r=1024,this.bb=Lb.ByteBuffer.allocate(r),this.space=r}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,r){e>this.minalign&&(this.minalign=e);let t=~(this.bb.capacity()-this.space+r)+1&e-1;for(;this.space=0&&this.vtable[r]==0;r--);let t=r+1;for(;r>=0;r--)this.addInt16(this.vtable[r]!=0?e-this.vtable[r]:0);let o=2;this.addInt16(e-this.object_start);let i=(t+o)*Vt.SIZEOF_SHORT;this.addInt16(i);let a=0,l=this.space;e:for(r=0;r=0;a--)this.writeInt8(i.charCodeAt(a))}this.prep(this.minalign,Vt.SIZEOF_INT+o),this.addOffset(e),o&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,r){this.finish(e,r,!0)}requiredField(e,r){let t=this.bb.capacity()-e,o=t-this.bb.readInt32(t);if(!(r{"use strict";Object.defineProperty(dt,"__esModule",{value:!0});dt.ByteBuffer=dt.Builder=dt.Encoding=dt.isLittleEndian=dt.float64=dt.float32=dt.int32=dt.SIZE_PREFIX_LENGTH=dt.FILE_IDENTIFIER_LENGTH=dt.SIZEOF_INT=dt.SIZEOF_SHORT=void 0;var b3=Vn();Object.defineProperty(dt,"SIZEOF_SHORT",{enumerable:!0,get:function(){return b3.SIZEOF_SHORT}});var y3=Vn();Object.defineProperty(dt,"SIZEOF_INT",{enumerable:!0,get:function(){return y3.SIZEOF_INT}});var _3=Vn();Object.defineProperty(dt,"FILE_IDENTIFIER_LENGTH",{enumerable:!0,get:function(){return _3.FILE_IDENTIFIER_LENGTH}});var v3=Vn();Object.defineProperty(dt,"SIZE_PREFIX_LENGTH",{enumerable:!0,get:function(){return v3.SIZE_PREFIX_LENGTH}});var Ri=hu();Object.defineProperty(dt,"int32",{enumerable:!0,get:function(){return Ri.int32}});Object.defineProperty(dt,"float32",{enumerable:!0,get:function(){return Ri.float32}});Object.defineProperty(dt,"float64",{enumerable:!0,get:function(){return Ri.float64}});Object.defineProperty(dt,"isLittleEndian",{enumerable:!0,get:function(){return Ri.isLittleEndian}});var w3=mu();Object.defineProperty(dt,"Encoding",{enumerable:!0,get:function(){return w3.Encoding}});var x3=Rb();Object.defineProperty(dt,"Builder",{enumerable:!0,get:function(){return x3.Builder}});var T3=bu();Object.defineProperty(dt,"ByteBuffer",{enumerable:!0,get:function(){return T3.ByteBuffer}})});var vu=ge(_r=>{"use strict";var I3=_r&&_r.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),S3=_r&&_r.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),$3=_r&&_r.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&I3(e,n,r);return S3(e,n),e};Object.defineProperty(_r,"__esModule",{value:!0});_r.ArgTypeAndIndex=void 0;var A3=$3(Je()),zb=fu(),_u=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsArgTypeAndIndex(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsArgTypeAndIndex(e,r){return e.setPosition(e.position()+A3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}argType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt8(this.bb_pos+e):zb.ArgType.INPUT}index(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb_pos+e):0}static startArgTypeAndIndex(e){e.startObject(2)}static addArgType(e,r){e.addFieldInt8(0,r,zb.ArgType.INPUT)}static addIndex(e,r){e.addFieldInt32(1,r,0)}static endArgTypeAndIndex(e){return e.endObject()}static createArgTypeAndIndex(e,r,t){return n.startArgTypeAndIndex(e),n.addArgType(e,r),n.addIndex(e,t),n.endArgTypeAndIndex(e)}};_r.ArgTypeAndIndex=_u});var wu=ge(zi=>{"use strict";Object.defineProperty(zi,"__esModule",{value:!0});zi.AttributeType=void 0;var Mb;(function(n){n[n.UNDEFINED=0]="UNDEFINED",n[n.FLOAT=1]="FLOAT",n[n.INT=2]="INT",n[n.STRING=3]="STRING",n[n.TENSOR=4]="TENSOR",n[n.GRAPH=5]="GRAPH",n[n.FLOATS=6]="FLOATS",n[n.INTS=7]="INTS",n[n.STRINGS=8]="STRINGS",n[n.TENSORS=9]="TENSORS",n[n.GRAPHS=10]="GRAPHS",n[n.SPARSE_TENSOR=11]="SPARSE_TENSOR",n[n.SPARSE_TENSORS=12]="SPARSE_TENSORS"})(Mb||(zi.AttributeType=Mb={}))});var xu=ge(Mi=>{"use strict";Object.defineProperty(Mi,"__esModule",{value:!0});Mi.NodeType=void 0;var Bb;(function(n){n[n.Primitive=0]="Primitive",n[n.Fused=1]="Fused"})(Bb||(Mi.NodeType=Bb={}))});var Iu=ge(vr=>{"use strict";var O3=vr&&vr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),C3=vr&&vr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),P3=vr&&vr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&O3(e,n,r);return C3(e,n),e};Object.defineProperty(vr,"__esModule",{value:!0});vr.Node=void 0;var E3=P3(Je()),D3=Su(),Fb=xu(),Tu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsNode(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNode(e,r){return e.setPosition(e.position()+E3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}name(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}docString(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}domain(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.__string(this.bb_pos+r,e):null}sinceVersion(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt32(this.bb_pos+e):0}index(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readUint32(this.bb_pos+e):0}opType(e){let r=this.bb.__offset(this.bb_pos,14);return r?this.bb.__string(this.bb_pos+r,e):null}type(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readInt32(this.bb_pos+e):Fb.NodeType.Primitive}executionProviderType(e){let r=this.bb.__offset(this.bb_pos,18);return r?this.bb.__string(this.bb_pos+r,e):null}inputs(e,r){let t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}inputsLength(){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.__vector_len(this.bb_pos+e):0}outputs(e,r){let t=this.bb.__offset(this.bb_pos,22);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}outputsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}attributes(e,r){let t=this.bb.__offset(this.bb_pos,24);return t?(r||new D3.Attribute).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}attributesLength(){let e=this.bb.__offset(this.bb_pos,24);return e?this.bb.__vector_len(this.bb_pos+e):0}inputArgCounts(e){let r=this.bb.__offset(this.bb_pos,26);return r?this.bb.readInt32(this.bb.__vector(this.bb_pos+r)+e*4):0}inputArgCountsLength(){let e=this.bb.__offset(this.bb_pos,26);return e?this.bb.__vector_len(this.bb_pos+e):0}inputArgCountsArray(){let e=this.bb.__offset(this.bb_pos,26);return e?new Int32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}implicitInputs(e,r){let t=this.bb.__offset(this.bb_pos,28);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}implicitInputsLength(){let e=this.bb.__offset(this.bb_pos,28);return e?this.bb.__vector_len(this.bb_pos+e):0}static startNode(e){e.startObject(13)}static addName(e,r){e.addFieldOffset(0,r,0)}static addDocString(e,r){e.addFieldOffset(1,r,0)}static addDomain(e,r){e.addFieldOffset(2,r,0)}static addSinceVersion(e,r){e.addFieldInt32(3,r,0)}static addIndex(e,r){e.addFieldInt32(4,r,0)}static addOpType(e,r){e.addFieldOffset(5,r,0)}static addType(e,r){e.addFieldInt32(6,r,Fb.NodeType.Primitive)}static addExecutionProviderType(e,r){e.addFieldOffset(7,r,0)}static addInputs(e,r){e.addFieldOffset(8,r,0)}static createInputsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startInputsVector(e,r){e.startVector(4,r,4)}static addOutputs(e,r){e.addFieldOffset(9,r,0)}static createOutputsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startOutputsVector(e,r){e.startVector(4,r,4)}static addAttributes(e,r){e.addFieldOffset(10,r,0)}static createAttributesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startAttributesVector(e,r){e.startVector(4,r,4)}static addInputArgCounts(e,r){e.addFieldOffset(11,r,0)}static createInputArgCountsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addInt32(r[t]);return e.endVector()}static startInputArgCountsVector(e,r){e.startVector(4,r,4)}static addImplicitInputs(e,r){e.addFieldOffset(12,r,0)}static createImplicitInputsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startImplicitInputsVector(e,r){e.startVector(4,r,4)}static endNode(e){return e.endObject()}static createNode(e,r,t,o,i,a,l,d,h,g,_,w,x,T){return n.startNode(e),n.addName(e,r),n.addDocString(e,t),n.addDomain(e,o),n.addSinceVersion(e,i),n.addIndex(e,a),n.addOpType(e,l),n.addType(e,d),n.addExecutionProviderType(e,h),n.addInputs(e,g),n.addOutputs(e,_),n.addAttributes(e,w),n.addInputArgCounts(e,x),n.addImplicitInputs(e,T),n.endNode(e)}};vr.Node=Tu});var Au=ge(Bi=>{"use strict";Object.defineProperty(Bi,"__esModule",{value:!0});Bi.EdgeEnd=void 0;var $u=class{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}nodeIndex(){return this.bb.readUint32(this.bb_pos)}srcArgIndex(){return this.bb.readInt32(this.bb_pos+4)}dstArgIndex(){return this.bb.readInt32(this.bb_pos+8)}static sizeOf(){return 12}static createEdgeEnd(e,r,t,o){return e.prep(4,12),e.writeInt32(o),e.writeInt32(t),e.writeInt32(r),e.offset()}};Bi.EdgeEnd=$u});var Cu=ge(wr=>{"use strict";var k3=wr&&wr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),N3=wr&&wr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),L3=wr&&wr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&k3(e,n,r);return N3(e,n),e};Object.defineProperty(wr,"__esModule",{value:!0});wr.NodeEdge=void 0;var R3=L3(Je()),Vb=Au(),Ou=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsNodeEdge(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNodeEdge(e,r){return e.setPosition(e.position()+R3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}nodeIndex(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb_pos+e):0}inputEdges(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new Vb.EdgeEnd).__init(this.bb.__vector(this.bb_pos+t)+e*12,this.bb):null}inputEdgesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}outputEdges(e,r){let t=this.bb.__offset(this.bb_pos,8);return t?(r||new Vb.EdgeEnd).__init(this.bb.__vector(this.bb_pos+t)+e*12,this.bb):null}outputEdgesLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}static startNodeEdge(e){e.startObject(3)}static addNodeIndex(e,r){e.addFieldInt32(0,r,0)}static addInputEdges(e,r){e.addFieldOffset(1,r,0)}static startInputEdgesVector(e,r){e.startVector(12,r,4)}static addOutputEdges(e,r){e.addFieldOffset(2,r,0)}static startOutputEdgesVector(e,r){e.startVector(12,r,4)}static endNodeEdge(e){return e.endObject()}static createNodeEdge(e,r,t,o){return n.startNodeEdge(e),n.addNodeIndex(e,r),n.addInputEdges(e,t),n.addOutputEdges(e,o),n.endNodeEdge(e)}};wr.NodeEdge=Ou});var Eu=ge(xr=>{"use strict";var z3=xr&&xr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),M3=xr&&xr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),B3=xr&&xr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&z3(e,n,r);return M3(e,n),e};Object.defineProperty(xr,"__esModule",{value:!0});xr.NodesToOptimizeIndices=void 0;var F3=B3(Je()),Pu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsNodesToOptimizeIndices(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNodesToOptimizeIndices(e,r){return e.setPosition(e.position()+F3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}nodeIndices(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.readUint32(this.bb.__vector(this.bb_pos+r)+e*4):0}nodeIndicesLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeIndicesArray(){let e=this.bb.__offset(this.bb_pos,4);return e?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}numInputs(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb_pos+e):0}numOutputs(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readUint32(this.bb_pos+e):0}hasVariadicInput(){let e=this.bb.__offset(this.bb_pos,10);return e?!!this.bb.readInt8(this.bb_pos+e):!1}hasVariadicOutput(){let e=this.bb.__offset(this.bb_pos,12);return e?!!this.bb.readInt8(this.bb_pos+e):!1}numVariadicInputs(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readUint32(this.bb_pos+e):0}numVariadicOutputs(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readUint32(this.bb_pos+e):0}static startNodesToOptimizeIndices(e){e.startObject(7)}static addNodeIndices(e,r){e.addFieldOffset(0,r,0)}static createNodeIndicesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addInt32(r[t]);return e.endVector()}static startNodeIndicesVector(e,r){e.startVector(4,r,4)}static addNumInputs(e,r){e.addFieldInt32(1,r,0)}static addNumOutputs(e,r){e.addFieldInt32(2,r,0)}static addHasVariadicInput(e,r){e.addFieldInt8(3,+r,0)}static addHasVariadicOutput(e,r){e.addFieldInt8(4,+r,0)}static addNumVariadicInputs(e,r){e.addFieldInt32(5,r,0)}static addNumVariadicOutputs(e,r){e.addFieldInt32(6,r,0)}static endNodesToOptimizeIndices(e){return e.endObject()}static createNodesToOptimizeIndices(e,r,t,o,i,a,l,d){return n.startNodesToOptimizeIndices(e),n.addNodeIndices(e,r),n.addNumInputs(e,t),n.addNumOutputs(e,o),n.addHasVariadicInput(e,i),n.addHasVariadicOutput(e,a),n.addNumVariadicInputs(e,l),n.addNumVariadicOutputs(e,d),n.endNodesToOptimizeIndices(e)}};xr.NodesToOptimizeIndices=Pu});var ku=ge(Tr=>{"use strict";var V3=Tr&&Tr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),j3=Tr&&Tr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),G3=Tr&&Tr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&V3(e,n,r);return j3(e,n),e};Object.defineProperty(Tr,"__esModule",{value:!0});Tr.RuntimeOptimizationRecord=void 0;var U3=G3(Je()),W3=Eu(),Du=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsRuntimeOptimizationRecord(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizationRecord(e,r){return e.setPosition(e.position()+U3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}actionId(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}nodesToOptimizeIndices(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new W3.NodesToOptimizeIndices).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}producedOpIds(e,r){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}producedOpIdsLength(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizationRecord(e){e.startObject(4)}static addActionId(e,r){e.addFieldOffset(0,r,0)}static addNodesToOptimizeIndices(e,r){e.addFieldOffset(1,r,0)}static addProducedOpIds(e,r){e.addFieldOffset(3,r,0)}static createProducedOpIdsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startProducedOpIdsVector(e,r){e.startVector(4,r,4)}static endRuntimeOptimizationRecord(e){return e.endObject()}};Tr.RuntimeOptimizationRecord=Du});var Lu=ge(Ir=>{"use strict";var H3=Ir&&Ir.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),q3=Ir&&Ir.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),K3=Ir&&Ir.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&H3(e,n,r);return q3(e,n),e};Object.defineProperty(Ir,"__esModule",{value:!0});Ir.RuntimeOptimizationRecordContainerEntry=void 0;var X3=K3(Je()),J3=ku(),Nu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsRuntimeOptimizationRecordContainerEntry(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizationRecordContainerEntry(e,r){return e.setPosition(e.position()+X3.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}optimizerName(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}runtimeOptimizationRecords(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new J3.RuntimeOptimizationRecord).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}runtimeOptimizationRecordsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizationRecordContainerEntry(e){e.startObject(2)}static addOptimizerName(e,r){e.addFieldOffset(0,r,0)}static addRuntimeOptimizationRecords(e,r){e.addFieldOffset(1,r,0)}static createRuntimeOptimizationRecordsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startRuntimeOptimizationRecordsVector(e,r){e.startVector(4,r,4)}static endRuntimeOptimizationRecordContainerEntry(e){let r=e.endObject();return e.requiredField(r,4),r}static createRuntimeOptimizationRecordContainerEntry(e,r,t){return n.startRuntimeOptimizationRecordContainerEntry(e),n.addOptimizerName(e,r),n.addRuntimeOptimizationRecords(e,t),n.endRuntimeOptimizationRecordContainerEntry(e)}};Ir.RuntimeOptimizationRecordContainerEntry=Nu});var zu=ge(Sr=>{"use strict";var Z3=Sr&&Sr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),Q3=Sr&&Sr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),Y3=Sr&&Sr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&Z3(e,n,r);return Q3(e,n),e};Object.defineProperty(Sr,"__esModule",{value:!0});Sr.RuntimeOptimizations=void 0;var eE=Y3(Je()),tE=Lu(),Ru=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsRuntimeOptimizations(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizations(e,r){return e.setPosition(e.position()+eE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}records(e,r){let t=this.bb.__offset(this.bb_pos,4);return t?(r||new tE.RuntimeOptimizationRecordContainerEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}recordsLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizations(e){e.startObject(1)}static addRecords(e,r){e.addFieldOffset(0,r,0)}static createRecordsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startRecordsVector(e,r){e.startVector(4,r,4)}static endRuntimeOptimizations(e){return e.endObject()}static createRuntimeOptimizations(e,r){return n.startRuntimeOptimizations(e),n.addRecords(e,r),n.endRuntimeOptimizations(e)}};Sr.RuntimeOptimizations=Ru});var Ro=ge(Fi=>{"use strict";Object.defineProperty(Fi,"__esModule",{value:!0});Fi.TensorDataType=void 0;var jb;(function(n){n[n.UNDEFINED=0]="UNDEFINED",n[n.FLOAT=1]="FLOAT",n[n.UINT8=2]="UINT8",n[n.INT8=3]="INT8",n[n.UINT16=4]="UINT16",n[n.INT16=5]="INT16",n[n.INT32=6]="INT32",n[n.INT64=7]="INT64",n[n.STRING=8]="STRING",n[n.BOOL=9]="BOOL",n[n.FLOAT16=10]="FLOAT16",n[n.DOUBLE=11]="DOUBLE",n[n.UINT32=12]="UINT32",n[n.UINT64=13]="UINT64",n[n.COMPLEX64=14]="COMPLEX64",n[n.COMPLEX128=15]="COMPLEX128",n[n.BFLOAT16=16]="BFLOAT16",n[n.FLOAT8E4M3FN=17]="FLOAT8E4M3FN",n[n.FLOAT8E4M3FNUZ=18]="FLOAT8E4M3FNUZ",n[n.FLOAT8E5M2=19]="FLOAT8E5M2",n[n.FLOAT8E5M2FNUZ=20]="FLOAT8E5M2FNUZ"})(jb||(Fi.TensorDataType=jb={}))});var zo=ge($r=>{"use strict";var rE=$r&&$r.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),nE=$r&&$r.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),oE=$r&&$r.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&rE(e,n,r);return nE(e,n),e};Object.defineProperty($r,"__esModule",{value:!0});$r.Tensor=void 0;var iE=oE(Je()),Gb=Ro(),Mu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsTensor(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTensor(e,r){return e.setPosition(e.position()+iE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}name(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}docString(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}dims(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.readInt64(this.bb.__vector(this.bb_pos+r)+e*8):BigInt(0)}dimsLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}dataType(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt32(this.bb_pos+e):Gb.TensorDataType.UNDEFINED}rawData(e){let r=this.bb.__offset(this.bb_pos,12);return r?this.bb.readUint8(this.bb.__vector(this.bb_pos+r)+e):0}rawDataLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}rawDataArray(){let e=this.bb.__offset(this.bb_pos,12);return e?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}stringData(e,r){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}stringDataLength(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__vector_len(this.bb_pos+e):0}externalDataOffset(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readInt64(this.bb_pos+e):BigInt("-1")}static startTensor(e){e.startObject(7)}static addName(e,r){e.addFieldOffset(0,r,0)}static addDocString(e,r){e.addFieldOffset(1,r,0)}static addDims(e,r){e.addFieldOffset(2,r,0)}static createDimsVector(e,r){e.startVector(8,r.length,8);for(let t=r.length-1;t>=0;t--)e.addInt64(r[t]);return e.endVector()}static startDimsVector(e,r){e.startVector(8,r,8)}static addDataType(e,r){e.addFieldInt32(3,r,Gb.TensorDataType.UNDEFINED)}static addRawData(e,r){e.addFieldOffset(4,r,0)}static createRawDataVector(e,r){e.startVector(1,r.length,1);for(let t=r.length-1;t>=0;t--)e.addInt8(r[t]);return e.endVector()}static startRawDataVector(e,r){e.startVector(1,r,1)}static addStringData(e,r){e.addFieldOffset(5,r,0)}static createStringDataVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startStringDataVector(e,r){e.startVector(4,r,4)}static addExternalDataOffset(e,r){e.addFieldInt64(6,r,BigInt("-1"))}static endTensor(e){return e.endObject()}static createTensor(e,r,t,o,i,a,l,d){return n.startTensor(e),n.addName(e,r),n.addDocString(e,t),n.addDims(e,o),n.addDataType(e,i),n.addRawData(e,a),n.addStringData(e,l),n.addExternalDataOffset(e,d),n.endTensor(e)}};$r.Tensor=Mu});var Fu=ge(Ar=>{"use strict";var aE=Ar&&Ar.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),sE=Ar&&Ar.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),uE=Ar&&Ar.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&aE(e,n,r);return sE(e,n),e};Object.defineProperty(Ar,"__esModule",{value:!0});Ar.SparseTensor=void 0;var lE=uE(Je()),Ub=zo(),Bu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsSparseTensor(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSparseTensor(e,r){return e.setPosition(e.position()+lE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}values(e){let r=this.bb.__offset(this.bb_pos,4);return r?(e||new Ub.Tensor).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}indices(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new Ub.Tensor).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}dims(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.readInt64(this.bb.__vector(this.bb_pos+r)+e*8):BigInt(0)}dimsLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}static startSparseTensor(e){e.startObject(3)}static addValues(e,r){e.addFieldOffset(0,r,0)}static addIndices(e,r){e.addFieldOffset(1,r,0)}static addDims(e,r){e.addFieldOffset(2,r,0)}static createDimsVector(e,r){e.startVector(8,r.length,8);for(let t=r.length-1;t>=0;t--)e.addInt64(r[t]);return e.endVector()}static startDimsVector(e,r){e.startVector(8,r,8)}static endSparseTensor(e){return e.endObject()}};Ar.SparseTensor=Bu});var ju=ge(Or=>{"use strict";var cE=Or&&Or.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),dE=Or&&Or.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),pE=Or&&Or.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&cE(e,n,r);return dE(e,n),e};Object.defineProperty(Or,"__esModule",{value:!0});Or.MapType=void 0;var fE=pE(Je()),Wb=Ro(),hE=Mo(),Vu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsMapType(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsMapType(e,r){return e.setPosition(e.position()+fE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}keyType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):Wb.TensorDataType.UNDEFINED}valueType(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new hE.TypeInfo).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startMapType(e){e.startObject(2)}static addKeyType(e,r){e.addFieldInt32(0,r,Wb.TensorDataType.UNDEFINED)}static addValueType(e,r){e.addFieldOffset(1,r,0)}static endMapType(e){return e.endObject()}};Or.MapType=Vu});var Uu=ge(Cr=>{"use strict";var mE=Cr&&Cr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),gE=Cr&&Cr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),bE=Cr&&Cr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&mE(e,n,r);return gE(e,n),e};Object.defineProperty(Cr,"__esModule",{value:!0});Cr.SequenceType=void 0;var yE=bE(Je()),_E=Mo(),Gu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsSequenceType(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSequenceType(e,r){return e.setPosition(e.position()+yE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}elemType(e){let r=this.bb.__offset(this.bb_pos,4);return r?(e||new _E.TypeInfo).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startSequenceType(e){e.startObject(1)}static addElemType(e,r){e.addFieldOffset(0,r,0)}static endSequenceType(e){return e.endObject()}static createSequenceType(e,r){return n.startSequenceType(e),n.addElemType(e,r),n.endSequenceType(e)}};Cr.SequenceType=Gu});var Wu=ge(Vi=>{"use strict";Object.defineProperty(Vi,"__esModule",{value:!0});Vi.DimensionValueType=void 0;var Hb;(function(n){n[n.UNKNOWN=0]="UNKNOWN",n[n.VALUE=1]="VALUE",n[n.PARAM=2]="PARAM"})(Hb||(Vi.DimensionValueType=Hb={}))});var qu=ge(Pr=>{"use strict";var vE=Pr&&Pr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),wE=Pr&&Pr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),xE=Pr&&Pr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&vE(e,n,r);return wE(e,n),e};Object.defineProperty(Pr,"__esModule",{value:!0});Pr.DimensionValue=void 0;var TE=xE(Je()),qb=Wu(),Hu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDimensionValue(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDimensionValue(e,r){return e.setPosition(e.position()+TE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}dimType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt8(this.bb_pos+e):qb.DimensionValueType.UNKNOWN}dimValue(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}dimParam(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.__string(this.bb_pos+r,e):null}static startDimensionValue(e){e.startObject(3)}static addDimType(e,r){e.addFieldInt8(0,r,qb.DimensionValueType.UNKNOWN)}static addDimValue(e,r){e.addFieldInt64(1,r,BigInt("0"))}static addDimParam(e,r){e.addFieldOffset(2,r,0)}static endDimensionValue(e){return e.endObject()}static createDimensionValue(e,r,t,o){return n.startDimensionValue(e),n.addDimType(e,r),n.addDimValue(e,t),n.addDimParam(e,o),n.endDimensionValue(e)}};Pr.DimensionValue=Hu});var Xu=ge(Er=>{"use strict";var IE=Er&&Er.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),SE=Er&&Er.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),$E=Er&&Er.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&IE(e,n,r);return SE(e,n),e};Object.defineProperty(Er,"__esModule",{value:!0});Er.Dimension=void 0;var AE=$E(Je()),OE=qu(),Ku=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDimension(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDimension(e,r){return e.setPosition(e.position()+AE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}value(e){let r=this.bb.__offset(this.bb_pos,4);return r?(e||new OE.DimensionValue).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}denotation(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}static startDimension(e){e.startObject(2)}static addValue(e,r){e.addFieldOffset(0,r,0)}static addDenotation(e,r){e.addFieldOffset(1,r,0)}static endDimension(e){return e.endObject()}static createDimension(e,r,t){return n.startDimension(e),n.addValue(e,r),n.addDenotation(e,t),n.endDimension(e)}};Er.Dimension=Ku});var Zu=ge(Dr=>{"use strict";var CE=Dr&&Dr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),PE=Dr&&Dr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),EE=Dr&&Dr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&CE(e,n,r);return PE(e,n),e};Object.defineProperty(Dr,"__esModule",{value:!0});Dr.Shape=void 0;var DE=EE(Je()),kE=Xu(),Ju=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsShape(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsShape(e,r){return e.setPosition(e.position()+DE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}dim(e,r){let t=this.bb.__offset(this.bb_pos,4);return t?(r||new kE.Dimension).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}dimLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startShape(e){e.startObject(1)}static addDim(e,r){e.addFieldOffset(0,r,0)}static createDimVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startDimVector(e,r){e.startVector(4,r,4)}static endShape(e){return e.endObject()}static createShape(e,r){return n.startShape(e),n.addDim(e,r),n.endShape(e)}};Dr.Shape=Ju});var Yu=ge(kr=>{"use strict";var NE=kr&&kr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),LE=kr&&kr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),RE=kr&&kr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&NE(e,n,r);return LE(e,n),e};Object.defineProperty(kr,"__esModule",{value:!0});kr.TensorTypeAndShape=void 0;var zE=RE(Je()),ME=Zu(),Kb=Ro(),Qu=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsTensorTypeAndShape(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTensorTypeAndShape(e,r){return e.setPosition(e.position()+zE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}elemType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):Kb.TensorDataType.UNDEFINED}shape(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new ME.Shape).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startTensorTypeAndShape(e){e.startObject(2)}static addElemType(e,r){e.addFieldInt32(0,r,Kb.TensorDataType.UNDEFINED)}static addShape(e,r){e.addFieldOffset(1,r,0)}static endTensorTypeAndShape(e){return e.endObject()}};kr.TensorTypeAndShape=Qu});var el=ge(xn=>{"use strict";Object.defineProperty(xn,"__esModule",{value:!0});xn.unionListToTypeInfoValue=xn.unionToTypeInfoValue=xn.TypeInfoValue=void 0;var Xb=ju(),Jb=Uu(),Zb=Yu(),ji;(function(n){n[n.NONE=0]="NONE",n[n.tensor_type=1]="tensor_type",n[n.sequence_type=2]="sequence_type",n[n.map_type=3]="map_type"})(ji||(xn.TypeInfoValue=ji={}));function BE(n,e){switch(ji[n]){case"NONE":return null;case"tensor_type":return e(new Zb.TensorTypeAndShape);case"sequence_type":return e(new Jb.SequenceType);case"map_type":return e(new Xb.MapType);default:return null}}xn.unionToTypeInfoValue=BE;function FE(n,e,r){switch(ji[n]){case"NONE":return null;case"tensor_type":return e(r,new Zb.TensorTypeAndShape);case"sequence_type":return e(r,new Jb.SequenceType);case"map_type":return e(r,new Xb.MapType);default:return null}}xn.unionListToTypeInfoValue=FE});var Mo=ge(Nr=>{"use strict";var VE=Nr&&Nr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),jE=Nr&&Nr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),GE=Nr&&Nr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&VE(e,n,r);return jE(e,n),e};Object.defineProperty(Nr,"__esModule",{value:!0});Nr.TypeInfo=void 0;var UE=GE(Je()),Qb=el(),tl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsTypeInfo(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTypeInfo(e,r){return e.setPosition(e.position()+UE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}denotation(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}valueType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):Qb.TypeInfoValue.NONE}value(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.__union(e,this.bb_pos+r):null}static startTypeInfo(e){e.startObject(3)}static addDenotation(e,r){e.addFieldOffset(0,r,0)}static addValueType(e,r){e.addFieldInt8(1,r,Qb.TypeInfoValue.NONE)}static addValue(e,r){e.addFieldOffset(2,r,0)}static endTypeInfo(e){return e.endObject()}static createTypeInfo(e,r,t,o){return n.startTypeInfo(e),n.addDenotation(e,r),n.addValueType(e,t),n.addValue(e,o),n.endTypeInfo(e)}};Nr.TypeInfo=tl});var nl=ge(Lr=>{"use strict";var WE=Lr&&Lr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),HE=Lr&&Lr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),qE=Lr&&Lr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&WE(e,n,r);return HE(e,n),e};Object.defineProperty(Lr,"__esModule",{value:!0});Lr.ValueInfo=void 0;var KE=qE(Je()),XE=Mo(),rl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsValueInfo(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsValueInfo(e,r){return e.setPosition(e.position()+KE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}name(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}docString(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}type(e){let r=this.bb.__offset(this.bb_pos,8);return r?(e||new XE.TypeInfo).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startValueInfo(e){e.startObject(3)}static addName(e,r){e.addFieldOffset(0,r,0)}static addDocString(e,r){e.addFieldOffset(1,r,0)}static addType(e,r){e.addFieldOffset(2,r,0)}static endValueInfo(e){return e.endObject()}};Lr.ValueInfo=rl});var Gi=ge(Rr=>{"use strict";var JE=Rr&&Rr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),ZE=Rr&&Rr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),QE=Rr&&Rr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&JE(e,n,r);return ZE(e,n),e};Object.defineProperty(Rr,"__esModule",{value:!0});Rr.Graph=void 0;var YE=QE(Je()),eD=Iu(),tD=Cu(),rD=zu(),nD=Fu(),oD=zo(),iD=nl(),ol=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsGraph(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsGraph(e,r){return e.setPosition(e.position()+YE.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}initializers(e,r){let t=this.bb.__offset(this.bb_pos,4);return t?(r||new oD.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}initializersLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeArgs(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new iD.ValueInfo).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodeArgsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}nodes(e,r){let t=this.bb.__offset(this.bb_pos,8);return t?(r||new eD.Node).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodesLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}maxNodeIndex(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readUint32(this.bb_pos+e):0}nodeEdges(e,r){let t=this.bb.__offset(this.bb_pos,12);return t?(r||new tD.NodeEdge).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodeEdgesLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}inputs(e,r){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}inputsLength(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__vector_len(this.bb_pos+e):0}outputs(e,r){let t=this.bb.__offset(this.bb_pos,16);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}outputsLength(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.__vector_len(this.bb_pos+e):0}sparseInitializers(e,r){let t=this.bb.__offset(this.bb_pos,18);return t?(r||new nD.SparseTensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}sparseInitializersLength(){let e=this.bb.__offset(this.bb_pos,18);return e?this.bb.__vector_len(this.bb_pos+e):0}runtimeOptimizations(e){let r=this.bb.__offset(this.bb_pos,20);return r?(e||new rD.RuntimeOptimizations).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startGraph(e){e.startObject(9)}static addInitializers(e,r){e.addFieldOffset(0,r,0)}static createInitializersVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startInitializersVector(e,r){e.startVector(4,r,4)}static addNodeArgs(e,r){e.addFieldOffset(1,r,0)}static createNodeArgsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startNodeArgsVector(e,r){e.startVector(4,r,4)}static addNodes(e,r){e.addFieldOffset(2,r,0)}static createNodesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startNodesVector(e,r){e.startVector(4,r,4)}static addMaxNodeIndex(e,r){e.addFieldInt32(3,r,0)}static addNodeEdges(e,r){e.addFieldOffset(4,r,0)}static createNodeEdgesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startNodeEdgesVector(e,r){e.startVector(4,r,4)}static addInputs(e,r){e.addFieldOffset(5,r,0)}static createInputsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startInputsVector(e,r){e.startVector(4,r,4)}static addOutputs(e,r){e.addFieldOffset(6,r,0)}static createOutputsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startOutputsVector(e,r){e.startVector(4,r,4)}static addSparseInitializers(e,r){e.addFieldOffset(7,r,0)}static createSparseInitializersVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startSparseInitializersVector(e,r){e.startVector(4,r,4)}static addRuntimeOptimizations(e,r){e.addFieldOffset(8,r,0)}static endGraph(e){return e.endObject()}};Rr.Graph=ol});var Su=ge(zr=>{"use strict";var aD=zr&&zr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),sD=zr&&zr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),uD=zr&&zr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&aD(e,n,r);return sD(e,n),e};Object.defineProperty(zr,"__esModule",{value:!0});zr.Attribute=void 0;var lD=uD(Je()),Yb=wu(),ey=Gi(),ty=zo(),il=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsAttribute(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsAttribute(e,r){return e.setPosition(e.position()+lD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}name(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}docString(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}type(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt32(this.bb_pos+e):Yb.AttributeType.UNDEFINED}f(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readFloat32(this.bb_pos+e):0}i(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}s(e){let r=this.bb.__offset(this.bb_pos,14);return r?this.bb.__string(this.bb_pos+r,e):null}t(e){let r=this.bb.__offset(this.bb_pos,16);return r?(e||new ty.Tensor).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}g(e){let r=this.bb.__offset(this.bb_pos,18);return r?(e||new ey.Graph).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}floats(e){let r=this.bb.__offset(this.bb_pos,20);return r?this.bb.readFloat32(this.bb.__vector(this.bb_pos+r)+e*4):0}floatsLength(){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.__vector_len(this.bb_pos+e):0}floatsArray(){let e=this.bb.__offset(this.bb_pos,20);return e?new Float32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}ints(e){let r=this.bb.__offset(this.bb_pos,22);return r?this.bb.readInt64(this.bb.__vector(this.bb_pos+r)+e*8):BigInt(0)}intsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}strings(e,r){let t=this.bb.__offset(this.bb_pos,24);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,r):null}stringsLength(){let e=this.bb.__offset(this.bb_pos,24);return e?this.bb.__vector_len(this.bb_pos+e):0}tensors(e,r){let t=this.bb.__offset(this.bb_pos,26);return t?(r||new ty.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}tensorsLength(){let e=this.bb.__offset(this.bb_pos,26);return e?this.bb.__vector_len(this.bb_pos+e):0}graphs(e,r){let t=this.bb.__offset(this.bb_pos,28);return t?(r||new ey.Graph).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}graphsLength(){let e=this.bb.__offset(this.bb_pos,28);return e?this.bb.__vector_len(this.bb_pos+e):0}static startAttribute(e){e.startObject(13)}static addName(e,r){e.addFieldOffset(0,r,0)}static addDocString(e,r){e.addFieldOffset(1,r,0)}static addType(e,r){e.addFieldInt32(2,r,Yb.AttributeType.UNDEFINED)}static addF(e,r){e.addFieldFloat32(3,r,0)}static addI(e,r){e.addFieldInt64(4,r,BigInt("0"))}static addS(e,r){e.addFieldOffset(5,r,0)}static addT(e,r){e.addFieldOffset(6,r,0)}static addG(e,r){e.addFieldOffset(7,r,0)}static addFloats(e,r){e.addFieldOffset(8,r,0)}static createFloatsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addFloat32(r[t]);return e.endVector()}static startFloatsVector(e,r){e.startVector(4,r,4)}static addInts(e,r){e.addFieldOffset(9,r,0)}static createIntsVector(e,r){e.startVector(8,r.length,8);for(let t=r.length-1;t>=0;t--)e.addInt64(r[t]);return e.endVector()}static startIntsVector(e,r){e.startVector(8,r,8)}static addStrings(e,r){e.addFieldOffset(10,r,0)}static createStringsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startStringsVector(e,r){e.startVector(4,r,4)}static addTensors(e,r){e.addFieldOffset(11,r,0)}static createTensorsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startTensorsVector(e,r){e.startVector(4,r,4)}static addGraphs(e,r){e.addFieldOffset(12,r,0)}static createGraphsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startGraphsVector(e,r){e.startVector(4,r,4)}static endAttribute(e){return e.endObject()}};zr.Attribute=il});var sl=ge(Mr=>{"use strict";var cD=Mr&&Mr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),dD=Mr&&Mr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),pD=Mr&&Mr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&cD(e,n,r);return dD(e,n),e};Object.defineProperty(Mr,"__esModule",{value:!0});Mr.DeprecatedKernelCreateInfos=void 0;var fD=pD(Je()),al=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDeprecatedKernelCreateInfos(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedKernelCreateInfos(e,r){return e.setPosition(e.position()+fD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}nodeIndices(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.readUint32(this.bb.__vector(this.bb_pos+r)+e*4):0}nodeIndicesLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeIndicesArray(){let e=this.bb.__offset(this.bb_pos,4);return e?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}kernelDefHashes(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.readUint64(this.bb.__vector(this.bb_pos+r)+e*8):BigInt(0)}kernelDefHashesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startDeprecatedKernelCreateInfos(e){e.startObject(2)}static addNodeIndices(e,r){e.addFieldOffset(0,r,0)}static createNodeIndicesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addInt32(r[t]);return e.endVector()}static startNodeIndicesVector(e,r){e.startVector(4,r,4)}static addKernelDefHashes(e,r){e.addFieldOffset(1,r,0)}static createKernelDefHashesVector(e,r){e.startVector(8,r.length,8);for(let t=r.length-1;t>=0;t--)e.addInt64(r[t]);return e.endVector()}static startKernelDefHashesVector(e,r){e.startVector(8,r,8)}static endDeprecatedKernelCreateInfos(e){return e.endObject()}static createDeprecatedKernelCreateInfos(e,r,t){return n.startDeprecatedKernelCreateInfos(e),n.addNodeIndices(e,r),n.addKernelDefHashes(e,t),n.endDeprecatedKernelCreateInfos(e)}};Mr.DeprecatedKernelCreateInfos=al});var ry=ge(Br=>{"use strict";var hD=Br&&Br.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),mD=Br&&Br.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),gD=Br&&Br.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&hD(e,n,r);return mD(e,n),e};Object.defineProperty(Br,"__esModule",{value:!0});Br.DeprecatedNodeIndexAndKernelDefHash=void 0;var bD=gD(Je()),ul=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDeprecatedNodeIndexAndKernelDefHash(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedNodeIndexAndKernelDefHash(e,r){return e.setPosition(e.position()+bD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}nodeIndex(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb_pos+e):0}kernelDefHash(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint64(this.bb_pos+e):BigInt("0")}static startDeprecatedNodeIndexAndKernelDefHash(e){e.startObject(2)}static addNodeIndex(e,r){e.addFieldInt32(0,r,0)}static addKernelDefHash(e,r){e.addFieldInt64(1,r,BigInt("0"))}static endDeprecatedNodeIndexAndKernelDefHash(e){return e.endObject()}static createDeprecatedNodeIndexAndKernelDefHash(e,r,t){return n.startDeprecatedNodeIndexAndKernelDefHash(e),n.addNodeIndex(e,r),n.addKernelDefHash(e,t),n.endDeprecatedNodeIndexAndKernelDefHash(e)}};Br.DeprecatedNodeIndexAndKernelDefHash=ul});var cl=ge(Fr=>{"use strict";var yD=Fr&&Fr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),_D=Fr&&Fr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),vD=Fr&&Fr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&yD(e,n,r);return _D(e,n),e};Object.defineProperty(Fr,"__esModule",{value:!0});Fr.DeprecatedSubGraphSessionState=void 0;var wD=vD(Je()),xD=dl(),ll=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDeprecatedSubGraphSessionState(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedSubGraphSessionState(e,r){return e.setPosition(e.position()+wD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}graphId(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}sessionState(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new xD.DeprecatedSessionState).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startDeprecatedSubGraphSessionState(e){e.startObject(2)}static addGraphId(e,r){e.addFieldOffset(0,r,0)}static addSessionState(e,r){e.addFieldOffset(1,r,0)}static endDeprecatedSubGraphSessionState(e){let r=e.endObject();return e.requiredField(r,4),r}};Fr.DeprecatedSubGraphSessionState=ll});var dl=ge(Vr=>{"use strict";var TD=Vr&&Vr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),ID=Vr&&Vr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),SD=Vr&&Vr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&TD(e,n,r);return ID(e,n),e};Object.defineProperty(Vr,"__esModule",{value:!0});Vr.DeprecatedSessionState=void 0;var $D=SD(Je()),AD=sl(),OD=cl(),pl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsDeprecatedSessionState(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedSessionState(e,r){return e.setPosition(e.position()+$D.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}kernels(e){let r=this.bb.__offset(this.bb_pos,4);return r?(e||new AD.DeprecatedKernelCreateInfos).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}subGraphSessionStates(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new OD.DeprecatedSubGraphSessionState).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}subGraphSessionStatesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startDeprecatedSessionState(e){e.startObject(2)}static addKernels(e,r){e.addFieldOffset(0,r,0)}static addSubGraphSessionStates(e,r){e.addFieldOffset(1,r,0)}static createSubGraphSessionStatesVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startSubGraphSessionStatesVector(e,r){e.startVector(4,r,4)}static endDeprecatedSessionState(e){return e.endObject()}static createDeprecatedSessionState(e,r,t){return n.startDeprecatedSessionState(e),n.addKernels(e,r),n.addSubGraphSessionStates(e,t),n.endDeprecatedSessionState(e)}};Vr.DeprecatedSessionState=pl});var hl=ge(jr=>{"use strict";var CD=jr&&jr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),PD=jr&&jr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),ED=jr&&jr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&CD(e,n,r);return PD(e,n),e};Object.defineProperty(jr,"__esModule",{value:!0});jr.KernelTypeStrArgsEntry=void 0;var DD=ED(Je()),kD=vu(),fl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsKernelTypeStrArgsEntry(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsKernelTypeStrArgsEntry(e,r){return e.setPosition(e.position()+DD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}kernelTypeStr(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}args(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new kD.ArgTypeAndIndex).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}argsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startKernelTypeStrArgsEntry(e){e.startObject(2)}static addKernelTypeStr(e,r){e.addFieldOffset(0,r,0)}static addArgs(e,r){e.addFieldOffset(1,r,0)}static createArgsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startArgsVector(e,r){e.startVector(4,r,4)}static endKernelTypeStrArgsEntry(e){let r=e.endObject();return e.requiredField(r,4),r}static createKernelTypeStrArgsEntry(e,r,t){return n.startKernelTypeStrArgsEntry(e),n.addKernelTypeStr(e,r),n.addArgs(e,t),n.endKernelTypeStrArgsEntry(e)}};jr.KernelTypeStrArgsEntry=fl});var gl=ge(Gr=>{"use strict";var ND=Gr&&Gr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),LD=Gr&&Gr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),RD=Gr&&Gr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&ND(e,n,r);return LD(e,n),e};Object.defineProperty(Gr,"__esModule",{value:!0});Gr.OpIdKernelTypeStrArgsEntry=void 0;var zD=RD(Je()),MD=hl(),ml=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsOpIdKernelTypeStrArgsEntry(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsOpIdKernelTypeStrArgsEntry(e,r){return e.setPosition(e.position()+zD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}opId(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}kernelTypeStrArgs(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new MD.KernelTypeStrArgsEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}kernelTypeStrArgsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startOpIdKernelTypeStrArgsEntry(e){e.startObject(2)}static addOpId(e,r){e.addFieldOffset(0,r,0)}static addKernelTypeStrArgs(e,r){e.addFieldOffset(1,r,0)}static createKernelTypeStrArgsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startKernelTypeStrArgsVector(e,r){e.startVector(4,r,4)}static endOpIdKernelTypeStrArgsEntry(e){let r=e.endObject();return e.requiredField(r,4),r}static createOpIdKernelTypeStrArgsEntry(e,r,t){return n.startOpIdKernelTypeStrArgsEntry(e),n.addOpId(e,r),n.addKernelTypeStrArgs(e,t),n.endOpIdKernelTypeStrArgsEntry(e)}};Gr.OpIdKernelTypeStrArgsEntry=ml});var yl=ge(Ur=>{"use strict";var BD=Ur&&Ur.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),FD=Ur&&Ur.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),VD=Ur&&Ur.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&BD(e,n,r);return FD(e,n),e};Object.defineProperty(Ur,"__esModule",{value:!0});Ur.KernelTypeStrResolver=void 0;var jD=VD(Je()),GD=gl(),bl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsKernelTypeStrResolver(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsKernelTypeStrResolver(e,r){return e.setPosition(e.position()+jD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}opKernelTypeStrArgs(e,r){let t=this.bb.__offset(this.bb_pos,4);return t?(r||new GD.OpIdKernelTypeStrArgsEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}opKernelTypeStrArgsLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startKernelTypeStrResolver(e){e.startObject(1)}static addOpKernelTypeStrArgs(e,r){e.addFieldOffset(0,r,0)}static createOpKernelTypeStrArgsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startOpKernelTypeStrArgsVector(e,r){e.startVector(4,r,4)}static endKernelTypeStrResolver(e){return e.endObject()}static createKernelTypeStrResolver(e,r){return n.startKernelTypeStrResolver(e),n.addOpKernelTypeStrArgs(e,r),n.endKernelTypeStrResolver(e)}};Ur.KernelTypeStrResolver=bl});var vl=ge(Wr=>{"use strict";var UD=Wr&&Wr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),WD=Wr&&Wr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),HD=Wr&&Wr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&UD(e,n,r);return WD(e,n),e};Object.defineProperty(Wr,"__esModule",{value:!0});Wr.OperatorSetId=void 0;var qD=HD(Je()),_l=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsOperatorSetId(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsOperatorSetId(e,r){return e.setPosition(e.position()+qD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}domain(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}version(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}static startOperatorSetId(e){e.startObject(2)}static addDomain(e,r){e.addFieldOffset(0,r,0)}static addVersion(e,r){e.addFieldInt64(1,r,BigInt("0"))}static endOperatorSetId(e){return e.endObject()}static createOperatorSetId(e,r,t){return n.startOperatorSetId(e),n.addDomain(e,r),n.addVersion(e,t),n.endOperatorSetId(e)}};Wr.OperatorSetId=_l});var xl=ge(Hr=>{"use strict";var KD=Hr&&Hr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),XD=Hr&&Hr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),JD=Hr&&Hr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&KD(e,n,r);return XD(e,n),e};Object.defineProperty(Hr,"__esModule",{value:!0});Hr.StringStringEntry=void 0;var ZD=JD(Je()),wl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsStringStringEntry(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsStringStringEntry(e,r){return e.setPosition(e.position()+ZD.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}key(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}value(e){let r=this.bb.__offset(this.bb_pos,6);return r?this.bb.__string(this.bb_pos+r,e):null}static startStringStringEntry(e){e.startObject(2)}static addKey(e,r){e.addFieldOffset(0,r,0)}static addValue(e,r){e.addFieldOffset(1,r,0)}static endStringStringEntry(e){return e.endObject()}static createStringStringEntry(e,r,t){return n.startStringStringEntry(e),n.addKey(e,r),n.addValue(e,t),n.endStringStringEntry(e)}};Hr.StringStringEntry=wl});var Il=ge(qr=>{"use strict";var QD=qr&&qr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),YD=qr&&qr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),ek=qr&&qr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&QD(e,n,r);return YD(e,n),e};Object.defineProperty(qr,"__esModule",{value:!0});qr.Model=void 0;var tk=ek(Je()),rk=Gi(),nk=vl(),ok=xl(),Tl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsModel(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsModel(e,r){return e.setPosition(e.position()+tk.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}irVersion(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}opsetImport(e,r){let t=this.bb.__offset(this.bb_pos,6);return t?(r||new nk.OperatorSetId).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}opsetImportLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}producerName(e){let r=this.bb.__offset(this.bb_pos,8);return r?this.bb.__string(this.bb_pos+r,e):null}producerVersion(e){let r=this.bb.__offset(this.bb_pos,10);return r?this.bb.__string(this.bb_pos+r,e):null}domain(e){let r=this.bb.__offset(this.bb_pos,12);return r?this.bb.__string(this.bb_pos+r,e):null}modelVersion(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}docString(e){let r=this.bb.__offset(this.bb_pos,16);return r?this.bb.__string(this.bb_pos+r,e):null}graph(e){let r=this.bb.__offset(this.bb_pos,18);return r?(e||new rk.Graph).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}graphDocString(e){let r=this.bb.__offset(this.bb_pos,20);return r?this.bb.__string(this.bb_pos+r,e):null}metadataProps(e,r){let t=this.bb.__offset(this.bb_pos,22);return t?(r||new ok.StringStringEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}metadataPropsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}static startModel(e){e.startObject(10)}static addIrVersion(e,r){e.addFieldInt64(0,r,BigInt("0"))}static addOpsetImport(e,r){e.addFieldOffset(1,r,0)}static createOpsetImportVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startOpsetImportVector(e,r){e.startVector(4,r,4)}static addProducerName(e,r){e.addFieldOffset(2,r,0)}static addProducerVersion(e,r){e.addFieldOffset(3,r,0)}static addDomain(e,r){e.addFieldOffset(4,r,0)}static addModelVersion(e,r){e.addFieldInt64(5,r,BigInt("0"))}static addDocString(e,r){e.addFieldOffset(6,r,0)}static addGraph(e,r){e.addFieldOffset(7,r,0)}static addGraphDocString(e,r){e.addFieldOffset(8,r,0)}static addMetadataProps(e,r){e.addFieldOffset(9,r,0)}static createMetadataPropsVector(e,r){e.startVector(4,r.length,4);for(let t=r.length-1;t>=0;t--)e.addOffset(r[t]);return e.endVector()}static startMetadataPropsVector(e,r){e.startVector(4,r,4)}static endModel(e){return e.endObject()}};qr.Model=Tl});var ny=ge(Kr=>{"use strict";var ik=Kr&&Kr.__createBinding||(Object.create?function(n,e,r,t){t===void 0&&(t=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(n,t,o)}:function(n,e,r,t){t===void 0&&(t=r),n[t]=e[r]}),ak=Kr&&Kr.__setModuleDefault||(Object.create?function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}:function(n,e){n.default=e}),sk=Kr&&Kr.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var r in n)r!=="default"&&Object.prototype.hasOwnProperty.call(n,r)&&ik(e,n,r);return ak(e,n),e};Object.defineProperty(Kr,"__esModule",{value:!0});Kr.InferenceSession=void 0;var uk=sk(Je()),lk=yl(),ck=Il(),Sl=class n{constructor(){this.bb=null,this.bb_pos=0}__init(e,r){return this.bb_pos=e,this.bb=r,this}static getRootAsInferenceSession(e,r){return(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsInferenceSession(e,r){return e.setPosition(e.position()+uk.SIZE_PREFIX_LENGTH),(r||new n).__init(e.readInt32(e.position())+e.position(),e)}static bufferHasIdentifier(e){return e.__has_identifier("ORTM")}ortVersion(e){let r=this.bb.__offset(this.bb_pos,4);return r?this.bb.__string(this.bb_pos+r,e):null}model(e){let r=this.bb.__offset(this.bb_pos,6);return r?(e||new ck.Model).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}kernelTypeStrResolver(e){let r=this.bb.__offset(this.bb_pos,10);return r?(e||new lk.KernelTypeStrResolver).__init(this.bb.__indirect(this.bb_pos+r),this.bb):null}static startInferenceSession(e){e.startObject(4)}static addOrtVersion(e,r){e.addFieldOffset(0,r,0)}static addModel(e,r){e.addFieldOffset(1,r,0)}static addKernelTypeStrResolver(e,r){e.addFieldOffset(3,r,0)}static endInferenceSession(e){return e.endObject()}static finishInferenceSessionBuffer(e,r){e.finish(r,"ORTM")}static finishSizePrefixedInferenceSessionBuffer(e,r){e.finish(r,"ORTM",!0)}};Kr.InferenceSession=Sl});var dk,pk,Ui,Xt,fk,hk,mk,gk,bk,yk,_k,vk,$l,Al,wk,xk,Tk,Ik,Ol,Sk,$k,Ak,Ok,Ck,Pk,Ek,Dk,kk,Nk,Lk,Rk,zk,Bo,Cl,Mk,Pl,Bk,oy=H(()=>{"use strict";dk=Ne(fu()),pk=Ne(vu()),Ui=Ne(Su()),Xt=Ne(wu()),fk=Ne(sl()),hk=Ne(ry()),mk=Ne(dl()),gk=Ne(cl()),bk=Ne(Xu()),yk=Ne(qu()),_k=Ne(Wu()),vk=Ne(Au()),$l=Ne(Gi()),Al=Ne(ny()),wk=Ne(hl()),xk=Ne(yl()),Tk=Ne(ju()),Ik=Ne(Il()),Ol=Ne(Iu()),Sk=Ne(Cu()),$k=Ne(xu()),Ak=Ne(Eu()),Ok=Ne(gl()),Ck=Ne(vl()),Pk=Ne(ku()),Ek=Ne(Lu()),Dk=Ne(zu()),kk=Ne(Uu()),Nk=Ne(Zu()),Lk=Ne(Fu()),Rk=Ne(xl()),zk=Ne(zo()),Bo=Ne(Ro()),Cl=Ne(Yu()),Mk=Ne(Mo()),Pl=Ne(el()),Bk=Ne(nl())});var Fo=H(()=>{"use strict";oy()});var ay=ge((bV,iy)=>{"use strict";iy.exports=Fk;function Fk(n,e){for(var r=new Array(arguments.length-1),t=0,o=2,i=!0;o{"use strict";var Hi=ly;Hi.length=function(e){var r=e.length;if(!r)return 0;for(var t=0;--r%4>1&&e.charAt(r)==="=";)++t;return Math.ceil(e.length*3)/4-t};var po=new Array(64),uy=new Array(123);for(ir=0;ir<64;)uy[po[ir]=ir<26?ir+65:ir<52?ir+71:ir<62?ir-4:ir-59|43]=ir++;var ir;Hi.encode=function(e,r,t){for(var o=null,i=[],a=0,l=0,d;r>2],d=(h&3)<<4,l=1;break;case 1:i[a++]=po[d|h>>4],d=(h&15)<<2,l=2;break;case 2:i[a++]=po[d|h>>6],i[a++]=po[h&63],l=0;break}a>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,i)),a=0)}return l&&(i[a++]=po[d],i[a++]=61,l===1&&(i[a++]=61)),o?(a&&o.push(String.fromCharCode.apply(String,i.slice(0,a))),o.join("")):String.fromCharCode.apply(String,i.slice(0,a))};var sy="invalid encoding";Hi.decode=function(e,r,t){for(var o=t,i=0,a,l=0;l1)break;if((d=uy[d])===void 0)throw Error(sy);switch(i){case 0:a=d,i=1;break;case 1:r[t++]=a<<2|(d&48)>>4,a=d,i=2;break;case 2:r[t++]=(a&15)<<4|(d&60)>>2,a=d,i=3;break;case 3:r[t++]=(a&3)<<6|d,i=0;break}}if(i===1)throw Error(sy);return t-o};Hi.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}});var py=ge((_V,dy)=>{"use strict";dy.exports=qi;function qi(){this._listeners={}}qi.prototype.on=function(e,r,t){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:r,ctx:t||this}),this};qi.prototype.off=function(e,r){if(e===void 0)this._listeners={};else if(r===void 0)this._listeners[e]=[];else for(var t=this._listeners[e],o=0;o{"use strict";yy.exports=fy(fy);function fy(n){return typeof Float32Array<"u"?function(){var e=new Float32Array([-0]),r=new Uint8Array(e.buffer),t=r[3]===128;function o(d,h,g){e[0]=d,h[g]=r[0],h[g+1]=r[1],h[g+2]=r[2],h[g+3]=r[3]}function i(d,h,g){e[0]=d,h[g]=r[3],h[g+1]=r[2],h[g+2]=r[1],h[g+3]=r[0]}n.writeFloatLE=t?o:i,n.writeFloatBE=t?i:o;function a(d,h){return r[0]=d[h],r[1]=d[h+1],r[2]=d[h+2],r[3]=d[h+3],e[0]}function l(d,h){return r[3]=d[h],r[2]=d[h+1],r[1]=d[h+2],r[0]=d[h+3],e[0]}n.readFloatLE=t?a:l,n.readFloatBE=t?l:a}():function(){function e(t,o,i,a){var l=o<0?1:0;if(l&&(o=-o),o===0)t(1/o>0?0:2147483648,i,a);else if(isNaN(o))t(2143289344,i,a);else if(o>34028234663852886e22)t((l<<31|2139095040)>>>0,i,a);else if(o<11754943508222875e-54)t((l<<31|Math.round(o/1401298464324817e-60))>>>0,i,a);else{var d=Math.floor(Math.log(o)/Math.LN2),h=Math.round(o*Math.pow(2,-d)*8388608)&8388607;t((l<<31|d+127<<23|h)>>>0,i,a)}}n.writeFloatLE=e.bind(null,hy),n.writeFloatBE=e.bind(null,my);function r(t,o,i){var a=t(o,i),l=(a>>31)*2+1,d=a>>>23&255,h=a&8388607;return d===255?h?NaN:l*(1/0):d===0?l*1401298464324817e-60*h:l*Math.pow(2,d-150)*(h+8388608)}n.readFloatLE=r.bind(null,gy),n.readFloatBE=r.bind(null,by)}(),typeof Float64Array<"u"?function(){var e=new Float64Array([-0]),r=new Uint8Array(e.buffer),t=r[7]===128;function o(d,h,g){e[0]=d,h[g]=r[0],h[g+1]=r[1],h[g+2]=r[2],h[g+3]=r[3],h[g+4]=r[4],h[g+5]=r[5],h[g+6]=r[6],h[g+7]=r[7]}function i(d,h,g){e[0]=d,h[g]=r[7],h[g+1]=r[6],h[g+2]=r[5],h[g+3]=r[4],h[g+4]=r[3],h[g+5]=r[2],h[g+6]=r[1],h[g+7]=r[0]}n.writeDoubleLE=t?o:i,n.writeDoubleBE=t?i:o;function a(d,h){return r[0]=d[h],r[1]=d[h+1],r[2]=d[h+2],r[3]=d[h+3],r[4]=d[h+4],r[5]=d[h+5],r[6]=d[h+6],r[7]=d[h+7],e[0]}function l(d,h){return r[7]=d[h],r[6]=d[h+1],r[5]=d[h+2],r[4]=d[h+3],r[3]=d[h+4],r[2]=d[h+5],r[1]=d[h+6],r[0]=d[h+7],e[0]}n.readDoubleLE=t?a:l,n.readDoubleBE=t?l:a}():function(){function e(t,o,i,a,l,d){var h=a<0?1:0;if(h&&(a=-a),a===0)t(0,l,d+o),t(1/a>0?0:2147483648,l,d+i);else if(isNaN(a))t(0,l,d+o),t(2146959360,l,d+i);else if(a>17976931348623157e292)t(0,l,d+o),t((h<<31|2146435072)>>>0,l,d+i);else{var g;if(a<22250738585072014e-324)g=a/5e-324,t(g>>>0,l,d+o),t((h<<31|g/4294967296)>>>0,l,d+i);else{var _=Math.floor(Math.log(a)/Math.LN2);_===1024&&(_=1023),g=a*Math.pow(2,-_),t(g*4503599627370496>>>0,l,d+o),t((h<<31|_+1023<<20|g*1048576&1048575)>>>0,l,d+i)}}}n.writeDoubleLE=e.bind(null,hy,0,4),n.writeDoubleBE=e.bind(null,my,4,0);function r(t,o,i,a,l){var d=t(a,l+o),h=t(a,l+i),g=(h>>31)*2+1,_=h>>>20&2047,w=4294967296*(h&1048575)+d;return _===2047?w?NaN:g*(1/0):_===0?g*5e-324*w:g*Math.pow(2,_-1075)*(w+4503599627370496)}n.readDoubleLE=r.bind(null,gy,0,4),n.readDoubleBE=r.bind(null,by,4,0)}(),n}function hy(n,e,r){e[r]=n&255,e[r+1]=n>>>8&255,e[r+2]=n>>>16&255,e[r+3]=n>>>24}function my(n,e,r){e[r]=n>>>24,e[r+1]=n>>>16&255,e[r+2]=n>>>8&255,e[r+3]=n&255}function gy(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0}function by(n,e){return(n[e]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3])>>>0}});var vy=ge((exports,module)=>{"use strict";module.exports=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(n){}return null}});var xy=ge(wy=>{"use strict";var El=wy;El.length=function(e){for(var r=0,t=0,o=0;o191&&d<224?a[l++]=(d&31)<<6|e[r++]&63:d>239&&d<365?(d=((d&7)<<18|(e[r++]&63)<<12|(e[r++]&63)<<6|e[r++]&63)-65536,a[l++]=55296+(d>>10),a[l++]=56320+(d&1023)):a[l++]=(d&15)<<12|(e[r++]&63)<<6|e[r++]&63,l>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,a)),l=0);return i?(l&&i.push(String.fromCharCode.apply(String,a.slice(0,l))),i.join("")):String.fromCharCode.apply(String,a.slice(0,l))};El.write=function(e,r,t){for(var o=t,i,a,l=0;l>6|192,r[t++]=i&63|128):(i&64512)===55296&&((a=e.charCodeAt(l+1))&64512)===56320?(i=65536+((i&1023)<<10)+(a&1023),++l,r[t++]=i>>18|240,r[t++]=i>>12&63|128,r[t++]=i>>6&63|128,r[t++]=i&63|128):(r[t++]=i>>12|224,r[t++]=i>>6&63|128,r[t++]=i&63|128);return t-o}});var Iy=ge((xV,Ty)=>{"use strict";Ty.exports=Vk;function Vk(n,e,r){var t=r||8192,o=t>>>1,i=null,a=t;return function(d){if(d<1||d>o)return n(d);a+d>t&&(i=n(t),a=0);var h=e.call(i,a,a+=d);return a&7&&(a=(a|7)+1),h}}});var $y=ge((TV,Sy)=>{"use strict";Sy.exports=xt;var Vo=In();function xt(n,e){this.lo=n>>>0,this.hi=e>>>0}var jn=xt.zero=new xt(0,0);jn.toNumber=function(){return 0};jn.zzEncode=jn.zzDecode=function(){return this};jn.length=function(){return 1};var jk=xt.zeroHash="\0\0\0\0\0\0\0\0";xt.fromNumber=function(e){if(e===0)return jn;var r=e<0;r&&(e=-e);var t=e>>>0,o=(e-t)/4294967296>>>0;return r&&(o=~o>>>0,t=~t>>>0,++t>4294967295&&(t=0,++o>4294967295&&(o=0))),new xt(t,o)};xt.from=function(e){if(typeof e=="number")return xt.fromNumber(e);if(Vo.isString(e))if(Vo.Long)e=Vo.Long.fromString(e);else return xt.fromNumber(parseInt(e,10));return e.low||e.high?new xt(e.low>>>0,e.high>>>0):jn};xt.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var r=~this.lo+1>>>0,t=~this.hi>>>0;return r||(t=t+1>>>0),-(r+t*4294967296)}return this.lo+this.hi*4294967296};xt.prototype.toLong=function(e){return Vo.Long?new Vo.Long(this.lo|0,this.hi|0,!!e):{low:this.lo|0,high:this.hi|0,unsigned:!!e}};var Tn=String.prototype.charCodeAt;xt.fromHash=function(e){return e===jk?jn:new xt((Tn.call(e,0)|Tn.call(e,1)<<8|Tn.call(e,2)<<16|Tn.call(e,3)<<24)>>>0,(Tn.call(e,4)|Tn.call(e,5)<<8|Tn.call(e,6)<<16|Tn.call(e,7)<<24)>>>0)};xt.prototype.toHash=function(){return String.fromCharCode(this.lo&255,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,this.hi&255,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)};xt.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this};xt.prototype.zzDecode=function(){var e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this};xt.prototype.length=function(){var e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,t=this.hi>>>24;return t===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:t<128?9:10}});var In=ge(Dl=>{"use strict";var be=Dl;be.asPromise=ay();be.base64=cy();be.EventEmitter=py();be.float=_y();be.inquire=vy();be.utf8=xy();be.pool=Iy();be.LongBits=$y();be.isNode=!!(typeof global<"u"&&global&&global.process&&global.process.versions&&global.process.versions.node);be.global=be.isNode&&global||typeof window<"u"&&window||typeof self<"u"&&self||Dl;be.emptyArray=Object.freeze?Object.freeze([]):[];be.emptyObject=Object.freeze?Object.freeze({}):{};be.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};be.isString=function(e){return typeof e=="string"||e instanceof String};be.isObject=function(e){return e&&typeof e=="object"};be.isset=be.isSet=function(e,r){var t=e[r];return t!=null&&e.hasOwnProperty(r)?typeof t!="object"||(Array.isArray(t)?t.length:Object.keys(t).length)>0:!1};be.Buffer=function(){try{var n=be.inquire("buffer").Buffer;return n.prototype.utf8Write?n:null}catch{return null}}();be._Buffer_from=null;be._Buffer_allocUnsafe=null;be.newBuffer=function(e){return typeof e=="number"?be.Buffer?be._Buffer_allocUnsafe(e):new be.Array(e):be.Buffer?be._Buffer_from(e):typeof Uint8Array>"u"?e:new Uint8Array(e)};be.Array=typeof Uint8Array<"u"?Uint8Array:Array;be.Long=be.global.dcodeIO&&be.global.dcodeIO.Long||be.global.Long||be.inquire("long");be.key2Re=/^true|false|0|1$/;be.key32Re=/^-?(?:0|[1-9][0-9]*)$/;be.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;be.longToHash=function(e){return e?be.LongBits.from(e).toHash():be.LongBits.zeroHash};be.longFromHash=function(e,r){var t=be.LongBits.fromHash(e);return be.Long?be.Long.fromBits(t.lo,t.hi,r):t.toNumber(!!r)};function Ay(n,e,r){for(var t=Object.keys(e),o=0;o-1;--i)if(r[o[i]]===1&&this[o[i]]!==void 0&&this[o[i]]!==null)return o[i]}};be.oneOfSetter=function(e){return function(r){for(var t=0;t{"use strict";Dy.exports=We;var Jt=In(),kl,Ki=Jt.LongBits,Cy=Jt.base64,Py=Jt.utf8;function jo(n,e,r){this.fn=n,this.len=e,this.next=void 0,this.val=r}function Ll(){}function Gk(n){this.head=n.head,this.tail=n.tail,this.len=n.len,this.next=n.states}function We(){this.len=0,this.head=new jo(Ll,0,0),this.tail=this.head,this.states=null}var Ey=function(){return Jt.Buffer?function(){return(We.create=function(){return new kl})()}:function(){return new We}};We.create=Ey();We.alloc=function(e){return new Jt.Array(e)};Jt.Array!==Array&&(We.alloc=Jt.pool(We.alloc,Jt.Array.prototype.subarray));We.prototype._push=function(e,r,t){return this.tail=this.tail.next=new jo(e,r,t),this.len+=r,this};function Rl(n,e,r){e[r]=n&255}function Uk(n,e,r){for(;n>127;)e[r++]=n&127|128,n>>>=7;e[r]=n}function zl(n,e){this.len=n,this.next=void 0,this.val=e}zl.prototype=Object.create(jo.prototype);zl.prototype.fn=Uk;We.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new zl((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this};We.prototype.int32=function(e){return e<0?this._push(Ml,10,Ki.fromNumber(e)):this.uint32(e)};We.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)};function Ml(n,e,r){for(;n.hi;)e[r++]=n.lo&127|128,n.lo=(n.lo>>>7|n.hi<<25)>>>0,n.hi>>>=7;for(;n.lo>127;)e[r++]=n.lo&127|128,n.lo=n.lo>>>7;e[r++]=n.lo}We.prototype.uint64=function(e){var r=Ki.from(e);return this._push(Ml,r.length(),r)};We.prototype.int64=We.prototype.uint64;We.prototype.sint64=function(e){var r=Ki.from(e).zzEncode();return this._push(Ml,r.length(),r)};We.prototype.bool=function(e){return this._push(Rl,1,e?1:0)};function Nl(n,e,r){e[r]=n&255,e[r+1]=n>>>8&255,e[r+2]=n>>>16&255,e[r+3]=n>>>24}We.prototype.fixed32=function(e){return this._push(Nl,4,e>>>0)};We.prototype.sfixed32=We.prototype.fixed32;We.prototype.fixed64=function(e){var r=Ki.from(e);return this._push(Nl,4,r.lo)._push(Nl,4,r.hi)};We.prototype.sfixed64=We.prototype.fixed64;We.prototype.float=function(e){return this._push(Jt.float.writeFloatLE,4,e)};We.prototype.double=function(e){return this._push(Jt.float.writeDoubleLE,8,e)};var Wk=Jt.Array.prototype.set?function(e,r,t){r.set(e,t)}:function(e,r,t){for(var o=0;o>>0;if(!r)return this._push(Rl,1,0);if(Jt.isString(e)){var t=We.alloc(r=Cy.length(e));Cy.decode(e,t,0),e=t}return this.uint32(r)._push(Wk,r,e)};We.prototype.string=function(e){var r=Py.length(e);return r?this.uint32(r)._push(Py.write,r,e):this._push(Rl,1,0)};We.prototype.fork=function(){return this.states=new Gk(this),this.head=this.tail=new jo(Ll,0,0),this.len=0,this};We.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new jo(Ll,0,0),this.len=0),this};We.prototype.ldelim=function(){var e=this.head,r=this.tail,t=this.len;return this.reset().uint32(t),t&&(this.tail.next=e.next,this.tail=r,this.len+=t),this};We.prototype.finish=function(){for(var e=this.head.next,r=this.constructor.alloc(this.len),t=0;e;)e.fn(e.val,r,t),t+=e.len,e=e.next;return r};We._configure=function(n){kl=n,We.create=Ey(),kl._configure()}});var Ly=ge(($V,Ny)=>{"use strict";Ny.exports=Xr;var ky=Bl();(Xr.prototype=Object.create(ky.prototype)).constructor=Xr;var Sn=In();function Xr(){ky.call(this)}Xr._configure=function(){Xr.alloc=Sn._Buffer_allocUnsafe,Xr.writeBytesBuffer=Sn.Buffer&&Sn.Buffer.prototype instanceof Uint8Array&&Sn.Buffer.prototype.set.name==="set"?function(e,r,t){r.set(e,t)}:function(e,r,t){if(e.copy)e.copy(r,t,0,e.length);else for(var o=0;o>>0;return this.uint32(r),r&&this._push(Xr.writeBytesBuffer,r,e),this};function Hk(n,e,r){n.length<40?Sn.utf8.write(n,e,r):e.utf8Write?e.utf8Write(n,r):e.write(n,r)}Xr.prototype.string=function(e){var r=Sn.Buffer.byteLength(e);return this.uint32(r),r&&this._push(Hk,r,e),this};Xr._configure()});var jl=ge((AV,Fy)=>{"use strict";Fy.exports=mt;var ar=In(),Vl,My=ar.LongBits,qk=ar.utf8;function sr(n,e){return RangeError("index out of range: "+n.pos+" + "+(e||1)+" > "+n.len)}function mt(n){this.buf=n,this.pos=0,this.len=n.length}var Ry=typeof Uint8Array<"u"?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new mt(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new mt(e);throw Error("illegal buffer")},By=function(){return ar.Buffer?function(r){return(mt.create=function(o){return ar.Buffer.isBuffer(o)?new Vl(o):Ry(o)})(r)}:Ry};mt.create=By();mt.prototype._slice=ar.Array.prototype.subarray||ar.Array.prototype.slice;mt.prototype.uint32=function(){var e=4294967295;return function(){if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,sr(this,10);return e}}();mt.prototype.int32=function(){return this.uint32()|0};mt.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(e&1)|0};function Fl(){var n=new My(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(n.lo=(n.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return n;if(n.lo=(n.lo|(this.buf[this.pos]&127)<<28)>>>0,n.hi=(n.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return n;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw sr(this);if(n.lo=(n.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return n}return n.lo=(n.lo|(this.buf[this.pos++]&127)<>>0,n}if(this.len-this.pos>4){for(;e<5;++e)if(n.hi=(n.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return n}else for(;e<5;++e){if(this.pos>=this.len)throw sr(this);if(n.hi=(n.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return n}throw Error("invalid varint encoding")}mt.prototype.bool=function(){return this.uint32()!==0};function Xi(n,e){return(n[e-4]|n[e-3]<<8|n[e-2]<<16|n[e-1]<<24)>>>0}mt.prototype.fixed32=function(){if(this.pos+4>this.len)throw sr(this,4);return Xi(this.buf,this.pos+=4)};mt.prototype.sfixed32=function(){if(this.pos+4>this.len)throw sr(this,4);return Xi(this.buf,this.pos+=4)|0};function zy(){if(this.pos+8>this.len)throw sr(this,8);return new My(Xi(this.buf,this.pos+=4),Xi(this.buf,this.pos+=4))}mt.prototype.float=function(){if(this.pos+4>this.len)throw sr(this,4);var e=ar.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e};mt.prototype.double=function(){if(this.pos+8>this.len)throw sr(this,4);var e=ar.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e};mt.prototype.bytes=function(){var e=this.uint32(),r=this.pos,t=this.pos+e;if(t>this.len)throw sr(this,e);if(this.pos+=e,Array.isArray(this.buf))return this.buf.slice(r,t);if(r===t){var o=ar.Buffer;return o?o.alloc(0):new this.buf.constructor(0)}return this._slice.call(this.buf,r,t)};mt.prototype.string=function(){var e=this.bytes();return qk.read(e,0,e.length)};mt.prototype.skip=function(e){if(typeof e=="number"){if(this.pos+e>this.len)throw sr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw sr(this);while(this.buf[this.pos++]&128);return this};mt.prototype.skipType=function(n){switch(n){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(n=this.uint32()&7)!==4;)this.skipType(n);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+n+" at offset "+this.pos)}return this};mt._configure=function(n){Vl=n,mt.create=By(),Vl._configure();var e=ar.Long?"toLong":"toNumber";ar.merge(mt.prototype,{int64:function(){return Fl.call(this)[e](!1)},uint64:function(){return Fl.call(this)[e](!0)},sint64:function(){return Fl.call(this).zzDecode()[e](!1)},fixed64:function(){return zy.call(this)[e](!0)},sfixed64:function(){return zy.call(this)[e](!1)}})}});var Uy=ge((OV,Gy)=>{"use strict";Gy.exports=Gn;var jy=jl();(Gn.prototype=Object.create(jy.prototype)).constructor=Gn;var Vy=In();function Gn(n){jy.call(this,n)}Gn._configure=function(){Vy.Buffer&&(Gn.prototype._slice=Vy.Buffer.prototype.slice)};Gn.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))};Gn._configure()});var Hy=ge((CV,Wy)=>{"use strict";Wy.exports=Go;var Gl=In();(Go.prototype=Object.create(Gl.EventEmitter.prototype)).constructor=Go;function Go(n,e,r){if(typeof n!="function")throw TypeError("rpcImpl must be a function");Gl.EventEmitter.call(this),this.rpcImpl=n,this.requestDelimited=!!e,this.responseDelimited=!!r}Go.prototype.rpcCall=function n(e,r,t,o,i){if(!o)throw TypeError("request must be specified");var a=this;if(!i)return Gl.asPromise(n,a,e,r,t,o);if(!a.rpcImpl){setTimeout(function(){i(Error("already ended"))},0);return}try{return a.rpcImpl(e,r[a.requestDelimited?"encodeDelimited":"encode"](o).finish(),function(d,h){if(d)return a.emit("error",d,e),i(d);if(h===null){a.end(!0);return}if(!(h instanceof t))try{h=t[a.responseDelimited?"decodeDelimited":"decode"](h)}catch(g){return a.emit("error",g,e),i(g)}return a.emit("data",h,e),i(null,h)})}catch(l){a.emit("error",l,e),setTimeout(function(){i(l)},0);return}};Go.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}});var Ky=ge(qy=>{"use strict";var Kk=qy;Kk.Service=Hy()});var Jy=ge((EV,Xy)=>{"use strict";Xy.exports={}});var Yy=ge(Qy=>{"use strict";var Lt=Qy;Lt.build="minimal";Lt.Writer=Bl();Lt.BufferWriter=Ly();Lt.Reader=jl();Lt.BufferReader=Uy();Lt.util=In();Lt.rpc=Ky();Lt.roots=Jy();Lt.configure=Zy;function Zy(){Lt.util._configure(),Lt.Writer._configure(Lt.BufferWriter),Lt.Reader._configure(Lt.BufferReader)}Zy()});var t_=ge((kV,e_)=>{"use strict";e_.exports=Yy()});var fo=ge((NV,r_)=>{"use strict";var it=t_(),se=it.Reader,gt=it.Writer,M=it.util,N=it.roots.default||(it.roots.default={});N.onnx=function(){var n={};return n.Version=function(){var e={},r=Object.create(e);return r[e[0]="_START_VERSION"]=0,r[e[1]="IR_VERSION_2017_10_10"]=1,r[e[2]="IR_VERSION_2017_10_30"]=2,r[e[3]="IR_VERSION_2017_11_3"]=3,r[e[4]="IR_VERSION_2019_1_22"]=4,r[e[5]="IR_VERSION_2019_3_18"]=5,r[e[6]="IR_VERSION_2019_9_19"]=6,r[e[7]="IR_VERSION_2020_5_8"]=7,r[e[8]="IR_VERSION_2021_7_30"]=8,r[e[9]="IR_VERSION"]=9,r}(),n.AttributeProto=function(){function e(r){if(this.floats=[],this.ints=[],this.strings=[],this.tensors=[],this.graphs=[],this.sparseTensors=[],this.typeProtos=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.name=t.string();break}case 21:{a.refAttrName=t.string();break}case 13:{a.docString=t.string();break}case 20:{a.type=t.int32();break}case 2:{a.f=t.float();break}case 3:{a.i=t.int64();break}case 4:{a.s=t.bytes();break}case 5:{a.t=N.onnx.TensorProto.decode(t,t.uint32());break}case 6:{a.g=N.onnx.GraphProto.decode(t,t.uint32());break}case 22:{a.sparseTensor=N.onnx.SparseTensorProto.decode(t,t.uint32());break}case 14:{a.tp=N.onnx.TypeProto.decode(t,t.uint32());break}case 7:{if(a.floats&&a.floats.length||(a.floats=[]),(l&7)===2)for(var d=t.uint32()+t.pos;t.pos>>0,t.i.high>>>0).toNumber())),t.s!=null&&(typeof t.s=="string"?M.base64.decode(t.s,o.s=M.newBuffer(M.base64.length(t.s)),0):t.s.length>=0&&(o.s=t.s)),t.t!=null){if(typeof t.t!="object")throw TypeError(".onnx.AttributeProto.t: object expected");o.t=N.onnx.TensorProto.fromObject(t.t)}if(t.g!=null){if(typeof t.g!="object")throw TypeError(".onnx.AttributeProto.g: object expected");o.g=N.onnx.GraphProto.fromObject(t.g)}if(t.sparseTensor!=null){if(typeof t.sparseTensor!="object")throw TypeError(".onnx.AttributeProto.sparseTensor: object expected");o.sparseTensor=N.onnx.SparseTensorProto.fromObject(t.sparseTensor)}if(t.tp!=null){if(typeof t.tp!="object")throw TypeError(".onnx.AttributeProto.tp: object expected");o.tp=N.onnx.TypeProto.fromObject(t.tp)}if(t.floats){if(!Array.isArray(t.floats))throw TypeError(".onnx.AttributeProto.floats: array expected");o.floats=[];for(var i=0;i>>0,t.ints[i].high>>>0).toNumber())}if(t.strings){if(!Array.isArray(t.strings))throw TypeError(".onnx.AttributeProto.strings: array expected");o.strings=[];for(var i=0;i=0&&(o.strings[i]=t.strings[i])}if(t.tensors){if(!Array.isArray(t.tensors))throw TypeError(".onnx.AttributeProto.tensors: array expected");o.tensors=[];for(var i=0;i>>0,t.i.high>>>0).toNumber():t.i),t.s!=null&&t.hasOwnProperty("s")&&(i.s=o.bytes===String?M.base64.encode(t.s,0,t.s.length):o.bytes===Array?Array.prototype.slice.call(t.s):t.s),t.t!=null&&t.hasOwnProperty("t")&&(i.t=N.onnx.TensorProto.toObject(t.t,o)),t.g!=null&&t.hasOwnProperty("g")&&(i.g=N.onnx.GraphProto.toObject(t.g,o)),t.floats&&t.floats.length){i.floats=[];for(var l=0;l>>0,t.ints[l].high>>>0).toNumber():t.ints[l]}if(t.strings&&t.strings.length){i.strings=[];for(var l=0;l>>3){case 1:{a.name=t.string();break}case 2:{a.type=N.onnx.TypeProto.decode(t,t.uint32());break}case 3:{a.docString=t.string();break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.name!=null&&t.hasOwnProperty("name")&&!M.isString(t.name))return"name: string expected";if(t.type!=null&&t.hasOwnProperty("type")){var o=N.onnx.TypeProto.verify(t.type);if(o)return"type."+o}return t.docString!=null&&t.hasOwnProperty("docString")&&!M.isString(t.docString)?"docString: string expected":null},e.fromObject=function(t){if(t instanceof N.onnx.ValueInfoProto)return t;var o=new N.onnx.ValueInfoProto;if(t.name!=null&&(o.name=String(t.name)),t.type!=null){if(typeof t.type!="object")throw TypeError(".onnx.ValueInfoProto.type: object expected");o.type=N.onnx.TypeProto.fromObject(t.type)}return t.docString!=null&&(o.docString=String(t.docString)),o},e.toObject=function(t,o){o||(o={});var i={};return o.defaults&&(i.name="",i.type=null,i.docString=""),t.name!=null&&t.hasOwnProperty("name")&&(i.name=t.name),t.type!=null&&t.hasOwnProperty("type")&&(i.type=N.onnx.TypeProto.toObject(t.type,o)),t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.ValueInfoProto"},e}(),n.NodeProto=function(){function e(r){if(this.input=[],this.output=[],this.attribute=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.input&&a.input.length||(a.input=[]),a.input.push(t.string());break}case 2:{a.output&&a.output.length||(a.output=[]),a.output.push(t.string());break}case 3:{a.name=t.string();break}case 4:{a.opType=t.string();break}case 7:{a.domain=t.string();break}case 5:{a.attribute&&a.attribute.length||(a.attribute=[]),a.attribute.push(N.onnx.AttributeProto.decode(t,t.uint32()));break}case 6:{a.docString=t.string();break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.input!=null&&t.hasOwnProperty("input")){if(!Array.isArray(t.input))return"input: array expected";for(var o=0;o>>3){case 1:{a.initialization=N.onnx.GraphProto.decode(t,t.uint32());break}case 2:{a.algorithm=N.onnx.GraphProto.decode(t,t.uint32());break}case 3:{a.initializationBinding&&a.initializationBinding.length||(a.initializationBinding=[]),a.initializationBinding.push(N.onnx.StringStringEntryProto.decode(t,t.uint32()));break}case 4:{a.updateBinding&&a.updateBinding.length||(a.updateBinding=[]),a.updateBinding.push(N.onnx.StringStringEntryProto.decode(t,t.uint32()));break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.initialization!=null&&t.hasOwnProperty("initialization")){var o=N.onnx.GraphProto.verify(t.initialization);if(o)return"initialization."+o}if(t.algorithm!=null&&t.hasOwnProperty("algorithm")){var o=N.onnx.GraphProto.verify(t.algorithm);if(o)return"algorithm."+o}if(t.initializationBinding!=null&&t.hasOwnProperty("initializationBinding")){if(!Array.isArray(t.initializationBinding))return"initializationBinding: array expected";for(var i=0;i>>3){case 1:{a.irVersion=t.int64();break}case 8:{a.opsetImport&&a.opsetImport.length||(a.opsetImport=[]),a.opsetImport.push(N.onnx.OperatorSetIdProto.decode(t,t.uint32()));break}case 2:{a.producerName=t.string();break}case 3:{a.producerVersion=t.string();break}case 4:{a.domain=t.string();break}case 5:{a.modelVersion=t.int64();break}case 6:{a.docString=t.string();break}case 7:{a.graph=N.onnx.GraphProto.decode(t,t.uint32());break}case 14:{a.metadataProps&&a.metadataProps.length||(a.metadataProps=[]),a.metadataProps.push(N.onnx.StringStringEntryProto.decode(t,t.uint32()));break}case 20:{a.trainingInfo&&a.trainingInfo.length||(a.trainingInfo=[]),a.trainingInfo.push(N.onnx.TrainingInfoProto.decode(t,t.uint32()));break}case 25:{a.functions&&a.functions.length||(a.functions=[]),a.functions.push(N.onnx.FunctionProto.decode(t,t.uint32()));break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.irVersion!=null&&t.hasOwnProperty("irVersion")&&!M.isInteger(t.irVersion)&&!(t.irVersion&&M.isInteger(t.irVersion.low)&&M.isInteger(t.irVersion.high)))return"irVersion: integer|Long expected";if(t.opsetImport!=null&&t.hasOwnProperty("opsetImport")){if(!Array.isArray(t.opsetImport))return"opsetImport: array expected";for(var o=0;o>>0,t.irVersion.high>>>0).toNumber())),t.opsetImport){if(!Array.isArray(t.opsetImport))throw TypeError(".onnx.ModelProto.opsetImport: array expected");o.opsetImport=[];for(var i=0;i>>0,t.modelVersion.high>>>0).toNumber())),t.docString!=null&&(o.docString=String(t.docString)),t.graph!=null){if(typeof t.graph!="object")throw TypeError(".onnx.ModelProto.graph: object expected");o.graph=N.onnx.GraphProto.fromObject(t.graph)}if(t.metadataProps){if(!Array.isArray(t.metadataProps))throw TypeError(".onnx.ModelProto.metadataProps: array expected");o.metadataProps=[];for(var i=0;i>>0,t.irVersion.high>>>0).toNumber():t.irVersion),t.producerName!=null&&t.hasOwnProperty("producerName")&&(i.producerName=t.producerName),t.producerVersion!=null&&t.hasOwnProperty("producerVersion")&&(i.producerVersion=t.producerVersion),t.domain!=null&&t.hasOwnProperty("domain")&&(i.domain=t.domain),t.modelVersion!=null&&t.hasOwnProperty("modelVersion")&&(typeof t.modelVersion=="number"?i.modelVersion=o.longs===String?String(t.modelVersion):t.modelVersion:i.modelVersion=o.longs===String?M.Long.prototype.toString.call(t.modelVersion):o.longs===Number?new M.LongBits(t.modelVersion.low>>>0,t.modelVersion.high>>>0).toNumber():t.modelVersion),t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),t.graph!=null&&t.hasOwnProperty("graph")&&(i.graph=N.onnx.GraphProto.toObject(t.graph,o)),t.opsetImport&&t.opsetImport.length){i.opsetImport=[];for(var l=0;l>>3){case 1:{a.key=t.string();break}case 2:{a.value=t.string();break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){return typeof t!="object"||t===null?"object expected":t.key!=null&&t.hasOwnProperty("key")&&!M.isString(t.key)?"key: string expected":t.value!=null&&t.hasOwnProperty("value")&&!M.isString(t.value)?"value: string expected":null},e.fromObject=function(t){if(t instanceof N.onnx.StringStringEntryProto)return t;var o=new N.onnx.StringStringEntryProto;return t.key!=null&&(o.key=String(t.key)),t.value!=null&&(o.value=String(t.value)),o},e.toObject=function(t,o){o||(o={});var i={};return o.defaults&&(i.key="",i.value=""),t.key!=null&&t.hasOwnProperty("key")&&(i.key=t.key),t.value!=null&&t.hasOwnProperty("value")&&(i.value=t.value),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.StringStringEntryProto"},e}(),n.TensorAnnotation=function(){function e(r){if(this.quantParameterTensorNames=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.tensorName=t.string();break}case 2:{a.quantParameterTensorNames&&a.quantParameterTensorNames.length||(a.quantParameterTensorNames=[]),a.quantParameterTensorNames.push(N.onnx.StringStringEntryProto.decode(t,t.uint32()));break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.tensorName!=null&&t.hasOwnProperty("tensorName")&&!M.isString(t.tensorName))return"tensorName: string expected";if(t.quantParameterTensorNames!=null&&t.hasOwnProperty("quantParameterTensorNames")){if(!Array.isArray(t.quantParameterTensorNames))return"quantParameterTensorNames: array expected";for(var o=0;o>>3){case 1:{a.node&&a.node.length||(a.node=[]),a.node.push(N.onnx.NodeProto.decode(t,t.uint32()));break}case 2:{a.name=t.string();break}case 5:{a.initializer&&a.initializer.length||(a.initializer=[]),a.initializer.push(N.onnx.TensorProto.decode(t,t.uint32()));break}case 15:{a.sparseInitializer&&a.sparseInitializer.length||(a.sparseInitializer=[]),a.sparseInitializer.push(N.onnx.SparseTensorProto.decode(t,t.uint32()));break}case 10:{a.docString=t.string();break}case 11:{a.input&&a.input.length||(a.input=[]),a.input.push(N.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 12:{a.output&&a.output.length||(a.output=[]),a.output.push(N.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 13:{a.valueInfo&&a.valueInfo.length||(a.valueInfo=[]),a.valueInfo.push(N.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 14:{a.quantizationAnnotation&&a.quantizationAnnotation.length||(a.quantizationAnnotation=[]),a.quantizationAnnotation.push(N.onnx.TensorAnnotation.decode(t,t.uint32()));break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.node!=null&&t.hasOwnProperty("node")){if(!Array.isArray(t.node))return"node: array expected";for(var o=0;o>>3){case 1:{if(a.dims&&a.dims.length||(a.dims=[]),(l&7)===2)for(var d=t.uint32()+t.pos;t.pos>>0,t.dims[i].high>>>0).toNumber())}if(t.dataType!=null&&(o.dataType=t.dataType|0),t.segment!=null){if(typeof t.segment!="object")throw TypeError(".onnx.TensorProto.segment: object expected");o.segment=N.onnx.TensorProto.Segment.fromObject(t.segment)}if(t.floatData){if(!Array.isArray(t.floatData))throw TypeError(".onnx.TensorProto.floatData: array expected");o.floatData=[];for(var i=0;i=0&&(o.stringData[i]=t.stringData[i])}if(t.int64Data){if(!Array.isArray(t.int64Data))throw TypeError(".onnx.TensorProto.int64Data: array expected");o.int64Data=[];for(var i=0;i>>0,t.int64Data[i].high>>>0).toNumber())}if(t.name!=null&&(o.name=String(t.name)),t.docString!=null&&(o.docString=String(t.docString)),t.rawData!=null&&(typeof t.rawData=="string"?M.base64.decode(t.rawData,o.rawData=M.newBuffer(M.base64.length(t.rawData)),0):t.rawData.length>=0&&(o.rawData=t.rawData)),t.externalData){if(!Array.isArray(t.externalData))throw TypeError(".onnx.TensorProto.externalData: array expected");o.externalData=[];for(var i=0;i>>0,t.uint64Data[i].high>>>0).toNumber(!0))}return o},e.toObject=function(t,o){o||(o={});var i={};if((o.arrays||o.defaults)&&(i.dims=[],i.floatData=[],i.int32Data=[],i.stringData=[],i.int64Data=[],i.doubleData=[],i.uint64Data=[],i.externalData=[]),o.defaults&&(i.dataType=0,i.segment=null,i.name="",o.bytes===String?i.rawData="":(i.rawData=[],o.bytes!==Array&&(i.rawData=M.newBuffer(i.rawData))),i.docString="",i.dataLocation=o.enums===String?"DEFAULT":0),t.dims&&t.dims.length){i.dims=[];for(var a=0;a>>0,t.dims[a].high>>>0).toNumber():t.dims[a]}if(t.dataType!=null&&t.hasOwnProperty("dataType")&&(i.dataType=t.dataType),t.segment!=null&&t.hasOwnProperty("segment")&&(i.segment=N.onnx.TensorProto.Segment.toObject(t.segment,o)),t.floatData&&t.floatData.length){i.floatData=[];for(var a=0;a>>0,t.int64Data[a].high>>>0).toNumber():t.int64Data[a]}if(t.name!=null&&t.hasOwnProperty("name")&&(i.name=t.name),t.rawData!=null&&t.hasOwnProperty("rawData")&&(i.rawData=o.bytes===String?M.base64.encode(t.rawData,0,t.rawData.length):o.bytes===Array?Array.prototype.slice.call(t.rawData):t.rawData),t.doubleData&&t.doubleData.length){i.doubleData=[];for(var a=0;a>>0,t.uint64Data[a].high>>>0).toNumber(!0):t.uint64Data[a]}if(t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),t.externalData&&t.externalData.length){i.externalData=[];for(var a=0;a>>3){case 1:{l.begin=o.int64();break}case 2:{l.end=o.int64();break}default:o.skipType(d&7);break}}return l},r.decodeDelimited=function(o){return o instanceof se||(o=new se(o)),this.decode(o,o.uint32())},r.verify=function(o){return typeof o!="object"||o===null?"object expected":o.begin!=null&&o.hasOwnProperty("begin")&&!M.isInteger(o.begin)&&!(o.begin&&M.isInteger(o.begin.low)&&M.isInteger(o.begin.high))?"begin: integer|Long expected":o.end!=null&&o.hasOwnProperty("end")&&!M.isInteger(o.end)&&!(o.end&&M.isInteger(o.end.low)&&M.isInteger(o.end.high))?"end: integer|Long expected":null},r.fromObject=function(o){if(o instanceof N.onnx.TensorProto.Segment)return o;var i=new N.onnx.TensorProto.Segment;return o.begin!=null&&(M.Long?(i.begin=M.Long.fromValue(o.begin)).unsigned=!1:typeof o.begin=="string"?i.begin=parseInt(o.begin,10):typeof o.begin=="number"?i.begin=o.begin:typeof o.begin=="object"&&(i.begin=new M.LongBits(o.begin.low>>>0,o.begin.high>>>0).toNumber())),o.end!=null&&(M.Long?(i.end=M.Long.fromValue(o.end)).unsigned=!1:typeof o.end=="string"?i.end=parseInt(o.end,10):typeof o.end=="number"?i.end=o.end:typeof o.end=="object"&&(i.end=new M.LongBits(o.end.low>>>0,o.end.high>>>0).toNumber())),i},r.toObject=function(o,i){i||(i={});var a={};if(i.defaults){if(M.Long){var l=new M.Long(0,0,!1);a.begin=i.longs===String?l.toString():i.longs===Number?l.toNumber():l}else a.begin=i.longs===String?"0":0;if(M.Long){var l=new M.Long(0,0,!1);a.end=i.longs===String?l.toString():i.longs===Number?l.toNumber():l}else a.end=i.longs===String?"0":0}return o.begin!=null&&o.hasOwnProperty("begin")&&(typeof o.begin=="number"?a.begin=i.longs===String?String(o.begin):o.begin:a.begin=i.longs===String?M.Long.prototype.toString.call(o.begin):i.longs===Number?new M.LongBits(o.begin.low>>>0,o.begin.high>>>0).toNumber():o.begin),o.end!=null&&o.hasOwnProperty("end")&&(typeof o.end=="number"?a.end=i.longs===String?String(o.end):o.end:a.end=i.longs===String?M.Long.prototype.toString.call(o.end):i.longs===Number?new M.LongBits(o.end.low>>>0,o.end.high>>>0).toNumber():o.end),a},r.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},r.getTypeUrl=function(o){return o===void 0&&(o="type.googleapis.com"),o+"/onnx.TensorProto.Segment"},r}(),e.DataLocation=function(){var r={},t=Object.create(r);return t[r[0]="DEFAULT"]=0,t[r[1]="EXTERNAL"]=1,t}(),e}(),n.SparseTensorProto=function(){function e(r){if(this.dims=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.values=N.onnx.TensorProto.decode(t,t.uint32());break}case 2:{a.indices=N.onnx.TensorProto.decode(t,t.uint32());break}case 3:{if(a.dims&&a.dims.length||(a.dims=[]),(l&7)===2)for(var d=t.uint32()+t.pos;t.pos>>0,t.dims[i].high>>>0).toNumber())}return o},e.toObject=function(t,o){o||(o={});var i={};if((o.arrays||o.defaults)&&(i.dims=[]),o.defaults&&(i.values=null,i.indices=null),t.values!=null&&t.hasOwnProperty("values")&&(i.values=N.onnx.TensorProto.toObject(t.values,o)),t.indices!=null&&t.hasOwnProperty("indices")&&(i.indices=N.onnx.TensorProto.toObject(t.indices,o)),t.dims&&t.dims.length){i.dims=[];for(var a=0;a>>0,t.dims[a].high>>>0).toNumber():t.dims[a]}return i},e.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.SparseTensorProto"},e}(),n.TensorShapeProto=function(){function e(r){if(this.dim=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.dim&&a.dim.length||(a.dim=[]),a.dim.push(N.onnx.TensorShapeProto.Dimension.decode(t,t.uint32()));break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.dim!=null&&t.hasOwnProperty("dim")){if(!Array.isArray(t.dim))return"dim: array expected";for(var o=0;o>>3){case 1:{d.dimValue=i.int64();break}case 2:{d.dimParam=i.string();break}case 3:{d.denotation=i.string();break}default:i.skipType(h&7);break}}return d},r.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},r.verify=function(i){if(typeof i!="object"||i===null)return"object expected";var a={};if(i.dimValue!=null&&i.hasOwnProperty("dimValue")&&(a.value=1,!M.isInteger(i.dimValue)&&!(i.dimValue&&M.isInteger(i.dimValue.low)&&M.isInteger(i.dimValue.high))))return"dimValue: integer|Long expected";if(i.dimParam!=null&&i.hasOwnProperty("dimParam")){if(a.value===1)return"value: multiple values";if(a.value=1,!M.isString(i.dimParam))return"dimParam: string expected"}return i.denotation!=null&&i.hasOwnProperty("denotation")&&!M.isString(i.denotation)?"denotation: string expected":null},r.fromObject=function(i){if(i instanceof N.onnx.TensorShapeProto.Dimension)return i;var a=new N.onnx.TensorShapeProto.Dimension;return i.dimValue!=null&&(M.Long?(a.dimValue=M.Long.fromValue(i.dimValue)).unsigned=!1:typeof i.dimValue=="string"?a.dimValue=parseInt(i.dimValue,10):typeof i.dimValue=="number"?a.dimValue=i.dimValue:typeof i.dimValue=="object"&&(a.dimValue=new M.LongBits(i.dimValue.low>>>0,i.dimValue.high>>>0).toNumber())),i.dimParam!=null&&(a.dimParam=String(i.dimParam)),i.denotation!=null&&(a.denotation=String(i.denotation)),a},r.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.denotation=""),i.dimValue!=null&&i.hasOwnProperty("dimValue")&&(typeof i.dimValue=="number"?l.dimValue=a.longs===String?String(i.dimValue):i.dimValue:l.dimValue=a.longs===String?M.Long.prototype.toString.call(i.dimValue):a.longs===Number?new M.LongBits(i.dimValue.low>>>0,i.dimValue.high>>>0).toNumber():i.dimValue,a.oneofs&&(l.value="dimValue")),i.dimParam!=null&&i.hasOwnProperty("dimParam")&&(l.dimParam=i.dimParam,a.oneofs&&(l.value="dimParam")),i.denotation!=null&&i.hasOwnProperty("denotation")&&(l.denotation=i.denotation),l},r.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},r.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TensorShapeProto.Dimension"},r}(),e}(),n.TypeProto=function(){function e(t){if(t)for(var o=Object.keys(t),i=0;i>>3){case 1:{l.tensorType=N.onnx.TypeProto.Tensor.decode(o,o.uint32());break}case 4:{l.sequenceType=N.onnx.TypeProto.Sequence.decode(o,o.uint32());break}case 5:{l.mapType=N.onnx.TypeProto.Map.decode(o,o.uint32());break}case 9:{l.optionalType=N.onnx.TypeProto.Optional.decode(o,o.uint32());break}case 8:{l.sparseTensorType=N.onnx.TypeProto.SparseTensor.decode(o,o.uint32());break}case 6:{l.denotation=o.string();break}default:o.skipType(d&7);break}}return l},e.decodeDelimited=function(o){return o instanceof se||(o=new se(o)),this.decode(o,o.uint32())},e.verify=function(o){if(typeof o!="object"||o===null)return"object expected";var i={};if(o.tensorType!=null&&o.hasOwnProperty("tensorType")){i.value=1;{var a=N.onnx.TypeProto.Tensor.verify(o.tensorType);if(a)return"tensorType."+a}}if(o.sequenceType!=null&&o.hasOwnProperty("sequenceType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=N.onnx.TypeProto.Sequence.verify(o.sequenceType);if(a)return"sequenceType."+a}}if(o.mapType!=null&&o.hasOwnProperty("mapType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=N.onnx.TypeProto.Map.verify(o.mapType);if(a)return"mapType."+a}}if(o.optionalType!=null&&o.hasOwnProperty("optionalType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=N.onnx.TypeProto.Optional.verify(o.optionalType);if(a)return"optionalType."+a}}if(o.sparseTensorType!=null&&o.hasOwnProperty("sparseTensorType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=N.onnx.TypeProto.SparseTensor.verify(o.sparseTensorType);if(a)return"sparseTensorType."+a}}return o.denotation!=null&&o.hasOwnProperty("denotation")&&!M.isString(o.denotation)?"denotation: string expected":null},e.fromObject=function(o){if(o instanceof N.onnx.TypeProto)return o;var i=new N.onnx.TypeProto;if(o.tensorType!=null){if(typeof o.tensorType!="object")throw TypeError(".onnx.TypeProto.tensorType: object expected");i.tensorType=N.onnx.TypeProto.Tensor.fromObject(o.tensorType)}if(o.sequenceType!=null){if(typeof o.sequenceType!="object")throw TypeError(".onnx.TypeProto.sequenceType: object expected");i.sequenceType=N.onnx.TypeProto.Sequence.fromObject(o.sequenceType)}if(o.mapType!=null){if(typeof o.mapType!="object")throw TypeError(".onnx.TypeProto.mapType: object expected");i.mapType=N.onnx.TypeProto.Map.fromObject(o.mapType)}if(o.optionalType!=null){if(typeof o.optionalType!="object")throw TypeError(".onnx.TypeProto.optionalType: object expected");i.optionalType=N.onnx.TypeProto.Optional.fromObject(o.optionalType)}if(o.sparseTensorType!=null){if(typeof o.sparseTensorType!="object")throw TypeError(".onnx.TypeProto.sparseTensorType: object expected");i.sparseTensorType=N.onnx.TypeProto.SparseTensor.fromObject(o.sparseTensorType)}return o.denotation!=null&&(i.denotation=String(o.denotation)),i},e.toObject=function(o,i){i||(i={});var a={};return i.defaults&&(a.denotation=""),o.tensorType!=null&&o.hasOwnProperty("tensorType")&&(a.tensorType=N.onnx.TypeProto.Tensor.toObject(o.tensorType,i),i.oneofs&&(a.value="tensorType")),o.sequenceType!=null&&o.hasOwnProperty("sequenceType")&&(a.sequenceType=N.onnx.TypeProto.Sequence.toObject(o.sequenceType,i),i.oneofs&&(a.value="sequenceType")),o.mapType!=null&&o.hasOwnProperty("mapType")&&(a.mapType=N.onnx.TypeProto.Map.toObject(o.mapType,i),i.oneofs&&(a.value="mapType")),o.denotation!=null&&o.hasOwnProperty("denotation")&&(a.denotation=o.denotation),o.sparseTensorType!=null&&o.hasOwnProperty("sparseTensorType")&&(a.sparseTensorType=N.onnx.TypeProto.SparseTensor.toObject(o.sparseTensorType,i),i.oneofs&&(a.value="sparseTensorType")),o.optionalType!=null&&o.hasOwnProperty("optionalType")&&(a.optionalType=N.onnx.TypeProto.Optional.toObject(o.optionalType,i),i.oneofs&&(a.value="optionalType")),a},e.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},e.getTypeUrl=function(o){return o===void 0&&(o="type.googleapis.com"),o+"/onnx.TypeProto"},e.Tensor=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{d.elemType=i.int32();break}case 2:{d.shape=N.onnx.TensorShapeProto.decode(i,i.uint32());break}default:i.skipType(h&7);break}}return d},t.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")&&!M.isInteger(i.elemType))return"elemType: integer expected";if(i.shape!=null&&i.hasOwnProperty("shape")){var a=N.onnx.TensorShapeProto.verify(i.shape);if(a)return"shape."+a}return null},t.fromObject=function(i){if(i instanceof N.onnx.TypeProto.Tensor)return i;var a=new N.onnx.TypeProto.Tensor;if(i.elemType!=null&&(a.elemType=i.elemType|0),i.shape!=null){if(typeof i.shape!="object")throw TypeError(".onnx.TypeProto.Tensor.shape: object expected");a.shape=N.onnx.TensorShapeProto.fromObject(i.shape)}return a},t.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.elemType=0,l.shape=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(l.elemType=i.elemType),i.shape!=null&&i.hasOwnProperty("shape")&&(l.shape=N.onnx.TensorShapeProto.toObject(i.shape,a)),l},t.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Tensor"},t}(),e.Sequence=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{d.elemType=N.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(h&7);break}}return d},t.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")){var a=N.onnx.TypeProto.verify(i.elemType);if(a)return"elemType."+a}return null},t.fromObject=function(i){if(i instanceof N.onnx.TypeProto.Sequence)return i;var a=new N.onnx.TypeProto.Sequence;if(i.elemType!=null){if(typeof i.elemType!="object")throw TypeError(".onnx.TypeProto.Sequence.elemType: object expected");a.elemType=N.onnx.TypeProto.fromObject(i.elemType)}return a},t.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.elemType=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(l.elemType=N.onnx.TypeProto.toObject(i.elemType,a)),l},t.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Sequence"},t}(),e.Map=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{d.keyType=i.int32();break}case 2:{d.valueType=N.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(h&7);break}}return d},t.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.keyType!=null&&i.hasOwnProperty("keyType")&&!M.isInteger(i.keyType))return"keyType: integer expected";if(i.valueType!=null&&i.hasOwnProperty("valueType")){var a=N.onnx.TypeProto.verify(i.valueType);if(a)return"valueType."+a}return null},t.fromObject=function(i){if(i instanceof N.onnx.TypeProto.Map)return i;var a=new N.onnx.TypeProto.Map;if(i.keyType!=null&&(a.keyType=i.keyType|0),i.valueType!=null){if(typeof i.valueType!="object")throw TypeError(".onnx.TypeProto.Map.valueType: object expected");a.valueType=N.onnx.TypeProto.fromObject(i.valueType)}return a},t.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.keyType=0,l.valueType=null),i.keyType!=null&&i.hasOwnProperty("keyType")&&(l.keyType=i.keyType),i.valueType!=null&&i.hasOwnProperty("valueType")&&(l.valueType=N.onnx.TypeProto.toObject(i.valueType,a)),l},t.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Map"},t}(),e.Optional=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{d.elemType=N.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(h&7);break}}return d},t.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")){var a=N.onnx.TypeProto.verify(i.elemType);if(a)return"elemType."+a}return null},t.fromObject=function(i){if(i instanceof N.onnx.TypeProto.Optional)return i;var a=new N.onnx.TypeProto.Optional;if(i.elemType!=null){if(typeof i.elemType!="object")throw TypeError(".onnx.TypeProto.Optional.elemType: object expected");a.elemType=N.onnx.TypeProto.fromObject(i.elemType)}return a},t.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.elemType=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(l.elemType=N.onnx.TypeProto.toObject(i.elemType,a)),l},t.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Optional"},t}(),e.SparseTensor=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{d.elemType=i.int32();break}case 2:{d.shape=N.onnx.TensorShapeProto.decode(i,i.uint32());break}default:i.skipType(h&7);break}}return d},t.decodeDelimited=function(i){return i instanceof se||(i=new se(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")&&!M.isInteger(i.elemType))return"elemType: integer expected";if(i.shape!=null&&i.hasOwnProperty("shape")){var a=N.onnx.TensorShapeProto.verify(i.shape);if(a)return"shape."+a}return null},t.fromObject=function(i){if(i instanceof N.onnx.TypeProto.SparseTensor)return i;var a=new N.onnx.TypeProto.SparseTensor;if(i.elemType!=null&&(a.elemType=i.elemType|0),i.shape!=null){if(typeof i.shape!="object")throw TypeError(".onnx.TypeProto.SparseTensor.shape: object expected");a.shape=N.onnx.TensorShapeProto.fromObject(i.shape)}return a},t.toObject=function(i,a){a||(a={});var l={};return a.defaults&&(l.elemType=0,l.shape=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(l.elemType=i.elemType),i.shape!=null&&i.hasOwnProperty("shape")&&(l.shape=N.onnx.TensorShapeProto.toObject(i.shape,a)),l},t.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.SparseTensor"},t}(),e}(),n.OperatorSetIdProto=function(){function e(r){if(r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.domain=t.string();break}case 2:{a.version=t.int64();break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){return typeof t!="object"||t===null?"object expected":t.domain!=null&&t.hasOwnProperty("domain")&&!M.isString(t.domain)?"domain: string expected":t.version!=null&&t.hasOwnProperty("version")&&!M.isInteger(t.version)&&!(t.version&&M.isInteger(t.version.low)&&M.isInteger(t.version.high))?"version: integer|Long expected":null},e.fromObject=function(t){if(t instanceof N.onnx.OperatorSetIdProto)return t;var o=new N.onnx.OperatorSetIdProto;return t.domain!=null&&(o.domain=String(t.domain)),t.version!=null&&(M.Long?(o.version=M.Long.fromValue(t.version)).unsigned=!1:typeof t.version=="string"?o.version=parseInt(t.version,10):typeof t.version=="number"?o.version=t.version:typeof t.version=="object"&&(o.version=new M.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber())),o},e.toObject=function(t,o){o||(o={});var i={};if(o.defaults)if(i.domain="",M.Long){var a=new M.Long(0,0,!1);i.version=o.longs===String?a.toString():o.longs===Number?a.toNumber():a}else i.version=o.longs===String?"0":0;return t.domain!=null&&t.hasOwnProperty("domain")&&(i.domain=t.domain),t.version!=null&&t.hasOwnProperty("version")&&(typeof t.version=="number"?i.version=o.longs===String?String(t.version):t.version:i.version=o.longs===String?M.Long.prototype.toString.call(t.version):o.longs===Number?new M.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber():t.version),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,it.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.OperatorSetIdProto"},e}(),n.OperatorStatus=function(){var e={},r=Object.create(e);return r[e[0]="EXPERIMENTAL"]=0,r[e[1]="STABLE"]=1,r}(),n.FunctionProto=function(){function e(r){if(this.input=[],this.output=[],this.attribute=[],this.attributeProto=[],this.node=[],this.opsetImport=[],r)for(var t=Object.keys(r),o=0;o>>3){case 1:{a.name=t.string();break}case 4:{a.input&&a.input.length||(a.input=[]),a.input.push(t.string());break}case 5:{a.output&&a.output.length||(a.output=[]),a.output.push(t.string());break}case 6:{a.attribute&&a.attribute.length||(a.attribute=[]),a.attribute.push(t.string());break}case 11:{a.attributeProto&&a.attributeProto.length||(a.attributeProto=[]),a.attributeProto.push(N.onnx.AttributeProto.decode(t,t.uint32()));break}case 7:{a.node&&a.node.length||(a.node=[]),a.node.push(N.onnx.NodeProto.decode(t,t.uint32()));break}case 8:{a.docString=t.string();break}case 9:{a.opsetImport&&a.opsetImport.length||(a.opsetImport=[]),a.opsetImport.push(N.onnx.OperatorSetIdProto.decode(t,t.uint32()));break}case 10:{a.domain=t.string();break}default:t.skipType(l&7);break}}return a},e.decodeDelimited=function(t){return t instanceof se||(t=new se(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.name!=null&&t.hasOwnProperty("name")&&!M.isString(t.name))return"name: string expected";if(t.input!=null&&t.hasOwnProperty("input")){if(!Array.isArray(t.input))return"input: array expected";for(var o=0;o{"use strict";pu();at=Ne(fo());Kn();Un=class{static arraysEqual(e,r){if(e.length!==r.length)return!1;for(let t=0;t1&&g>1)return;l[a-d]=Math.max(h,g)}return l}static index(e,r){let t=new Array(r.length);return n.fillIndex(e,r,t),t}static fillIndex(e,r,t){let o=e.length-r.length;for(let i=0;i=0;O--)h[O]=P%a[O],P=Math.floor(P/a[O]);T||(n.fillIndex(h,e.dims,g),w=e.get(g)),S||(n.fillIndex(h,r.dims,_),x=r.get(_)),d.set(h,t(w,x))}}return d}}static isValidBroadcast(e,r){let t=e.length,o=r.length;if(t>o)return!1;for(let i=1;i<=t;i++)if(e[t-i]!==1&&e[t-i]!==r[o-i])return!1;return!0}static getBroadcastDims(e,r){let t=e.length,o=[];for(let i=0;i1&&l===1&&o.unshift(a)}return o}},Ji=class{static getShapeOfGemmResult(e,r,t,o,i){if(e.length!==2||t.length!==2)throw new Error("shape need to be of size 2");let a,l,d;r?(a=e[1],l=e[0]):(a=e[0],l=e[1]);let h=-1;if(o?(d=t[0],h=1):(d=t[1],h=0),t[h]!==l)throw new Error("dimension mismatch");if(a<=0||d<=0||l<=0)throw new Error("invalid shape specified");if(i&&!Ct.isValidBroadcast(i,[a,d]))throw new Error("gemm: invalid bias shape for broadcast");return[a,d,l]}},$t=class n{static tensorDataTypeFromProto(e){switch(e){case at.onnx.TensorProto.DataType.INT8:return"int8";case at.onnx.TensorProto.DataType.UINT8:return"uint8";case at.onnx.TensorProto.DataType.BOOL:return"bool";case at.onnx.TensorProto.DataType.INT16:return"int16";case at.onnx.TensorProto.DataType.UINT16:return"uint16";case at.onnx.TensorProto.DataType.INT32:return"int32";case at.onnx.TensorProto.DataType.UINT32:return"uint32";case at.onnx.TensorProto.DataType.FLOAT:return"float32";case at.onnx.TensorProto.DataType.DOUBLE:return"float64";case at.onnx.TensorProto.DataType.STRING:return"string";case at.onnx.TensorProto.DataType.INT64:return"int32";case at.onnx.TensorProto.DataType.UINT64:return"uint32";default:throw new Error(`unsupported data type: ${at.onnx.TensorProto.DataType[e]}`)}}static tensorDataTypeStringToEnum(e){switch(e){case"int8":return at.onnx.TensorProto.DataType.INT8;case"uint8":return at.onnx.TensorProto.DataType.UINT8;case"bool":return at.onnx.TensorProto.DataType.BOOL;case"int16":return at.onnx.TensorProto.DataType.INT16;case"uint16":return at.onnx.TensorProto.DataType.UINT16;case"int32":return at.onnx.TensorProto.DataType.INT32;case"uint32":return at.onnx.TensorProto.DataType.UINT32;case"float32":return at.onnx.TensorProto.DataType.FLOAT;case"float64":return at.onnx.TensorProto.DataType.DOUBLE;case"string":return at.onnx.TensorProto.DataType.STRING;case"int64":return at.onnx.TensorProto.DataType.INT64;case"uint64":return at.onnx.TensorProto.DataType.UINT64;default:throw new Error(`unsupported data type: ${e}`)}}static tensorDimsFromProto(e){return e.map(r=>wn.isLong(r)?r.toNumber():r)}static tensorValueTypeFromProto(e){return{tensorType:n.tensorDataTypeFromProto(e.elemType),shape:{dims:n.tensorDimsFromProto(e.shape.dim.map(r=>r.dimValue))}}}static tensorDimsFromORTFormat(e){let r=[];for(let t=0;te.length)throw new Error(`invalid dimension of ${r} for sizeFromDimension as Tensor has ${e.length} dimensions.`);return n.getSizeFromDimensionRange(e,r,e.length)}static sizeToDimension(e,r){if(r<0||r>e.length)throw new Error(`invalid dimension of ${r} for sizeToDimension as Tensor has ${e.length} dimensions.`);return n.getSizeFromDimensionRange(e,0,r)}static getSizeFromDimensionRange(e,r,t){let o=1;for(let i=r;i=0;--o)t[o]=t[o+1]*e[o+1];return t}static transpose(e){return e.slice().reverse()}static indicesToOffset(e,r,t){t===void 0&&(t=e.length);let o=0;for(let i=0;i=r)throw new Error("unsupported axis for this operation.");return e<0?e+r:e}static normalizeAxes(e,r){return e.map(t=>this.normalizeAxis(t,r))}static incrementIndex(e,r,t){if(r.length===0||e.length===0)throw new Error("Index incrementing unsupported for scalar Tensor");if(t===void 0)t=r.length;else if(t<=0||t>r.length)throw new Error("Incorrect axis to increment on");for(let o=t-1;o>=0&&(e[o]++,!(e[o]=e.length)throw new Error("the dimension with value zero exceeds the dimension size of the input tensor");o[d]=e[d]}else o[d]=r[d];a*=o[d]}}let l=n.size(e);if(i!==-1){if(l%a!==0)throw new Error(`the input tensor cannot be reshaped to the requested shape. Input shape: [${e}] Output shape: [${r}]`);o[i]=l/a}else if(a!==l)throw new Error("reshapedDims and originalDims don't have matching sizes");return o}static sortBasedOnPerm(e,r){return r?r.map(t=>e[t]):e.slice().reverse()}static padShape(e,r){let t=e.length;return e.map((o,i)=>o+r[i]+r[i+t])}static areEqual(e,r){return e.length!==r.length?!1:e.every((t,o)=>t===r[o])}static validateDimsAndCalcSize(e){if(e.length>6)throw new TypeError("Only rank 0 to 6 is supported for tensor shape.");let r=1;for(let t of e){if(!Number.isInteger(t))throw new TypeError(`Invalid shape: ${t} is not an integer`);if(t<0||t>2147483647)throw new TypeError(`Invalid shape: length ${t} is not allowed`);r*=t}return r}static flattenShape(e,r){r<0&&(r+=e.length);let t=e.reduce((a,l)=>a*l,1),o=e.slice(r).reduce((a,l)=>a*l,1);return[t/o,o]}static squeezeShape(e,r){let t=new Array;r=n.normalizeAxes(r,e.length);for(let o=0;o=0;if(i&&e[o]!==1)throw new Error("squeeze an axis of size different than 1");(r.length===0&&e[o]>1||r.length>0&&!i)&&t.push(e[o])}return t}static unsqueezeShape(e,r){let t=new Array(e.length+r.length);t.fill(0);for(let i=0;i=t.length)throw new Error("'axes' has an out of range axis");if(t[a]!==0)throw new Error("'axes' has a duplicate axis");t[a]=1}let o=0;for(let i=0;i=t.length?t.push(r[l+2]):t[l]=r[l+2];for(let l=0;l=t[l]||a[l+t.length]>=t[l])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(e,r,t,o,i,a){if(a){if(i.length!==2*(e.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(r.length!==e.length-2)throw new Error("length of strides should be the length of data dimensions");if(o.length!==e.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let l=0;l{"use strict";i_=Ne(xb());pu();Fo();Re=Ne(fo());Ze();yt=class n{constructor(e,r,t,o,i,a=i_.Guid.create()){this.dims=e;this.type=r;this.dataProvider=t;this.asyncDataProvider=o;this.cache=i;this.dataId=a;this.size=fe.validateDimsAndCalcSize(e);let l=this.size,d=t===void 0&&o===void 0&&i===void 0;if(i!==void 0&&i.length!==l)throw new RangeError("Input dims doesn't match data length.");if(r==="string"){if(i!==void 0&&(!Array.isArray(i)||!i.every(h=>typeof h=="string")))throw new TypeError("cache should be a string array");d&&(this.cache=new Array(l))}else{if(i!==void 0){let h=a_(r);if(!(i instanceof h))throw new TypeError(`cache should be type ${h.name}`)}if(d){let h=new ArrayBuffer(l*Xk(r));this.cache=Jk(h,r)}}}get data(){if(this.cache===void 0){let e=this.dataProvider(this.dataId);if(e.length!==this.size)throw new Error("Length of data provided by the Data Provider is inconsistent with the dims of this Tensor.");this.cache=e}return this.cache}get stringData(){if(this.type!=="string")throw new TypeError("data type is not string");return this.data}get integerData(){switch(this.type){case"uint8":case"int8":case"uint16":case"int16":case"int32":case"uint32":case"bool":return this.data;default:throw new TypeError("data type is not integer (uint8, int8, uint16, int16, int32, uint32, bool)")}}get floatData(){switch(this.type){case"float32":case"float64":return this.data;default:throw new TypeError("data type is not float (float32, float64)")}}get numberData(){if(this.type!=="string")return this.data;throw new TypeError("type cannot be non-number (string)")}get(e){return this.data[fe.indicesToOffset(e,this.strides)]}set(e,r){this.data[fe.indicesToOffset(e,this.strides)]=r}async getData(){return this.cache===void 0&&(this.cache=await this.asyncDataProvider(this.dataId)),this.cache}get strides(){return this._strides||(this._strides=fe.computeStrides(this.dims)),this._strides}static fromProto(e){if(!e)throw new Error("cannot construct Value from an empty tensor");let r=$t.tensorDataTypeFromProto(e.dataType),t=$t.tensorDimsFromProto(e.dims),o=new n(t,r);if(r==="string")e.stringData.forEach((i,a)=>{o.data[a]=Wo(i)});else if(e.rawData&&typeof e.rawData.byteLength=="number"&&e.rawData.byteLength>0){let i=o.data,a=new DataView(e.rawData.buffer,e.rawData.byteOffset,e.rawData.byteLength),l=n_(e.dataType),d=e.rawData.byteLength/l;if(e.rawData.byteLength%l!==0)throw new Error("invalid buffer length");if(i.length!==d)throw new Error("buffer length mismatch");for(let h=0;h0){let i=o.data,a=new DataView(e.rawDataArray().buffer,e.rawDataArray().byteOffset,e.rawDataLength()),l=n_(e.dataType()),d=e.rawDataLength()/l;if(e.rawDataLength()%l!==0)throw new Error("invalid buffer length");if(i.length!==d)throw new Error("buffer length mismatch");for(let h=0;h{"use strict";Zk={version:"",attribute:"attribute",varyingVertex:"varying",varyingFrag:"varying",texture2D:"texture2D",output:"gl_FragColor",outputDeclaration:""},Qk={version:"#version 300 es",attribute:"in",varyingVertex:"out",varyingFrag:"in",texture2D:"texture",output:"outputColor",outputDeclaration:"out vec4 outputColor;"}});var Ve=H(()=>{"use strict"});async function Hl(n,e=t=>0,r){return new Promise((t,o)=>{let i=0,a=()=>{if(n()){t();return}i++;let l=e(i);if(r!=null&&i>=r){o();return}setTimeout(a,l)};a()})}function Zi(n){return ho(typeof n<"u"&&n.length!==0,()=>"empty string found for sampler name"),"get"+n.charAt(0).toUpperCase()+n.slice(1)}function c_(n){return ho(typeof n<"u"&&n.length!==0,()=>"empty string found for sampler name"),"get"+n.charAt(0).toUpperCase()+n.slice(1)+"AtOutCoords"}function mo(n,e){let r=JSON.parse(JSON.stringify(n));return r=e,r}function go(n,e){return e.map(r=>n[r]).join(", ")}function Pt(n){if(n<=1)return"int";if(n===2)return"ivec2";if(n===3)return"ivec3";if(n===4)return"ivec4";if(n===5)return"ivec5";if(n===6)return"ivec6";throw Error(`GPU for rank ${n} is not yet supported`)}function ur(n=6){return["x","y","z","w","u","v"].slice(0,n)}var Jr=H(()=>{"use strict";Ze()});function Yk(n,e){return ur(e).map(r=>`${n}.${r}`)}function bo(n,e){return e===1?[n]:Yk(n,e)}function Zr(){return` + float getChannel(vec4 frag, int dim) { + int modCoord = imod(dim, 2); + return modCoord == 0 ? frag.r : frag.g; + } + + float getChannel(vec4 frag, vec2 innerDims) { + vec2 modCoord = mod(innerDims, 2.); + return modCoord.x == 0. ? + (modCoord.y == 0. ? frag.r : frag.g) : + (modCoord.y == 0. ? frag.b : frag.a); + } + `}var Xn=H(()=>{"use strict";Jr()});function t4(n,e,r){if(n===0)return"false";if(n===1)return`rc > ${e[0]}`;let t="";for(let o=n-2;o= ${e[o-n+2]}`,o= ${n[0]} ? 0. : getA(rc + 1), + 0, 0`;let t="r, c",o="r, cp1",i="rp1, c",a="rp1, cp1",l="";if(r>2)for(let d=0;d= ${t}; + bool cEdge = cp1 >= ${r}; + `}var d_,e4,p_,f_=H(()=>{"use strict";pt();Ve();Jr();Xn();d_={name:"pack",inputNames:["A"],inputTypes:[1]},e4=(n,e)=>{let r=_e(n.session.backend.glContext.version),t=e.dims,o=t.length,i=e.dims.length,a=Pt(i),l=bo("rc",i),d=n4(i,l,t[t.length-2],t[t.length-1]),h;o===0?h=[1,1]:o===1?h=[t[0],1]:h=[t[i-1],t[i-2]];let g=t4(i,h,l),_=r4(t,l),w=` + void main() { + ${a} rc = getOutputCoords(); + + if(${g}) { + ${r.output} = vec4(0); + } else { + ${d} + + ${r.output} = vec4(${_}); + } + } + `;return{...d_,hasMain:!0,output:{dims:e.dims,type:e.type,textureType:2},shaderSource:w}},p_=(n,e)=>({...d_,get:()=>e4(n,e)})});function ql(n){if(n.length===0)return[1,1,1];let e=1;for(let r=0;r1?n[n.length-2]:1,n[n.length-1]]}function m_(n,e){let r=!1;return n.length===0||e.length===0?r=!0:n.length<2||e.length<2?r=n[n.length-1]===e[e.length-1]:r=n[n.length-1]===e[e.length-1]&&n[n.length-2]===e[e.length-2],r}function a4(n){let e=fe.computeStrides(n),r=["b","r","c"],t="index";return` + ivec3 inputCoordsFromReshapedOutCoords(int index) { + ${e.map((i,a)=>{let l=`int ${r[a]} = ${t} / ${i}`,d=a===e.length-1?`int ${r[a+1]} = ${t} - ${r[a]} * ${i}`:`index -= ${r[a]} * ${i}`;return`${l}; ${d};`}).join("")} + return ivec3(b, r, c); + } + `}function s4(n){let e=fe.computeStrides(n);return` + int getFlattenedIndex(ivec3 coords) { + // reverse y, z order + return coords.x * ${e[0]} + coords.z * ${e[1]} + coords.y; + } +`}var o4,i4,h_,g_=H(()=>{"use strict";Ze();pt();Ve();Xn();o4=n=>({name:"Reshape (packed)",inputTypes:[2],inputNames:["A"],cacheHint:`${n}`}),i4=(n,e,r,t)=>{let o=e.dims,i=t,a="";for(let h=0;h<4;h++){let g="";switch(h){case 0:g="outputCoords = rc;";break;case 1:g="outputCoords = ivec3(rc.x, rc.y+1, rc.z);";break;case 2:g="outputCoords = ivec3(rc.x, rc.y, rc.z+1);";break;case 3:g="outputCoords = ivec3(rc.x, rc.y+1, rc.z+1);";break;default:throw new Error}a+=` + ${g} + ${h>0?"if(outputCoords.y < rows && outputCoords.z < cols){":""} + int flattenedIndex = getFlattenedIndex(outputCoords); + + ivec3 inputRC = inputCoordsFromReshapedOutCoords(flattenedIndex); + vec2 innerDims = vec2(float(inputRC.y),float(inputRC.z)); + + result[${h}] = getChannel(getA(inputRC.x, inputRC.y, inputRC.z), innerDims); + + ${h>0?"}":""} + `}let l=_e(n.session.backend.glContext.version),d=` + ${a4(o)} + ${s4(i)} + ${Zr()} + + void main() { + ivec3 rc = getOutputCoords(); + + vec4 result = vec4(0.0); + + ivec3 outputCoords; + int rows = ${i[2]}; + int cols = ${i[1]}; + + ${a} + ${l.output} = result; + } + `;return{...r,output:{dims:i,type:e.type,textureType:2},shaderSource:d,hasMain:!0}},h_=(n,e,r)=>{let t=o4(r);return{...t,get:()=>i4(n,e,t,r)}}});var Kl,b_=H(()=>{"use strict";pt();Ve();Kl=(n,e)=>{let r=e.shape,t=_e(n.session.backend.glContext.version),o=` + const float FLOAT_MAX = 1.70141184e38; + const float FLOAT_MIN = 1.17549435e-38; + + bool isNaN(float val) { + return (val < 1.0 || 0.0 < val || val == 0.0) ? false : true; + } + + highp vec4 encodeAsUint8(highp float v) { + if (isNaN(v)) { + return vec4(255, 255, 255, 255); + } + + highp float av = abs(v); + + if(av < FLOAT_MIN) { + return vec4(0.0, 0.0, 0.0, 0.0); + } else if(v > FLOAT_MAX) { + return vec4(0.0, 0.0, 128.0, 127.0) / 255.0; + } else if(v < -FLOAT_MAX) { + return vec4(0.0, 0.0, 128.0, 255.0) / 255.0; + } + + highp vec4 c = vec4(0,0,0,0); + + highp float e = floor(log2(av)); + highp float m = exp2(fract(log2(av))) - 1.0; + + c[2] = floor(128.0 * m); + m -= c[2] / 128.0; + c[1] = floor(32768.0 * m); + m -= c[1] / 32768.0; + c[0] = floor(8388608.0 * m); + + highp float ebias = e + 127.0; + c[3] = floor(ebias / 2.0); + ebias -= c[3] * 2.0; + c[2] += floor(ebias) * 128.0; + + c[3] += 128.0 * step(0.0, -v); + + return c / 255.0; + } + + void main() { + float value = ${t.texture2D}(X,TexCoords).r; + ${t.output} = encodeAsUint8(value); + }`,i={name:"Uint8Encode",inputTypes:[0],inputNames:["X"],output:{dims:r,type:e.tensor.type,textureType:3},shaderSource:o,hasMain:!0};return n.executeProgram(i,[e.tensor])}});function l4(n,e){if(n===1)return"rc";let r="";for(let t=0;t{"use strict";pt();Ve();Jr();Xn();y_={name:"unpack",inputNames:["A"],inputTypes:[2]},u4=(n,e)=>{let r=e.dims.length,t=bo("rc",r),o=t.slice(-2),i=Pt(r),a=Zr(),d=e.dims.length===0?"":l4(r,t),h=r<=1?"rc":`vec2(${o.join(",")})`,g=_e(n.session.backend.glContext.version),_=` + ${a} + void main() { + ${i} rc = getOutputCoords(); + + // Sample the texture with the coords to get the rgba channel value. + vec4 packedInput = getA(${d}); + + ${g.output} = vec4(getChannel(packedInput, ${h}), 0, 0, 0); + } + `;return{...y_,hasMain:!0,output:{dims:e.dims,type:e.type,textureType:0},shaderSource:_}},__=(n,e)=>({...y_,get:()=>u4(n,e)})});var Qi,Ho,Yi,qo=H(()=>{"use strict";Wt();Qi=class{constructor(e,r=1){if(r===1)this.internalFormat=e.R32F,this.format=e.RED,this.textureType=e.FLOAT,this.channelSize=r;else if(r===4)this.internalFormat=e.RGBA32F,this.format=e.RGBA,this.textureType=e.FLOAT,this.channelSize=r;else throw new Error(`Invalid number of channels: ${r}`)}encode(e,r){let t,o;return e.constructor!==Float32Array&&(Ye.warning("Encoder","data was not of type Float32; creating new Float32Array"),o=new Float32Array(e)),r*this.channelSize>e.length?(Ye.warning("Encoder","Source data too small. Allocating larger array"),o=e,t=this.allocate(r*this.channelSize),o.forEach((i,a)=>t[a]=i)):(o=e,t=o),t}allocate(e){return new Float32Array(e*4)}decode(e,r){return this.channelSize===1?e.filter((o,i)=>i%4===0).subarray(0,r):e.subarray(0,r)}},Ho=class{constructor(e,r=1,t){if(r!==1&&r!==4)throw new Error(`Invalid number of channels: ${r}`);this.internalFormat=e.RGBA,this.format=e.RGBA,this.channelSize=r,this.textureType=t||e.FLOAT}encode(e,r){let t=e;return this.channelSize===1&&(Ye.verbose("Encoder","Exploding into a larger array"),t=this.allocate(r),e.forEach((o,i)=>t[i*4]=o)),t}allocate(e){return new Float32Array(e*4)}decode(e,r){return this.channelSize===1?e.filter((o,i)=>i%4===0).subarray(0,r):e.subarray(0,r)}},Yi=class{constructor(e,r=1){this.channelSize=4;if(r===1)this.internalFormat=e.ALPHA,this.format=e.ALPHA,this.textureType=e.UNSIGNED_BYTE,this.channelSize=r;else if(r===4)this.internalFormat=e.RGBA,this.format=e.RGBA,this.textureType=e.UNSIGNED_BYTE,this.channelSize=r;else throw new Error(`Invalid number of channels: ${r}`)}encode(e,r){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}allocate(e){return new Uint8Array(e*this.channelSize)}decode(e,r){if(e instanceof Uint8Array)return e.subarray(0,r);throw new Error(`Invalid array type: ${e.constructor}`)}}});var Ko,w_,Xl,x_=H(()=>{"use strict";Ze();Ve();Ko=(n,e,r)=>{let t=r===0||r===1?1:4,o=r===2,i=r===1||r===2,a=r===4?e.length-1:void 0,l=r===4?e.map((d,h)=>h===e.length-1?d*4:d):void 0;return Xl(n,e,t,l,{isPacked:o,reverseWH:i,breakAxis:a})},w_=(n,e,r)=>{let t=Ko(n,e,r);return[t.width,t.height]},Xl=(n,e,r=1,t,o)=>{let i=!!(o&&o.isPacked),[a,l]=n.computeTextureWH(i&&t||e,o),d=e.length,h=e.slice(0);if(d===0&&(h=[1]),r===1)t=e;else if(i){if(r!==4)throw new Error("a packed texture must be 4-channel");t=e,d>0&&(h[d-1]=Math.ceil(h[d-1]/2)),d>1&&(h[d-2]=Math.ceil(h[d-2]/2))}else if(!t)throw new Error("Unpacked shape is needed when using channels > 1");return{width:a,height:l,channels:r,isPacked:i,shape:h,strides:fe.computeStrides(h),unpackedShape:t,reversedWH:o&&o.reverseWH}}});var d4,ea,I_=H(()=>{"use strict";Wt();Kn();Ze();f_();g_();b_();v_();qo();x_();Ve();d4=(n,e)=>{let r=e.map(o=>`${o.unpackedShape.join(",")};${o.width}x${o.height}`).join("_"),t=n.name;return n.cacheHint&&(t+="["+n.cacheHint+"]"),t+=":"+r,t},ea=class{constructor(e){this.session=e;this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map}calculateTextureWidthAndHeight(e,r){return w_(this.session.layoutStrategy,e,r)}executeProgram(e,r){if(r.lengththis.readTexture(a),async l=>this.readTextureAsync(a),void 0,i),texture:t};return this.setTextureData(a.tensor.dataId,a,e.isPacked),a}getTextureData(e,r=!1){return this.session.isInitializer(e)?this.session.getTextureData(e,r):r?this.packedTextureDataCache.get(e):this.unpackedTextureDataCache.get(e)}setTextureData(e,r,t=!1){this.session.isInitializer(e)?this.session.setTextureData(e,r,t):(t?this.packedTextureDataCache:this.unpackedTextureDataCache).set(e,r)}isTextureLayoutCached(e,r=!1){return!!this.getTextureData(e.dataId,r)}dispose(){this.session.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(e=>this.session.textureManager.releaseTexture(e)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(e=>this.session.textureManager.releaseTexture(e)),this.unpackedTextureDataCache=new Map}readTexture(e){return e.isPacked?this.readTexture(this.unpack(e)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTexture(e,e.tensor.type,e.channels):this.session.textureManager.readUint8TextureAsFloat(Kl(this,e))}async readTextureAsync(e){return e.isPacked?this.readTextureAsync(this.unpack(e)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTextureAsync(e,e.tensor.type,e.channels):this.session.textureManager.readUint8TextureAsFloat(Kl(this,e))}pack(e){return this.executeProgram(p_(this,e.tensor),[e.tensor])}unpack(e){return this.executeProgram(__(this,e.tensor),[e.tensor])}}});var Jl,Le,Tt=H(()=>{"use strict";Jl=class{constructor(e){Object.assign(this,e)}get cacheKey(){return this.key||(this.key=Object.getOwnPropertyNames(this).sort().map(e=>`${this[e]}`).join(";")),this.key}},Le=n=>new Jl(n)});var S_,$_,A_,p4,f4,O_=H(()=>{"use strict";Tt();pt();Ve();S_={name:"BatchNormalization",inputNames:["A","Scale","B","Mean","Variance"],inputTypes:[0,0,0,0,0]},$_=(n,e,r)=>(f4(e),[n.run({...S_,cacheHint:r.cacheKey,get:()=>p4(n,e,r)},e)]),A_=n=>{let e=n.attributes.getFloat("epsilon",1e-5),r=n.attributes.getFloat("momentum",.9),t=n.attributes.getInt("spatial",1);return Le({epsilon:e,momentum:r,spatial:t})},p4=(n,e,r)=>{let t=_e(n.session.backend.glContext.version),o=e[0].dims.length,[i,a]=n.calculateTextureWidthAndHeight(e[1].dims,0),l=` + float process(int[${o}] indices) { + vec2 position = offsetToCoords(indices[1], ${i}, ${a}); + float scale = getColorAsFloat(${t.texture2D}(Scale, position)); + float mean = getColorAsFloat(${t.texture2D}(Mean, position)); + float variance = getColorAsFloat(${t.texture2D}(Variance, position)); + float b = getColorAsFloat(${t.texture2D}(B, position)); + + return scale * ( (_A(indices) - mean) / sqrt(variance + float(${r.epsilon})) ) + b; + }`;return{...S_,output:{dims:e[0].dims,type:e[0].type,textureType:0},shaderSource:l}},f4=n=>{if(!n||n.length!==5)throw new Error("BatchNormalization requires 5 inputs.");let e=n[0],r=n[1],t=n[2],o=n[3],i=n[4];if(e.dims.length<3||r.dims.length!==1||t.dims.length!==1||o.dims.length!==1||i.dims.length!==1)throw new Error("invalid input shape.");if(r.dims[0]!==e.dims[1]||t.dims[0]!==e.dims[1]||o.dims[0]!==e.dims[1]||i.dims[0]!==e.dims[1])throw new Error("invalid input shape.");if(e.type!=="float32"&&e.type!=="float64"||r.type!=="float32"&&r.type!=="float64"||t.type!=="float32"&&t.type!=="float64"||o.type!=="float32"&&o.type!=="float64"||i.type!=="float32"&&i.type!=="float64")throw new Error("invalid input tensor types.")}});var ta,Zt,ce,Xo,ra,pn=H(()=>{"use strict";ta=class{constructor(e,r,t,o){this.glContext=e;this.programInfo=r;this.inputTextureLayouts=t;this.outputTextureLayout=o}},Zt=class{constructor(e){this.context=e}},ce=class{constructor(e,r){this.routineBody=e;this.dependencies=r}},Xo=class{constructor(e,r,t){this.name=e;t?this.dependencies=t:this.dependencies=[],r&&(this.routineBody=r)}addDependency(e){e&&this.dependencies.push(e)}},ra=class{static returnOrderedNodes(e){if(!e||e.length===0)return[];if(e.length===1)return e;let r=new Set,t=new Set,o=new Array;return this.createOrderedNodes(e,r,t,o),o}static createOrderedNodes(e,r,t,o){for(let i=0;i0)for(let a=0;a b); + } + vec4 ${n}(vec4 v1, vec4 v2) { + return vec4( v1.r > v2.r , + v1.g > v2.g, + v1.b > v2.b, + v1.a > v2.a ); + } + `,name:n,type:0}}function w4(){let n="less_";return{body:` + float ${n}(float a, float b) { + return float(a < b); + } + vec4 ${n}(vec4 v1, vec4 v2) { + return vec4( v1.r < v2.r , + v1.g < v2.g, + v1.b < v2.b, + v1.a < v2.a ); + } + `,name:n,type:0}}function x4(){let n="and_";return{body:` + float ${n}(float a, float b) { + return float( bool(a) && bool(b) ); + } + vec4 ${n}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r && b2.r , + b1.g && b2.g, + b1.b && b2.b, + b1.a && b2.a ); + } + `,name:n,type:0}}function T4(){let n="or_";return{body:` + float ${n}(float a, float b) { + return float( bool(a) || bool(b) ); + } + vec4 ${n}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r || b2.r , + b1.g || b2.g, + b1.b || b2.b, + b1.a || b2.a ); + } + `,name:n,type:0}}function I4(){let n="xor_";return{body:` + float ${n}(float a, float b) { + return float( bool(a) ^^ bool(b) ); + } + vec4 ${n}(vec4 v1, vec4 v2) { + bvec4 b1 = bvec4(v1); + bvec4 b2 = bvec4(v2); + return vec4( b1.r ^^ b2.r , + b1.g ^^ b2.g, + b1.b ^^ b2.b, + b1.a ^^ b2.a ); + } + `,name:n,type:0}}function S4(){return A4("pow")}function $4(){let n="prelu_";return{body:` + float ${n}(float a, float b) { + return a < 0.0 ? a * b: a; + } + vec4 ${n}(vec4 v1, vec4 v2) { + return vec4( + v1.r < 0.0 ? v1.r * v2.r: v1.r, + v1.g < 0.0 ? v1.g * v2.g: v1.g, + v1.b < 0.0 ? v1.b * v2.b: v1.b, + v1.a < 0.0 ? v1.a * v2.a: v1.a + ); + } + `,name:n,type:0}}function A4(n){let e=`${n}_`;return{body:` + float ${e}(float a, float b) { + return ${n}(a, b); + } + vec4 ${e}(vec4 v1, vec4 v2) { + return ${n}(v1, v2); + } + `,name:e,type:0}}var Qt,O4,C_,P_,E_,D_,k_,N_,L_,R_,z_,M_,B_,F_,V_=H(()=>{"use strict";Ze();pn();pt();Ve();Qt=(n,e,r,t=e[0].type,o)=>{let i=n.session.pack?2:0;return{name:r.name,inputNames:["A","B"],inputTypes:[i,i],cacheHint:o,get:()=>O4(n,e,r,t)}},O4=(n,e,r,t=e[0].type)=>{let o=n.session.pack?2:0,i=!fe.areEqual(e[0].dims,e[1].dims),a=e[0].dims,l=n.session.pack;if(i){let g=Ct.calcShape(e[0].dims,e[1].dims,!1);if(!g)throw new Error("Can't perform binary op on the given tensors");a=g;let _=a.length,w=e[0].dims.length!==0?e[0].dims.length:1,x=e[1].dims.length!==0?e[1].dims.length:1,T=e[0].dims.length!==0?"bcastIndices_A(indices, aindices);":"aindices[0] = 0;",S=e[1].dims.length!==0?"bcastIndices_B(indices, bindices);":"bindices[0] = 0;",P=_e(n.session.backend.glContext.version),A=l?` + ${r.body} + void main() { + vec4 a = getAAtOutCoords(); + vec4 b = getBAtOutCoords(); + vec4 result = ${r.name}(a, b); + ${P.output} = result; + }`:` + ${r.body} + float process(int indices[${_}]) { + int aindices[${w}]; + int bindices[${x}]; + ${T} + ${S} + return ${r.name}(_A(aindices), _B(bindices)); + }`;return{name:r.name,inputNames:["A","B"],inputTypes:[o,o],output:{dims:a,type:t,textureType:o},shaderSource:A,hasMain:l}}let d=_e(n.session.backend.glContext.version),h=` + ${r.body} + void main() { + vec4 v1 = ${d.texture2D}(A, TexCoords); + vec4 v2 = ${d.texture2D}(B, TexCoords); + vec4 result = ${r.name}(v1, v2); + ${d.output} = result; + } + `;return{name:r.name,inputNames:["A","B"],inputTypes:[o,o],output:{dims:e[0].dims,type:t,textureType:o},shaderSource:h,hasMain:!0}},C_=(n,e)=>[n.run(Qt(n,e,m4()),e)],P_=(n,e)=>[n.run(Qt(n,e,x4(),"bool"),e)],E_=(n,e)=>[n.run(Qt(n,e,g4()),e)],D_=(n,e)=>[n.run(Qt(n,e,_4(),"bool"),e)],k_=(n,e)=>[n.run(Qt(n,e,v4(),"bool"),e)],N_=(n,e)=>[n.run(Qt(n,e,w4(),"bool"),e)],L_=(n,e)=>[n.run(Qt(n,e,b4()),e)],R_=(n,e)=>[n.run(Qt(n,e,T4(),"bool"),e)],z_=(n,e)=>[n.run(Qt(n,e,S4()),e)],M_=(n,e)=>[n.run(Qt(n,e,$4()),e)],B_=(n,e)=>[n.run(Qt(n,e,y4()),e)],F_=(n,e)=>[n.run(Qt(n,e,I4(),"bool"),e)]});var j_,G_,P4,U_=H(()=>{"use strict";Ze();j_=(n,e,r)=>(P4(e),[n.cast(e[0],r)]),G_=n=>$t.tensorDataTypeFromProto(n.attributes.getInt("to")),P4=n=>{if(!n||n.length!==1)throw new Error("Cast requires 1 input.");if(n[0].type==="string")throw new Error("Invalid input type.")}});var E4,D4,W_,na,H_=H(()=>{"use strict";pt();Ve();Jr();Xn();E4=(n,e)=>({name:"Concat (packed)",inputNames:Array.from({length:n},(r,t)=>`X${t}`),inputTypes:Array(n).fill(2),cacheHint:e}),D4=(n,e,r,t)=>{let o=r[0].dims.slice();if(t>=o.length||t<-1*o.length)throw new Error("axis specified for concat doesn't match input dimensionality");t<0&&(t=o.length+t);let i=o.slice(0);for(let z=1;zz.dims),_=ur(a),w=new Array(g.length-1);w[0]=g[0][t];for(let z=1;z= ${w[z-1]}) { + return getChannel( + getX${z}(${na(_,x,B)}), + vec2(${na(T,x,B)})); + }`}let A=w.length,O=w[w.length-1];P+=` + return getChannel( + getX${A}(${na(_,x,O)}), + vec2(${na(T,x,O)}));`;let E=_e(n.session.backend.glContext.version),L=` + ${h} + float getValue(${_.map(z=>"int "+z)}) { + ${P} + } + + void main() { + ${d} coords = getOutputCoords(); + int lastDim = coords.${_[a-1]}; + coords.${_[a-1]} = coords.${_[a-2]}; + coords.${_[a-2]} = lastDim; + + vec4 result = vec4(getValue(${l}), 0., 0., 0.); + + ${l[a-1]} = ${l[a-1]} + 1; + if (${l[a-1]} < ${i[a-1]}) { + result.g = getValue(${l}); + } + + ${l[a-2]} = ${l[a-2]} + 1; + if (${l[a-2]} < ${i[a-2]}) { + result.a = getValue(${l}); + } + + ${l[a-1]} = ${l[a-1]} - 1; + if (${l[a-2]} < ${i[a-2]} && + ${l[a-1]} < ${i[a-1]}) { + result.b = getValue(${l}); + } + ${E.output} = result; + } + `;return{...e,output:{dims:i,type:r[0].type,textureType:2},shaderSource:L,hasMain:!0}},W_=(n,e,r)=>{let t=E4(e.length,r.cacheKey);return{...t,get:()=>D4(n,t,e,r.axis)}},na=(n,e,r)=>{let t=n.indexOf(e);return n.map((i,a)=>a===t?`${i} - ${r}`:i).join()}});var q_,k4,N4,L4,K_,R4,z4,M4,X_,B4,J_=H(()=>{"use strict";Tt();Ve();H_();q_=(n,e,r)=>(B4(e),n.session.pack&&e[0].dims.length>1?[n.run(W_(n,e,r),e)]:[n.run(L4(n,e,r),e)]),k4=(n,e)=>({name:"Concat",inputNames:Array.from({length:n},(r,t)=>`X${t}`),inputTypes:Array(n).fill(0),cacheHint:e}),N4=(n,e,r,t)=>{let o=r[0].dims.slice();if(t>=o.length||t<-1*o.length)throw new Error("axis specified for concat doesn't match input dimensionality");t<0&&(t=o.length+t);let i=o.slice(0);for(let x=1;x{let t=k4(e.length,r.cacheKey);return{...t,get:()=>N4(n,t,e,r.axis)}},K_=n=>`int getTextureWhereDataResides(int index) { + ${n.map((r,t)=>`if(index<${r}) {return ${t};} +`).join("")} + }`,R4=n=>K_(n),z4=(n,e)=>{let r=[`float fetchDataFromCorrectTexture(int textureIndex, int indices[${e}]) {`];for(let t=0;t{let e=["int getSizeInConcatAxisValueFromIndex(int index) {"];for(let r=0;rLe({axis:n.attributes.getInt("axis")}),B4=n=>{if(!n||n.length<1)throw new Error("too few inputs");let e=n[0].type,r=n[0].dims.length;if(e==="string")throw new Error("string tensor is not supported yet");for(let t of n){if(t.type!==e)throw new Error("input tensors should be one type");if(t.dims.length!==r)throw new Error("input tensors should have the same shape")}}});function F4(){return Yt("abs")}function V4(){return Yt("acos")}function j4(){return Yt("asin")}function G4(){return Yt("atan")}function U4(){return Yt("ceil")}function W4(){return Yt("cos")}function H4(n){let e="elu";return{body:` + const float alpha = float(${n}); + + float ${e}_(float a) { + return a >= 0.0 ? a: (exp(a) - 1.0) * alpha; + } + vec4 ${e}_(vec4 v) { + return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w)); + } + `,name:e,type:0}}function q4(){return Yt("exp")}function K4(){return Yt("floor")}function Zl(n,e){let r="clip";return{body:` + const float min = float(${n}); + const float max = float(${e}); + + float ${r}_(float a) { + return clamp(a, min, max); + } + vec4 ${r}_(vec4 v) { + return clamp(v, min, max); + } + `,name:r,type:0}}function X4(){let n="indentity";return{body:` + float ${n}_(float a) { + return a; + } + vec4 ${n}_(vec4 v) { + return v; + } + `,name:n,type:0}}function J4(n){let e="leakyRelu";return{body:` + const float alpha = float(${n}); + + float ${e}_(float a) { + return a < 0.0 ? a * alpha : a; + } + vec4 ${e}_(vec4 v) { + return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w)); + } + `,name:e,type:0}}function Z4(){return Yt("log")}function Q4(){let n="neg";return{body:` + float ${n}_(float a) { + return -a; + } + vec4 ${n}_(vec4 v) { + return -v; + } + `,name:n,type:0}}function Y4(){let n="not";return{body:` + float ${n}_(float a) { + return float( ! bool(a) ); + } + bool ${n}_(bool a) { + return !a; + } + vec4 ${n}_(vec4 v) { + return vec4(!bool(v.x), !bool(v.y), !bool(v.z), !bool(v.w)); + } + bvec4 ${n}_(bvec4 v) { + return bvec4(!v.x, !v.y, !v.z, !v.w); + } + `,name:n,type:0}}function eN(){return Yt("sin")}function Ql(){let n="relu";return{body:` + float ${n}_(float a) { + return max( a, 0.0 ); + } + vec4 ${n}_(vec4 v) { + return max( v, 0.0 ); + } + `,name:n,type:0}}function Yl(){let n="sigmoid";return{body:` + float ${n}_(float a) { + return 1.0 / (1.0 + exp(-a)); + } + vec4 ${n}_(vec4 v) { + return 1.0 / (1.0 + exp(-v)); + } + `,name:n,type:0}}function tN(){return Yt("sqrt")}function rN(){return Yt("tan")}function nN(){let n="tanh";return{body:` + float ${n}_(float a) { + a = clamp(a, -10., 10.); + a = exp(2.*a); + return (a - 1.) / (a + 1.); + } + vec4 ${n}_(vec4 v) { + v = clamp(v, -10., 10.); + v = exp(2.*v); + return (v - 1.) / (v + 1.); + } + `,name:n,type:0}}function Yt(n){return{body:` + float ${n}_(float a) { + return ${n}(a); + } + vec4 ${n}_(vec4 v) { + return ${n}(v); + } + `,name:n,type:0}}var oN,bt,Z_,Q_,Y_,e0,ec,t0,r0,iN,n0,o0,i0,a0,s0,u0,tc,l0,c0,d0,p0,f0,h0,m0,g0,b0,y0,_0,rc=H(()=>{"use strict";Tt();Ze();pn();pt();Ve();oN=(n,e,r,t)=>{let o=n.session.pack?2:0,i=_e(n.session.backend.glContext.version);return{...e,output:{dims:r.dims,type:r.type,textureType:o},shaderSource:` + ${t.body} + void main() { + vec4 v = ${i.texture2D}(A, TexCoords); + v = ${t.name}_(v); + ${i.output} = v; + } + `,hasMain:!0}},bt=(n,e,r,t)=>{let o=n.session.pack?2:0,i={name:r.name,inputTypes:[o],inputNames:["A"],cacheHint:t};return{...i,get:()=>oN(n,i,e,r)}},Z_=(n,e)=>[n.run(bt(n,e[0],F4()),e)],Q_=(n,e)=>[n.run(bt(n,e[0],V4()),e)],Y_=(n,e)=>[n.run(bt(n,e[0],j4()),e)],e0=(n,e)=>[n.run(bt(n,e[0],G4()),e)],ec=(n,e,r)=>[n.run(bt(n,e[0],Zl(r.min,r.max),r.cacheKey),e)],t0=n=>Le({min:n.attributes.getFloat("min",Hn),max:n.attributes.getFloat("max",qn)}),r0=(n,e)=>{let r=iN(n,e);return ec(n,[e[0]],r)},iN=(n,e)=>{if(e.length>=3&&(!n.session.isInitializer(e[1].dataId)||!n.session.isInitializer(e[2].dataId)))throw new Error("dynamic clip attributes are not allowed");let r=e.length>=3?e[1].numberData[0]:Hn,t=e.length>=3?e[2].numberData[0]:qn;return Le({min:r,max:t})},n0=(n,e)=>[n.run(bt(n,e[0],U4()),e)],o0=(n,e)=>[n.run(bt(n,e[0],W4()),e)],i0=(n,e,r)=>[n.run(bt(n,e[0],H4(r.alpha),r.cacheKey),e)],a0=n=>Le({alpha:n.attributes.getFloat("alpha",1)}),s0=(n,e)=>[n.run(bt(n,e[0],q4()),e)],u0=(n,e)=>[n.run(bt(n,e[0],K4()),e)],tc=(n,e)=>[n.run(bt(n,e[0],X4()),e)],l0=(n,e,r)=>[n.run(bt(n,e[0],J4(r.alpha),r.cacheKey),e)],c0=n=>Le({alpha:n.attributes.getFloat("alpha",.01)}),d0=(n,e)=>[n.run(bt(n,e[0],Z4()),e)],p0=(n,e)=>[n.run(bt(n,e[0],Q4()),e)],f0=(n,e)=>[n.run(bt(n,e[0],Y4()),e)],h0=(n,e)=>[n.run(bt(n,e[0],Ql()),e)],m0=(n,e)=>[n.run(bt(n,e[0],Yl()),e)],g0=(n,e)=>[n.run(bt(n,e[0],eN()),e)],b0=(n,e)=>[n.run(bt(n,e[0],tN()),e)],y0=(n,e)=>[n.run(bt(n,e[0],rN()),e)],_0=(n,e)=>[n.run(bt(n,e[0],nN()),e)]});function Qr(n){let e;switch(n.activation){case"Relu":e=Ql();break;case"Sigmoid":e=Yl();break;case"Clip":e=Zl(n.clipMin,n.clipMax);break;default:return{activationFunction:"",applyActivation:""}}let r=e.name,t=e.body,o=`value = ${r}_(value);`;return{activationFunction:t,applyActivation:o}}var yo,Jn=H(()=>{"use strict";Ze();rc();yo=n=>{let e=n.getString("activation","");if(e==="Clip"){let[r,t]=n.getFloats("activation_params",[Hn,qn]);return{activation:e,clipMax:t,clipMin:r,activationCacheKey:`${e}:${r},${t}`}}return{activation:e,activationCacheKey:e}}});var sN,uN,v0,w0=H(()=>{"use strict";Wt();pt();Ve();oa();Jn();sN=(n,e)=>({name:"GroupedConv",inputNames:n?["X","W","Bias"]:["X","W"],inputTypes:n?[0,0,0]:[0,0],cacheHint:e}),uN=(n,e,r,t)=>{let i=e.length>2?"value += getBias(output_channel);":"",a=e[0].dims.slice(),l=e[1].dims.slice(),d=l[0]/t.group;Ye.verbose("GroupedConv",`autpPad:${t.autoPad}, dilations:${t.dilations}, group:${t.group}, kernelShape:${t.kernelShape}, pads:${t.pads}, strides:${t.strides}`);let h=_o(a,l,t.dilations,t.pads,t.strides),g=_e(n.session.backend.glContext.version),{activationFunction:_,applyActivation:w}=Qr(t),x=` + const ivec2 strides = ivec2(${t.strides[0]}, ${t.strides[1]}); + const ivec2 pads = ivec2(${t.pads[0]}, ${t.pads[1]}); + ${_} + void main() { + ivec4 coords = getOutputCoords(); + int batch = coords.x; + int output_channel = coords.y; + ivec2 xRCCorner = coords.zw * strides - pads; + int group_id = output_channel / ${d}; + + float value = 0.0; + for (int wInChannel = 0; wInChannel < ${l[1]}; wInChannel++) { + int input_channel = group_id * ${l[1]} + wInChannel; + for (int wHeight = 0; wHeight < ${l[2]}; wHeight++) { + int xHeight = xRCCorner.x + wHeight * ${t.dilations[0]}; + + if (xHeight < 0 || xHeight >= ${a[2]}) { + continue; + } + + for (int wWidth = 0; wWidth < ${l[3]}; wWidth++) { + int xWidth = xRCCorner.y + wWidth * ${t.dilations[1]}; + if (xWidth < 0 || xWidth >= ${a[3]}) { + continue; + } + + float xVal = getX(batch, input_channel, xWidth, xHeight); + float wVal = getW(output_channel, wInChannel, wWidth, wHeight); + value += xVal*wVal; + } + } + } + ${i} + ${w} + ${g.output} = vec4(value, .0, .0, .0); + } +`;return{...r,output:{dims:h,type:e[0].type,textureType:0},shaderSource:x,hasMain:!0}},v0=(n,e,r)=>{let t=sN(e.length>2,r.cacheKey);return{...t,get:()=>uN(n,e,t,r)}}});var lN,cN,x0,T0=H(()=>{"use strict";pt();Ve();Xn();lN=n=>({name:"Im2Col (packed)",inputNames:["A"],inputTypes:[2],cacheHint:n}),cN=(n,e,r,t,o,i)=>{let a=r.dims,l=t.dims,d=2,h=3,g=o.length,_=[l[1]*l[2]*l[3],o[2]*o[3]],w=l[2]*l[3],x=Zr(),T=_e(n.session.backend.glContext.version),S="";for(let A=0;A<=1;A++)for(let O=0;O<=1;O++)S+=` + blockIndex = rc.x + ${O}; + pos = rc.y + ${A}; + + if(blockIndex < ${_[1]} && pos < ${_[0]}) { + offsetY = int(blockIndex / (${o[g-1]})) * ${i.strides[0]} - + ${i.pads[0]}; + d0 = offsetY + ${i.dilations[0]} * (imod(pos, ${w}) / ${l[2]}); + + if(d0 < ${a[d]} && d0 >= 0) { + offsetX = imod(blockIndex, ${o[g-1]}) * ${i.strides[1]} - + ${i.pads[1]}; + d1 = offsetX + ${i.dilations[1]} * imod(imod(pos, ${w}), ${l[2]}); + + if(d1 < ${a[h]} && d1 >= 0) { + + ch = int(float(pos)/ ${w}.); + innerDims = vec2(d0, d1); + result[${A*2+O}] = getChannel( + getA(0, ch, int(innerDims.x), + int(innerDims.y)), innerDims); + } + } + } + + `;let P=` + ${x} + + void main() { + ivec2 rc = getOutputCoords(); + vec4 result = vec4(0.0); + int blockIndex, pos, offsetY, d0, offsetX, d1, ch; + vec2 innerDims; + ${S} + ${T.output} = result; + } + `;return{...e,output:{dims:_,type:r.type,textureType:2},shaderSource:P,hasMain:!0}},x0=(n,e,r,t,o)=>{let i=lN(o.cacheKey);return{...i,get:()=>cN(n,i,e,r,t,o)}}});function pN(n,e,r){let t=e[0].dims,o=e[1].dims,i=Ct.calcShape(t,o,!0);if(!i)throw new Error("Can't use matmul on the given tensors");let a=Pt(i.length),l=ur(),{activationFunction:d,applyActivation:h}=Qr(r),g=e.length>2,_=g?"value += getBiasForMatmul();":"",w=g?`${oc(a,l,e[2].dims,i,!1)}`:"",x=i.length,T=t.length,S=o.length,P=t[t.length-1],A=` + ${d} + ${w} + float process(int indices[${x}]) { + int a[${T}]; + int b[${S}]; + bcastMatmulIndices_A(indices, a); + bcastMatmulIndices_B(indices, b); + + float value; + for (int k=0; k<${P}; ++k) { + a[${T-1}] = k; + b[${S-2}] = k; + value += _A(a) * _B(b); + } + ${_} + ${h} + return value; + }`;return{...n,output:{dims:i,type:e[0].type,textureType:0},shaderSource:A}}function nc(n,e){let r=dN(n.length>2,e.activationCacheKey);return{...r,get:()=>pN(r,n,e)}}function oc(n,e,r,t,o){let i="",a=r.length,l=t.length,d=l-a;l<2&&a>0?i="coords":i=r.map((S,P)=>`coords.${e[P+d]}`).join(", ");let g=Ct.getBroadcastDims(r,t).map(S=>`coords.${e[S+d]} = 0;`).join(` +`),w=fe.size(r)===1,x="vec4(outputValue.xx, outputValue.yy)";return w&&(x="vec4(outputValue.x)"),o?` +vec4 getBiasForMatmul() { + ${n} coords = getOutputCoords(); + ${g} + vec4 outputValue = getBias(${i}); + return ${x}; +}`:` +float getBiasForMatmul() { + ${n} coords = getOutputCoords(); + ${g} + return getBias(coords.x); +}`}var I0,S0,dN,fN,ia=H(()=>{"use strict";Ze();Ve();Jr();Jn();ic();I0=(n,e,r)=>(fN(e),n.session.pack?[n.run(aa(n,e,r),e)]:[n.run(nc(e,r),e)]),S0=n=>yo(n.attributes),dN=(n,e)=>({name:"MatMul",inputNames:n?["A","B","Bias"]:["A","B"],inputTypes:n?[0,0,0]:[0,0],cacheHint:e});fN=n=>{if(!n||n.length!==2)throw new Error("MatMul requires 2 inputs.");if(n[0].dims[n[0].dims.length-1]!==n[1].dims[n[1].dims.length-2])throw new Error("shared dimension does not match.");if(n[0].type!=="float32"&&n[0].type!=="float64"||n[1].type!=="float32"&&n[1].type!=="float64")throw new Error("inputs should be float type");if(n[0].type!==n[1].type)throw new Error("inputs types should match")}});function gN(n,e,r,t){let o=[],i=[],a=r[0].dims,l=r[1].dims,d=a.length,h=l.length,g=t.length,_=g-d,w=g-h;o=a.map((E,L)=>`coords.${e[L+_]}`),o[d-1]="i*2",o.join(", "),i=l.map((E,L)=>`coords.${e[L+w]}`),i[h-2]="i*2",i.join(", ");let x=Ct.getBroadcastDims(a,t),T=Ct.getBroadcastDims(l,t),S=x.map(E=>`coords.${e[E+_]} = 0;`).join(` +`),P=T.map(E=>`coords.${e[E+w]} = 0;`).join(` +`),A=`int lastDim = coords.${e[g-1]}; + coords.${e[g-1]} = coords.${e[g-2]}; + coords.${e[g-2]} = lastDim;`;return` +vec4 getAAtOutCoordsMatmul(int i) { + ${n} coords = getOutputCoords(); + ${A} + ${S} + vec4 outputValue = getA(${o}); + return outputValue; +} + +vec4 getBAtOutCoordsMatmul(int i) { + ${n} coords = getOutputCoords(); + ${A} + ${P} + vec4 outputValue = getB(${i}); + return outputValue; +}`}function bN(n,e){let r="";for(let t=0;t{"use strict";Ze();pt();Ve();Jr();Jn();ia();hN=(n,e)=>({name:"MatMul (packed)",inputNames:n?["A","B","Bias"]:["A","B"],inputTypes:n?[2,2,2]:[2,2],cacheHint:e}),mN=(n,e,r,t)=>{let o=r.length>2,i=o?"value += getBiasForMatmul();":"",a=r[0].dims,l=r[1].dims,d=Ct.calcShape(a,l,!0),h=!fe.areEqual(r[0].dims,r[1].dims);if(!d)throw new Error("Can't use matmul on the given tensors");let g=a[a.length-1],_=Math.ceil(g/2),w=a.length,x=l.length,T=_e(n.session.backend.glContext.version),S=Pt(d.length),P=d.length,A=ur(),{activationFunction:O,applyActivation:E}=Qr(t),L=o?`${oc(S,A,r[2].dims,d,!0)}`:"",z=h?`${gN(S,A,r,d)}`:"",B=h?"getAAtOutCoordsMatmul(i)":`getA(${bN(A,w)})`,K=h?"getBAtOutCoordsMatmul(i)":`getB(${yN(A,x)})`,Z=h?"":`${S} rc = + getOutputCoords(); int lastDim = rc.${A[P-1]}; rc.${A[P-1]} = + rc.${A[P-2]}; rc.${A[P-2]} = lastDim; + `,ee=` + ${z} + ${L} + ${O} + void main() { + ${Z} + + vec4 value = vec4(0); + for (int i = 0; i < ${_}; i++) { + vec4 a = ${B}; + vec4 b = ${K}; + + value += (a.rrbb * b.rgrg); + value += (a.ggaa * b.baba); + } + ${i} + ${E} + ${T.output} = value; + }`;return{...e,output:{dims:d,type:r[0].type,textureType:2},shaderSource:ee,hasMain:!0}},aa=(n,e,r)=>{let t=hN(e.length>2,r.activationCacheKey);return{...t,get:()=>mN(n,t,e,r)}}});var $0,A0=H(()=>{"use strict";oa();T0();ic();$0=(n,e,r)=>{let t=e[0].dims,o=e[1].dims,i=_o(t,o,r.dilations,r.pads,r.strides),a=n.run(x0(n,e[0],e[1],i,r),[e[0]]),l=n.reshapePacked(e[1],[o[0],o[1]*o[2]*o[3]]),d=e.length===3?[l,a,e[2]]:[l,a],h=n.run(aa(n,d,r),d);return n.reshapePacked(h,i)}});var _N,vN,O0,ac,sc=H(()=>{"use strict";Ve();_N=n=>({name:"Im2Col",inputNames:["X"],inputTypes:[0],cacheHint:n}),vN=(n,e,r,t,o,i)=>{let a=r.dims,l=t.dims,d=o.length,h=ac(a,l,o,4),g=` + const int XC = ${a[1]}; + const int XH = ${a[2]}; + const int XW = ${a[3]}; + const int KH = ${i.kernelShape[0]}; + const int KW = ${i.kernelShape[1]}; + const int dilationH = ${i.dilations[0]}; + const int dilationW = ${i.dilations[1]}; + const int strideH = ${i.strides[0]}; + const int strideW = ${i.strides[1]}; + const int padH = ${i.pads[0]}; + const int padW = ${i.pads[1]}; + const int KHKW = KH*KW; + const int XCKHKW = XC * KHKW; + const int outputChannels = 4; + vec4 process(int indices[${d}]) { + int b = indices[0]; // batch size + int oh = indices[1] * strideH - padH; //output height + int ow = indices[2] * strideW - padW; //output width + int p = indices[3] * outputChannels; //patch + vec4 value = vec4(0.0); + for(int i=0; i < outputChannels; ++i) { + if(p < XCKHKW) { + int patchC = p / KHKW; + int patchH = (p - patchC*KHKW) / KW; + int patchW = (p - patchC*KHKW) - patchH * KW; + int xh2 = oh + patchH * dilationH; + int xw2 = ow + patchW * dilationW; + int x[${a.length}]; + x[0] = b; + x[1] = patchC; + x[2] = xh2; + x[3] = xw2; + if(xh2 >= 0 && + xh2 < XH && + xw2 >= 0 && + xw2 < XW) { + value[i] = _X(x); + } + } + ++p; + } + return value; + } + `;return{...e,output:{dims:h,type:r.type,textureType:4},shaderSource:g}},O0=(n,e,r,t,o)=>{let i=_N(o.cacheKey);return{...i,get:()=>vN(n,i,e,r,t,o)}},ac=(n,e,r,t=4)=>[r[0],r[2],r[3],Math.ceil(n[1]*e[2]*e[3]/t)]});var wN,xN,C0,P0=H(()=>{"use strict";Ze();pt();Ve();Jn();sc();wN=(n,e)=>({name:"ConvDotProduct",inputNames:n?["Im2Col","K","B"]:["Im2Col","K"],inputTypes:n?[0,4,0]:[0,4],cacheKey:e.activationCacheKey}),xN=(n,e,r,t,o)=>{let i=r[0].dims,a=r[1].dims,l=[a[0],Math.ceil(i[1]*a[2]*a[3]/4)],d=ac(i,a,t),[h,g]=n.calculateTextureWidthAndHeight(l,4),_=fe.computeStrides(d),[w,x]=n.calculateTextureWidthAndHeight(d,4),T=t.length,S=r.length<3?"0.0":"_B(b)",P=Math.ceil(i[1]*a[2]*a[3]/4),{activationFunction:A,applyActivation:O}=Qr(o),E=_e(n.session.backend.glContext.version),L=` +${A} +float process(int indices[${T}]) { + int b[1]; + b[0] = indices[1]; + int im2col[4]; + im2col[0] = indices[0]; + im2col[1] = indices[2]; + im2col[2] = indices[3]; + int im2colOffset = im2col[0] * ${_[0]} + im2col[1] * ${_[1]} + im2col[2] * ${_[2]}; + int kernelOffset = indices[1] * ${l[1]}; + float value = ${S}; + for (int i = 0; i < ${P}; ++i) { + vec2 im2colCoords = offsetToCoords(im2colOffset, ${w}, ${x}); + vec2 kernelCoords = offsetToCoords(kernelOffset, ${h}, ${g}); + value += dot(${E.texture2D}(Im2Col, im2colCoords), ${E.texture2D}(K, kernelCoords)); + ++im2colOffset; + ++kernelOffset; + } + ${O} + return value; +}`;return{...e,output:{dims:t,type:r[0].type,textureType:0},shaderSource:L}},C0=(n,e,r,t)=>{let o=wN(e.length>2,t);return{...o,get:()=>xN(n,o,e,r,t)}}});var _o,uc,TN,IN,SN,$N,lc,AN,oa=H(()=>{"use strict";Tt();Ze();w0();A0();P0();Jn();sc();ia();_o=(n,e,r,t,o)=>{let i=n[0],a=n.slice(2),l=a.length,d=e[0],g=e.slice(2).map((T,S)=>T+(T-1)*(r[S]-1)),w=a.map((T,S)=>T+t[S]+t[S+l]).map((T,S)=>Math.floor((T-g[S]+o[S])/o[S]));return[i,d].concat(...w)},uc=(n,e,r)=>(AN(e,r),TN(n,e,r)),TN=(n,e,r)=>{let t=$N(r,e),o=n.session.pack,i=t.kernelShape[0]===1&&t.kernelShape[1]===1;return t.group>1?[n.run(v0(n,e,t),e)]:i&&o?[IN(n,e,t)]:o&&e[0].dims.length===4&&e[0].dims[0]===1&&!i?[$0(n,e,t)]:[SN(n,e,t)]},IN=(n,e,r)=>{let t=e[0].dims,o=e[1].dims,i=_o(t,o,r.dilations,r.pads,r.strides),a=n.reshapeUnpacked(e[0],[t[1],t[2]*t[3]]),l=n.reshapeUnpacked(e[1],[o[0],o[1]]),d=e.length>2?[l,a,e[2]]:[l,a],h=n.run(nc(d,r),d);return n.reshapeUnpacked(h,i)},SN=(n,e,r)=>{let t=e[0].dims,o=e[1].dims,i=_o(t,o,r.dilations,r.pads,r.strides),a=n.run(O0(n,e[0],e[1],i,r),[e[0]]),l=e.length===3?[a,e[1],e[2]]:[a,e[1]];return n.run(C0(n,e,i,r),l)},$N=(n,e)=>{let r=n.kernelShape.slice();if(n.kernelShape.length===0)for(let i=2;i{let e=n.attributes,r=yo(e),t=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),i=e.getInt("group",1),a=e.getInts("kernel_shape",[]),l=e.getInts("pads",[0,0,0,0]),d=e.getInts("strides",[1,1]);return Le({autoPad:t,dilations:o,group:i,kernelShape:a,pads:l,strides:d,...r})},AN=(n,e)=>{if(!n||n.length!==2&&n.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(n[0].dims.length!==4||n[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");let r=n[0].dims[1],t=n[1].dims[1]*e.group;if(r!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(n.length===3&&(n[2].dims.length!==1||n[1].dims[0]!==n[2].dims[0]))throw new Error("invalid bias");let o=n[0].dims.length-2;if(e.dilations.length!==o)throw new Error(`dilations should be ${o}D`);if(e.strides.length!==o)throw new Error(`strides should be ${o}D`);if(e.pads.length!==o*2)throw new Error(`pads should be ${o*2}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==n[1].dims.length-2)throw new Error("invalid kernel shape");if(n[0].type!=="float32"||n[1].type!=="float32")throw new Error("Conv input(X,W) should be float tensor");if(n.length===3&&n[2].type!=="float32")throw new Error("Conv input(bias) should be float tensor")}});var ON,CN,PN,E0,EN,DN,kN,NN,LN,RN,D0,zN,k0=H(()=>{"use strict";Tt();pt();Ve();Jn();ON=(n,e,r,t,o,i)=>(n-1)*e+r+(t-1)*o+1-i,CN=(n,e,r,t,o)=>{let i=Math.floor(n/2);e==="SAME_UPPER"?(r[t]=i,r[o]=n-i):e==="SAME_LOWER"&&(r[t]=n-i,r[o]=i)},PN=(n,e,r,t,o,i,a,l)=>{let d=n.length-2,h=l.length===0;for(let g=0;g(zN(e,r),EN(n,e,r)),EN=(n,e,r)=>{let t=RN(r,e);return[LN(n,e,t)]},DN=(n,e)=>({name:"ConvTranspose",inputNames:n?["X","W","B"]:["X","W"],inputTypes:n?[0,0,0]:[0,0],cacheHint:e}),kN=(n,e,r,t)=>{let i=e.length>2?"getB(output_channel)":"0.0",a=e[0].dims,l=e[1].dims,d=l[1],h=l[0]/t.group,g=[e[0].dims[0],e[1].dims[1]*t.group,...t.outputShape],_=_e(n.session.backend.glContext.version),{activationFunction:w,applyActivation:x}=Qr(t),T=` + const ivec2 strides = ivec2(${t.strides[0]}, ${t.strides[1]}); + const ivec2 pads = ivec2(${t.pads[0]}, ${t.pads[1]}); + ${w} + void main() { + ivec4 coords = getOutputCoords(); + int batch = coords.x; + int output_channel = coords.y; + + ivec2 loc = coords.zw + pads; + + int group_id = output_channel / ${d}; + int wOutChannel = output_channel - group_id * ${d}; + + float value = ${i}; + for (int inChannelOffset = 0; inChannelOffset < ${h}; inChannelOffset++) { + int input_channel = group_id * ${h} + inChannelOffset; + for (int wWOff = 0; wWOff < ${l[2]}; wWOff++) { + for (int wHOff = 0; wHOff < ${l[3]}; wHOff++) { + ivec2 wOff = ivec2(wWOff * ${t.dilations[0]}, wHOff * ${t.dilations[1]}); + ivec2 wLoc = loc - wOff; + ivec2 wLocIn = wLoc / strides; + if ( + wLocIn * strides == wLoc && + wLocIn.x >= 0 && wLocIn.x < ${a[2]} && + wLocIn.y >= 0 && wLocIn.y < ${a[3]} + ) { + float xVal = getX(batch, input_channel, wLocIn.y, wLocIn.x); + float wVal = getW(input_channel, wOutChannel, wHOff, wWOff); + value += xVal * wVal; + } + } + } + } + ${x} + ${_.output} = vec4(value, .0, .0, .0); + } +`;return{...r,output:{dims:g,type:e[0].type,textureType:0},shaderSource:T,hasMain:!0}},NN=(n,e,r)=>{let t=DN(e.length>2,r.cacheKey);return{...t,get:()=>kN(n,e,t,r)}},LN=(n,e,r)=>n.run(NN(n,e,r),e),RN=(n,e)=>{let r=n.kernelShape.slice();if(n.kernelShape.length===0)for(let l=2;l{let e=n.attributes,r=yo(e),t=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),i=e.getInt("group",1),a=e.getInts("kernel_shape",[]),l=e.getInts("output_padding",[0,0]),d=e.getInts("output_shape",[]),h=e.getInts("pads",[0,0,0,0]),g=e.getInts("strides",[1,1]);return Le({autoPad:t,dilations:o,group:i,kernelShape:a,outputPadding:l,outputShape:d,pads:h,strides:g,...r})},zN=(n,e)=>{if(!n||n.length!==2&&n.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(n[0].dims.length!==4||n[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");let r=n[0].dims[1],t=n[1].dims[0];if(r!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");let o=n[1].dims[1]*e.group;if(n.length===3&&(n[2].dims.length!==1||n[2].dims[0]!==o))throw new Error("invalid bias");let i=n[0].dims.length-2;if(e.dilations.length!==i)throw new Error(`dilations should be ${i}D`);if(e.strides.length!==i)throw new Error(`strides should be ${i}D`);if(e.pads.length!==i*2)throw new Error(`pads should be ${i*2}D`);if(e.outputPadding.length!==i)throw new Error(`output_padding should be ${i}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==n[1].dims.length-2)throw new Error("invalid kernel shape");if(e.outputShape.length!==0&&e.outputShape.length!==n[0].dims.length-2)throw new Error("invalid output shape");if(n[0].type!=="float32"||n[1].type!=="float32")throw new Error("ConvTranspose input(X,W) should be float tensor");if(n.length===3&&n[2].type!=="float32")throw new Error("ConvTranspose input(bias) should be float tensor")}});var N0,Zn,L0,MN,R0,BN,FN,VN,sa=H(()=>{"use strict";Tt();Ze();Ve();N0={name:"Transpose",inputNames:["A"],inputTypes:[0]},Zn=(n,e,r)=>(VN(e),[n.run({...N0,cacheHint:r.cacheKey,get:()=>MN(n,e[0],r.perm)},e)]),L0=n=>Le({perm:n.attributes.getInts("perm",[])}),MN=(n,e,r)=>{let t=e.dims;r=R0(t,r);let o=BN(t,r),i=t.length,a=` + ${FN("perm",r,i)} + float process(int indices[${i}]) { + int a[${i}]; + perm(a, indices); + return _A(a); + }`;return{...N0,output:{dims:o,type:e.type,textureType:0},shaderSource:a}},R0=(n,e)=>(e&&e.length!==n.length&&(e=[...n.keys()].reverse()),e),BN=(n,e)=>(e=R0(n,e),fe.sortBasedOnPerm(n,e)),FN=(n,e,r)=>{let t=[];t.push(`void ${n}(out int a[${r}], int src[${r}]) {`);for(let o=0;o{if(!n||n.length!==1)throw new Error("Transpose requires 1 input.");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("input should be float tensor")}});var z0,M0,jN,B0=H(()=>{"use strict";sa();z0=(n,e,r)=>{jN(e);let t=r.blocksize,o=t*t,i=r.mode==="DCR"?[0,3,4,1,5,2]:[0,1,4,2,5,3],a=r.mode==="DCR"?[e[0].dims[0],t,t,e[0].dims[1]/o,e[0].dims[2],e[0].dims[3]]:[e[0].dims[0],e[0].dims[1]/o,t,t,e[0].dims[2],e[0].dims[3]],l=n.reshapeUnpacked(e[0],a),d={perm:i,cacheKey:`${i}`},[h]=Zn(n,[l],d),g=[e[0].dims[0],e[0].dims[1]/o,e[0].dims[2]*t,e[0].dims[3]*t];return[n.reshapeUnpacked(h,g)]},M0=n=>{let e=n.attributes.getInt("blocksize");if(e<1)throw new Error(`blocksize must be >= 1, but got : ${e} for DepthToSpace`);let r=n.attributes.getString("mode","DCR");if(r!=="DCR"&&r!=="CRD")throw new Error(`unrecognized mode: ${r} for DepthToSpace`);return{mode:r,blocksize:e}},jN=n=>{if(n.length!==1)throw new Error(`DepthToSpace expect 1 inputs, but got ${n.length}`);if(n[0].type==="string"||n[0].dims.length!==4)throw new TypeError("DepthToSpace input should be a 4-D numeric tensor")}});var F0,V0,GN,j0=H(()=>{"use strict";Ze();F0=(n,e,r)=>{GN(e,r);let t=fe.flattenShape(e[0].dims,r);return[n.reshapeUnpacked(e[0],t)]},V0=n=>n.attributes.getInt("axis",1),GN=(n,e)=>{if(!n||n.length!==1)throw new Error("Flatten requires 1 input.");let r=n[0].dims.length;if(r===0)throw new Error("scalar tensor is not supported.");if(e<-r||e>r)throw new Error("Invalid axis");if(n[0].type==="string")throw new Error("string tensor is not supported.")}});var $n,Jo=H(()=>{"use strict";$n=["float32","float64","int32","int16","int8","uint16","uint32","uint8"]});var G0,U0,UN,WN,HN,qN,W0=H(()=>{"use strict";Tt();Jo();Ze();Ve();G0=(n,e,r)=>(qN(e,r.axis),[n.run(HN(n,e,r),e)]),U0=n=>Le({axis:n.attributes.getInt("axis",0)}),UN={name:"Gather",inputNames:["A","B"],inputTypes:[0,0]},WN=(n,e,r,t)=>{let o=r[0].dims.slice(),i=r[1].dims.slice(),a=new Array(o.length+i.length-1);t=fe.normalizeAxis(t,o.length);let l=[];for(let w=0;w{let t={...UN,cacheHint:r.cacheKey};return{...t,get:()=>WN(n,t,e,r.axis)}},qN=(n,e)=>{if(!n||n.length!==2)throw new Error("Gather requires 2 inputs.");let r=n[0].dims.length;if(r<1)throw new Error("Invalid input shape.");if(e<-r||e>r-1)throw new Error("Invalid axis.");if($n.indexOf(n[0].type)===-1)throw new Error("Invaid input type.");if(n[1].type!=="int32"&&n[1].type!=="int16")throw new Error("Invaid input type.")}});var cc,H0,q0,K0,KN,XN,JN,X0=H(()=>{"use strict";Tt();Ze();Ve();cc=(n,e,r)=>(JN(e,r),[n.run(KN(e,r),e)]),H0=(n,e)=>{let r=n.attributes.getInt("transA",0)!==0,t=n.attributes.getInt("transB",0)!==0,o=n.attributes.getFloat("alpha",1),i=n.attributes.getFloat("beta",1);return Le({transA:r,transB:t,alpha:o,beta:i,isOptionalC:e})},q0=n=>H0(n,!1),K0=n=>H0(n,!0),KN=(n,e)=>{let r={name:"Gemm",inputNames:n.length===3?["A","B","C"]:["A","B"],inputTypes:n.length===3?[0,0,0]:[0,0],key:e.cacheKey};return{...r,get:()=>XN(r,n,e)}},XN=(n,e,r)=>{let t=e[0].dims.slice(),o=e[1].dims.slice(),[i,a]=Ji.getShapeOfGemmResult(t,r.transA,o,r.transB,e.length===3?e[2].dims:void 0),l=[i,a];if(!l)throw new Error("Can't use gemm on the given tensors");let d=t[t.length-1],h="";r.transA&&(d=t[0]),r.transA&&r.transB?h="value += _A_T(a) * _B_T(b);":r.transA&&!r.transB?h="value += _A_T(a) * _B(b);":!r.transA&&r.transB?h="value += _A(a) * _B_T(b);":!r.transA&&!r.transB&&(h="value += _A(a) * _B(b);");let g=l.length,_=e.length===3?`int c[${e[2].dims.length}];`:"",w=e.length===3?"bcastIndices_C(indices, c);":"",x=e.length===3?"value += beta * _C(c);":"",T=` + float process(int indices[${g}]) { + int a[${g}]; + int b[${g}]; + ${_} + + copyVec(indices, a); + copyVec(indices, b); + ${w} + + float value = 0.0; + for (int k=0; k<${d}; ++k) { + a[${g-1}] = k; + b[${g-2}] = k; + ${h} + } + + value = value * alpha; + ${x} + return value; + }`;return{...n,output:{dims:l,type:e[0].type,textureType:0},variables:[{name:"alpha",type:"float",data:r.alpha},{name:"beta",type:"float",data:r.beta}],shaderSource:T}},JN=(n,e)=>{if(!n)throw new Error("Input is missing");if(e.isOptionalC&&(n.length<2||n.length>3))throw new Error("Invaid input shape.");if(!e.isOptionalC&&n.length!==3)throw new Error("Gemm requires 3 inputs");if(n.length===3&&n[2].dims.length!==1&&n[2].dims.length!==2)throw new Error("Invalid input shape of C");if(n[0].type!=="float32"&&n[0].type!=="float64"||n[1].type!=="float32"&&n[1].type!=="float64"||n.length===3&&n[2].type!=="float32"&&n[2].type!=="float64")throw new Error("Invalid input type.");if(n[0].type!==n[1].type||n.length===3&&n[0].type!==n[2].type)throw new Error("Input types are mismatched")}});var J0,Z0,ZN,QN,YN,eL,tL,Q0=H(()=>{"use strict";Tt();Ve();J0=(n,e,r)=>(tL(e),[n.run(YN(n,e,r),e)]),Z0=n=>{let e=n.attributes.getFloat("scale"),r=n.attributes.getFloats("bias");return Le({scale:e,bias:r})},ZN={name:"ImageScaler",inputNames:["X"],inputTypes:[0]},QN=(n,e,r,t)=>{let o=r[0].dims.slice(),i=o.length,l=` + ${eL(t.bias.length)} + float process(int indices[${i}]) { + return _X(indices) * scale + getBias(bias, indices[1]); + }`;return{...e,output:{dims:o,type:r[0].type,textureType:0},variables:[{name:"bias",type:"float",arrayLength:t.bias.length,data:t.bias},{name:"scale",type:"float",data:t.scale}],shaderSource:l}},YN=(n,e,r)=>{let t={...ZN,cacheHint:r.cacheKey};return{...t,get:()=>QN(n,t,e,r)}},eL=n=>{let e=[`float getBias(float bias[${n}], int channel) {`];for(let r=0;r{if(!n||n.length!==1)throw new Error("ImageScaler requires 1 input.");if(n[0].dims.length!==4)throw new Error("Invalid input shape.");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("Invalid input type.")}});var ev,tv,Y0,rL,nL,oL,iL,aL,sL,rv=H(()=>{"use strict";pt();Ve();ev=(n,e,r)=>{sL(e);let t=n.run(nL(e[0]),e);return[n.run(aL(n,e[0],r,t.dims),[e[0],t,e[1],e[2]])]},tv=n=>n.attributes.getFloat("epsilon",1e-5),Y0={name:"InstanceNormalization_MeanAndVariance",inputNames:["X"],inputTypes:[0]},rL=(n,e)=>{let r=e.dims.slice(),t=r[1],o=r[2]*r[3],i=[r[0],t],a=` + vec4 process(int[2] indices) { + vec4 v = vec4(0.0); + int a[4]; + a[0] = indices[0]; + a[1] = indices[1]; + float temp = 0.0; + for(int a2=0; a2<${r[2]}; a2++) { + a[2] = a2; + for(int a3=0; a3<${r[3]}; a3++) { + a[3] = a3; + float x = _X(a); + temp += x; + } + } + float mean = temp / float(${o}); + temp = 0.0; + for(int a2=0; a2<${r[2]}; a2++) { + a[2] = a2; + for(int a3=0; a3<${r[3]}; a3++) { + a[3] = a3; + float x = _X(a); + temp += (x - mean) * (x - mean); + } + } + v.r = mean; + v.g = temp / float(${o}); + + return v; + }`;return{...n,output:{dims:i,type:e.type,textureType:4},shaderSource:a}},nL=n=>({...Y0,get:()=>rL(Y0,n)}),oL={name:"InstanceNormalization_ComputeOutput",inputNames:["X","MeanAndVariance","Scale","B"],inputTypes:[0,4,0,0]},iL=(n,e,r,t,o)=>{let i=_e(n.session.backend.glContext.version),[a,l]=n.calculateTextureWidthAndHeight(o,4),[d,h]=[a/4,l],g=` + vec4 get_MeanAndVariance(int[2] mv) { + int offset = indicesToOffset_MeanAndVariance(mv); + vec2 coords = offsetToCoords(offset, ${d}, ${h}); + return ${i.texture2D}(MeanAndVariance, coords); + } + + float process(int[4] indices) { + int mv[2]; + mv[0] = indices[0]; + mv[1] = indices[1]; + vec4 mean_and_variance = get_MeanAndVariance(mv); + float mean = mean_and_variance.r; + float variance = mean_and_variance.g; + + int sb[1]; + sb[0] = indices[1]; + float scale = _Scale(sb); + float b = _B(sb); + + return scale * (_X(indices) - mean) / sqrt(variance + epsilon) + b; + }`;return{...e,output:{dims:r.dims,type:r.type,textureType:0},variables:[{name:"epsilon",type:"float",data:t}],shaderSource:g}},aL=(n,e,r,t)=>{let o={...oL,cacheHint:`${r}`};return{...o,get:()=>iL(n,o,e,r,t)}},sL=n=>{if(!n||n.length!==3)throw new Error("InstanceNormalization requires 3 inputs.");let e=n[0],r=n[1],t=n[2];if(e.dims.length<3||r.dims.length!==1||t.dims.length!==1)throw new Error("Invalid input shape.");if(r.dims[0]!==e.dims[1]||t.dims[0]!==e.dims[1])throw new Error("Input shapes are mismatched.");if(e.type!=="float32"&&e.type!=="float64"||r.type!=="float32"&&r.type!=="float64"||t.type!=="float32"&&t.type!=="float64")throw new Error("Invalid input type.");if(n[0].dims.length!==4)throw new Error("Only support 4-D input shape.")}});function uL(n,e){let r=n[0].dims[1],t=n[0].dims.length,o=-Math.floor((e.size-1)/2),i=Math.ceil((e.size-1)/2),a=`float(${e.alpha}) / float(${e.size})`,l=`float(${e.bias})`,d=`float(${e.beta})`,h=` + float process(int indices[${t}]) { + int c = indices[1]; + float x = _X(indices); + float square_sum = 0.0; + + for (int i = ${o}; i <= ${i}; i++) { + int idx = c + i; + if (c >= 0 && c < ${r}) { + indices[1] = idx; + float j = _X(indices); + square_sum += j * j; + } + } + return x / pow(${l} + ${a} * square_sum, ${d}); + }`;return{...iv,cacheHint:e.cacheKey,output:{dims:n[0].dims,type:n[0].type,textureType:0},shaderSource:h}}function lL(n,e){return{...iv,cacheHint:e.cacheKey,get:()=>uL(n,e)}}var nv,ov,iv,cL,av=H(()=>{"use strict";Tt();Ve();nv=(n,e,r)=>(cL(e),[n.run(lL(e,r),e)]),ov=n=>{let e=n.attributes.getFloat("alpha",1e-4),r=n.attributes.getFloat("beta",.75),t=n.attributes.getFloat("bias",1),o=n.attributes.getInt("size");return Le({alpha:e,beta:r,bias:t,size:o})},iv={name:"LRN",inputNames:["X"],inputTypes:[0]};cL=n=>{if(!n||n.length!==1)throw new Error("LRN requires 1 input.");if(n[0].dims.length!==4)throw new Error('currently only support LRN for input with "NCHW" format');if(n[0].type!=="float32")throw new Error("input should be float type")}});var dL,dc,sv,uv,lv,pL,fL,hL,mL,gL,bL,yL,_L,cv=H(()=>{"use strict";Tt();Ze();pt();Ve();dL={name:"Pad",inputNames:["A"],inputTypes:[0]},dc=(n,e,r)=>(hL(e),[n.run({...dL,cacheHint:r.cacheKey,get:()=>fL(n,e[0],r)},e)]),sv=n=>{let e=n.attributes.getString("mode","constant"),r=n.attributes.getFloat("value",0),t=n.attributes.getInts("pads");return Le({mode:e,value:r,pads:t})},uv=(n,e,r)=>{mL(e);let t=pL(n,e,r);return dc(n,[e[0]],t)},lv=n=>n.attributes.getString("mode","constant"),pL=(n,e,r)=>{if(!n.session.isInitializer(e[1].dataId)||e.length>=3&&!n.session.isInitializer(e[2].dataId))throw new Error("dynamic pad attributes are not allowed");let t=Array.from(e[1].integerData),o=e.length>=3?e[2].floatData[0]:0;return Le({mode:r,pads:t,value:o})},fL=(n,e,r)=>{let t=fe.padShape(e.dims.slice(),r.pads),o=t.length,a=` + ${gL(n,e,r)} + float process(int[${o}] indices) { + return padA(indices); + }`;return{name:"Pad",inputNames:["A"],inputTypes:[0],output:{dims:t,type:e.type,textureType:0},shaderSource:a}},hL=n=>{if(!n||n.length!==1)throw new Error("Pad requires 1 input");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("Invalid input type.")},mL=n=>{if(!n||n.length!==2&&n.length!==3)throw new Error("Pad requires 2 or 3 inputs");if(n[1].type!=="int32")throw new Error("Invalid input type.");if(n.length>=3&&n[2].type==="string")throw new Error("Invalid input type.")},gL=(n,e,r)=>{let t=_e(n.session.backend.glContext.version),[o,i]=n.calculateTextureWidthAndHeight(e.dims,0),a=fe.computeStrides(e.dims);switch(r.mode){case"constant":return bL(t,e.dims,a,o,i,r.pads,r.value);case"reflect":return yL(t,e.dims,a,o,i,r.pads);case"edge":return _L(t,e.dims,a,o,i,r.pads);default:throw new Error("Invalid mode")}},bL=(n,e,r,t,o,i,a)=>{let l=e.length,d="";for(let h=l-1;h>=0;--h)d+=` + k = m[${h}] - ${i[h]}; + if (k < 0) return constant; + if (k >= ${e[h]}) return constant; + offset += k * ${r[h]}; + `;return` + float padA(int m[${l}]) { + const float constant = float(${a}); + int offset = 0; + int k = 0; + ${d} + vec2 coords = offsetToCoords(offset, ${t}, ${o}); + float value = getColorAsFloat(${n.texture2D}(A, coords)); + return value; + } + `},yL=(n,e,r,t,o,i)=>{let a=e.length,l="";for(let d=a-1;d>=0;--d)l+=` + k = m[${d}] - ${i[d]}; + if (k < 0) { k = -k; } + { + const int _2n_1 = ${2*(e[d]-1)}; + k = int( mod( float(k), float(_2n_1) ) ) ; + if(k >= ${e[d]}) { k = _2n_1 - k; } + } + offset += k * ${r[d]}; + `;return` + float padA(int m[${a}]) { + int offset = 0; + int k = 0; + ${l} + vec2 coords = offsetToCoords(offset, ${t}, ${o}); + float value = getColorAsFloat(${n.texture2D}(A, coords)); + return value; + } + `},_L=(n,e,r,t,o,i)=>{let a=e.length,l="";for(let d=a-1;d>=0;--d)l+=` + k = m[${d}] - ${i[d]}; + if (k < 0) k = 0; + if (k >= ${e[d]}) k = ${e[d]-1}; + offset += k * ${r[d]}; + `;return` + float padA(int m[${a}]) { + int offset = 0; + int k = 0; + ${l} + vec2 coords = offsetToCoords(offset, ${t}, ${o}); + float value = getColorAsFloat(${n.texture2D}(A, coords)); + return value; + } + `}});var pv,fv,hv,mv,gv,bv,yv,_v,vv,vL,dv,wv,la,xv,ua,wL,Tv=H(()=>{"use strict";Tt();Ze();Ve();pv=(n,e,r)=>{la(e);let t={name:"AveragePool",inputNames:["X"],inputTypes:[0],cacheHint:r.cacheKey};return[n.run({...t,get:()=>hv(e,t,!1,r)},e)]},fv=n=>{let e=n.attributes.getString("auto_pad","NOTSET"),r=n.attributes.getInt("ceil_mode",0),t=n.attributes.getInt("count_include_pad",0)!==0,o=n.attributes.getInts("kernel_shape"),i=n.attributes.getInts("strides",[]),a=n.attributes.getInts("pads",[]);if(r!==0)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");return Le({autoPad:e,ceilMode:r,countIncludePad:t,kernelShape:o,strides:i,pads:a})},hv=(n,e,r,t)=>{let[o,i]=vv(n,t,r),a=fe.size(o.kernelShape),l="value += _X(x);",d="";o.countIncludePad?d+=`value /= float(${a});`:d+=`value /= float(${a} - pad);`;let g=` + ${xv(n[0].dims,o,l,d,"0.0")} + `;return{...e,output:{dims:i,type:n[0].type,textureType:0},shaderSource:g}},mv=(n,e,r)=>{la(e);let t={name:"GlobalAveragePool",inputNames:["X"],inputTypes:[0],cacheHint:`${r.countIncludePad}`};return[n.run({...t,get:()=>hv(e,t,!0,r)},e)]},gv=n=>{let e=n.attributes.getInt("count_include_pad",0)!==0;return Le({autoPad:"",ceilMode:0,countIncludePad:e,kernelShape:[],strides:[],pads:[]})},bv=(n,e,r)=>{la(e);let t={name:"MaxPool",inputNames:["X"],inputTypes:[0],cacheHint:r.cacheKey};return[n.run({...t,get:()=>_v(e,t,!1,r)},e)]},yv=n=>{let e=n.attributes.getString("auto_pad","NOTSET"),r=n.attributes.getInt("ceil_mode",0),t=n.attributes.getInts("kernel_shape"),o=n.attributes.getInts("strides",[]),i=n.attributes.getInts("pads",[]),a=n.attributes.getInt("storage_order",0),l=n.attributes.getInts("dilations",[]);if(a!==0)throw new Error("column major storage order is not yet supported for MaxPool");if(r!==0)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");return Le({autoPad:e,ceilMode:r,countIncludePad:!1,kernelShape:t,strides:o,pads:i,storageOrder:a,dilations:l})},_v=(n,e,r,t)=>{let[o,i]=vv(n,t,r),h=` + ${xv(n[0].dims,o,` + value = max(_X(x), value); + `,"","-1e5")} + `;return{...e,output:{dims:i,type:n[0].type,textureType:0},shaderSource:h}},vv=(n,e,r)=>{let t=n[0].dims.slice(),o=Object.hasOwnProperty.call(e,"dilations"),i=e.kernelShape.slice(),a=e.strides.slice(),l=o?e.dilations.slice():[],d=e.pads.slice();Wn.adjustPoolAttributes(r,t,i,a,l,d);let h=Wn.computePoolOutputShape(r,t,a,l,i,d,e.autoPad),g=Object.assign({},e);return o?Object.assign(g,{kernelShape:i,strides:a,pads:d,dilations:l,cacheKey:e.cacheKey}):Object.assign(g,{kernelShape:i,strides:a,pads:d,cacheKey:e.cacheKey}),[g,h]},vL={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[],cacheKey:""},dv={name:"GlobalMaxPool",inputNames:["X"],inputTypes:[0]},wv=(n,e)=>(la(e),[n.run({...dv,get:()=>_v(e,dv,!0,vL)},e)]),la=n=>{if(!n||n.length!==1)throw new Error("Pool ops requires 1 input.");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("Invalid input type.")},xv=(n,e,r,t,o)=>{let i=n.length;if(e.kernelShape.length<=2){let a=e.kernelShape[e.kernelShape.length-1],l=e.strides[e.strides.length-1],d=e.pads[e.pads.length/2-1],h=e.pads[e.pads.length-1],g=n[i-1],_="",w="",x="";if(d+h!==0?_=` + for (int i = 0; i < ${a}; i++) { + x[${i} - 1] = indices[${i} - 1] * ${l} - ${d} + i; + if (x[${i} - 1] < 0 || x[${i} - 1] >= ${g}) { + pad++; + continue; + } + ${r} + }`:_=` + for (int i = 0; i < ${a}; i++) { + x[${i} - 1] = indices[${i} - 1] * ${l} - ${d} + i; + ${r} + }`,e.kernelShape.length===2){let S=e.kernelShape[e.kernelShape.length-2],P=e.strides[e.strides.length-2],A=e.pads[e.pads.length/2-2],O=e.pads[e.pads.length-2],E=n[i-2];A+O!==0?w=` + for (int j = 0; j < ${S}; j++) { + x[${i} - 2] = indices[${i} - 2] * ${P} - ${A} + j; + if (x[${i} - 2] < 0 || x[${i} - 2] >= ${E}) { + pad+= ${a}; + continue; + } + `:w=` + for (int j = 0; j < ${S}; j++) { + x[${i} - 2] = indices[${i} - 2] * ${P} - ${A} + j; + `,x=` + } + `}return` + float process(int indices[${i}]) { + int x[${i}]; + copyVec(indices, x); + + float value = ${o}; + int pad = 0; + ${w} + ${_} + ${x} + ${t} + return value; + } + `}else{let a=fe.size(e.kernelShape),l=fe.computeStrides(e.kernelShape),d=l.length,h=e.pads.length,g=wL(d),_=ua(n,"inputDims"),w=ua(e.pads,"pads"),x=ua(l,"kernelStrides"),T=ua(e.strides,"strides"),S=e.pads.reduce((O,E)=>O+E),P="";return S?P=` + if (x[j] >= inputDims[j] || x[j] < 0) { + pad++; + isPad = true; + break; + } + } + if (!isPad) { + ${r} + }`:P=` + } + ${r} + `,` + ${g} + float process(int indices[${i}]) { + int x[${i}]; + copyVec(indices, x); + int offset[${d}]; + int pads[${h}]; + int inputDims[${i}]; + int kernelStrides[${d}]; + int strides[${d}]; + ${w} + ${_} + ${T} + ${x} + + float value = ${o}; + int pad = 0; + bool isPad = false; + for (int i = 0; i < ${a}; i++) { + offsetToIndices(i, kernelStrides, offset); + isPad = false; + for (int j = ${i} - ${d}; j < ${i}; j++) { + x[j] = indices[j] * strides[j - ${i} + ${d}] + + offset[j - ${i} + ${d}] - pads[j - 2]; + ${P} + } + ${t} + + return value; + } + `}},ua=(n,e)=>{let r="";for(let t=0;t` + void offsetToIndices(int offset, int[${n}] strides, out int[${n}] indices) { + if (${n} == 0) { + return; + } + for (int i = 0; i < ${n} - 1; ++i) { + indices[i] = offset / strides[i]; + offset -= indices[i] * strides[i]; + } + indices[${n} - 1] = offset; + }`});var Qn,An,xL,TL,Iv,Sv,$v,Av,Ov,Cv,Pv,Ev=H(()=>{"use strict";Tt();Jo();Ze();Ve();Qn=(n,e,r,t,o)=>{TL(e);let i={name:t,inputNames:["A"],inputTypes:[0]};return[n.run({...i,cacheHint:r.cacheKey,get:()=>xL(n,e,r,t,o,i)},e)]},An=n=>{let e=n.attributes.getInts("axes",[]),r=n.attributes.getInt("keepdims",1)===1;return Le({axes:e,keepDims:r})},xL=(n,e,r,t,o,i)=>{let a=[],l=e[0].dims.length||1,d=[],h=fe.normalizeAxes(r.axes,e[0].dims.length),g=o(e,h),_=g[1];for(let T=0;T=0||h.length===0?(r.keepDims&&a.push(1),_=` + for(int j${T} = 0; j${T} < ${e[0].dims[T]}; j${T}++) { + inputIdx[${T}] = j${T}; + ${_} + }`):(d.push(`inputIdx[${T}] = outputIdx[${a.length}];`),a.push(e[0].dims[T]));let x=` + float process(int outputIdx[${a.length||1}]) { + float value; // final result + int inputIdx[${l}]; // addressing input data + ${d.join(` +`)} + ${g[0]} // init ops for reduce max/min + ${_} + ${g[2]} // final computation for reduce mean + return value; + }`;return{...i,output:{dims:a,type:e[0].type,textureType:0},shaderSource:x}},TL=n=>{if(!n||n.length!==1)throw new Error("Reduce op requires 1 input.");if($n.indexOf(n[0].type)===-1)throw new Error("Invalid input type.")},Iv=(n,e,r)=>Qn(n,e,r,"ReduceSum",()=>["value = 0.0;","value += _A(inputIdx);",""]),Sv=(n,e,r)=>Qn(n,e,r,"ReduceMean",(o,i)=>{let a=1;for(let l=0;l=0||i.length===0)&&(a*=o[0].dims[l]);return["value = 0.0;","value += _A(inputIdx);",`value /= ${a}.;`]}),$v=(n,e,r)=>Qn(n,e,r,"ReduceMax",(o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(`inputIdx[${l}] = 0;`);return[`${a.join(` +`)} +value = _A(inputIdx);`,"value = max(value, _A(inputIdx));",""]}),Av=(n,e,r)=>Qn(n,e,r,"ReduceMin",(o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(`inputIdx[${l}] = 0;`);return[`${a.join(` +`)} +value = _A(inputIdx);`,"value = min(value, _A(inputIdx));",""]}),Ov=(n,e,r)=>Qn(n,e,r,"ReduceProd",()=>["value = 1.0;","value *= _A(inputIdx);",""]),Cv=(n,e,r)=>Qn(n,e,r,"ReduceLogSum",()=>["value = 0.0;","value += _A(inputIdx);","value = log(value);"]),Pv=(n,e,r)=>Qn(n,e,r,"ReduceLogSumSquare",()=>["float t; value = 0.0;","t = _A(inputIdx); value += t * t;",""])});var Dv,kv=H(()=>{"use strict";Ze();Dv=(n,e)=>{let r=fe.calculateReshapedDims(e[0].dims,e[1].integerData);return n.session.pack?[n.reshapePacked(e[0],r)]:[n.reshapeUnpacked(e[0],r)]}});var Nv,pc,Lv,Rv,Zo,IL,fc,ca,hc=H(()=>{"use strict";Tt();pt();Ve();Nv={name:"Upsample",inputNames:["X"],inputTypes:[0]},pc=(n,e,r)=>(fc(e,r),[n.run({...Nv,cacheHint:r.cacheKey,get:()=>IL(n,e,r)},e)]),Lv=n=>Zo(n,7),Rv=n=>Zo(n,9),Zo=(n,e)=>{let r=e>=10,t=n.attributes.getString("mode","nearest");if(t!=="nearest"&&t!=="linear"&&(e<11||t!=="cubic"))throw new Error(`unrecognized mode: ${t}`);let o=[];e<9&&(o=n.attributes.getFloats("scales"),ca(o,t,r));let i=n.attributes.getFloat("extrapolation_value",0),a=e>10?n.attributes.getString("coordinate_transformation_mode","half_pixel"):"asymmetric";if(["asymmetric","pytorch_half_pixel","tf_half_pixel_for_nn","align_corners","tf_crop_and_resize","half_pixel"].indexOf(a)===-1)throw new Error(`coordinate_transform_mode '${a}' is not supported`);let l=a==="tf_crop_and_resize",d=l,h=t==="nearest"&&e>=11?n.attributes.getString("nearest_mode","round_prefer_floor"):"";if(["round_prefer_floor","round_prefer_ceil","floor","ceil",""].indexOf(h)===-1)throw new Error(`nearest_mode '${h}' is not supported`);let g=n.attributes.getFloat("cubic_coeff_a",-.75),_=n.attributes.getInt("exclude_outside",0)!==0;if(_&&t!=="cubic")throw new Error("exclude_outside can be set to 1 only when mode is CUBIC.");let w=e<11?!0:t==="nearest"&&a==="asymmetric"&&h==="floor",x=0,T=0,S=0;return e>10?n.inputs.length>2?(x=1,T=2,S=3):(T=1,S=2):e===9&&(T=1),Le({opset:e,isResize:r,mode:t,scales:o,extrapolationValue:i,coordinateTransformMode:a,useExtrapolation:d,needRoiInput:l,nearestMode:h,cubicCoefficientA:g,excludeOutside:_,useNearest2xOptimization:w,roiInputIdx:x,scalesInputIdx:T,sizesInputIdx:S})},IL=(n,e,r)=>{let t=_e(n.session.backend.glContext.version),[o,i]=n.calculateTextureWidthAndHeight(e[0].dims,0),a=e[0].dims.map((S,P)=>Math.floor(S*r.scales[P])),[l,d]=n.calculateTextureWidthAndHeight(a,0),h=a.length,g=new Array(h),_=new Array(h),w=` + int output_pitches[${h}]; + int input_pitches[${h}]; + `;for(let S=h-1;S>=0;S--)g[S]=S===h-1?1:g[S+1]*a[S+1],_[S]=S===h-1?1:_[S+1]*e[0].dims[S+1],w+=` + output_pitches[${S}] = ${g[S]}; + input_pitches[${S}] = ${_[S]}; + `;let x=` + float getInputFloat(int index) { + vec2 coords = offsetToCoords(index, ${o}, ${i}); + float value = getColorAsFloat(${t.texture2D}(X, coords)); + return value; + } + `,T=r.mode==="nearest"?` + ${x} + float process(int indices[${h}]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${l}, ${d}); + + ${w} + + int d, m; + for (int dim = 0; dim < ${h}; ++dim) { + d = output_index / output_pitches[dim]; + m = output_index - d * output_pitches[dim]; + output_index = m; + + if (scales[dim] != 1 && d > 0) { + int d2 = d / scales[dim]; + m = d - d2 * scales[dim]; + d = d2; + } + input_index += input_pitches[dim] * d; + } + + return getInputFloat(input_index); + }`:h===4?` + ${x} + float process(int indices[4]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${l}, ${d}); + + ${w} + + int m; + int index_of_dim0, index_of_dim1, index_of_dim2, index_of_dim3; + index_of_dim0 = output_index / output_pitches[0]; + m = output_index - index_of_dim0 * output_pitches[0]; + index_of_dim1 = m / output_pitches[1]; + m = m - index_of_dim1 * output_pitches[1]; + index_of_dim2 = m / output_pitches[2]; + m = m - index_of_dim2 * output_pitches[2]; + index_of_dim3 = m; + + int index_of_input_dim2, index_of_input_dim3, x_offset, y_offset; + index_of_input_dim2 = index_of_dim2 / scales[2]; + y_offset = index_of_dim2 - index_of_input_dim2 * scales[2]; + index_of_input_dim3 = index_of_dim3 / scales[3]; + x_offset = index_of_dim3 - index_of_input_dim3 * scales[3]; + + input_index = index_of_dim0 * input_pitches[0] + + index_of_dim1 * input_pitches[1] + + index_of_input_dim2 * input_pitches[2] + + index_of_input_dim3; + + float x00 = getInputFloat(input_index); + float x10, x01, x11; + + bool end_of_dim2 = false; + if (index_of_input_dim2 == (${e[0].dims[2]} - 1)) { + // It's the end in dimension 2 + x01 = x00; + end_of_dim2 = true; + } else { + x01 = getInputFloat(input_index + input_pitches[2]); + } + + if (index_of_input_dim3 == (input_pitches[2] - 1)) { + // It's the end in dimension 3 + x10 = x00; + x11 = x01; + } + else { + x10 = getInputFloat(input_index + 1); + x11 = end_of_dim2 ? x10 : getInputFloat(input_index + input_pitches[2] + 1); + } + + float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[2]); + float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[2]); + return y0 + float(x_offset) * (y1 - y0) / float(scales[3]); + }`:` + ${x} + float process(int indices[2]) { + int input_index = 0; + int output_index = coordsToOffset(TexCoords, ${l}, ${d}); + + ${w} + + int m; + int index_of_dim0, index_of_dim1; + index_of_dim0 = output_index / output_pitches[0]; + m = output_index - index_of_dim0 * output_pitches[0]; + index_of_dim1 = m; + + int index_of_input_dim0, index_of_input_dim1, x_offset, y_offset; + index_of_input_dim0 = index_of_dim0 / scales[0]; + y_offset = index_of_dim0 - index_of_input_dim0 * scales[0]; + index_of_input_dim1 = index_of_dim1 / scales[1]; + x_offset = index_of_dim1 - index_of_input_dim1 * scales[1]; + + input_index = index_of_input_dim0 * input_pitches[0] + index_of_input_dim1; + + float x00 = getInputFloat(input_index); + float x10, x01, x11; + + bool end_of_dim0 = false; + if (index_of_input_dim0 == (${e[0].dims[0]} - 1)) { + // It's the end in dimension 0 + x01 = x00; + end_of_dim0 = true; + } else { + x01 = getInputFloat(input_index + input_pitches[0]); + } + + if (index_of_input_dim1 == (input_pitches[0] - 1)) { + // It's the end in dimension 1 + x10 = x00; + x11 = x01; + } + else { + x10 = getInputFloat(input_index + 1); + x11 = end_of_dim0 ? x10 : getInputFloat(input_index + input_pitches[0] + 1); + } + + float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[0]); + float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[0]); + return y0 + float(x_offset) * (y1 - y0) / float(scales[1]); + }`;return{...Nv,output:{dims:a,type:e[0].type,textureType:0},shaderSource:T,variables:[{name:"scales",type:"int",arrayLength:r.scales.length,data:r.scales.map(S=>Math.ceil(S))}]}},fc=(n,e)=>{if(!n||e.opset<9&&n.length!==1||e.opset>=9&&e.opset<11&&n.length!==2||e.opset>=11&&n.length<2)throw new Error("invalid inputs.");if(e.scales.length>0&&n[0].dims.length!==e.scales.length)throw new Error("Invalid input shape.");if(n[0].type==="string")throw new Error("Invalid input tensor types.")},ca=(n,e,r)=>{if(r){for(let t of n)if(t<=0)throw new Error("Scale value should be greater than 0.")}else for(let t of n)if(t<1)throw new Error("Scale value should be greater than or equal to 1.");if((e==="linear"||e==="cubic")&&n.length!==2&&(n.length!==4||n[0]!==1||n[1]!==1))throw new Error(`'Linear' mode and 'Cubic' mode only support 2-D inputs ('Bilinear', 'Bicubic') or 4-D inputs with the corresponding outermost 2 scale values being 1 in the ${r?"Resize":"Upsample"} opeartor.`)}});var mc,gc,zv,Mv,SL,$L,AL,OL,Bv=H(()=>{"use strict";pt();Ve();Jr();Xn();hc();mc={name:"Resize",inputNames:["A"],inputTypes:[2]},gc=(n,e,r)=>(fc(e,r),[n.run({...mc,cacheHint:r.cacheKey,get:()=>SL(n,e,r)},e)]),zv=n=>Zo(n,10),Mv=n=>Zo(n,11),SL=(n,e,r)=>{let t=_e(n.session.backend.glContext.version),[o,i]=$L(e,r);if(o.every(E=>E===1)&&r.coordinateTransformMode!=="tf_crop_and_resize")return{...mc,output:{dims:i,type:e[0].type,textureType:2},hasMain:!0,shaderSource:`void main() { + vec4 v = ${t.texture2D}(X, TexCoords); + ${t.output} = v; + }`};let l=i.length;if(l<2)throw new Error(`output dimension should be at least 2, but got ${l}`);let d=i[l-2],h=i[l-1],g=e[0].dims;if(l!==g.length)throw new Error(`output dimension should match input ${g.length}, but got ${l}`);let _=g[l-2],w=g[l-1],x=o[l-2],T=o[l-1],S="";if(r.mode!=="linear")throw new Error(`resize (packed) does not support mode: '${r.mode}'`);switch(r.coordinateTransformMode){case"asymmetric":S=` + vec4 getSourceFracIndex(ivec4 coords) { + return vec4(coords) / scaleWHWH; + } + `;break;case"half_pixel":S=` + vec4 getSourceFracIndex(ivec4 coords) { + return (vec4(coords) + 0.5) / scaleWHWH - 0.5; + } + `;break;case"pytorch_half_pixel":S=` + vec4 getSourceFracIndex(ivec4 coords) { + vec4 fcoords = vec4(coords); + return vec4( + ${h}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0, + ${d}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0, + ${h}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0, + ${d}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0 + ); + } + `;break;case"align_corners":S=` + vec4 getSourceFracIndex(ivec4 coords) { + vec4 resized = vec4(${h}.0 - 1.0, ${d}.0 - 1.0, ${h}.0 - 1.0, + ${d}.0 - 1.0); + vec4 original = vec4(${w}.0 - 1.0, ${_}.0 - 1.0, ${w}.0 - 1.0, + ${_}.0 - 1.0); + vec4 new_scale = original / resized; + return vec4(coords) * new_scale; + } + `;break;default:throw new Error(`resize (packed) does not support coordinateTransformMode: '${r.coordinateTransformMode}'`)}let P=Pt(l),A=Zr(),O=` + const vec2 inputWH = vec2(${_}.0, ${w}.0); + const vec4 scaleWHWH = vec4(float(${x}), float(${T}), float(${x}), float(${T})); + ${A} + ${S} + float getAValue(int x10, int r, int c, int d) { + return getChannel(getA(x10, r, c, d), vec2(c, d)); + } + void main() { + ${P} rc = getOutputCoords(); + + int batch = rc[0]; + int depth = rc[1]; + + // retrieve the 4 coordinates that is used in the 4 packed output values. + ivec4 coords = ivec4(rc.wz, rc.w + 1, rc.z + 1); + + // calculate the source index in fraction + vec4 sourceFrac = getSourceFracIndex(coords); + + // get the lower and upper bound of the 4 values that will be packed into one texel. + ivec4 x00 = ivec4(max(sourceFrac.xy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xy))); + ivec4 x01 = ivec4(max(sourceFrac.xw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xw))); + ivec4 x10 = ivec4(max(sourceFrac.zy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zy))); + ivec4 x11 = ivec4(max(sourceFrac.zw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zw))); + + bool hasNextRow = rc.w < ${d-1}; + bool hasNextCol = rc.z < ${h-1}; + + // pack x00, x01, x10, x11's top-left corner into one vec4 structure + vec4 topLeft = vec4( + getAValue(batch, depth, x00.x, x00.y), + hasNextCol ? getAValue(batch, depth, x01.x, x01.y) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.x, x10.y) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.y) : 0.0); + + // pack x00, x01, x10, x11's top-right corner into one vec4 structure + vec4 topRight = vec4( + getAValue(batch, depth, x00.x, x00.w), + hasNextCol ? getAValue(batch, depth, x01.x, x01.w) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.x, x10.w) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.w) : 0.0); + + // pack x00, x01, x10, x11's bottom-left corner into one vec4 structure + vec4 bottomLeft = vec4( + getAValue(batch, depth, x00.z, x00.y), + hasNextCol ? getAValue(batch, depth, x01.z, x01.y) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.z, x10.y) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.y) : 0.0); + + // pack x00, x01, x10, x11's bottom-right corner into one vec4 structure + vec4 bottomRight = vec4( + getAValue(batch, depth, x00.z, x00.w), + hasNextCol ? getAValue(batch, depth, x01.z, x01.w) : 0.0, + hasNextRow ? getAValue(batch, depth, x10.z, x10.w) : 0.0, + (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.w) : 0.0); + + // calculate the interpolation fraction on u and v direction + vec4 frac = vec4(sourceFrac) - floor(sourceFrac); + vec4 clampFrac = clamp(frac, vec4(0.0), vec4(1.0)); + + vec4 top = mix(topLeft, topRight, clampFrac.ywyw); + vec4 bottom = mix(bottomLeft, bottomRight, clampFrac.ywyw); + vec4 newValue = mix(top, bottom, clampFrac.xxzz); + + ${t.output} = vec4(newValue); + } + `;return{...mc,output:{dims:i,type:e[0].type,textureType:2},hasMain:!0,shaderSource:O}},$L=(n,e)=>{let t=n[0].dims,o=e.scales,i;if(o.length===0){let l=n[e.scalesInputIdx];if(l&&l.size!==0){if(n[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");o=AL(l,e.mode,e.isResize)}else{let d=n[e.sizesInputIdx];if(!d||d.size===0)throw new Error("Either scales or sizes MUST be provided as input.");i=Array.from(d.integerData),o=OL(i,t,e.mode,e.isResize)}}else if(n[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");let a=i||t.map((l,d)=>Math.floor(l*o[d]));return[o,a]},AL=(n,e,r)=>{let t=Array.from(n.floatData);return ca(t,e,r),t},OL=(n,e,r,t)=>{let o=e.length,i=new Array(o);for(let a=0,l=o;a{"use strict";Kn();Fv=(n,e)=>(CL(e),[new yt([e[0].dims.length],"int32",void 0,void 0,new Int32Array(e[0].dims))]),CL=n=>{if(!n||n.length!==1)throw new Error("Shape requires 1 input.")}});var bc,jv,Gv,Uv,PL,Wv,EL,DL,Hv=H(()=>{"use strict";Tt();Jo();Ze();Ve();bc={name:"Slice",inputNames:["A"],inputTypes:[0]},jv=(n,e,r)=>(PL(e),[n.run({...bc,cacheHint:r.cacheKey,get:()=>Uv(n,e[0],r)},e)]),Gv=n=>{let e=n.attributes.getInts("starts"),r=n.attributes.getInts("ends"),t=n.attributes.getInts("axes",[]);return Le({starts:e,ends:r,axes:t})},Uv=(n,e,r)=>{let t=r.axes.length===0?e.dims.slice(0).map((_,w)=>w):r.axes,o=fe.normalizeAxes(t,e.dims.length),i=r.starts.map((_,w)=>_>e.dims[o[w]]-1?e.dims[o[w]]:fe.normalizeAxis(_,e.dims[o[w]])),a=r.ends.map((_,w)=>_>e.dims[o[w]]-1?e.dims[o[w]]:fe.normalizeAxis(_,e.dims[o[w]])),l=e.dims.slice(),d=[];for(let _=0;_0&&d.push(`outputIdx[${o[_]}] += ${i[_]};`);let g=` + float process(int outputIdx[${l.length}]) { + ${d.join(` + `)} + return _A(outputIdx); + }`;return{...bc,output:{dims:l,type:e.type,textureType:0},shaderSource:g}},PL=n=>{if(!n||n.length!==1)throw new Error("Slice requires 1 input.");if($n.indexOf(n[0].type)===-1)throw new Error("Invalid input type.")},Wv=(n,e)=>{DL(e);let r=EL(n,e);return[n.run({...bc,cacheHint:r.cacheKey,get:()=>Uv(n,e[0],r)},[e[0]])]},EL=(n,e)=>{if(!n.session.isInitializer(e[1].dataId)||!n.session.isInitializer(e[2].dataId)||e.length>=4&&!n.session.isInitializer(e[3].dataId)||e.length>=5&&!n.session.isInitializer(e[4].dataId))throw new Error("dynamic slice attributes are not allowed");if(e.length>=5&&e[4].integerData.some(a=>a!==1))throw new Error("currently non-1 steps is not supported for Slice");let r=Array.from(e[1].integerData),t=Array.from(e[2].integerData),o=e.length>=4?Array.from(e[3].integerData):[],i=`${o};${r};${t}`;return{starts:r,ends:t,axes:o,cacheKey:i}},DL=n=>{if(!n||n.length<3||n.length>5)throw new Error("Invalid input number.");if(n[1].type!=="int32"||n[1].dims.length!==1)throw new Error("Invalid input type.");if(n[2].type!=="int32"||n[2].dims.length!==1)throw new Error("Invalid input type.");if(n.length>=4&&(n[3].type!=="int32"||n[3].dims.length!==1))throw new Error("Invalid input type.");if(n.length>=5&&(n[4].type!=="int32"||n[4].dims.length!==1))throw new Error("Invalid input type.")}});var qv,Kv,Xv,Jv,Zv,Qv,Yv,ew,kL,NL,LL,tw,rw=H(()=>{"use strict";Tt();Ze();pt();Ve();sa();qv={name:"SoftmaxComputeMax",inputNames:["A"],inputTypes:[0]},Kv={name:"SoftmaxComputeScale",inputNames:["A","Max"],inputTypes:[0,0]},Xv={name:"SoftMax",inputNames:["A","Max","Norm"],inputTypes:[0,0,0]},Jv=(n,e,r)=>{tw(e);let t=e[0].dims.slice(),o=fe.normalizeAxis(r.axis,t.length),i=fe.sizeToDimension(t,o),a=fe.sizeFromDimension(t,o);return ew(n,e,r,i,a)},Zv=n=>Le({axis:n.attributes.getInt("axis",1)}),Qv=n=>Le({axis:n.attributes.getInt("axis",-1)}),Yv=(n,e,r)=>{tw(e);let t=e[0].dims.slice(),o=fe.normalizeAxis(r.axis,t.length),i=t.length,a=o!==i-1,l=[],d=[],h=[],g;a&&(d=Array.from({length:i}).map((T,S)=>S),d[o]=i-1,d[i-1]=o,d.map(T=>l.push(t[T])),g=Le({perm:d}),h=Zn(n,e,g));let _=a?fe.sizeToDimension(l,i-1):fe.sizeToDimension(t,i-1),w=a?fe.sizeFromDimension(l,i-1):fe.sizeFromDimension(t,i-1),x=ew(n,a?h:e,r,_,w);return a?Zn(n,x,g):x},ew=(n,e,r,t,o)=>{let i=kL(n,e[0],t,o,[t]),a=n.run({...qv,cacheHint:r.cacheKey,get:()=>i},e),l=NL(n,e[0],t,o,i.output.dims,[t]),d=n.run({...Kv,cacheHint:r.cacheKey,get:()=>l},[e[0],a]),h=LL(n,e[0],t,o,i.output.dims,l.output.dims);return[n.run({...Xv,cacheHint:r.cacheKey,get:()=>h},[e[0],a,d])]},kL=(n,e,r,t,o)=>{let[i,a]=n.calculateTextureWidthAndHeight(e.dims,0),l=o.length;if(r<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(o.length!==1)throw new Error("Dimensionality of the output should be 1");if(o[0]!==r)throw new Error("Shape of the output should be equal to logical row count");let d=_e(n.session.backend.glContext.version),h=` + float process(int[${l}] indices) { + int logical_row_start_offset = indices[0] * ${t}; + + float max = getColorAsFloat(${d.texture2D}(A, offsetToCoords(logical_row_start_offset, ${i}, + ${a} ))); + for(int i=1; i<${t}; ++i) + { + float current = getColorAsFloat(${d.texture2D}(A, offsetToCoords(logical_row_start_offset + i, + ${i}, ${a}))); + if(current > max) + max = current; + } + + return max; + }`;return{...qv,output:{dims:o,type:e.type,textureType:0},shaderSource:h}},NL=(n,e,r,t,o,i)=>{let[a,l]=n.calculateTextureWidthAndHeight(e.dims,0),d=i.length;if(r<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(i.length!==1)throw new Error("Dimensionality of the output should be 1");if(i[0]!==r)throw new Error("Shape of the output should be equal to logical row count");if(o.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(o[0]!==r)throw new Error("Shape of the intermediate results should be equal to logical row count");let h=_e(n.session.backend.glContext.version),g=` + float process(int[${d}] indices) { + int logical_row_start_offset = indices[0] * ${t}; + + float norm_factor = 0.0; + float max = _Max(indices); + for(int i=0; i<${t}; ++i) + { + norm_factor += exp(getColorAsFloat(${h.texture2D}(A, offsetToCoords(logical_row_start_offset + i, + ${a}, ${l}))) - max); + } + + return norm_factor; + }`;return{...Kv,output:{dims:i,type:e.type,textureType:0},shaderSource:g}},LL=(n,e,r,t,o,i)=>{let[a,l]=n.calculateTextureWidthAndHeight(e.dims,0),d=e.dims.length;if(r<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(o.length!==1||i.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(o[0]!==r||i[0]!==r)throw new Error("Shape of the intermediate results should be equal to logical row count");let h=` + float process(int[${d}] indices) { + + // get offset of current logical tensor index from the 2-D texture coordinates (TexCoords) + int offset = coordsToOffset(TexCoords, ${a}, ${l}); + + //determine the logical row for this index + int logical_row_index[1]; + logical_row_index[0] = offset / ${t}; + + float norm_factor = _Norm(logical_row_index); + + // avoid possible division by 0 + // if norm_facor is 0, all elements are zero + // if so, return 0 + if(norm_factor == 0.0) + return 0.0; + + return exp(_A(indices) - _Max(logical_row_index)) / norm_factor; + }`;return{...Xv,output:{dims:e.dims,type:e.type,textureType:0},shaderSource:h}},tw=n=>{if(!n||n.length!==1)throw new Error("Softmax requires 1 input.");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("Invalid input type")}});var nw,ow,iw,RL,zL,ML,aw=H(()=>{"use strict";Tt();Ze();Ve();nw={name:"Split",inputNames:["A"],inputTypes:[0]},ow=(n,e,r)=>{ML(e);let t=fe.normalizeAxis(r.axis,e[0].dims.length),o=RL(n,e,t,r),i=[];for(let a=0;azL(n,e[0],r,t,a)},e));return i},iw=n=>{let e=n.attributes.getInt("axis",0),r=n.attributes.getInts("split",[]),t=n.outputs.length;return Le({axis:e,split:r,numOutputs:t})},RL=(n,e,r,t)=>{let[,o]=Uo.splitShape(e[0].dims,r,t.split,t.numOutputs);return o.length},zL=(n,e,r,t,o)=>{let[i,a]=Uo.splitShape(e.dims,t,r.split,r.numOutputs),l=a[o],d=i[o],g=` + float process(int indices[${d.length}]) { + indices[${t}] += ${l}; + return _A(indices); + } + `;return{...nw,cacheHint:`${r.cacheKey}:${o}`,output:{dims:d,type:e.type,textureType:0},shaderSource:g}},ML=n=>{if(!n||n.length!==1)throw new Error("Split requires one input.");if(n[0].type!=="int8"&&n[0].type!=="uint8"&&n[0].type!=="int16"&&n[0].type!=="uint16"&&n[0].type!=="int32"&&n[0].type!=="uint32"&&n[0].type!=="float32"&&n[0].type!=="float64"&&n[0].type!=="bool")throw new Error("Invalid input type.")}});var yc,sw,uw,BL,FL,lw=H(()=>{"use strict";Ze();yc=(n,e,r)=>{BL(e);let t=fe.squeezeShape(e[0].dims,r);return[n.reshapeUnpacked(e[0],t)]},sw=(n,e)=>(FL(e),yc(n,[e[0]],Array.from(e[1].integerData))),uw=n=>n.attributes.getInts("axes"),BL=n=>{if(!n||n.length!==1)throw new Error("Squeeze requires 1 input.");if(n[0].type==="string")throw new Error("invalid input tensor types.")},FL=n=>{if(!n||n.length!==2)throw new Error("Squeeze requires 2 inputs.");if(n[1].type!=="int32")throw new Error("Invalid input type.")}});var cw,VL,jL,dw=H(()=>{"use strict";pt();Ve();cw=(n,e)=>{jL(e);let r={name:"Sum",inputNames:e.map((o,i)=>`X${i}`),inputTypes:new Array(e.length).fill(0)};return[n.run({...r,get:()=>VL(n,e,r)},e)]},VL=(n,e,r)=>{let t=_e(n.session.backend.glContext.version),o=e[0].dims.slice(),a=` + void main() { + vec4 result = ${e.map((l,d)=>`${t.texture2D}(X${d},TexCoords)`).join(" + ")}; + ${t.output} = result; + } + `;return{...r,output:{dims:o,type:e[0].type,textureType:0},hasMain:!0,shaderSource:a}},jL=n=>{if(!n||n.length===0)throw new Error("Sum requires inputs.");let e=n[0].dims.length;for(let r=1;r{"use strict";Jo();Ve();pw=(n,e)=>{UL(e);let r={name:"Tile",inputNames:["A"],inputTypes:[0]};return[n.run({...r,get:()=>GL(n,e,r)},e)]},GL=(n,e,r)=>{let t=e[0].dims.slice(),o=new Array(t.length),i=[];for(let d=0;d{if(!n||n.length!==2)throw new Error("Tile requires 2 input.");if(n[1].dims.length!==1)throw new Error("The second input shape must 1 dimension.");if(n[1].dims[0]!==n[0].dims.length)throw new Error("Invalid input shape.");if($n.indexOf(n[0].type)===-1)throw new Error("Invalid input type.");if(n[1].type!=="int32"&&n[1].type!=="int16")throw new Error("Invalid repeat type.")}});var _c,hw,mw,WL,HL,gw=H(()=>{"use strict";Ze();_c=(n,e,r)=>{WL(e);let t=fe.unsqueezeShape(e[0].dims,r);return[n.reshapeUnpacked(e[0],t)]},hw=(n,e)=>(HL(e),_c(n,[e[0]],Array.from(e[1].integerData))),mw=n=>n.attributes.getInts("axes"),WL=n=>{if(!n||n.length!==1)throw new Error("Unsqueeze requires 1 input.");if(n[0].type==="string")throw new Error("invalid input tensor types.")},HL=n=>{if(!n||n.length!==2)throw new Error("Unsqueeze requires 2 inputs.");if(n[1].type!=="int32")throw new Error("Invalid input type.")}});var bw,yw=H(()=>{"use strict";O_();V_();U_();J_();oa();k0();B0();j0();W0();X0();Q0();rv();av();ia();cv();Tv();Ev();kv();Bv();Vv();Hv();rw();aw();lw();dw();fw();sa();rc();gw();hc();bw=[["Abs","","6+",Z_],["Acos","","7+",Q_],["Add","","7+",C_],["And","","7+",P_],["Asin","","7+",Y_],["Atan","","7+",e0],["AveragePool","","7+",pv,fv],["BatchNormalization","","7+",$_,A_],["Cast","","6+",j_,G_],["Ceil","","6+",n0],["Clip","","6-10",ec,t0],["Clip","","11+",r0],["Concat","","4+",q_,X_],["Conv","","1+",uc,lc],["ConvTranspose","","1+",E0,D0],["Cos","","7+",o0],["Div","","7+",E_],["Dropout","","7+",tc],["DepthToSpace","","1+",z0,M0],["Equal","","7+",D_],["Elu","","6+",i0,a0],["Exp","","6+",s0],["Flatten","","1+",F0,V0],["Floor","","6+",u0],["FusedConv","com.microsoft","1+",uc,lc],["Gather","","1+",G0,U0],["Gemm","","7-10",cc,q0],["Gemm","","11+",cc,K0],["GlobalAveragePool","","1+",mv,gv],["GlobalMaxPool","","1+",wv],["Greater","","7+",k_],["Identity","","1+",tc],["ImageScaler","","1+",J0,Z0],["InstanceNormalization","","6+",ev,tv],["LeakyRelu","","6+",l0,c0],["Less","","7+",N_],["LRN","","1+",nv,ov],["Log","","6+",d0],["MatMul","","1+",I0,S0],["MaxPool","","1+",bv,yv],["Mul","","7+",L_],["Neg","","6+",p0],["Not","","1+",f0],["Or","","7+",R_],["Pad","","2-10",dc,sv],["Pad","","11+",uv,lv],["Pow","","7+",z_],["PRelu","","7+",M_],["ReduceLogSum","","1+",Cv,An],["ReduceMax","","1+",$v,An],["ReduceMean","","1+",Sv,An],["ReduceMin","","1+",Av,An],["ReduceProd","","1+",Ov,An],["ReduceSum","","1-12",Iv,An],["ReduceSumSquare","","1+",Pv,An],["Relu","","6+",h0],["Reshape","","5+",Dv],["Resize","","10",gc,zv],["Resize","","11+",gc,Mv],["Shape","","1+",Fv],["Sigmoid","","6+",m0],["Sin","","7+",g0],["Slice","","10+",Wv],["Slice","","1-9",jv,Gv],["Softmax","","1-12",Jv,Zv],["Softmax","","13+",Yv,Qv],["Split","","2-12",ow,iw],["Sqrt","","6+",b0],["Squeeze","","1-12",yc,uw],["Squeeze","","13+",sw],["Sub","","7+",B_],["Sum","","6+",cw],["Tan","","7+",y0],["Tanh","","6+",_0],["Tile","","6+",pw],["Transpose","","1+",Zn,L0],["Upsample","","7-8",pc,Lv],["Upsample","","9",pc,Rv],["Unsqueeze","","1-12",_c,mw],["Unsqueeze","","13+",hw],["Xor","","7+",F_]]});function vw(n){let e={},r;for(;(r=_w.exec(n))!==null;){let t=r[3].split(",").map(o=>{let i=o.trim().split(" ");return i&&i.length===2?{type:i[0],name:i[1]}:null}).filter(o=>o!==null);e[r[2]]={params:t,body:r[4]}}for(let t in e){let o=qL.replace("__FUNC__",t),i=new RegExp(o,"gm");for(;(r=i.exec(n))!==null;){let a=r[1],l=r[2],d=r[3].split(","),h=a?`${a} ${l};`:"",g=e[t].body,_="";e[t].params.forEach((x,T)=>{x&&(_+=`${x.type} ${x.name} = ${d[T]}; +`)}),g=`${_} + ${g}`,g=g.replace("return",`${l} = `);let w=` + ${h} + { + ${g} + } + `;n=n.replace(r[0],w)}}return n=n.replace(_w,""),n}var _w,qL,ww=H(()=>{"use strict";_w=/@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm,qL="(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;"});function vo(n,e){let r=[],t=[],o=e!=null&&Array.isArray(e)&&e.length===0,i=e==null||o?null:KL(e,n).sort(),a=0;for(let l=0;ll)&&n[l]===1&&(r.push(n[l]),t.push(l)),i[a]<=l&&a++}n[l]!==1&&(r.push(n[l]),t.push(l))}return{newShape:r,keptDims:t}}function KL(n,e){let r=e.length;return n=n==null?e.map((t,o)=>o):[].concat(n),ho(n.every(t=>t>=-r&&t`All values in axis param must be in range [-${r}, ${r}) but got axis ${n}`),ho(n.every(XL),()=>`All values in axis param must be integers but got axis ${n}`),n.map(t=>t<0?r+t:t)}function XL(n){return n%1===0}function JL(n){if(n.length===0)return 1;let e=n[0];for(let r=1;r{"use strict";Wt();Ze();da=class{constructor(e){this.maxTextureSize=e}computeTextureWH(e,r){let t=this.computeTexture(e,r);return r&&r.isPacked&&(t[0]/=2,t[1]/=2),r&&r.reverseWH?[t[1],t[0]]:t}computeTexture(e,r){let t=r&&r.isPacked;if(e.length===0)return t?[2,2]:[1,1];let o=this.maxTextureSize;if(r&&r.breakAxis!==void 0){let l=r.breakAxis>=e.length?1:e.slice(r.breakAxis).reduce((h,g)=>h*g),d=r.breakAxis<=0?1:e.slice(0,r.breakAxis).reduce((h,g)=>h*g);if(l>o||d>o)Ye.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${e}, breakAxis:${r.breakAxis}`);else return[l,d]}let i=e.slice(0);t&&(o=o*2,i=i.map((l,d)=>d>=i.length-2?i[d]%2===0?i[d]:i[d]+1:i[d]),i.length===1&&(i=[2,i[0]])),i.length!==2&&(i=vo(i).newShape);let a=JL(i);return i.length<=1&&a<=o?[1,a]:i.length===2&&i[0]<=o&&i[1]<=o?i:i.length===3&&i[0]*i[1]<=o&&i[2]<=o?[i[0]*i[1],i[2]]:i.length===3&&i[0]<=o&&i[1]*i[2]<=o?[i[0],i[1]*i[2]]:i.length===4&&i[0]*i[1]*i[2]<=o&&i[3]<=o?[i[0]*i[1]*i[2],i[3]]:i.length===4&&i[0]<=o&&i[1]*i[2]*i[3]<=o?[i[0],i[1]*i[2]*i[3]]:t?xw(a/4).map(l=>l*2):xw(a)}}});var pa,Tw=H(()=>{"use strict";Ze();pn();pt();vc();Jr();pa=class extends Zt{constructor(e){super(e)}getFunctions(){return{...this.offsetToCoords(),...this.coordsToOffset(),...this.toVec(),...this.valueFrom(),...this.getCommonUtilFuncs(),...this.getInputsSamplingSnippets(),...this.getOutputSamplingSnippet()}}getCustomTypes(){return{}}offsetToCoords(){let e="offsetToCoords";return{offsetToCoords:new ce(` + vec2 ${e}(int offset, int width, int height) { + int t = offset / width; + int s = offset - t*width; + vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height); + return coords; + } + `)}}coordsToOffset(){let e="coordsToOffset";return{coordsToOffset:new ce(` + int ${e}(vec2 coords, int width, int height) { + float s = coords.s * float(width); + float t = coords.t * float(height); + int offset = int(t) * width + int(s); + return offset; + } + `)}}getOutputSamplingSnippet(){let e=this.context.outputTextureLayout;return e.isPacked?this.getPackedOutputSamplingSnippet(e):this.getUnpackedOutputSamplingSnippet(e)}getPackedOutputSamplingSnippet(e){let r=e.unpackedShape,t=[e.width,e.height],o={},i="getOutputCoords";switch(r.length){case 0:o[i]=this.getOutputScalarCoords();break;case 1:o[i]=this.getOutputPacked1DCoords(r,t);break;case 2:o[i]=this.getOutputPacked2DCoords(r,t);break;case 3:o[i]=this.getOutputPacked3DCoords(r,t);break;default:o[i]=this.getOutputPackedNDCoords(r,t)}let l=` + void setOutput(vec4 val) { + ${_e(this.context.glContext.version).output} = val; + } + `,d="floatTextureSetRGBA";return o[d]=new ce(l),o}getUnpackedOutputSamplingSnippet(e){let r=e.unpackedShape,t=[e.width,e.height],o={},i="getOutputCoords";switch(r.length){case 0:o[i]=this.getOutputScalarCoords();break;case 1:o[i]=this.getOutputUnpacked1DCoords(r,t);break;case 2:o[i]=this.getOutputUnpacked2DCoords(r,t);break;case 3:o[i]=this.getOutputUnpacked3DCoords(r,t);break;case 4:o[i]=this.getOutputUnpacked4DCoords(r,t);break;case 5:o[i]=this.getOutputUnpacked5DCoords(r,t);break;case 6:o[i]=this.getOutputUnpacked6DCoords(r,t);break;default:throw new Error(`Unsupported output dimensionality: ${r.length}`)}let l=` + void setOutput(float val) { + ${_e(this.context.glContext.version).output} = vec4(val, 0, 0, 0); + } + `,d="floatTextureSetR";return o[d]=new ce(l),o}getOutputScalarCoords(){return new ce(` + int getOutputCoords() { + return 0; + } + `)}getOutputPacked1DCoords(e,r){let t=r,o="";return t[0]===1?(o=` + int getOutputCoords() { + return 2 * int(TexCoords.y * ${t[1]}.0); + } + `,new ce(o)):t[1]===1?(o=` + int getOutputCoords() { + return 2 * int(TexCoords.x * ${t[0]}.0); + } + `,new ce(o)):(o=` + int getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${t[0]}, ${t[1]})); + return 2 * (resTexRC.y * ${t[0]} + resTexRC.x); + } + `,new ce(o))}getOutputPacked2DCoords(e,r){let t="";if(Un.arraysEqual(e,r))return t=` + ivec2 getOutputCoords() { + return 2 * ivec2(TexCoords.xy * vec2(${r[0]}, ${r[1]})); + } + `,new ce(t);let o=r,i=Math.ceil(e[1]/2);return t=` + ivec2 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${o[0]}, ${o[1]})); + + int index = resTexRC.y * ${o[0]} + resTexRC.x; + + // reverse r and c order for packed texture + int r = imod(index, ${i}) * 2; + int c = 2 * (index / ${i}); + + return ivec2(r, c); + } + `,new ce(t)}getOutputPacked3DCoords(e,r){let t=[r[0],r[1]],o=Math.ceil(e[2]/2),i=o*Math.ceil(e[1]/2),a=` + ivec3 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${t[0]}, ${t[1]})); + int index = resTexRC.y * ${t[0]} + resTexRC.x; + + int b = index / ${i}; + index -= b * ${i}; + + // reverse r and c order for packed texture + int r = imod(index, ${o}) * 2; + int c = 2 * (index / ${o}); + + return ivec3(b, r, c); + } + `;return new ce(a)}getOutputPackedNDCoords(e,r){let t=[r[0],r[1]],o=Math.ceil(e[e.length-1]/2),i=o*Math.ceil(e[e.length-2]/2),a=i,l="",d="b, r, c";for(let g=2;g=0;--d)i[d]=i[d+1]*e[d+1];let a=["r","c","d"],l=i.map((d,h)=>{let g=`int ${a[h]} = index / ${d}`,_=h===i.length-1?`int ${a[h+1]} = index - ${a[h]} * ${d}`:`index -= ${a[h]} * ${d}`;return`${g}; ${_};`}).join("");return t=` + ivec3 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${r[0]}, ${r[1]})); + int index = resTexRC.y * ${r[0]} + resTexRC.x; + ${l} + return ivec3(r, c, d); + } + `,new ce(t)}getOutputUnpacked4DCoords(e,r){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let d=o-3;d>=0;--d)i[d]=i[d+1]*e[d+1];let a=["r","c","d","d2"],l=i.map((d,h)=>{let g=`int ${a[h]} = index / ${d}`,_=h===i.length-1?`int ${a[h+1]} = index - ${a[h]} * ${d}`:`index -= ${a[h]} * ${d}`;return`${g}; ${_};`}).join("");return t=` + ivec4 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${r[0]}, ${r[1]})); + int index = resTexRC.y * ${r[0]} + resTexRC.x; + ${l} + return ivec4(r, c, d, d2); + } + `,new ce(t)}getOutputUnpacked5DCoords(e,r){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let d=o-3;d>=0;--d)i[d]=i[d+1]*e[d+1];let a=["r","c","d","d2","d3"],l=i.map((d,h)=>{let g=`int ${a[h]} = index / ${d}`,_=h===i.length-1?`int ${a[h+1]} = index - ${a[h]} * ${d}`:`index -= ${a[h]} * ${d}`;return`${g}; ${_};`}).join("");return t=` + ivec5 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${r[0]}, ${r[1]})); + int index = resTexRC.y * ${r[0]} + resTexRC.x; + ${l} + return ivec5(r, c, d, d2, d3); + } + `,new ce(t)}getOutputUnpacked6DCoords(e,r){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let d=o-3;d>=0;--d)i[d]=i[d+1]*e[d+1];let a=["r","c","d","d2","d3","d4"],l=i.map((d,h)=>{let g=`int ${a[h]} = index / ${d}`,_=h===i.length-1?`int ${a[h+1]} = index - ${a[h]} * ${d}`:`index -= ${a[h]} * ${d}`;return`${g}; ${_};`}).join("");return t=` + ivec6 getOutputCoords() { + ivec2 resTexRC = ivec2(TexCoords.xy * + vec2(${r[0]}, ${r[1]})); + int index = resTexRC.y * ${r[0]} + resTexRC.x; + ${l} + return ivec6(r, c, d, d2, d3, d4); + } + `,new ce(t)}getCommonUtilFuncs(){let e={},r="uvFromFlat";e[r]=new ce(` + vec2 uvFromFlat(int texNumR, int texNumC, int index) { + int texC = index / texNumR; + int texR = index - texC * texNumR; + // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to + // v. + return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC); + } + `),r="packedUVfrom1D",e[r]=new ce(` + vec2 packedUVfrom1D(int texNumR, int texNumC, int index) { + int texelIndex = index / 2; + int texR = texelIndex / texNumC; + int texC = texelIndex - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `),r="packedUVfrom2D",e[r]=new ce(` + vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) { + int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2); + int texR = texelIndex / texNumC; + int texC = texelIndex - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `),r="packedUVfrom3D",e[r]=new ce(` + vec2 packedUVfrom3D(int texNumR, int texNumC, + int texelsInBatch, int texelsInLogicalRow, int b, + int row, int col) { + int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2); + int texR = index / texNumC; + int texC = index - texR * texNumC; + return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); + } + `),r="sampleTexture";let t=_e(this.context.glContext.version);return e[r]=new ce(` + float sampleTexture(sampler2D textureSampler, vec2 uv) { + return ${t.texture2D}(textureSampler, uv).r; + }`),e}getInputsSamplingSnippets(){let e={},r=this.context.outputTextureLayout;return this.context.programInfo.inputNames.forEach((t,o)=>{let i=this.context.inputTextureLayouts[o],a=Zi(t);i.isPacked?e[a]=this.getPackedSamplerFromInput(a,t,i):e[a]=this.getUnpackedSamplerFromInput(a,t,i);let l=c_(t);i.unpackedShape.length<=r.unpackedShape.length&&(i.isPacked?e[l]=this.getPackedSamplerAtOutputCoords(l,i,r,t):e[l]=this.getUnpackedSamplerAtOutputCoords(l,i,r,t))}),e}getPackedSamplerAtOutputCoords(e,r,t,o){let i=r.unpackedShape,a=t.unpackedShape,d=Zi(o),h=i.length,g=a.length,_=Ct.getBroadcastDims(i,a),w=Pt(g),x=g-h,T,S=ur();h===0?T="":g<2&&_.length>=1?T="coords = 0;":T=_.map(Z=>`coords.${S[Z+x]} = 0;`).join(` +`);let P="";g<2&&h>0?P="coords":P=i.map((Z,ee)=>`coords.${S[ee+x]}`).join(", ");let A="return outputValue;",E=fe.size(i)===1,z=fe.size(a)===1;if(h===1&&!E&&!z)A=` + return vec4(outputValue.xy, outputValue.xy); + `;else if(E&&!z)g===1?A=` + return vec4(outputValue.x, outputValue.x, 0., 0.); + `:A=` + return vec4(outputValue.x); + `;else if(_.length){let Z=h-2,ee=h-1;_.indexOf(Z)>-1&&_.indexOf(ee)>-1?A="return vec4(outputValue.x);":_.indexOf(Z)>-1?A="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":_.indexOf(ee)>-1&&(A="return vec4(outputValue.xx, outputValue.zz);")}let B=` + int lastDim = coords.${S[g-1]}; + coords.${S[g-1]} = coords.${S[g-2]}; + coords.${S[g-2]} = lastDim; + `,K=` + vec4 ${e}() { + ${w} coords = getOutputCoords(); + ${B} + ${T} + vec4 outputValue = ${d}(${P}); + ${A} + } + `;return new ce(K,["coordinates.getOutputCoords"])}getUnpackedSamplerAtOutputCoords(e,r,t,o){let i=[t.width,t.height],a=[r.width,r.height],l=r.unpackedShape.length,d=t.unpackedShape.length,h=r.unpackedShape,g=t.unpackedShape,_=Zi(o);if(l===d&&Un.arraysEqual(a,i)){let E=` + float ${e}() { + return sampleTexture(${o}, TexCoords); + } + `;return new ce(E,["coordinates.sampleTexture"])}let w=Pt(d),x=Ct.getBroadcastDims(h,g),T=d-l,S,P=ur();l===0?S="":d<2&&x.length>=1?S="coords = 0;":S=x.map(E=>`coords.${P[E+T]} = 0;`).join(` +`);let A="";d<2&&l>0?A="coords":A=r.unpackedShape.map((E,L)=>`coords.${P[L+T]}`).join(", ");let O=` + float ${e}() { + ${w} coords = getOutputCoords(); + ${S} + return ${_}(${A}); + } + `;return new ce(O,["coordinates.getOutputCoords"])}getPackedSamplerFromInput(e,r,t){switch(t.unpackedShape.length){case 0:return this.getPackedSamplerScalar(e,r);case 1:return this.getPackedSampler1D(e,r,t);case 2:return this.getPackedSampler2D(e,r,t);case 3:return this.getPackedSampler3D(e,r,t);default:return this.getPackedSamplerND(e,r,t)}}getUnpackedSamplerFromInput(e,r,t){let o=t.unpackedShape;switch(o.length){case 0:return this.getUnpackedSamplerScalar(e,r,t);case 1:return this.getUnpackedSampler1D(e,r,t);case 2:return this.getUnpackedSampler2D(e,r,t);case 3:return this.getUnpackedSampler3D(e,r,t);case 4:return this.getUnpackedSampler4D(e,r,t);case 5:return this.getUnpackedSampler5D(e,r,t);case 6:return this.getUnpackedSampler6D(e,r,t);default:throw new Error(`Unsupported dimension ${o.length}-D`)}}getPackedSamplerScalar(e,r){let t=_e(this.context.glContext.version),o=` + vec4 ${e}() { + return ${t.texture2D}(${r}, halfCR); + } + `;return new ce(o)}getPackedSampler1D(e,r,t){let o=[t.width,t.height],i=[o[1],o[0]],a=_e(this.context.glContext.version),d=`vec4 ${e}(int index) { + vec2 uv = packedUVfrom1D( + ${i[0]}, ${i[1]}, index); + return ${a.texture2D}(${r}, uv); + }`;return new ce(d,["coordinates.packedUVfrom1D"])}getPackedSampler2D(e,r,t){let o=t.unpackedShape,i=[t.width,t.height],a=_e(this.context.glContext.version),l=i[0],d=i[1];if(i!=null&&Un.arraysEqual(o,i)){let x=`vec4 ${e}(int row, int col) { + vec2 uv = (vec2(col, row) + halfCR) / vec2(${d}.0, ${l}.0); + return ${a.texture2D}(${r}, uv); + }`;return new ce(x)}let h=i,g=Math.ceil(o[1]/2),w=`vec4 ${e}(int row, int col) { + vec2 uv = packedUVfrom2D(${h[1]}, ${h[0]}, ${g}, row, col); + return ${a.texture2D}(${r}, uv); + }`;return new ce(w,["coordinates.packedUVfrom2D"])}getPackedSampler3D(e,r,t){let o=t.unpackedShape,i=[t.width,t.height],a=[i[0],i[1]],l=_e(this.context.glContext.version);if(o[0]===1){let T=o.slice(1),S=[1,2],P=mo(o,T),A=["b","row","col"],O=JSON.parse(JSON.stringify(t));O.unpackedShape=P;let E=this.getPackedSamplerFromInput(e,r,O),z=`${E.routineBody} + vec4 ${e}(int b, int row, int col) { + return ${e}(${go(A,S)}); + } `;return new ce(z,E.dependencies)}let d=a[0],h=a[1],g=Math.ceil(o[2]/2),_=g*Math.ceil(o[1]/2),x=`vec4 ${e}(int b, int row, int col) { + vec2 uv = packedUVfrom3D( + ${h}, ${d}, ${_}, ${g}, b, row, col); + return ${l.texture2D}(${r}, uv);}`;return new ce(x,["coordinates.packedUVfrom3D"])}getPackedSamplerND(e,r,t){let o=t.unpackedShape,i=o.length,a=[t.width,t.height],l=_e(this.context.glContext.version),d=[a[0],a[1]],h=d[1],g=d[0],_=Math.ceil(o[i-1]/2),w=_*Math.ceil(o[i-2]/2),x="int b, int row, int col",T=`b * ${w} + (row / 2) * ${_} + (col / 2)`;for(let A=2;A{let o=this.context.inputTextureLayouts[t],a=(o.unpackedShape.length>0?o.unpackedShape:o.shape).length,l=`_${r}`;e[l]=new ce(this.getValueFromSingle(r,a,o.width,o.height,!1),[`shapeUtils.indicesToOffset${l}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"]),l=l+"_T",e[l]=new ce(this.getValueFromSingle(r,a,o.width,o.height,!0),[`shapeUtils.indicesToOffset${l}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"])}),e}getValueFromSingle(e,r,t,o,i){let a=`_${e}`;i&&(a=a+"_T");let l=_e(this.context.glContext.version);return` + float ${a}(int m[${r}]) { + int offset = indicesToOffset${a}(m); + vec2 coords = offsetToCoords(offset, ${t}, ${o}); + float value = getColorAsFloat(${l.texture2D}(${e}, coords)); + return value; + } + `}getPackedValueFrom(e,r,t,o,i){let a=`_${e}_Pack`;i&&(a=a+"_T");let l=_e(this.context.glContext.version);return` + vec4 ${a}(int m[${r}]) { + int offset = indicesToOffset_${e}(m); + vec2 coords = offsetToCoords(offset, ${t}, ${o}); + return ${l.texture2D}(${e}, coords); + } + `}}});var fa,Iw=H(()=>{"use strict";pn();fa=class n extends Zt{constructor(e){super(e)}getFunctions(){return{...this.encodeFloat32(),...this.decodeFloat32()}}getCustomTypes(){return{}}encodeFloat32(){return{encode:new ce(`highp vec4 encode(highp float f) { + return vec4(f, 0.0, 0.0, 0.0); + } + `)}}decodeFloat32(){return{decode:new ce(`highp float decode(highp vec4 rgba) { + return rgba.r; + } + `)}}encodeUint8(){let e=n.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{encode:new ce(` + highp vec4 encode(highp float f) { + highp float F = abs(f); + highp float Sign = step(0.0,-f); + highp float Exponent = floor(log2(F)); + highp float Mantissa = (exp2(- Exponent) * F); + Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa)); + highp vec4 rgba; + rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0)); + rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0); + rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0))); + rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0))); + ${e} + rgba = rgba / 255.0; // values need to be normalized to [0,1] + return rgba; + } + `)}}decodeUint8(){let e=n.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{decode:new ce(` + highp float decode(highp vec4 rgba) { + rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255] + ${e} + highp float Sign = 1.0 - step(128.0,rgba[0])*2.0; + highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0; + highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000); + highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 )); + return Result; + } + `)}}static isLittleEndian(){let e=new ArrayBuffer(4),r=new Uint32Array(e),t=new Uint8Array(e);if(r[0]=3735928559,t[0]===239)return!0;if(t[0]===222)return!1;throw new Error("unknown endianness")}}});var ha,Sw=H(()=>{"use strict";pn();pt();ha=class extends Zt{constructor(e){super(e)}getFunctions(){return{...this.setFragColor(),...this.getColorAsFloat()}}getCustomTypes(){return{}}setFragColor(){let e=_e(this.context.glContext.version);return{setFragColor:new ce(` + void setFragColor(float value) { + ${e.output} = encode(value); + } + `,["encoding.encode"])}}getColorAsFloat(){return{getColorAsFloat:new ce(` + float getColorAsFloat(vec4 color) { + return decode(color); + } + `,["encoding.decode"])}}}});var ma,$w=H(()=>{"use strict";pn();ma=class n extends Zt{constructor(e){super(e)}getFunctions(){return{...this.bcastIndex(),...this.bcastMatmulIndex(),...this.offsetToIndices(),...this.indicesToOffset(),...this.incrementIndices()}}getCustomTypes(){return{}}bcastIndex(){let e=this.context.outputTextureLayout.shape.length,r={};return this.context.programInfo.inputNames.forEach((t,o)=>{let i=this.context.inputTextureLayouts[o].unpackedShape;if(i.length<=e){let a=i.length,l=e-a,d=`bcastIndices_${t}`,h="";for(let _=0;_{let i=this.context.inputTextureLayouts[o].shape;if(!(i.length<2||i.length>e)){let a=i.length,l=e-a,d=`bcastMatmulIndices_${t}`,h="";for(let _=0;_{let o=this.context.inputTextureLayouts[t].shape,i=this.context.inputTextureLayouts[t].strides,a=o.length,l=`indicesToOffset_${r}`;e[l]=new ce(n.indexToOffsetSingle(l,a,i)),l=`indicesToOffset_${r}_T`,e[l]=new ce(n.indexToOffsetSingle(l,a,i.slice().reverse()))}),e}static indexToOffsetSingle(e,r,t){let o="";for(let i=r-1;i>=0;--i)o+=` + offset += indices[${i}] * ${t[i]}; + `;return` + int ${e}(int indices[${r}]) { + int offset = 0; + ${o} + return offset; + } + `}offsetToIndices(){let e={};return this.context.programInfo.inputNames.forEach((r,t)=>{let o=this.context.inputTextureLayouts[t].shape,i=this.context.inputTextureLayouts[t].strides,a=o.length,l=`offsetToIndices_${r}`;e[l]=new ce(n.offsetToIndicesSingle(l,a,i)),l=`offsetToIndices_${r}_T`,e[l]=new ce(n.offsetToIndicesSingle(l,a,i.slice().reverse()))}),e}static offsetToIndicesSingle(e,r,t){let o=[];for(let i=0;i{let o=this.context.inputTextureLayouts[t].shape,i=o.length,a=`incrementIndices_${r}`,l="";for(let h=0;h= 0; --i) { + if(i > axis) continue; + indices[i] += 1; + if(indices[i] < shape[i]) { + break; + } + indices[i] = 0; + } + } + `;e[a]=new ce(d)}),e}}});var ga,Aw=H(()=>{"use strict";pn();ga=class extends Zt{constructor(e){super(e)}getCustomTypes(){return{}}getFunctions(){return{...this.binaryVecFunctions(),...this.copyVec(),...this.setVecItem(),...this.getVecItem()}}binaryVecFunctions(){let r=this.context.outputTextureLayout.shape.length,t={add:"+=",sub:"-=",mul:"*=",div:"/="},o={};for(let i in t){let a=`${i}Vec`,l="";for(let h=0;h{"use strict";Tw();Iw();Sw();$w();Aw();wc={encoding:fa,fragcolor:ha,vec:ga,shapeUtils:ma,coordinates:pa}});var ba,Cw=H(()=>{"use strict";pn();ww();Ow();pt();ba=class{constructor(e,r,t,o){this.libs={};this.glslLibRoutineDependencyGraph={};this.context=new ta(e,r,t,o),Object.keys(wc).forEach(a=>{let l=new wc[a](this.context);this.libs[a]=l});let i=this.glslLibRoutineDependencyGraph;for(let a in this.libs){let d=this.libs[a].getFunctions();for(let h in d){let g=a+"."+h,_;i[g]?(_=i[g],_.routineBody=d[h].routineBody):(_=new Xo(g,d[h].routineBody),i[g]=_);let w=d[h].dependencies;if(w)for(let x=0;x{let o=t.split(".")[1];e.indexOf(o)!==-1&&r.push(this.glslLibRoutineDependencyGraph[t])}),ra.returnOrderedNodes(r)}getUniforms(e,r){let t=[];if(e)for(let o of e)t.push(`uniform sampler2D ${o};`);if(r)for(let o of r)t.push(`uniform ${o.type} ${o.name}${o.arrayLength?`[${o.arrayLength}]`:""};`);return t.join(` +`)}}});var ya,Pw=H(()=>{"use strict";At();Wt();Cw();pt();ya=class{constructor(e,r,t){this.profiler=e;this.glContext=r;this.textureLayoutStrategy=t;this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,r){this.repo.set(e,r)}run(e,r,t){this.profiler.event("op",`ProgramManager.run ${e.programInfo.name??"unknown kernel"}`,()=>{let o=this.glContext.gl,i=e.program;o.useProgram(i);try{this.bindOutput(t),this.attributesBound||this.bindAttributes(e.attribLocations),this.bindUniforms(e.uniformLocations,e.programInfo.variables??[],r)}catch(a){throw Ye.error("ProgramManager",e.programInfo.shaderSource),a}this.profiler.event("backend","GlContext.draw()",()=>{this.glContext.draw()})},this.glContext)}dispose(){this.vertexShader&&this.glContext.deleteShader(this.vertexShader),this.repo.forEach(e=>this.glContext.deleteProgram(e.program))}build(e,r,t){return this.profiler.event("backend","ProgramManager.build",()=>{let o=new ba(this.glContext,e,r,t),i=o.preprocess(),a=this.compile(i);return{programInfo:e,program:a,uniformLocations:this.getUniformLocations(a,o.context.programInfo.inputNames,o.context.programInfo.variables),attribLocations:this.getAttribLocations(a)}})}compile(e){if(!this.vertexShader){Ye.verbose("ProrgramManager","Compiling and caching Vertex shader for the first time");let o=s_(this.glContext.version);this.vertexShader=this.glContext.compileShader(o,this.glContext.gl.VERTEX_SHADER)}Ae.debug&&Ye.verbose("ProrgramManager",`FragShader: +${e} +`);let r=this.glContext.compileShader(e,this.glContext.gl.FRAGMENT_SHADER),t=this.glContext.createProgram(this.vertexShader,r);return this.glContext.deleteShader(r),t}bindOutput(e){let r=e.width,t=e.height;Ye.verbose("ProrgramManager",`Binding output texture to Framebuffer: w/h=${r}/${t}, shape=${e.shape}, type=${e.tensor.type}`),this.glContext.attachFramebuffer(e.texture,r,t)}bindAttributes(e){let r=e.position,t=e.textureCoord;this.glContext.setVertexAttributes(r,t),this.attributesBound=!0}bindUniforms(e,r,t){let o=this.glContext.gl,i=0;for(let{name:a,type:l,location:d,arrayLength:h}of e){let g=r.find(_=>_.name===a)?.data;if(l!=="sampler2D"&&!g)throw new Error(`variable '${a}' does not have data defined in program info`);switch(l){case"sampler2D":this.bindTexture(t[i],d,i),i++;break;case"float":h?o.uniform1fv(d,g):o.uniform1f(d,g);break;case"int":h?o.uniform1iv(d,g):o.uniform1i(d,g);break;default:throw new Error(`Uniform not implemented: ${l}`)}}}bindTexture(e,r,t){this.glContext.bindTextureToUniform(e.texture,t,r)}getAttribLocations(e){return{position:this.getAttribLocation(e,"position"),textureCoord:this.getAttribLocation(e,"textureCoord")}}getUniformLocations(e,r,t){let o=[];if(r)for(let i of r)o.push({name:i,type:"sampler2D",location:this.getUniformLocation(e,i)});if(t)for(let i of t)o.push({...i,location:this.getUniformLocation(e,i.name)});return o}getUniformLocation(e,r){let o=this.glContext.gl.getUniformLocation(e,r);if(o===null)throw new Error(`Uniform ${r} not found.`);return o}getAttribLocation(e,r){return this.glContext.gl.getAttribLocation(e,r)}}});var _a,Ew=H(()=>{"use strict";Wt();qo();_a=class{constructor(e,r,t,o){this.glContext=e;this.layoutStrategy=r;this.profiler=t;this.config=o;this.pendingRead=new Map;o.reuseTextures&&(this.inUseTextures=new Map,this.idleTextures=new Map,this.textureLookup=new Map)}createTextureFromLayout(e,r,t,o){let i=this.toEncoderType(e),a=this.glContext.getEncoder(i,r.channels||1,o);if(r.isPacked&&o===1)throw new Error("not implemented");let l=r.width,d=r.height,h,g;if(this.config.reuseTextures){h=`${l}x${d}_${a.format}_${a.internalFormat}_${a.textureType}`,g=this.inUseTextures.get(h),g||(g=[],this.inUseTextures.set(h,g));let w=this.idleTextures.get(h);if(w&&w.length>0){let x=w.pop();return g.push(x),o===1&&this.glContext.updateTexture(x,l,d,a,this.toTextureData(e,t)),x}}Ye.verbose("TextureManager",`Creating new texture of size ${r.width}x${r.height}`);let _=this.glContext.allocateTexture(l,d,a,this.toTextureData(e,t));return this.config.reuseTextures&&(g.push(_),this.textureLookup.set(_,h)),_}readTexture(e,r,t){return t||(t=1),this.profiler.event("backend","TextureManager.readTexture",()=>{let o=e.shape.reduce((a,l)=>a*l)*t,i=this.glContext.readTexture(e.texture,e.width,e.height,o,this.toEncoderType(r),t);return this.toTensorData(r,i)})}async readTextureAsync(e,r,t){let o=e.tensor.dataId;if(t||(t=1),this.pendingRead.has(o)){let i=this.pendingRead.get(o);return new Promise(a=>i?.push(a))}return this.profiler.event("backend","TextureManager.readTextureAsync",async()=>{this.pendingRead.set(o,[]);let i=e.shape.reduce((h,g)=>h*g)*t;await this.glContext.createAndWaitForFence();let a=this.glContext.readTexture(e.texture,e.width,e.height,i,this.toEncoderType(r),t),l=this.toTensorData(r,a),d=this.pendingRead.get(o);return this.pendingRead.delete(o),d?.forEach(h=>h(l)),l})}readUint8TextureAsFloat(e){return this.profiler.event("backend","TextureManager.readUint8TextureAsFloat",()=>{let r=e.shape.reduce((o,i)=>o*i),t=this.glContext.readTexture(e.texture,e.width,e.height,r*4,"byte",4);return new Float32Array(t.buffer,t.byteOffset,r)})}releaseTexture(e,r){let t;if(this.config.reuseTextures&&(t=this.textureLookup.get(e.texture),t)){r&&this.textureLookup.delete(t);let o=this.inUseTextures.get(t);if(o){let i=o.indexOf(e.texture);if(i!==-1){o.splice(i,1);let a=this.idleTextures.get(t);a||(a=[],this.idleTextures.set(t,a)),a.push(e.texture)}}}(!t||r)&&(Ye.verbose("TextureManager",`Deleting texture of size ${e.width}x${e.height}`),this.glContext.deleteTexture(e.texture))}toTensorData(e,r){switch(e){case"int16":return r instanceof Int16Array?r:Int16Array.from(r);case"int32":return r instanceof Int32Array?r:Int32Array.from(r);case"int8":return r instanceof Int8Array?r:Int8Array.from(r);case"uint16":return r instanceof Uint16Array?r:Uint16Array.from(r);case"uint32":return r instanceof Uint32Array?r:Uint32Array.from(r);case"uint8":case"bool":return r instanceof Uint8Array?r:Uint8Array.from(r);case"float32":return r instanceof Float32Array?r:Float32Array.from(r);case"float64":return r instanceof Float64Array?r:Float64Array.from(r);default:throw new Error(`TensorData type ${e} is not supported`)}}toTextureData(e,r){if(r)return r instanceof Float32Array?r:new Float32Array(r)}toEncoderType(e){return"float"}clearActiveTextures(){this.glContext.clearActiveTextures()}}});var va,Dw=H(()=>{"use strict";Wt();wb();I_();yw();Pw();vc();Ew();va=class{constructor(e,r){this.backend=e;this.context=r;this.layoutStrategy=new da(e.glContext.maxTextureSize),this.programManager=new ya(this.context.profiler,e.glContext,this.layoutStrategy),this.textureManager=new _a(e.glContext,this.layoutStrategy,this.context.profiler,{reuseTextures:e.textureCacheMode==="full"}),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map,this.pack=e.pack,this.pack2unpackMap=new Map,this.unpack2packMap=new Map}createInferenceHandler(){return new ea(this)}onGraphInitialized(e){let r=e.getValues().filter(t=>t.from===-1&&t.tensor).map(t=>t.tensor.dataId);this.initializers=new Set(r)}isInitializer(e){return this.initializers?this.initializers.has(e):!1}addInitializer(e){this.initializers.add(e)}getTextureData(e,r){return r?this.packedTextureDataCache.get(e):this.unpackedTextureDataCache.get(e)}setTextureData(e,r,t=!1){Ye.verbose("WebGLSessionHandler","Storing Texture data in cache"),t?this.packedTextureDataCache.set(e,r):this.unpackedTextureDataCache.set(e,r)}dispose(){this.programManager.dispose(),this.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(e=>this.textureManager.releaseTexture(e,!0)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(e=>this.textureManager.releaseTexture(e,!0)),this.unpackedTextureDataCache=new Map}resolve(e,r,t){let o=vb(e,r,bw);return{impl:o.opImpl,context:o.opInit?o.opInit(e,t):e}}}});function ZL(n){let e=0;for(;e{"use strict";At();qo();qo();Jr();Qo=class{constructor(e,r){this.frameBufferBound=!1;this.itemsToPoll=[];this.gl=e,this.version=r,this.getExtensions(),this.vertexbuffer=this.createVertexbuffer(),this.framebuffer=this.createFramebuffer(),this.queryVitalParameters()}allocateTexture(e,r,t,o){let i=this.gl,a=i.createTexture();i.bindTexture(i.TEXTURE_2D,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let l=o?t.encode(o,e*r):null;return i.texImage2D(i.TEXTURE_2D,0,t.internalFormat,e,r,0,t.format,t.textureType,l),this.checkError(),a}updateTexture(e,r,t,o,i){let a=this.gl;a.bindTexture(a.TEXTURE_2D,e);let l=o.encode(i,r*t);a.texSubImage2D(a.TEXTURE_2D,0,0,0,r,t,o.format,o.textureType,l),this.checkError()}attachFramebuffer(e,r,t){let o=this.gl;o.bindTexture(o.TEXTURE_2D,e),o.bindFramebuffer(o.FRAMEBUFFER,this.framebuffer),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,e,0),this.checkError(),o.viewport(0,0,r,t),o.scissor(0,0,r,t)}readTexture(e,r,t,o,i,a){let l=this.gl;a||(a=1),this.frameBufferBound||this.attachFramebuffer(e,r,t);let d=this.getEncoder(i,a),h=d.allocate(r*t);return l.bindTexture(l.TEXTURE_2D,e),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,e,0),l.readPixels(0,0,r,t,l.RGBA,d.textureType,h),this.checkError(),d.decode(h,o)}isFramebufferReady(){return!0}getActiveTexture(){let e=this.gl;return`TEXTURE${e.getParameter(this.gl.ACTIVE_TEXTURE)-e.TEXTURE0}`}getTextureBinding(){return this.gl.getParameter(this.gl.TEXTURE_BINDING_2D)}getFramebufferBinding(){return this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING)}setVertexAttributes(e,r){let t=this.gl;t.vertexAttribPointer(e,3,t.FLOAT,!1,20,0),t.enableVertexAttribArray(e),r!==-1&&(t.vertexAttribPointer(r,2,t.FLOAT,!1,20,12),t.enableVertexAttribArray(r)),this.checkError()}createProgram(e,r){let t=this.gl,o=t.createProgram();return t.attachShader(o,e),t.attachShader(o,r),t.linkProgram(o),o}compileShader(e,r){let t=this.gl,o=t.createShader(r);if(!o)throw new Error(`createShader() returned null with type ${r}`);if(t.shaderSource(o,e),t.compileShader(o),t.getShaderParameter(o,t.COMPILE_STATUS)===!1)throw new Error(`Failed to compile shader: ${t.getShaderInfoLog(o)} +Shader source: +${e}`);return o}deleteShader(e){this.gl.deleteShader(e)}bindTextureToUniform(e,r,t){let o=this.gl;o.activeTexture(o.TEXTURE0+r),this.checkError(),o.bindTexture(o.TEXTURE_2D,e),this.checkError(),o.uniform1i(t,r),this.checkError()}draw(){this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),this.checkError()}checkError(){if(Ae.debug){let e=this.gl,r=e.getError(),t="";switch(r){case e.NO_ERROR:return;case e.INVALID_ENUM:t="INVALID_ENUM";break;case e.INVALID_VALUE:t="INVALID_VALUE";break;case e.INVALID_OPERATION:t="INVALID_OPERATION";break;case e.INVALID_FRAMEBUFFER_OPERATION:t="INVALID_FRAMEBUFFER_OPERATION";break;case e.OUT_OF_MEMORY:t="OUT_OF_MEMORY";break;case e.CONTEXT_LOST_WEBGL:t="CONTEXT_LOST_WEBGL";break;default:t=`Unknown WebGL Error: ${r.toString(16)}`}throw new Error(t)}}deleteTexture(e){this.gl.deleteTexture(e)}deleteProgram(e){this.gl.deleteProgram(e)}getEncoder(e,r,t=0){if(this.version===2)return new Qi(this.gl,r);switch(e){case"float":return t===1||this.isRenderFloat32Supported?new Ho(this.gl,r):new Ho(this.gl,r,this.textureHalfFloatExtension.HALF_FLOAT_OES);case"int":throw new Error("not implemented");case"byte":return new Yi(this.gl,r);default:throw new Error(`Invalid dataType: ${e}`)}}clearActiveTextures(){let e=this.gl;for(let r=0;rthis.isTimerResultAvailable(e)),this.getTimerResult(e)}async createAndWaitForFence(){let e=this.createFence(this.gl);return this.pollFence(e)}createFence(e){let r,t=e,o=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),o===null?r=()=>!0:r=()=>{let i=t.clientWaitSync(o,0,0);return i===t.ALREADY_SIGNALED||i===t.CONDITION_SATISFIED},{query:o,isFencePassed:r}}async pollFence(e){return new Promise(r=>{this.addItemToPoll(()=>e.isFencePassed(),()=>r())})}pollItems(){let e=ZL(this.itemsToPoll.map(r=>r.isDoneFn));for(let r=0;r<=e;++r){let{resolveFn:t}=this.itemsToPoll[r];t()}this.itemsToPoll=this.itemsToPoll.slice(e+1)}async addItemToPoll(e,r){this.itemsToPoll.push({isDoneFn:e,resolveFn:r}),!(this.itemsToPoll.length>1)&&await Hl(()=>(this.pollItems(),this.itemsToPoll.length===0))}}});function xc(n){let e;if((!n||n==="webgl2")&&"webgl2"in wo?e=wo.webgl2:(!n||n==="webgl")&&"webgl"in wo&&(e=wo.webgl),!e)try{let t=YL();e=Nw(t,n)}catch{let o=QL();e=Nw(o,n)}n=n||e.version===1?"webgl":"webgl2";let r=e.gl;return wo[n]=e,r.isContextLost()?(delete wo[n],xc(n)):(r.disable(r.DEPTH_TEST),r.disable(r.STENCIL_TEST),r.disable(r.BLEND),r.disable(r.DITHER),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SAMPLE_COVERAGE),r.enable(r.SCISSOR_TEST),r.enable(r.CULL_FACE),r.cullFace(r.BACK),e)}function Nw(n,e){let r={alpha:!1,depth:!1,antialias:!1,stencil:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1,failIfMajorPerformanceCaveat:!1},t,o=r;if((!e||e==="webgl2")&&(t=n.getContext("webgl2",o),t))try{return new Qo(t,2)}catch(i){Ye.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl2'. Error: ${i}`)}if((!e||e==="webgl")&&(t=n.getContext("webgl",o)||n.getContext("experimental-webgl",o),t))try{return new Qo(t,1)}catch(i){Ye.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${i}`)}throw new Error("WebGL is not supported")}function QL(){if(typeof document>"u")throw new TypeError("failed to create canvas: document is not supported");let n=document.createElement("canvas");return n.width=1,n.height=1,n}function YL(){if(typeof OffscreenCanvas>"u")throw new TypeError("failed to create offscreen canvas: OffscreenCanvas is not supported");return new OffscreenCanvas(1,1)}var wo,Lw=H(()=>{"use strict";Wt();kw();wo={}});var wa,Rw=H(()=>{"use strict";At();Wt();Dw();Lw();wa=class{get contextId(){return Ae.webgl.contextId}set contextId(e){Ae.webgl.contextId=e}get matmulMaxBatchSize(){return Ae.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(e){Ae.webgl.matmulMaxBatchSize=e}get textureCacheMode(){return Ae.webgl.textureCacheMode}set textureCacheMode(e){Ae.webgl.textureCacheMode=e}get pack(){return Ae.webgl.pack}set pack(e){Ae.webgl.pack=e}get async(){return Ae.webgl.async}set async(e){Ae.webgl.async=e}initialize(){try{return this.glContext=xc(this.contextId),typeof this.matmulMaxBatchSize!="number"&&(this.matmulMaxBatchSize=16),typeof this.textureCacheMode!="string"&&(this.textureCacheMode="full"),typeof this.pack!="boolean"&&(this.pack=!1),typeof this.async!="boolean"&&(this.async=!1),Ye.setWithEnv(Ae),Ae.webgl.context||Object.defineProperty(Ae.webgl,"context",{value:this.glContext.gl}),Ye.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(e){return Ye.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${e}`),!1}}createSessionHandler(e){return new va(this,e)}dispose(){this.glContext.dispose()}}});async function Tc(n){if(n){let e=typeof n=="string"?[n]:n;for(let r of e){let t=zw.get(r);if(t)return t;let o=await tR(r);if(o)return o}}else return Tc(["webgl"]);throw new Error("no available backend to use")}async function tR(n){let e=eR;if(typeof e[n]<"u"&&rR(e[n])){let r=e[n],t=r.initialize();if(typeof t=="object"&&"then"in t&&(t=await t),t)return zw.set(n,r),r}}function rR(n){let e=n;return"initialize"in e&&typeof e.initialize=="function"&&"createSessionHandler"in e&&typeof e.createSessionHandler=="function"&&"dispose"in e&&typeof e.dispose=="function"}var zw,eR,Mw=H(()=>{"use strict";Rw();zw=new Map,eR={webgl:new wa}});var Ic,xa,Bw=H(()=>{"use strict";Wt();Ic=class{constructor(e,r){this.op=e;this.node=r}},xa=class{constructor(e,r,t){this.graph=e;this.profiler=t;this.initialize(r)}initialize(e){this.profiler.event("session","ExecutionPlan.initialize",()=>{let r=this.graph.getNodes();if(r.length!==e.length)throw new Error("The size of nodes and OPs do not match.");this._ops=e.map((t,o)=>new Ic(t,r[o])),this.reset(),this._starter=[],this._ops.forEach((t,o)=>{let i=!0;for(let a of t.node.inputs)if(!this._values[a]&&this.graph.getInputIndices().indexOf(a)===-1){i=!1;break}i&&this._starter.push(o)})})}reset(){this._values=this.graph.getValues().map(e=>e.tensor)}async execute(e,r){return this.profiler.event("session","ExecutionPlan.execute",async()=>{this.reset();let t=e.createInferenceHandler(),o=this.graph.getInputIndices();if(r.length!==o.length)throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${r.length} expected: ${o.length}`);r.forEach((g,_)=>{let w=o[_];this._values[w]=g});let i=this._starter.slice(0),a=this.graph.getValues(),l=this.graph.getNodes(),d=0;for(;dthis._values[P]);if(w.indexOf(void 0)!==-1)throw new Error(`unresolved input detected: op: ${_.node}`);let x=w;Ye.verbose("ExecPlan",`Running op:${_.node.name} (${x.map((P,A)=>`'${_.node.inputs[A]}': ${P.type}[${P.dims.join(",")}]`).join(", ")})`);let T=await this.profiler.event("node",_.node.name,async()=>_.op.impl(t,x,_.op.context));if(T.length!==_.node.outputs.length)throw new Error("the size of output does not match model definition.");T.forEach((P,A)=>{let O=_.node.outputs[A];if(this._values[O])throw new Error(`output [${O}] already has value: op:${_.node.name}`);this._values[O]=P});let S=new Set;T.forEach((P,A)=>{let O=_.node.outputs[A];for(let E of a[O].to){let L=l[E],z=!0;for(let B of L.inputs)if(!this._values[B]){z=!1;break}z&&S.add(E)}}),i.push(...S)}let h=[];for(let g=0;g{"use strict";Fo();Me=Ne(fo());Kn();Ze();Yo=class n{constructor(e){if(this._attributes=new Map,e!=null){for(let r of e)r instanceof Me.onnx.AttributeProto?this._attributes.set(r.name,[n.getValue(r),n.getType(r)]):r instanceof Ui.Attribute&&this._attributes.set(r.name(),[n.getValue(r),n.getType(r)]);if(this._attributes.sizeyt.fromProto(i));if(e instanceof Ui.Attribute)return t.map(i=>yt.fromOrtTensor(i))}return r===Me.onnx.AttributeProto.AttributeType.STRING&&e instanceof Me.onnx.AttributeProto?Wo(t):r===Me.onnx.AttributeProto.AttributeType.STRINGS&&e instanceof Me.onnx.AttributeProto?t.map(Wo):t}static getValueNoCheck(e){return e instanceof Me.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(e):this.getValueNoCheckFromOrtFormat(e)}static getValueNoCheckFromOnnxFormat(e){switch(e.type){case Me.onnx.AttributeProto.AttributeType.FLOAT:return e.f;case Me.onnx.AttributeProto.AttributeType.INT:return e.i;case Me.onnx.AttributeProto.AttributeType.STRING:return e.s;case Me.onnx.AttributeProto.AttributeType.TENSOR:return e.t;case Me.onnx.AttributeProto.AttributeType.GRAPH:return e.g;case Me.onnx.AttributeProto.AttributeType.FLOATS:return e.floats;case Me.onnx.AttributeProto.AttributeType.INTS:return e.ints;case Me.onnx.AttributeProto.AttributeType.STRINGS:return e.strings;case Me.onnx.AttributeProto.AttributeType.TENSORS:return e.tensors;case Me.onnx.AttributeProto.AttributeType.GRAPHS:return e.graphs;default:throw new Error(`unsupported attribute type: ${Me.onnx.AttributeProto.AttributeType[e.type]}`)}}static getValueNoCheckFromOrtFormat(e){switch(e.type()){case Xt.AttributeType.FLOAT:return e.f();case Xt.AttributeType.INT:return e.i();case Xt.AttributeType.STRING:return e.s();case Xt.AttributeType.TENSOR:return e.t();case Xt.AttributeType.GRAPH:return e.g();case Xt.AttributeType.FLOATS:return e.floatsArray();case Xt.AttributeType.INTS:{let r=[];for(let t=0;t{"use strict";Fw();Fo();$c=Ne(fo());Kn();Ze();Ac={from:(n,e)=>new Sc(n,e)},Yr=class{constructor(e){this._from=void 0,this._to=[],this.tensor=void 0,this.type=void 0,e&&(this.type=$t.tensorValueTypeFromProto(e.type.tensorType))}get from(){return this._from}get to(){return this._to}},Ta=class{constructor(e,r){e instanceof $c.onnx.NodeProto?(this.name=e.name,this.opType=e.opType,this.attributes=new Yo(e.attribute)):e instanceof Ol.Node&&(this.name=r??e.name(),this.opType=e.opType(),this.attributes=new Yo($t.tensorAttributesFromORTFormat(e))),this.inputs=[],this.outputs=[],this.executeNode=!0}},Sc=class{constructor(e,r){if(!e)throw new TypeError("graph is empty");this.buildGraph(e),this.transformGraph(r),this.checkIsAcyclic()}getInputIndices(){return this._allInputIndices}getInputNames(){return this._allInputNames}getOutputIndices(){return this._allOutputIndices}getOutputNames(){return this._allOutputNames}getValues(){return this._allData}getNodes(){return this._nodes}buildGraph(e){if(e instanceof $c.onnx.GraphProto)this.buildGraphFromOnnxFormat(e);else if(e instanceof $l.Graph)this.buildGraphFromOrtFormat(e);else throw new TypeError("Graph type is not supported.")}buildGraphFromOnnxFormat(e){let r=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map;if(!e.input)throw new Error("missing information in graph: input");let o=[];for(let i of e.input){if(r.has(i.name))throw new Error(`duplicated input name: ${i.name}`);let a=this._allData.push(new Yr(i))-1;r.set(i.name,a),o.push(i.name)}if(!e.initializer)throw new Error("missing information in graph: initializer");for(let i of e.initializer){let a=r.get(i.name);if(a===void 0){let l=new Yr;l.type={shape:{dims:$t.tensorDimsFromProto(i.dims)},tensorType:$t.tensorDataTypeFromProto(i.dataType)},a=this._allData.push(l)-1,r.set(i.name,a)}this._allData[a]._from=-1,this._allData[a].tensor=yt.fromProto(i)}for(let i=0;i"u"&&(h=this._allData.push(new Yr)-1,r.set(d,h)),a.outputs.push(h),this._allData[h]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${h}`);if(this._allData[h]._from=i,l.opType==="Constant"){if(!l.attribute||l.attribute.length!==1||!l.attribute[0].t)throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(!l.output||l.output.length!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");a.outputs.pop(),a.executeNode=!1,this._allData[h]._from=-1,this._allData[h].tensor=yt.fromProto(l.attribute[0].t)}}}for(let i=0;i"u"){if(d===""&&(l.input.length===3||l.input.length===4)&&l.opType==="Resize")continue;throw new Error(`unrecognized input '${d}' for node: ${l.name}`)}a.inputs.push(h),this._allData[h]._to.push(i)}}return!0}buildGraphFromOrtFormat(e){let r=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map,o=[];for(let i=0;i"u"&&(g=this._allData.push(new Yr)-1,r.set(h,g)),a.outputs.push(g),this._allData[g]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${g}`);if(this._allData[g]._from=i,l.opType()==="Constant"){if(l.attributesLength()!==1||!l.attributes(0).t())throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(l.outputsLength()!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");a.outputs.pop(),a.executeNode=!1,this._allData[g]._from=-1,this._allData[g].tensor=yt.fromOrtTensor(l.attributes(0).t())}}}for(let i=0;i"u")throw new Error(`unrecognized input '${h}' for node: ${l.name()}`);a.inputs.push(g),this._allData[g]._to.push(i)}}}checkIsAcyclic(){let e=new Set;this._allInputIndices.forEach(o=>{this._allData[o]._to.forEach(a=>{e.add(a)})});let r=Array.from(e),t=new Array(this._nodes.length).fill("white");for(;r.length>0;){let o=r.pop();t[o]==="gray"?t[o]="black":(r.push(o),t[o]="gray",this._nodes[o].outputs.forEach(i=>{let a=this._allData[i];if(typeof a.tensor<"u")throw new Error("node outputs should not be initialized");if(a._from!==o)throw new Error("from property of the Value object doesn't match index of Node being processed");a._to.forEach(l=>{if(t[l]==="gray")throw new Error("model graph is cyclic");t[l]==="white"&&r.push(l)})}))}}transformGraph(e){this.removeAllIdentityNodes(),this.removeAllDropoutNodes(),this.fuseConvActivationNodes(),e&&e.transformGraph(this),this.finalizeGraph()}finalizeGraph(){let e=0,r=new Array(this._nodes.length,0),t=0;for(let o=0;o{this._allData[i]._from=-2});this._nodes.splice(t,this._nodes.length-t);for(let o=0;o=0)i._to[a]=r[i._to[a]];else throw new Error("Trying to update a removed node")}e=0;for(let o=0;o0){let i=-1;this._allData[o].from!==void 0&&this._allData[o].from!==-1?(i=this._nodes[this._allData[o].from].outputs.indexOf(o+e),i!==-1&&(this._nodes[this._allData[o].from].outputs[i]=o)):(i=this._allInputIndices.indexOf(o+e),i!==-1&&(this._allInputIndices[i]=o)),this._allData[o].to.forEach(a=>{i=this._nodes[a].inputs.indexOf(o+e),i!==-1&&(this._nodes[a].inputs[i]=o)}),this._allData[o].to.length===0&&(i=this._allOutputIndices.indexOf(o+e),i!==-1&&(this._allOutputIndices[i]=o))}}}deleteNode(e){let r=this._nodes[e];if(r.outputs.length>1){for(let l=1;l0)throw new Error("Node deletion with more than one output connected to other nodes is not supported. ")}r.executeNode=!1;let t=r.inputs[0],o=r.outputs[0],i=this._allData[o].to;for(let l=0;l0)for(let l of i){let d=this._nodes[l].inputs.indexOf(o);if(d===-1)throw new Error("The Node object doesn't have the output Value in it's 'inputs' property ");this._nodes[l].inputs[d]=t,this._allData[t].to.push(l)}}removeAllDropoutNodes(){let e=0;for(let r of this._nodes){if(r.opType==="Dropout"){if(r.inputs.length!==1)throw new Error("Dropout nodes should only contain one input. ");if(r.outputs.length!==1&&r.outputs.length!==2)throw new Error("Dropout nodes should contain either 1 or 2 output(s)");if(r.outputs.length===2&&this._allData[r.outputs[1]]._to.length!==0)throw new Error("Dropout nodes's second output should not be referenced by other nodes");this.deleteNode(e)}e++}}removeAllIdentityNodes(){let e=0;for(let r of this._nodes)r.opType==="Identity"&&this.deleteNode(e),e++}isActivation(e){switch(e.opType){case"Relu":case"Sigmoid":case"Clip":return!0;default:return!1}}fuseConvActivationNodes(){for(let e of this._nodes)if(e.opType==="Conv"){let r=this._allData[e.outputs[0]]._to;if(r.length===1&&this.isActivation(this._nodes[r[0]])){let t=this._nodes[r[0]];if(t.opType==="Clip")if(t.inputs.length===1)try{e.attributes.set("activation_params","floats",[t.attributes.getFloat("min"),t.attributes.getFloat("max")])}catch{e.attributes.set("activation_params","floats",[Hn,qn])}else if(t.inputs.length>=3&&this._allData[t.inputs[1]].tensor!==void 0&&this._allData[t.inputs[2]].tensor!==void 0)e.attributes.set("activation_params","floats",[this._allData[t.inputs[1]].tensor.floatData[0],this._allData[t.inputs[2]].tensor.floatData[0]]);else continue;e.attributes.set("activation","string",t.opType),this.deleteNode(r[0])}}}}});var jw,Gw,Ia,Uw=H(()=>{"use strict";jw=Ne(Je());Vw();Fo();Gw=Ne(fo());Ze();Ia=class{constructor(){}load(e,r,t){let o;if(!t)try{this.loadFromOnnxFormat(e,r);return}catch(i){if(t!==void 0)throw i;o=i}try{this.loadFromOrtFormat(e,r)}catch(i){throw t!==void 0?i:new Error(`Failed to load model as ONNX format: ${o} +as ORT format: ${i}`)}}loadFromOnnxFormat(e,r){let t=Gw.onnx.ModelProto.decode(e);if(Rt.longToNumber(t.irVersion)<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=t.opsetImport.map(i=>({domain:i.domain,version:Rt.longToNumber(i.version)})),this._graph=Ac.from(t.graph,r)}loadFromOrtFormat(e,r){let t=new jw.ByteBuffer(e),o=Al.InferenceSession.getRootAsInferenceSession(t).model();if(Rt.longToNumber(o.irVersion())<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=[];for(let a=0;a{"use strict";Mw();Bw();Wt();Uw();Sa=class{constructor(e={}){this._initialized=!1,this.backendHint=e.backendHint,this.profiler=Pi.create(e.profiler),this.context={profiler:this.profiler,graphInputTypes:[],graphInputDims:[]}}get inputNames(){return this._model.graph.getInputNames()}get outputNames(){return this._model.graph.getOutputNames()}startProfiling(){this.profiler.start()}endProfiling(){this.profiler.stop()}async loadModel(e,r,t){await this.profiler.event("session","Session.loadModel",async()=>{let o=await Tc(this.backendHint);if(this.sessionHandler=o.createSessionHandler(this.context),this._model=new Ia,typeof e=="string"){let i=e.endsWith(".ort");{let l=await(await fetch(e)).arrayBuffer();this.initialize(new Uint8Array(l),i)}}else if(ArrayBuffer.isView(e))this.initialize(e);else{let i=new Uint8Array(e,r||0,t||e.byteLength);this.initialize(i)}})}initialize(e,r){if(this._initialized)throw new Error("already initialized");this.profiler.event("session","Session.initialize",()=>{let t=this.sessionHandler.transformGraph?this.sessionHandler:void 0;this._model.load(e,t,r),this.sessionHandler.onGraphInitialized&&this.sessionHandler.onGraphInitialized(this._model.graph),this.initializeOps(this._model.graph),this._executionPlan=new xa(this._model.graph,this._ops,this.profiler)}),this._initialized=!0}async run(e){if(!this._initialized)throw new Error("session not initialized yet");return this.profiler.event("session","Session.run",async()=>{let r=this.normalizeAndValidateInputs(e),t=await this._executionPlan.execute(this.sessionHandler,r);return this.createOutput(t)})}normalizeAndValidateInputs(e){let r=this._model.graph.getInputNames();if(Array.isArray(e)){if(e.length!==r.length)throw new Error(`incorrect input array length: expected ${r.length} but got ${e.length}`)}else{if(e.size!==r.length)throw new Error(`incorrect input map size: expected ${r.length} but got ${e.size}`);let t=new Array(e.size),o=0;for(let i=0;i{"use strict";At();Kn();$a=class{constructor(e){this.session=e;this.inputNames=this.session.inputNames,this.outputNames=this.session.outputNames}get inputMetadata(){throw new Error("Getting model metadata is not supported in webgl backend.")}get outputMetadata(){throw new Error("Getting model metadata is not supported in webgl backend.")}async dispose(){}async run(e,r,t){let o=new Map;for(let l in e)if(Object.hasOwnProperty.call(e,l)){let d=e[l];o.set(l,new yt(d.dims,d.type,void 0,void 0,d.data))}let i=await this.session.run(o),a={};return i.forEach((l,d)=>{a[d]=new Bt(l.type,l.data,l.dims)}),a}startProfiling(){this.session.startProfiling()}endProfiling(){this.session.endProfiling()}}});var qw={};zn(qw,{onnxjsBackend:()=>nR});var Oc,nR,Kw=H(()=>{"use strict";Ww();Hw();Oc=class{async init(){}async createInferenceSessionHandler(e,r){let t=new Sa(r);return typeof e=="string"?await t.loadModel(e):await t.loadModel(e),new $a(t)}},nR=new Oc});var Aa=H(()=>{"use strict"});var Zw={};zn(Zw,{default:()=>oR});var Xw,Jw,oR,Qw=H(()=>{"use strict";Cc();On();Oa();Xw="ort-wasm-proxy-worker",Jw=globalThis.self?.name===Xw;Jw&&(self.onmessage=n=>{let{type:e,in:r}=n.data;try{switch(e){case"init-wasm":Ca(r.wasm).then(()=>{Pa(r).then(()=>{postMessage({type:e})},t=>{postMessage({type:e,err:t})})},t=>{postMessage({type:e,err:t})});break;case"init-ep":{let{epName:t,env:o}=r;Ea(o,t).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:t}=r,o=ei(t);postMessage({type:e,out:o});break}case"create":{let{model:t,options:o}=r;Da(t,o).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":ka(r),postMessage({type:e});break;case"run":{let{sessionId:t,inputIndices:o,inputs:i,outputIndices:a,options:l}=r;Na(t,o,i,a,new Array(a.length).fill(null),l).then(d=>{d.some(h=>h[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:d},Ra([...i,...d]))},d=>{postMessage({type:e,err:d})});break}case"end-profiling":La(r),postMessage({type:e});break;default:}}catch(t){postMessage({type:e,err:t})}});oR=Jw?null:n=>new Worker(n??jt,{type:"module",name:Xw})});var ex={};zn(ex,{default:()=>iR});var Pc,Yw,iR,aR,tx=H(()=>{"use strict";Yw=(Pc=import.meta.url,async function(n={}){var e,r,t=n,o=new Promise((s,u)=>{e=s,r=u}),i=typeof window=="object",a=typeof WorkerGlobalScope<"u",l=a&&self.name?.startsWith("em-pthread");t.mountExternalData=(s,u)=>{s.startsWith("./")&&(s=s.substring(2)),(t.MountedFiles||(t.MountedFiles=new Map)).set(s,u)},t.unmountExternalData=()=>{delete t.MountedFiles};var d=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor;let h=s=>async(...u)=>{try{if(t.jsepSessionState)throw new Error("Session already started");let c=t.jsepSessionState={sessionHandle:u[0],errors:[]},p=await s(...u);if(t.jsepSessionState!==c)throw new Error("Session mismatch");t.jsepBackend?.flush();let f=c.errors;if(f.length>0){let m=await Promise.all(f);if(m=m.filter(b=>b),m.length>0)throw new Error(m.join(` +`))}return p}finally{t.jsepSessionState=null}};t.jsepInit=(s,u)=>{if(s==="webgpu"){[t.jsepBackend,t.jsepAlloc,t.jsepFree,t.jsepCopy,t.jsepCopyAsync,t.jsepCreateKernel,t.jsepReleaseKernel,t.jsepRunKernel,t.jsepCaptureBegin,t.jsepCaptureEnd,t.jsepReplay]=u;let c=t.jsepBackend;t.jsepRegisterBuffer=(p,f,m,b)=>c.registerBuffer(p,f,m,b),t.jsepGetBuffer=p=>c.getBuffer(p),t.jsepCreateDownloader=(p,f,m)=>c.createDownloader(p,f,m),t.jsepOnCreateSession=p=>{c.onCreateSession(p)},t.jsepOnReleaseSession=p=>{c.onReleaseSession(p)},t.jsepOnRunStart=p=>c.onRunStart(p),t.jsepUploadExternalBuffer=(p,f)=>{c.upload(p,f)}}else if(s==="webnn"){let c=u[0];[t.webnnReserveTensorId,t.webnnReleaseTensorId,t.webnnEnsureTensor,t.webnnUploadTensor,t.webnnDownloadTensor]=u.slice(1),t.webnnReleaseTensorId=t.webnnReleaseTensorId,t.webnnUploadTensor=t.webnnUploadTensor,t.webnnOnRunStart=p=>c.onRunStart(p),t.webnnOnRunEnd=c.onRunEnd.bind(c),t.webnnRegisterMLContext=(p,f)=>{c.registerMLContext(p,f)},t.webnnOnReleaseSession=p=>{c.onReleaseSession(p)},t.webnnCreateMLTensorDownloader=(p,f)=>c.createMLTensorDownloader(p,f),t.webnnRegisterMLTensor=(p,f,m,b)=>c.registerMLTensor(p,f,m,b),t.webnnCreateMLContext=p=>c.createMLContext(p),t.webnnRegisterMLConstant=(p,f,m,b,y,v)=>c.registerMLConstant(p,f,m,b,y,t.MountedFiles,v),t.webnnRegisterGraphInput=c.registerGraphInput.bind(c),t.webnnIsGraphInput=c.isGraphInput.bind(c),t.webnnRegisterGraphOutput=c.registerGraphOutput.bind(c),t.webnnIsGraphOutput=c.isGraphOutput.bind(c),t.webnnCreateTemporaryTensor=c.createTemporaryTensor.bind(c),t.webnnIsGraphInputOutputTypeSupported=c.isGraphInputOutputTypeSupported.bind(c)}};let g=()=>{let s=(u,c,p)=>(...f)=>{let m=ye.currData,b=c?.(),y=u(...f),v=c?.();return b!==v&&(u=v,p(b),p=null,c=null),ye.currData!=m?ye.whenDone():y};(()=>{for(let u of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])t[u]=s(t[u],()=>t[u],c=>t[u]=c)})(),h!==void 0&&(t._OrtRun=h(t._OrtRun),t._OrtRunWithBinding=h(t._OrtRunWithBinding)),g=void 0};t.asyncInit=()=>{g?.()};var _,w,x=Object.assign({},t),T=(s,u)=>{throw u},S="";(i||a)&&(a?S=self.location.href:typeof document<"u"&&document.currentScript&&(S=document.currentScript.src),Pc&&(S=Pc),S=S.startsWith("blob:")?"":S.slice(0,S.replace(/[?#].*/,"").lastIndexOf("/")+1),a&&(w=s=>{var u=new XMLHttpRequest;return u.open("GET",s,!1),u.responseType="arraybuffer",u.send(null),new Uint8Array(u.response)}),_=async s=>{if(me(s))return new Promise((c,p)=>{var f=new XMLHttpRequest;f.open("GET",s,!0),f.responseType="arraybuffer",f.onload=()=>{f.status==200||f.status==0&&f.response?c(f.response):p(f.status)},f.onerror=p,f.send(null)});var u=await fetch(s,{credentials:"same-origin"});if(u.ok)return u.arrayBuffer();throw new Error(u.status+" : "+u.url)});var P=console.log.bind(console),A=console.error.bind(console),O=P,E=A;Object.assign(t,x),x=null;var L,z,B,K,Z,ee,ae,pe,he,Se,oe,Be,xe,ue=t.wasmBinary,Ee=!1,me=s=>s.startsWith("file://");function Te(){return L.buffer!=K.buffer&&je(),K}function Ue(){return L.buffer!=K.buffer&&je(),Z}function rt(){return L.buffer!=K.buffer&&je(),ee}function Ie(){return L.buffer!=K.buffer&&je(),ae}function j(){return L.buffer!=K.buffer&&je(),pe}function U(){return L.buffer!=K.buffer&&je(),he}function ze(){return L.buffer!=K.buffer&&je(),Se}function lt(){return L.buffer!=K.buffer&&je(),xe}if(l){let s=function(...p){var f=p.join(" ");console.error(f)},u=function(...p){var f=p.join(" ");postMessage({cmd:"alert",text:f,threadId:vi()})},c=function(p){try{var f=p.data,m=f.cmd;if(m==="load"){let b=[];self.onmessage=y=>b.push(y),self.startWorker=y=>{postMessage({cmd:"loaded"});for(let v of b)c(v);self.onmessage=c};for(let y of f.handlers)t[y]&&!t[y].proxy||(t[y]=(...v)=>{postMessage({cmd:"callHandler",handler:y,args:v})},y=="print"&&(O=t[y]),y=="printErr"&&(E=t[y]));L=f.wasmMemory,je(),Et(f.wasmModule)}else if(m==="run"){KI(f.pthread_ptr),Ks(f.pthread_ptr,0,0,1,0,0),Fe.threadInitTLS(),Es(f.pthread_ptr),ct||(yp(),ct=!0);try{XI(f.start_routine,f.arg)}catch(b){if(b!="unwind")throw b}}else f.target==="setimmediate"||(m==="checkMailbox"?ct&&fi():m&&(E(`worker: received unknown command ${m}`),E(f)))}catch(b){throw Lp(),b}};var kB=s,NB=u,LB=c,Et,ct=!1;E=s,self.alert=u,self.onunhandledrejection=p=>{throw p.reason||p},self.onmessage=c}function je(){var s=L.buffer;t.HEAP8=K=new Int8Array(s),t.HEAP16=ee=new Int16Array(s),t.HEAPU8=Z=new Uint8Array(s),t.HEAPU16=ae=new Uint16Array(s),t.HEAP32=pe=new Int32Array(s),t.HEAPU32=he=new Uint32Array(s),t.HEAPF32=Se=new Float32Array(s),t.HEAPF64=xe=new Float64Array(s),t.HEAP64=oe=new BigInt64Array(s),t.HEAPU64=Be=new BigUint64Array(s)}function tr(){if(l)return startWorker(t);D.qf()}l||(L=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),je());var mn,kn=0,io=null;function _d(s){kn++}function vd(s){if(--kn==0&&io){var u=io;io=null,u()}}function fr(s){E(s="Aborted("+s+")"),Ee=!0,s+=". Build with -sASSERTIONS for more info.";var u=new WebAssembly.RuntimeError(s);throw r(u),u}async function WI(s,u,c){if(!s&&typeof WebAssembly.instantiateStreaming=="function"&&!me(u))try{var p=fetch(u,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(p,c)}catch(f){E(`wasm streaming compile failed: ${f}`),E("falling back to ArrayBuffer instantiation")}return async function(f,m){try{var b=await async function(y){if(!ue)try{var v=await _(y);return new Uint8Array(v)}catch{}return function(I){if(I==mn&&ue)return new Uint8Array(ue);if(w)return w(I);throw"both async and sync fetching of the wasm failed"}(y)}(f);return await WebAssembly.instantiate(b,m)}catch(y){E(`failed to asynchronously prepare wasm: ${y}`),fr(y)}}(u,c)}function wd(){return{a:{rd:qI,Md:HI,v:JI,_:ZI,b:YI,o:eS,A:tS,F:rS,r:nS,uc:oS,u:iS,Bb:aS,pf:Ed,g:QI,tc:Nd,of:Ld,nf:Rd,mf:zd,lf:Md,kf:Bd,jf:Fd,hf:Vd,qd:jd,gf:Gd,ff:Ud,ef:Wd,df:Hd,Ze:uS,nd:dS,Ye:pS,Xe:hS,md:gS,Ma:bS,na:yS,We:_S,rc:$S,Ve:AS,Ue:OS,Te:CS,Se:PS,Re:ES,ld:DS,Qe:Es,Pe:kS,kd:NS,Oe:LS,Ne:Qd,Ab:RS,sa:MS,Me:Os,Le:BS,Ke:FS,ma:GS,zb:US,Je:WS,Z:HS,qc:qS,Ie:KS,ha:XS,lb:JS,He:QS,Ge:YS,fb:e$,Fe:t$,Ee:o$,De:i$,Ce:rp,Be:np,Ae:op,ze:a$,cf:l$,C:c$,pc:d$,jd:p$,ye:ip,Tb:f$,xe:h$,we:m$,ba:Ds,ve:g$,Sb:b$,id:y$,ue:w$,te:x$,se:T$,re:I$,hd:S$,gd:$$,fd:A$,qe:O$,oc:C$,wa:P$,pe:E$,oe:D$,ne:k$,me:N$,le:L$,ke:cp,bf:dp,af:pp,je:xs,sc:fp,pd:hp,$e:mp,od:gp,Rb:HA,Qb:rP,qa:GP,S:WP,R:UP,Ca:NC,Ga:UA,ed:XC,nc:tP,ie:VP,Y:mC,y:OA,c:gA,dd:hO,va:LA,he:DP,cd:NP,h:hA,eb:FP,Ja:QP,d:fA,ja:BO,k:SA,ge:r3,j:wA,Pb:OP,s:_A,t:eO,q:GA,yb:iC,O:FA,Ba:FC,oa:aO,mc:fC,kb:gC,lc:vP,xb:aP,bd:FO,ad:YA,$c:UO,jb:NO,_c:jO,kc:t3,ra:MC,Ob:BA,wb:zO,da:BP,la:MO,Zc:DO,N:oC,Yc:VO,Ya:yC,H:CA,Xc:HP,vb:vO,fe:GO,Aa:JC,La:TO,B:RA,jc:JO,Wc:WO,Vc:CO,Uc:OO,ic:AO,ee:qO,Xa:yO,aa:HC,ib:XP,hc:ZP,hb:YP,db:qP,Tc:PO,Sc:e3,gc:LC,fa:WA,K:rO,D:EA,Ia:xO,U:PC,Rc:sP,Qc:KO,Pc:EO,X:XO,e:yA,cb:uC,l:bA,Oc:cO,Wa:LP,pa:kO,Nb:ZO,i:mA,Nc:lO,V:RO,ua:cC,Mb:uP,ub:QO,f:xA,de:$P,ce:TP,m:IA,Mc:lC,n:AA,be:SP,Lc:YO,ae:xP,Kc:dC,Jc:kP,$d:cP,p:$A,_d:EP,Va:xC,Lb:wC,Ua:TC,fc:oP,E:MA,G:ZA,J:jA,bb:AP,Zd:IP,Kb:sC,$:sO,ga:fO,Ha:gP,Fa:hC,Ta:ZC,Yd:eC,ab:wO,Ea:uO,Ic:bP,gb:mP,Jb:hP,Sa:lP,Xd:pC,za:YC,Wd:_P,Vd:WC,Ud:_C,ec:RC,Ra:QC,W:nO,tb:eP,Hc:BC,Ib:zC,ta:qC,Qa:mO,Gc:$O,Hb:JA,sb:HO,dc:yP,P:dO,Gb:UC,ka:KA,Td:gO,ea:jC,rb:iO,cc:wP,Fc:fP,bc:zP,Ec:RP,Dc:PP,$a:LO,Cc:KP,qb:bO,z:NA,T:tO,ya:PA,Ka:XA,Sd:_O,ac:tC,Fb:DA,L:zA,pb:iP,Da:GC,Bc:JP,Ac:nP,Rd:oO,x:kA,I:QA,ca:vA,Qd:KC,$b:OC,zc:pP,Pa:CP,_a:qA,_b:CC,Za:pO,Zb:VC,Pd:TA,Od:SO,Yb:dP,Xb:bC,ob:MP,yc:VA,Wb:nC,ia:EC,xc:rC,M:aC,nb:IO,Nd:jP,xa:kC,Q:DC,Eb:$C,Oa:SC,Na:vC,Db:AC,Cb:IC,w:M$,a:L,_e:ws,Ld:B$,Kd:F$,mb:V$,wc:j$,Jd:G$,Id:U$,Hd:W$,Gd:H$,Fd:q$,Vb:K$,Ed:X$,Dd:J$,Cd:Z$,Bd:Q$,Ad:eA,Ub:tA,zd:rA,yd:nA,xd:iA,wd:aA,vd:sA,ud:uA,vc:lA,td:cA,sd:dA}}}var xd={1635076:(s,u,c,p,f)=>{if(t===void 0||!t.MountedFiles)return 1;let m=ut(Number(s>>>0));m.startsWith("./")&&(m=m.substring(2));let b=t.MountedFiles.get(m);if(!b)return 2;let y=Number(u>>>0),v=Number(c>>>0),I=Number(p>>>0),$=f;if(y+v>b.byteLength)return 3;try{let C=b.subarray(y,y+v);switch($){case 0:Ue().set(C,I>>>0);break;case 1:t.webgpuUploadExternalBuffer?t.webgpuUploadExternalBuffer(I,C):t.jsepUploadExternalBuffer(I,C);break;default:return 4}return 0}catch{return 4}},1635900:(s,u,c)=>{let p=Number(s),f=Number(u),m=ut(c),b=new Uint8Array(f);b.set(Ue().subarray(p>>>0,p+f>>>0));{let y=new File([b],m,{type:"application/octet-stream"}),v=URL.createObjectURL(y);window.open(v,"_blank")}},1636424:(s,u,c)=>{t.webnnUploadTensor(s,Ue().subarray(u>>>0,u+c>>>0))},1636488:()=>t.webnnReserveTensorId(),1636530:s=>{t.webnnReleaseTensorId(s)},1636567:()=>{t.jsepCaptureBegin()},1636598:()=>{t.jsepCaptureEnd()},1636627:()=>{t.jsepReplay()},1636652:s=>t.jsepAlloc(s),1636685:s=>t.jsepFree(s),1636717:(s,u,c)=>{t.jsepCopy(Number(s),Number(u),Number(c),!0)},1636780:(s,u,c)=>{t.jsepCopy(Number(s),Number(u),Number(c))},1636837:()=>typeof wasmOffsetConverter<"u",1636894:s=>{t.jsepCreateKernel("Abs",s,void 0)},1636945:s=>{t.jsepCreateKernel("Neg",s,void 0)},1636996:s=>{t.jsepCreateKernel("Floor",s,void 0)},1637049:s=>{t.jsepCreateKernel("Ceil",s,void 0)},1637101:s=>{t.jsepCreateKernel("Reciprocal",s,void 0)},1637159:s=>{t.jsepCreateKernel("Sqrt",s,void 0)},1637211:s=>{t.jsepCreateKernel("Exp",s,void 0)},1637262:s=>{t.jsepCreateKernel("Erf",s,void 0)},1637313:s=>{t.jsepCreateKernel("Sigmoid",s,void 0)},1637368:(s,u,c)=>{t.jsepCreateKernel("HardSigmoid",s,{alpha:u,beta:c})},1637447:s=>{t.jsepCreateKernel("Log",s,void 0)},1637498:s=>{t.jsepCreateKernel("Sin",s,void 0)},1637549:s=>{t.jsepCreateKernel("Cos",s,void 0)},1637600:s=>{t.jsepCreateKernel("Tan",s,void 0)},1637651:s=>{t.jsepCreateKernel("Asin",s,void 0)},1637703:s=>{t.jsepCreateKernel("Acos",s,void 0)},1637755:s=>{t.jsepCreateKernel("Atan",s,void 0)},1637807:s=>{t.jsepCreateKernel("Sinh",s,void 0)},1637859:s=>{t.jsepCreateKernel("Cosh",s,void 0)},1637911:s=>{t.jsepCreateKernel("Asinh",s,void 0)},1637964:s=>{t.jsepCreateKernel("Acosh",s,void 0)},1638017:s=>{t.jsepCreateKernel("Atanh",s,void 0)},1638070:s=>{t.jsepCreateKernel("Tanh",s,void 0)},1638122:s=>{t.jsepCreateKernel("Not",s,void 0)},1638173:(s,u,c)=>{t.jsepCreateKernel("Clip",s,{min:u,max:c})},1638242:s=>{t.jsepCreateKernel("Clip",s,void 0)},1638294:(s,u)=>{t.jsepCreateKernel("Elu",s,{alpha:u})},1638352:s=>{t.jsepCreateKernel("Gelu",s,void 0)},1638404:s=>{t.jsepCreateKernel("Relu",s,void 0)},1638456:(s,u)=>{t.jsepCreateKernel("LeakyRelu",s,{alpha:u})},1638520:(s,u)=>{t.jsepCreateKernel("ThresholdedRelu",s,{alpha:u})},1638590:(s,u)=>{t.jsepCreateKernel("Cast",s,{to:u})},1638648:s=>{t.jsepCreateKernel("Add",s,void 0)},1638699:s=>{t.jsepCreateKernel("Sub",s,void 0)},1638750:s=>{t.jsepCreateKernel("Mul",s,void 0)},1638801:s=>{t.jsepCreateKernel("Div",s,void 0)},1638852:s=>{t.jsepCreateKernel("Pow",s,void 0)},1638903:s=>{t.jsepCreateKernel("Equal",s,void 0)},1638956:s=>{t.jsepCreateKernel("Greater",s,void 0)},1639011:s=>{t.jsepCreateKernel("GreaterOrEqual",s,void 0)},1639073:s=>{t.jsepCreateKernel("Less",s,void 0)},1639125:s=>{t.jsepCreateKernel("LessOrEqual",s,void 0)},1639184:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceMean",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1639359:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceMax",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1639533:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceMin",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1639707:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceProd",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1639882:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceSum",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640056:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceL1",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640229:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceL2",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640402:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceLogSum",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640579:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceSumSquare",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640759:(s,u,c,p,f)=>{t.jsepCreateKernel("ReduceLogSumExp",s,{keepDims:!!u,noopWithEmptyAxes:!!c,axes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1640939:s=>{t.jsepCreateKernel("Where",s,void 0)},1640992:(s,u,c)=>{t.jsepCreateKernel("Transpose",s,{perm:u?Array.from(j().subarray(Number(u)>>>0,Number(c)>>>0)):[]})},1641116:(s,u,c,p)=>{t.jsepCreateKernel("DepthToSpace",s,{blocksize:u,mode:ut(c),format:p?"NHWC":"NCHW"})},1641249:(s,u,c,p)=>{t.jsepCreateKernel("DepthToSpace",s,{blocksize:u,mode:ut(c),format:p?"NHWC":"NCHW"})},1641382:(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>{t.jsepCreateKernel("ConvTranspose",s,{format:v?"NHWC":"NCHW",autoPad:u,dilations:[c],group:p,kernelShape:[f],pads:[m,b],strides:[y],wIsConst:()=>!!Te()[I>>>0],outputPadding:$?Array.from(j().subarray(Number($)>>>0,Number(C)>>>0)):[],outputShape:k?Array.from(j().subarray(Number(k)>>>0,Number(R)>>>0)):[],activation:ut(X)})},1641815:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("ConvTranspose",s,{format:y?"NHWC":"NCHW",autoPad:u,dilations:Array.from(j().subarray(Number(c)>>>0,2+(Number(c)>>>0)>>>0)),group:p,kernelShape:Array.from(j().subarray(Number(f)>>>0,2+(Number(f)>>>0)>>>0)),pads:Array.from(j().subarray(Number(m)>>>0,4+(Number(m)>>>0)>>>0)),strides:Array.from(j().subarray(Number(b)>>>0,2+(Number(b)>>>0)>>>0)),wIsConst:()=>!!Te()[v>>>0],outputPadding:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],outputShape:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[],activation:ut(R)})},1642476:(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>{t.jsepCreateKernel("ConvTranspose",s,{format:v?"NHWC":"NCHW",autoPad:u,dilations:[c],group:p,kernelShape:[f],pads:[m,b],strides:[y],wIsConst:()=>!!Te()[I>>>0],outputPadding:$?Array.from(j().subarray(Number($)>>>0,Number(C)>>>0)):[],outputShape:k?Array.from(j().subarray(Number(k)>>>0,Number(R)>>>0)):[],activation:ut(X)})},1642909:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("ConvTranspose",s,{format:y?"NHWC":"NCHW",autoPad:u,dilations:Array.from(j().subarray(Number(c)>>>0,2+(Number(c)>>>0)>>>0)),group:p,kernelShape:Array.from(j().subarray(Number(f)>>>0,2+(Number(f)>>>0)>>>0)),pads:Array.from(j().subarray(Number(m)>>>0,4+(Number(m)>>>0)>>>0)),strides:Array.from(j().subarray(Number(b)>>>0,2+(Number(b)>>>0)>>>0)),wIsConst:()=>!!Te()[v>>>0],outputPadding:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],outputShape:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[],activation:ut(R)})},1643570:(s,u)=>{t.jsepCreateKernel("GlobalAveragePool",s,{format:u?"NHWC":"NCHW"})},1643661:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("AveragePool",s,{format:R?"NHWC":"NCHW",auto_pad:u,ceil_mode:c,count_include_pad:p,storage_order:f,dilations:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[],kernel_shape:y?Array.from(j().subarray(Number(y)>>>0,Number(v)>>>0)):[],pads:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],strides:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[]})},1644140:(s,u)=>{t.jsepCreateKernel("GlobalAveragePool",s,{format:u?"NHWC":"NCHW"})},1644231:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("AveragePool",s,{format:R?"NHWC":"NCHW",auto_pad:u,ceil_mode:c,count_include_pad:p,storage_order:f,dilations:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[],kernel_shape:y?Array.from(j().subarray(Number(y)>>>0,Number(v)>>>0)):[],pads:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],strides:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[]})},1644710:(s,u)=>{t.jsepCreateKernel("GlobalMaxPool",s,{format:u?"NHWC":"NCHW"})},1644797:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("MaxPool",s,{format:R?"NHWC":"NCHW",auto_pad:u,ceil_mode:c,count_include_pad:p,storage_order:f,dilations:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[],kernel_shape:y?Array.from(j().subarray(Number(y)>>>0,Number(v)>>>0)):[],pads:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],strides:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[]})},1645272:(s,u)=>{t.jsepCreateKernel("GlobalMaxPool",s,{format:u?"NHWC":"NCHW"})},1645359:(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>{t.jsepCreateKernel("MaxPool",s,{format:R?"NHWC":"NCHW",auto_pad:u,ceil_mode:c,count_include_pad:p,storage_order:f,dilations:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[],kernel_shape:y?Array.from(j().subarray(Number(y)>>>0,Number(v)>>>0)):[],pads:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],strides:C?Array.from(j().subarray(Number(C)>>>0,Number(k)>>>0)):[]})},1645834:(s,u,c,p,f)=>{t.jsepCreateKernel("Gemm",s,{alpha:u,beta:c,transA:p,transB:f})},1645938:s=>{t.jsepCreateKernel("MatMul",s,void 0)},1645992:(s,u,c,p)=>{t.jsepCreateKernel("ArgMax",s,{keepDims:!!u,selectLastIndex:!!c,axis:p})},1646100:(s,u,c,p)=>{t.jsepCreateKernel("ArgMin",s,{keepDims:!!u,selectLastIndex:!!c,axis:p})},1646208:(s,u)=>{t.jsepCreateKernel("Softmax",s,{axis:u})},1646271:(s,u)=>{t.jsepCreateKernel("Concat",s,{axis:u})},1646331:(s,u,c,p,f)=>{t.jsepCreateKernel("Split",s,{axis:u,numOutputs:c,splitSizes:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1646487:s=>{t.jsepCreateKernel("Expand",s,void 0)},1646541:(s,u)=>{t.jsepCreateKernel("Gather",s,{axis:Number(u)})},1646612:(s,u)=>{t.jsepCreateKernel("GatherElements",s,{axis:Number(u)})},1646691:(s,u)=>{t.jsepCreateKernel("GatherND",s,{batch_dims:Number(u)})},1646770:(s,u,c,p,f,m,b,y,v,I,$)=>{t.jsepCreateKernel("Resize",s,{antialias:u,axes:c?Array.from(j().subarray(Number(c)>>>0,Number(p)>>>0)):[],coordinateTransformMode:ut(f),cubicCoeffA:m,excludeOutside:b,extrapolationValue:y,keepAspectRatioPolicy:ut(v),mode:ut(I),nearestMode:ut($)})},1647132:(s,u,c,p,f,m,b)=>{t.jsepCreateKernel("Slice",s,{starts:u?Array.from(j().subarray(Number(u)>>>0,Number(c)>>>0)):[],ends:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[],axes:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[]})},1647396:s=>{t.jsepCreateKernel("Tile",s,void 0)},1647448:(s,u,c)=>{t.jsepCreateKernel("InstanceNormalization",s,{epsilon:u,format:c?"NHWC":"NCHW"})},1647562:(s,u,c)=>{t.jsepCreateKernel("InstanceNormalization",s,{epsilon:u,format:c?"NHWC":"NCHW"})},1647676:s=>{t.jsepCreateKernel("Range",s,void 0)},1647729:(s,u)=>{t.jsepCreateKernel("Einsum",s,{equation:ut(u)})},1647810:(s,u,c,p,f)=>{t.jsepCreateKernel("Pad",s,{mode:u,value:c,pads:p?Array.from(j().subarray(Number(p)>>>0,Number(f)>>>0)):[]})},1647953:(s,u,c,p,f,m)=>{t.jsepCreateKernel("BatchNormalization",s,{epsilon:u,momentum:c,spatial:!!f,trainingMode:!!p,format:m?"NHWC":"NCHW"})},1648122:(s,u,c,p,f,m)=>{t.jsepCreateKernel("BatchNormalization",s,{epsilon:u,momentum:c,spatial:!!f,trainingMode:!!p,format:m?"NHWC":"NCHW"})},1648291:(s,u,c)=>{t.jsepCreateKernel("CumSum",s,{exclusive:Number(u),reverse:Number(c)})},1648388:(s,u,c)=>{t.jsepCreateKernel("DequantizeLinear",s,{axis:u,blockSize:c})},1648478:(s,u,c,p,f)=>{t.jsepCreateKernel("GridSample",s,{align_corners:u,mode:ut(c),padding_mode:ut(p),format:f?"NHWC":"NCHW"})},1648648:(s,u,c,p,f)=>{t.jsepCreateKernel("GridSample",s,{align_corners:u,mode:ut(c),padding_mode:ut(p),format:f?"NHWC":"NCHW"})},1648818:(s,u)=>{t.jsepCreateKernel("ScatterND",s,{reduction:ut(u)})},1648903:(s,u,c,p,f,m,b,y,v)=>{t.jsepCreateKernel("Attention",s,{numHeads:u,isUnidirectional:c,maskFilterValue:p,scale:f,doRotary:m,qkvHiddenSizes:b?Array.from(j().subarray(Number(y)>>>0,Number(y)+b>>>0)):[],pastPresentShareBuffer:!!v})},1649175:s=>{t.jsepCreateKernel("BiasAdd",s,void 0)},1649230:s=>{t.jsepCreateKernel("BiasSplitGelu",s,void 0)},1649291:s=>{t.jsepCreateKernel("FastGelu",s,void 0)},1649347:(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)=>{t.jsepCreateKernel("Conv",s,{format:C?"NHWC":"NCHW",auto_pad:u,dilations:c?Array.from(j().subarray(Number(c)>>>0,Number(p)>>>0)):[],group:f,kernel_shape:m?Array.from(j().subarray(Number(m)>>>0,Number(b)>>>0)):[],pads:y?Array.from(j().subarray(Number(y)>>>0,Number(v)>>>0)):[],strides:I?Array.from(j().subarray(Number(I)>>>0,Number($)>>>0)):[],w_is_const:()=>!!Te()[Number(k)>>>0],activation:ut(R),activation_params:X?Array.from(ze().subarray(Number(X)>>>0,Number(Y)>>>0)):[]})},1649931:s=>{t.jsepCreateKernel("Gelu",s,void 0)},1649983:(s,u,c,p,f,m,b,y,v)=>{t.jsepCreateKernel("GroupQueryAttention",s,{numHeads:u,kvNumHeads:c,scale:p,softcap:f,doRotary:m,rotaryInterleaved:b,smoothSoftmax:y,localWindowSize:v})},1650200:(s,u,c,p)=>{t.jsepCreateKernel("LayerNormalization",s,{axis:u,epsilon:c,simplified:!!p})},1650311:(s,u,c,p)=>{t.jsepCreateKernel("LayerNormalization",s,{axis:u,epsilon:c,simplified:!!p})},1650422:(s,u,c,p,f,m)=>{t.jsepCreateKernel("MatMulNBits",s,{k:u,n:c,accuracyLevel:p,bits:f,blockSize:m})},1650549:(s,u,c,p,f,m)=>{t.jsepCreateKernel("MultiHeadAttention",s,{numHeads:u,isUnidirectional:c,maskFilterValue:p,scale:f,doRotary:m})},1650708:(s,u)=>{t.jsepCreateKernel("QuickGelu",s,{alpha:u})},1650772:(s,u,c,p,f)=>{t.jsepCreateKernel("RotaryEmbedding",s,{interleaved:!!u,numHeads:c,rotaryEmbeddingDim:p,scale:f})},1650911:(s,u,c)=>{t.jsepCreateKernel("SkipLayerNormalization",s,{epsilon:u,simplified:!!c})},1651013:(s,u,c)=>{t.jsepCreateKernel("SkipLayerNormalization",s,{epsilon:u,simplified:!!c})},1651115:(s,u,c,p)=>{t.jsepCreateKernel("GatherBlockQuantized",s,{gatherAxis:u,quantizeAxis:c,blockSize:p})},1651236:s=>{t.jsepReleaseKernel(s)},1651270:(s,u)=>t.jsepRunKernel(Number(s),Number(u),t.jsepSessionState.sessionHandle,t.jsepSessionState.errors)};function HI(s,u,c){return ye.handleAsync(async()=>{await t.jsepCopyAsync(Number(s),Number(u),Number(c))})}function qI(){return typeof wasmOffsetConverter<"u"}class Td{name="ExitStatus";constructor(u){this.message=`Program terminated with exit(${u})`,this.status=u}}var Id=s=>{s.terminate(),s.onmessage=u=>{}},Sd=s=>{var u=Fe.pthreads[s];Fe.returnWorkerToPool(u)},$d=[],Ad=s=>{var u=Fe.getNewWorker();if(!u)return 6;Fe.runningWorkers.push(u),Fe.pthreads[s.pthread_ptr]=u,u.pthread_ptr=s.pthread_ptr;var c={cmd:"run",start_routine:s.startRoutine,arg:s.arg,pthread_ptr:s.pthread_ptr};return u.postMessage(c,s.transferList),0},Oo=0,_s=()=>Oo>0,F=()=>Up(),V=s=>jp(s),vs=s=>Gp(s),It=s=>s<-9007199254740992||s>9007199254740992?NaN:Number(s),st=(s,u,c,...p)=>{for(var f=2*p.length,m=F(),b=vs(8*f),y=b>>>3,v=0;v>>0]=I)}var $=Rp(s,u,f,b,c);return V(m),$};function ws(s){if(l)return st(0,0,1,s);B=s,_s()||(Fe.terminateAllThreads(),Ee=!0),T(0,new Td(s))}var Od=s=>{if(s instanceof Td||s=="unwind")return B;T(0,s)};function Cd(s){if(l)return st(1,0,0,s);xs(s)}var xs=(s,u)=>{if(B=s,l)throw Cd(s),"unwind";ws(s)},Fe={unusedWorkers:[],runningWorkers:[],tlsInitFunctions:[],pthreads:{},init(){l||Fe.initMainThread()},initMainThread(){for(var s,u=t.numThreads-1;u--;)Fe.allocateUnusedWorker();s=()=>{_d(),Fe.loadWasmModuleToAllWorkers(()=>vd())},$d.unshift(s)},terminateAllThreads:()=>{for(var s of Fe.runningWorkers)Id(s);for(var s of Fe.unusedWorkers)Id(s);Fe.unusedWorkers=[],Fe.runningWorkers=[],Fe.pthreads={}},returnWorkerToPool:s=>{var u=s.pthread_ptr;delete Fe.pthreads[u],Fe.unusedWorkers.push(s),Fe.runningWorkers.splice(Fe.runningWorkers.indexOf(s),1),s.pthread_ptr=0,zp(u)},threadInitTLS(){Fe.tlsInitFunctions.forEach(s=>s())},loadWasmModuleToWorker:s=>new Promise(u=>{s.onmessage=f=>{var m=f.data,b=m.cmd;if(m.targetThread&&m.targetThread!=vi()){var y=Fe.pthreads[m.targetThread];y?y.postMessage(m,m.transferList):E(`Internal error! Worker sent a message "${b}" to target pthread ${m.targetThread}, but that thread no longer exists!`)}else b==="checkMailbox"?fi():b==="spawnThread"?Ad(m):b==="cleanupThread"?Sd(m.thread):b==="loaded"?(s.loaded=!0,u(s)):b==="alert"?alert(`Thread ${m.threadId}: ${m.text}`):m.target==="setimmediate"?s.postMessage(m):b==="callHandler"?t[m.handler](...m.args):b&&E(`worker sent an unknown command ${b}`)},s.onerror=f=>{throw E(`worker sent an error! ${f.filename}:${f.lineno}: ${f.message}`),f};var c=[];for(var p of[])t.propertyIsEnumerable(p)&&c.push(p);s.postMessage({cmd:"load",handlers:c,wasmMemory:L,wasmModule:z})}),loadWasmModuleToAllWorkers(s){if(l)return s();Promise.all(Fe.unusedWorkers.map(Fe.loadWasmModuleToWorker)).then(s)},allocateUnusedWorker(){var s;s=new Worker((()=>{let u=URL;return import.meta.url>"file:"&&import.meta.url<"file;"?new u("ort.all.bundle.min.mjs",import.meta.url):new URL(import.meta.url)})(),{type:"module",workerData:"em-pthread",name:"em-pthread"}),Fe.unusedWorkers.push(s)},getNewWorker:()=>(Fe.unusedWorkers.length==0&&(Fe.allocateUnusedWorker(),Fe.loadWasmModuleToWorker(Fe.unusedWorkers[0])),Fe.unusedWorkers.pop())},KI=s=>{je();var u=U()[s+52>>>2>>>0],c=U()[s+56>>>2>>>0];Vp(u,u-c),V(u)},XI=(s,u)=>{var c;Oo=0,c=Zs(s,u),_s()?B=c:Xs(c)},ci=[],di=0;function JI(s){var u=new Ts(s>>>=0);return u.get_caught()||(u.set_caught(!0),di--),u.set_rethrown(!1),ci.push(u),Hp(s),Kp(s)}var Nn=0,ZI=()=>{G(0,0);var s=ci.pop();Wp(s.excPtr),Nn=0};class Ts{constructor(u){this.excPtr=u,this.ptr=u-24}set_type(u){U()[this.ptr+4>>>2>>>0]=u}get_type(){return U()[this.ptr+4>>>2>>>0]}set_destructor(u){U()[this.ptr+8>>>2>>>0]=u}get_destructor(){return U()[this.ptr+8>>>2>>>0]}set_caught(u){u=u?1:0,Te()[this.ptr+12>>>0]=u}get_caught(){return Te()[this.ptr+12>>>0]!=0}set_rethrown(u){u=u?1:0,Te()[this.ptr+13>>>0]=u}get_rethrown(){return Te()[this.ptr+13>>>0]!=0}init(u,c){this.set_adjusted_ptr(0),this.set_type(u),this.set_destructor(c)}set_adjusted_ptr(u){U()[this.ptr+16>>>2>>>0]=u}get_adjusted_ptr(){return U()[this.ptr+16>>>2>>>0]}}function QI(s){throw Nn||(Nn=s>>>=0),Nn}var pi=s=>Fp(s),Co=s=>{var u=Nn;if(!u)return pi(0),0;var c=new Ts(u);c.set_adjusted_ptr(u);var p=c.get_type();if(!p)return pi(0),u;for(var f of s){if(f===0||f===p)break;var m=c.ptr+16;if(qp(f,p,m))return pi(f),u}return pi(p),u};function YI(){return Co([])}function eS(s){return Co([s>>>=0])}function tS(s,u){return Co([s>>>=0,u>>>=0])}function rS(s,u,c){return Co([s>>>=0,u>>>=0,c>>>=0])}function nS(s,u,c,p){return Co([s>>>=0,u>>>=0,c>>>=0,p>>>=0])}var oS=()=>{var s=ci.pop();s||fr("no exception to throw");var u=s.excPtr;throw s.get_rethrown()||(ci.push(s),s.set_rethrown(!0),s.set_caught(!1),di++),Nn=u};function iS(s,u,c){throw u>>>=0,c>>>=0,new Ts(s>>>=0).init(u,c),di++,Nn=s}var aS=()=>di;function Pd(s,u,c,p){return l?st(2,0,1,s,u,c,p):Ed(s,u,c,p)}var sS=()=>d!==void 0;function Ed(s,u,c,p){if(s>>>=0,u>>>=0,c>>>=0,p>>>=0,!sS())return 6;var f=[];if(l&&f.length===0)return Pd(s,u,c,p);var m={startRoutine:c,pthread_ptr:s,arg:p,transferList:f};return l?(m.cmd="spawnThread",postMessage(m,f),0):Ad(m)}var Dd=typeof TextDecoder<"u"?new TextDecoder:void 0,kd=(s,u=0,c=NaN)=>{for(var p=(u>>>=0)+c,f=u;s[f]&&!(f>=p);)++f;if(f-u>16&&s.buffer&&Dd)return Dd.decode(s.buffer instanceof ArrayBuffer?s.subarray(u,f):s.slice(u,f));for(var m="";u>10,56320|1023&I)}}else m+=String.fromCharCode((31&b)<<6|y)}else m+=String.fromCharCode(b)}return m},ut=(s,u)=>(s>>>=0)?kd(Ue(),s,u):"",Is={varargs:void 0,getStr:s=>ut(s)};function Nd(s,u,c){return l?st(3,0,1,s,u,c):(c>>>=0,Is.varargs=c,0)}function Ld(s,u){if(l)return st(4,0,1,s,u);u>>>=0}var gn=s=>{for(var u=0,c=0;c=55296&&p<=57343?(u+=4,++c):u+=3}return u},bn=(s,u,c)=>((p,f,m,b)=>{if(!(b>0))return 0;for(var y=m>>>=0,v=m+b-1,I=0;I=55296&&$<=57343&&($=65536+((1023&$)<<10)|1023&p.charCodeAt(++I)),$<=127){if(m>=v)break;f[m++>>>0]=$}else if($<=2047){if(m+1>=v)break;f[m++>>>0]=192|$>>6,f[m++>>>0]=128|63&$}else if($<=65535){if(m+2>=v)break;f[m++>>>0]=224|$>>12,f[m++>>>0]=128|$>>6&63,f[m++>>>0]=128|63&$}else{if(m+3>=v)break;f[m++>>>0]=240|$>>18,f[m++>>>0]=128|$>>12&63,f[m++>>>0]=128|$>>6&63,f[m++>>>0]=128|63&$}}return f[m>>>0]=0,m-y})(s,Ue(),u,c);function Rd(s,u){if(l)return st(5,0,1,s,u);s>>>=0,u>>>=0}function zd(s,u,c){if(l)return st(6,0,1,s,u,c);u>>>=0,c>>>=0}function Md(s,u,c){return l?st(7,0,1,s,u,c):(c>>>=0,Is.varargs=c,0)}function Bd(s,u){if(l)return st(8,0,1,s,u);s>>>=0,u>>>=0}function Fd(s,u,c){if(l)return st(9,0,1,s,u,c);u>>>=0}function Vd(s,u,c,p){if(l)return st(10,0,1,s,u,c,p);u>>>=0,c>>>=0}function jd(s,u,c,p){if(l)return st(11,0,1,s,u,c,p);u>>>=0,p>>>=0,Is.varargs=p}function Gd(s,u,c,p){if(l)return st(12,0,1,s,u,c,p);u>>>=0,c>>>=0,p>>>=0}function Ud(s){if(l)return st(13,0,1,s);s>>>=0}function Wd(s,u){if(l)return st(14,0,1,s,u);s>>>=0,u>>>=0}function Hd(s,u,c){if(l)return st(15,0,1,s,u,c);u>>>=0}var qd,Kd,uS=()=>fr(""),lS=s=>{if(s===null)return"null";var u=typeof s;return u==="object"||u==="array"||u==="function"?s.toString():""+s},hr=s=>{for(var u="",c=s;Ue()[c>>>0];)u+=qd[Ue()[c++>>>0]];return u},Ss={},$s={},cS={},Ln=s=>{throw new Kd(s)};function ln(s,u,c={}){return function(p,f,m={}){var b=f.name;if(p||Ln(`type "${b}" must have a positive integer typeid pointer`),$s.hasOwnProperty(p)){if(m.ignoreDuplicateRegistrations)return;Ln(`Cannot register type '${b}' twice`)}if($s[p]=f,delete cS[p],Ss.hasOwnProperty(p)){var y=Ss[p];delete Ss[p],y.forEach(v=>v())}}(s,u,c)}var Xd=(s,u,c)=>{switch(u){case 1:return c?p=>Te()[p>>>0]:p=>Ue()[p>>>0];case 2:return c?p=>rt()[p>>>1>>>0]:p=>Ie()[p>>>1>>>0];case 4:return c?p=>j()[p>>>2>>>0]:p=>U()[p>>>2>>>0];case 8:return c?p=>oe[p>>>3]:p=>Be[p>>>3];default:throw new TypeError(`invalid integer width (${u}): ${s}`)}};function dS(s,u,c,p,f){s>>>=0,c>>>=0;var m=(u=hr(u>>>=0)).indexOf("u")!=-1;ln(s,{name:u,fromWireType:b=>b,toWireType:function(b,y){if(typeof y!="bigint"&&typeof y!="number")throw new TypeError(`Cannot convert "${lS(y)}" to ${this.name}`);return typeof y=="number"&&(y=BigInt(y)),y},argPackAdvance:yn,readValueFromPointer:Xd(u,c,!m),destructorFunction:null})}var yn=8;function pS(s,u,c,p){ln(s>>>=0,{name:u=hr(u>>>=0),fromWireType:function(f){return!!f},toWireType:function(f,m){return m?c:p},argPackAdvance:yn,readValueFromPointer:function(f){return this.fromWireType(Ue()[f>>>0])},destructorFunction:null})}var As=[],cn=[];function Os(s){(s>>>=0)>9&&--cn[s+1]==0&&(cn[s]=void 0,As.push(s))}var nt={toValue:s=>(s||Ln("Cannot use deleted val. handle = "+s),cn[s]),toHandle:s=>{switch(s){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let u=As.pop()||cn.length;return cn[u]=s,cn[u+1]=1,u}}}};function Cs(s){return this.fromWireType(U()[s>>>2>>>0])}var fS={name:"emscripten::val",fromWireType:s=>{var u=nt.toValue(s);return Os(s),u},toWireType:(s,u)=>nt.toHandle(u),argPackAdvance:yn,readValueFromPointer:Cs,destructorFunction:null};function hS(s){return ln(s>>>=0,fS)}var mS=(s,u)=>{switch(u){case 4:return function(c){return this.fromWireType(ze()[c>>>2>>>0])};case 8:return function(c){return this.fromWireType(lt()[c>>>3>>>0])};default:throw new TypeError(`invalid float width (${u}): ${s}`)}},gS=function(s,u,c){c>>>=0,ln(s>>>=0,{name:u=hr(u>>>=0),fromWireType:p=>p,toWireType:(p,f)=>f,argPackAdvance:yn,readValueFromPointer:mS(u,c),destructorFunction:null})};function bS(s,u,c,p,f){s>>>=0,c>>>=0,u=hr(u>>>=0),f===-1&&(f=4294967295);var m=v=>v;if(p===0){var b=32-8*c;m=v=>v<>>b}var y=u.includes("unsigned");ln(s,{name:u,fromWireType:m,toWireType:y?function(v,I){return this.name,I>>>0}:function(v,I){return this.name,I},argPackAdvance:yn,readValueFromPointer:Xd(u,c,p!==0),destructorFunction:null})}function yS(s,u,c){c>>>=0;var p=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][u];function f(m){var b=U()[m>>>2>>>0],y=U()[m+4>>>2>>>0];return new p(Te().buffer,y,b)}ln(s>>>=0,{name:c=hr(c),fromWireType:f,argPackAdvance:yn,readValueFromPointer:f},{ignoreDuplicateRegistrations:!0})}function _S(s,u){ln(s>>>=0,{name:u=hr(u>>>=0),fromWireType(c){for(var p,f=U()[c>>>2>>>0],m=c+4,b=m,y=0;y<=f;++y){var v=m+y;if(y==f||Ue()[v>>>0]==0){var I=ut(b,v-b);p===void 0?p=I:(p+="\0",p+=I),b=v+1}}return Ut(c),p},toWireType(c,p){var f;p instanceof ArrayBuffer&&(p=new Uint8Array(p));var m=typeof p=="string";m||p instanceof Uint8Array||p instanceof Uint8ClampedArray||p instanceof Int8Array||Ln("Cannot pass non-string to std::string"),f=m?gn(p):p.length;var b=so(4+f+1),y=b+4;if(U()[b>>>2>>>0]=f,m)bn(p,y,f+1);else if(m)for(var v=0;v255&&(Ut(b),Ln("String has UTF-16 code units that do not fit in 8 bits")),Ue()[y+v>>>0]=I}else for(v=0;v>>0]=p[v];return c!==null&&c.push(Ut,b),b},argPackAdvance:yn,readValueFromPointer:Cs,destructorFunction(c){Ut(c)}})}var Jd=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0,vS=(s,u)=>{for(var c=s,p=c>>1,f=p+u/2;!(p>=f)&&Ie()[p>>>0];)++p;if((c=p<<1)-s>32&&Jd)return Jd.decode(Ue().slice(s,c));for(var m="",b=0;!(b>=u/2);++b){var y=rt()[s+2*b>>>1>>>0];if(y==0)break;m+=String.fromCharCode(y)}return m},wS=(s,u,c)=>{if(c??=2147483647,c<2)return 0;for(var p=u,f=(c-=2)<2*s.length?c/2:s.length,m=0;m>>1>>>0]=b,u+=2}return rt()[u>>>1>>>0]=0,u-p},xS=s=>2*s.length,TS=(s,u)=>{for(var c=0,p="";!(c>=u/4);){var f=j()[s+4*c>>>2>>>0];if(f==0)break;if(++c,f>=65536){var m=f-65536;p+=String.fromCharCode(55296|m>>10,56320|1023&m)}else p+=String.fromCharCode(f)}return p},IS=(s,u,c)=>{if(u>>>=0,c??=2147483647,c<4)return 0;for(var p=u,f=p+c-4,m=0;m=55296&&b<=57343&&(b=65536+((1023&b)<<10)|1023&s.charCodeAt(++m)),j()[u>>>2>>>0]=b,(u+=4)+4>f)break}return j()[u>>>2>>>0]=0,u-p},SS=s=>{for(var u=0,c=0;c=55296&&p<=57343&&++c,u+=4}return u},$S=function(s,u,c){var p,f,m,b;s>>>=0,u>>>=0,c=hr(c>>>=0),u===2?(p=vS,f=wS,b=xS,m=y=>Ie()[y>>>1>>>0]):u===4&&(p=TS,f=IS,b=SS,m=y=>U()[y>>>2>>>0]),ln(s,{name:c,fromWireType:y=>{for(var v,I=U()[y>>>2>>>0],$=y+4,C=0;C<=I;++C){var k=y+4+C*u;if(C==I||m(k)==0){var R=p($,k-$);v===void 0?v=R:(v+="\0",v+=R),$=k+u}}return Ut(y),v},toWireType:(y,v)=>{typeof v!="string"&&Ln(`Cannot pass non-string to C++ string type ${c}`);var I=b(v),$=so(4+I+u);return U()[$>>>2>>>0]=I/u,f(v,$+4,I+u),y!==null&&y.push(Ut,$),$},argPackAdvance:yn,readValueFromPointer:Cs,destructorFunction(y){Ut(y)}})},AS=function(s,u){ln(s>>>=0,{isVoid:!0,name:u=hr(u>>>=0),argPackAdvance:0,fromWireType:()=>{},toWireType:(c,p)=>{}})};function OS(s){Ks(s>>>=0,!a,1,!i,131072,!1),Fe.threadInitTLS()}var Ps=s=>{if(!Ee)try{s(),(()=>{if(!_s())try{l?Xs(B):xs(B)}catch(u){Od(u)}})()}catch(u){Od(u)}};function Es(s){if(s>>>=0,typeof Atomics.waitAsync=="function"){Atomics.waitAsync(j(),s>>>2,s).value.then(fi);var u=s+128;Atomics.store(j(),u>>>2,1)}}var fi=()=>{var s=vi();s&&(Es(s),Ps(Bp))};function CS(s,u){if((s>>>=0)==(u>>>=0))setTimeout(fi);else if(l)postMessage({targetThread:s,cmd:"checkMailbox"});else{var c=Fe.pthreads[s];if(!c)return;c.postMessage({cmd:"checkMailbox"})}}var hi=[];function PS(s,u,c,p,f){u>>>=0,c>>>=0,f>>>=0,p/=2,hi.length=p;for(var m=f>>>3,b=0;b>>0];var y=u?xd[u]:pA[s];Fe.currentProxiedOperationCallerThread=c;var v=y(...hi);return Fe.currentProxiedOperationCallerThread=0,v}var ES=()=>{Oo=0};function DS(s){s>>>=0,l?postMessage({cmd:"cleanupThread",thread:s}):Sd(s)}function kS(s){}var mi=(s,u)=>{var c,p,f,m=$s[s];return m===void 0&&Ln(`${u} has unknown type ${c=s,p=bp(c),f=hr(p),Ut(p),f}`),m},Zd=(s,u,c)=>{var p=[],f=s.toWireType(p,c);return p.length&&(U()[u>>>2>>>0]=nt.toHandle(p)),f};function NS(s,u,c){return s>>>=0,u>>>=0,c>>>=0,s=nt.toValue(s),u=mi(u,"emval::as"),Zd(u,c,s)}function LS(s,u){return s>>>=0,u>>>=0,s=nt.toValue(s),(u=mi(u,"emval::as")).toWireType(null,s)}var gi=s=>{try{return s()}catch(u){fr(u)}},Rn=()=>{Oo+=1},mr=()=>{Oo-=1},ye={instrumentWasmImports(s){var u=/^(invoke_.*|__asyncjs__.*)$/;for(let[c,p]of Object.entries(s))typeof p=="function"&&(p.isAsync||u.test(c))},instrumentWasmExports(s){var u={};for(let[c,p]of Object.entries(s))u[c]=typeof p=="function"?(...f)=>{ye.exportCallStack.push(c);try{return p(...f)}finally{Ee||(ye.exportCallStack.pop(),ye.maybeStopUnwind())}}:p;return u},State:{Normal:0,Unwinding:1,Rewinding:2,Disabled:3},state:0,StackSize:65536,currData:null,handleSleepReturnValue:0,exportCallStack:[],callStackNameToId:{},callStackIdToName:{},callStackId:0,asyncPromiseHandlers:null,sleepCallbacks:[],getCallStackId(s){var u=ye.callStackNameToId[s];return u===void 0&&(u=ye.callStackId++,ye.callStackNameToId[s]=u,ye.callStackIdToName[u]=s),u},maybeStopUnwind(){ye.currData&&ye.state===ye.State.Unwinding&&ye.exportCallStack.length===0&&(ye.state=ye.State.Normal,Rn(),gi(Bg),typeof Fibers<"u"&&Fibers.trampoline())},whenDone:()=>new Promise((s,u)=>{ye.asyncPromiseHandlers={resolve:s,reject:u}}),allocateData(){var s=so(12+ye.StackSize);return ye.setDataHeader(s,s+12,ye.StackSize),ye.setDataRewindFunc(s),s},setDataHeader(s,u,c){U()[s>>>2>>>0]=u,U()[s+4>>>2>>>0]=u+c},setDataRewindFunc(s){var u=ye.exportCallStack[0],c=ye.getCallStackId(u);j()[s+8>>>2>>>0]=c},getDataRewindFuncName(s){var u=j()[s+8>>>2>>>0];return ye.callStackIdToName[u]},getDataRewindFunc:s=>D[s],doRewind(s){var u=ye.getDataRewindFuncName(s),c=ye.getDataRewindFunc(u);return mr(),c()},handleSleep(s){if(!Ee){if(ye.state===ye.State.Normal){var u=!1,c=!1;s((p=0)=>{if(!Ee&&(ye.handleSleepReturnValue=p,u=!0,c)){ye.state=ye.State.Rewinding,gi(()=>Fg(ye.currData)),typeof MainLoop<"u"&&MainLoop.func&&MainLoop.resume();var f,m=!1;try{f=ye.doRewind(ye.currData)}catch(v){f=v,m=!0}var b=!1;if(!ye.currData){var y=ye.asyncPromiseHandlers;y&&(ye.asyncPromiseHandlers=null,(m?y.reject:y.resolve)(f),b=!0)}if(m&&!b)throw f}}),c=!0,u||(ye.state=ye.State.Unwinding,ye.currData=ye.allocateData(),typeof MainLoop<"u"&&MainLoop.func&&MainLoop.pause(),gi(()=>Mg(ye.currData)))}else ye.state===ye.State.Rewinding?(ye.state=ye.State.Normal,gi(Vg),Ut(ye.currData),ye.currData=null,ye.sleepCallbacks.forEach(Ps)):fr(`invalid state: ${ye.state}`);return ye.handleSleepReturnValue}},handleAsync:s=>ye.handleSleep(u=>{s().then(u)})},Qd=function(s){return s>>>=0,ye.handleAsync(async()=>{var u=await nt.toValue(s);return nt.toHandle(u)})};Qd.isAsync=!0;var bi=[];function RS(s,u,c,p){return u>>>=0,c>>>=0,p>>>=0,(s=bi[s>>>=0])(null,u=nt.toValue(u),c,p)}var zS={},yi=s=>{var u=zS[s];return u===void 0?hr(s):u};function MS(s,u,c,p,f){return u>>>=0,c>>>=0,p>>>=0,f>>>=0,(s=bi[s>>>=0])(u=nt.toValue(u),u[c=yi(c)],p,f)}function BS(s,u){return s>>>=0,u>>>=0,(s=nt.toValue(s))==nt.toValue(u)}var Yd=()=>typeof globalThis=="object"?globalThis:Function("return this")();function FS(s){return(s>>>=0)==0?nt.toHandle(Yd()):(s=yi(s),nt.toHandle(Yd()[s]))}var VS=s=>{var u=bi.length;return bi.push(s),u},jS=(s,u)=>{for(var c=new Array(s),p=0;p>>2>>>0],"parameter "+p);return c},ep=(s,u)=>Object.defineProperty(u,"name",{value:s});function GS(s,u,c){var p=jS(s,u>>>=0),f=p.shift();s--;var m=`return function (obj, func, destructorsRef, args) { +`,b=0,y=[];c===0&&y.push("obj");for(var v=["retType"],I=[f],$=0;$R.name).join(", ")}) => ${f.name}>`;return VS(ep(k,C))}function US(s){return s=yi(s>>>=0),nt.toHandle(t[s])}function WS(s,u){return s>>>=0,u>>>=0,s=nt.toValue(s),u=nt.toValue(u),nt.toHandle(s[u])}function HS(s){(s>>>=0)>9&&(cn[s+1]+=1)}function qS(){return nt.toHandle([])}function KS(s){s>>>=0,s=nt.toValue(s);for(var u=new Array(s.length),c=0;c>>=0,nt.toHandle(yi(s))}function JS(){return nt.toHandle({})}var ZS=s=>{for(;s.length;){var u=s.pop();s.pop()(u)}};function QS(s){s>>>=0;var u=nt.toValue(s);ZS(u),Os(s)}function YS(s,u,c){s>>>=0,u>>>=0,c>>>=0,s=nt.toValue(s),u=nt.toValue(u),c=nt.toValue(c),s[u]=c}function e$(s,u){u>>>=0;var c=(s=mi(s>>>=0,"_emval_take_value")).readValueFromPointer(u);return nt.toHandle(c)}function t$(s,u){s=It(s),u>>>=0;var c=new Date(1e3*s);j()[u>>>2>>>0]=c.getUTCSeconds(),j()[u+4>>>2>>>0]=c.getUTCMinutes(),j()[u+8>>>2>>>0]=c.getUTCHours(),j()[u+12>>>2>>>0]=c.getUTCDate(),j()[u+16>>>2>>>0]=c.getUTCMonth(),j()[u+20>>>2>>>0]=c.getUTCFullYear()-1900,j()[u+24>>>2>>>0]=c.getUTCDay();var p=Date.UTC(c.getUTCFullYear(),0,1,0,0,0,0),f=(c.getTime()-p)/864e5|0;j()[u+28>>>2>>>0]=f}var r$=[0,31,60,91,121,152,182,213,244,274,305,335],n$=[0,31,59,90,120,151,181,212,243,273,304,334],tp=s=>{var u;return((u=s.getFullYear())%4!=0||u%100==0&&u%400!=0?n$:r$)[s.getMonth()]+s.getDate()-1};function o$(s,u){s=It(s),u>>>=0;var c=new Date(1e3*s);j()[u>>>2>>>0]=c.getSeconds(),j()[u+4>>>2>>>0]=c.getMinutes(),j()[u+8>>>2>>>0]=c.getHours(),j()[u+12>>>2>>>0]=c.getDate(),j()[u+16>>>2>>>0]=c.getMonth(),j()[u+20>>>2>>>0]=c.getFullYear()-1900,j()[u+24>>>2>>>0]=c.getDay();var p=0|tp(c);j()[u+28>>>2>>>0]=p,j()[u+36>>>2>>>0]=-60*c.getTimezoneOffset();var f=new Date(c.getFullYear(),0,1),m=new Date(c.getFullYear(),6,1).getTimezoneOffset(),b=f.getTimezoneOffset(),y=0|(m!=b&&c.getTimezoneOffset()==Math.min(b,m));j()[u+32>>>2>>>0]=y}var i$=function(s){s>>>=0;var u=(()=>{var c=new Date(j()[s+20>>>2>>>0]+1900,j()[s+16>>>2>>>0],j()[s+12>>>2>>>0],j()[s+8>>>2>>>0],j()[s+4>>>2>>>0],j()[s>>>2>>>0],0),p=j()[s+32>>>2>>>0],f=c.getTimezoneOffset(),m=new Date(c.getFullYear(),0,1),b=new Date(c.getFullYear(),6,1).getTimezoneOffset(),y=m.getTimezoneOffset(),v=Math.min(y,b);if(p<0)j()[s+32>>>2>>>0]=+(b!=y&&v==f);else if(p>0!=(v==f)){var I=Math.max(y,b),$=p>0?v:I;c.setTime(c.getTime()+6e4*($-f))}j()[s+24>>>2>>>0]=c.getDay();var C=0|tp(c);j()[s+28>>>2>>>0]=C,j()[s>>>2>>>0]=c.getSeconds(),j()[s+4>>>2>>>0]=c.getMinutes(),j()[s+8>>>2>>>0]=c.getHours(),j()[s+12>>>2>>>0]=c.getDate(),j()[s+16>>>2>>>0]=c.getMonth(),j()[s+20>>>2>>>0]=c.getYear();var k=c.getTime();return isNaN(k)?-1:k/1e3})();return BigInt(u)};function rp(s,u,c,p,f,m,b){return l?st(16,0,1,s,u,c,p,f,m,b):(s>>>=0,f=It(f),m>>>=0,b>>>=0,-52)}function np(s,u,c,p,f,m){if(l)return st(17,0,1,s,u,c,p,f,m);s>>>=0,u>>>=0,m=It(m)}var Po={},Ds=()=>performance.timeOrigin+performance.now();function op(s,u){if(l)return st(18,0,1,s,u);if(Po[s]&&(clearTimeout(Po[s].id),delete Po[s]),!u)return 0;var c=setTimeout(()=>{delete Po[s],Ps(()=>Mp(s,Ds()))},u);return Po[s]={id:c,timeout_ms:u},0}var a$=function(s,u,c,p){s>>>=0,u>>>=0,c>>>=0,p>>>=0;var f=new Date().getFullYear(),m=new Date(f,0,1),b=new Date(f,6,1),y=m.getTimezoneOffset(),v=b.getTimezoneOffset(),I=Math.max(y,v);U()[s>>>2>>>0]=60*I,j()[u>>>2>>>0]=+(y!=v);var $=R=>{var X=R>=0?"-":"+",Y=Math.abs(R);return`UTC${X}${String(Math.floor(Y/60)).padStart(2,"0")}${String(Y%60).padStart(2,"0")}`},C=$(y),k=$(v);vDate.now(),s$=1,u$=s=>s>=0&&s<=3;function l$(s,u,c){if(u=It(u),c>>>=0,!u$(s))return 28;var p;if(s===0)p=ip();else{if(!s$)return 52;p=Ds()}var f=Math.round(1e3*p*1e3);return oe[c>>>3]=BigInt(f),0}var ks=[],ap=(s,u,c)=>{var p=((f,m)=>{var b;for(ks.length=0;b=Ue()[f++>>>0];){var y=b!=105;m+=(y&=b!=112)&&m%8?4:0,ks.push(b==112?U()[m>>>2>>>0]:b==106?oe[m>>>3]:b==105?j()[m>>>2>>>0]:lt()[m>>>3>>>0]),m+=y?8:4}return ks})(u,c);return xd[s](...p)};function c$(s,u,c){return ap(s>>>=0,u>>>=0,c>>>=0)}function d$(s,u,c){return ap(s>>>=0,u>>>=0,c>>>=0)}var Eo=s=>{Eo.shown||={},Eo.shown[s]||(Eo.shown[s]=1,E(s))},p$=()=>{};function f$(s,u){return E(ut(s>>>=0,u>>>=0))}var h$=()=>{throw Rn(),"unwind"},sp=()=>4294901760;function m$(){return sp()}var g$=()=>1,b$=()=>navigator.hardwareConcurrency;function y$(s){return fr("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER"),0}var _$=(s,u)=>Math.ceil(s/u)*u,v$=s=>{var u=(s-L.buffer.byteLength+65535)/65536|0;try{return L.grow(u),je(),1}catch{}};function w$(s){s>>>=0;var u=Ue().length;if(s<=u)return!1;var c=sp();if(s>c)return!1;for(var p=1;p<=4;p*=2){var f=u*(1+.2/p);f=Math.min(f,s+100663296);var m=Math.min(c,_$(Math.max(s,f),65536));if(v$(m))return!0}return!1}var _i=s=>(fr("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER"),0),ao={},up=s=>{s.forEach(u=>{var c=_i(u);c&&(ao[c]=u)})},lp=()=>new Error().stack.toString();function x$(){var s=lp().split(` +`);return s[0]=="Error"&&s.shift(),up(s),ao.last_addr=_i(s[3]),ao.last_stack=s,ao.last_addr}function T$(s,u,c){var p;s>>>=0,u>>>=0,ao.last_addr==s?p=ao.last_stack:((p=lp().split(` +`))[0]=="Error"&&p.shift(),up(p));for(var f=3;p[f]&&_i(p[f])!=s;)++f;for(var m=0;m>>2>>>0]=_i(p[m+f]);return m}var gr=s=>{var u=gn(s)+1,c=vs(u);return bn(s,c,u),c},q={Internals:{jsObjects:[],jsObjectInsert:(s,u)=>{q.Internals.jsObjects[s]=u},bufferOnUnmaps:[],futures:[],futureInsert:(s,u)=>{q.Internals.futures[s]=new Promise(c=>u.finally(()=>c(s)))}},getJsObject:s=>{if(s)return q.Internals.jsObjects[s]},importJsAdapter:(s,u=0)=>{var c=Pp(u);return q.Internals.jsObjects[c]=s,c},importJsBindGroup:(s,u=0)=>{var c=Rs(u);return q.Internals.jsObjects[c]=s,c},importJsBindGroupLayout:(s,u=0)=>{var c=zs(u);return q.Internals.jsObjects[c]=s,c},importJsBuffer:(s,u=0)=>{s.mapState!="pending"||fr(void 0);var c=s.mapState=="mapped"?3:1,p=Ep(u,c);return q.Internals.jsObjectInsert(p,s),s.mapState=="mapped"&&(q.Internals.bufferOnUnmaps[p]=[]),p},importJsCommandBuffer:(s,u=0)=>{var c=Ms(u);return q.Internals.jsObjects[c]=s,c},importJsCommandEncoder:(s,u=0)=>{var c=Bs(u);return q.Internals.jsObjects[c]=s,c},importJsComputePassEncoder:(s,u=0)=>{var c=Fs(u);return q.Internals.jsObjects[c]=s,c},importJsComputePipeline:(s,u=0)=>{var c=Vs(u);return q.Internals.jsObjects[c]=s,c},importJsDevice:(s,u=0)=>{var c=Gs(u),p=Dp(u,c);return q.Internals.jsObjectInsert(c,s.queue),q.Internals.jsObjectInsert(p,s),p},importJsPipelineLayout:(s,u=0)=>{var c=wp(u);return q.Internals.jsObjects[c]=s,c},importJsQuerySet:(s,u=0)=>{var c=js(u);return q.Internals.jsObjects[c]=s,c},importJsQueue:(s,u=0)=>{var c=Gs(u);return q.Internals.jsObjects[c]=s,c},importJsRenderBundle:(s,u=0)=>{var c=xp(u);return q.Internals.jsObjects[c]=s,c},importJsRenderBundleEncoder:(s,u=0)=>{var c=Tp(u);return q.Internals.jsObjects[c]=s,c},importJsRenderPassEncoder:(s,u=0)=>{var c=Ip(u);return q.Internals.jsObjects[c]=s,c},importJsRenderPipeline:(s,u=0)=>{var c=Sp(u);return q.Internals.jsObjects[c]=s,c},importJsSampler:(s,u=0)=>{var c=$p(u);return q.Internals.jsObjects[c]=s,c},importJsShaderModule:(s,u=0)=>{var c=kp(u);return q.Internals.jsObjects[c]=s,c},importJsSurface:(s,u=0)=>{var c=Ap(u);return q.Internals.jsObjects[c]=s,c},importJsTexture:(s,u=0)=>{var c=Op(u);return q.Internals.jsObjects[c]=s,c},importJsTextureView:(s,u=0)=>{var c=Cp(u);return q.Internals.jsObjects[c]=s,c},errorCallback:(s,u,c,p)=>{var f=F(),m=gr(c);Qs(s,u,m,p),V(f)},setStringView:(s,u,c)=>{U()[s>>>2>>>0]=u,U()[s+4>>>2>>>0]=c},makeStringFromStringView:s=>{var u=U()[s>>>2>>>0],c=U()[s+4>>>2>>>0];return ut(u,c)},makeStringFromOptionalStringView:s=>{var u=U()[s>>>2>>>0],c=U()[s+4>>>2>>>0];return u?ut(u,c):c===0?"":void 0},makeColor:s=>({r:lt()[s>>>3>>>0],g:lt()[s+8>>>3>>>0],b:lt()[s+16>>>3>>>0],a:lt()[s+24>>>3>>>0]}),makeExtent3D:s=>({width:U()[s>>>2>>>0],height:U()[s+4>>>2>>>0],depthOrArrayLayers:U()[s+8>>>2>>>0]}),makeOrigin3D:s=>({x:U()[s>>>2>>>0],y:U()[s+4>>>2>>>0],z:U()[s+8>>>2>>>0]}),makeTexelCopyTextureInfo:s=>({texture:q.getJsObject(U()[s>>>2>>>0]),mipLevel:U()[s+4>>>2>>>0],origin:q.makeOrigin3D(s+8),aspect:q.TextureAspect[U()[s+20>>>2>>>0]]}),makeTexelCopyBufferLayout:s=>{var u=U()[s+8>>>2>>>0],c=U()[s+12>>>2>>>0];return{offset:4294967296*U()[s+4>>>2>>>0]+U()[s>>>2>>>0],bytesPerRow:u===4294967295?void 0:u,rowsPerImage:c===4294967295?void 0:c}},makeTexelCopyBufferInfo:s=>{var u=s+0,c=q.makeTexelCopyBufferLayout(u);return c.buffer=q.getJsObject(U()[s+16>>>2>>>0]),c},makePassTimestampWrites:s=>{if(s!==0)return{querySet:q.getJsObject(U()[s+4>>>2>>>0]),beginningOfPassWriteIndex:U()[s+8>>>2>>>0],endOfPassWriteIndex:U()[s+12>>>2>>>0]}},makePipelineConstants:(s,u)=>{if(s){for(var c={},p=0;p>>3>>>0]}return c}},makePipelineLayout:s=>s?q.getJsObject(s):"auto",makeComputeState:s=>{if(s)return{module:q.getJsObject(U()[s+4>>>2>>>0]),constants:q.makePipelineConstants(U()[s+16>>>2>>>0],U()[s+20>>>2>>>0]),entryPoint:q.makeStringFromOptionalStringView(s+8)}},makeComputePipelineDesc:s=>({label:q.makeStringFromOptionalStringView(s+4),layout:q.makePipelineLayout(U()[s+12>>>2>>>0]),compute:q.makeComputeState(s+16)}),makeRenderPipelineDesc:s=>{function u(v){if(v)return{operation:q.BlendOperation[U()[v>>>2>>>0]],srcFactor:q.BlendFactor[U()[v+4>>>2>>>0]],dstFactor:q.BlendFactor[U()[v+8>>>2>>>0]]}}function c(v){if(v)return{alpha:u(v+12),color:u(v+0)}}function p(v,I){for(var $,C,k=[],R=0;R>>2>>>0])===0?void 0:{format:q.TextureFormat[C],blend:c(U()[$+8>>>2>>>0]),writeMask:U()[$+16>>>2>>>0]}));return k}function f(v){return{compare:q.CompareFunction[U()[v>>>2>>>0]],failOp:q.StencilOperation[U()[v+4>>>2>>>0]],depthFailOp:q.StencilOperation[U()[v+8>>>2>>>0]],passOp:q.StencilOperation[U()[v+12>>>2>>>0]]}}function m(v,I){for(var $,C=[],k=0;k>>2>>>0]],offset:4294967296*U()[$+4+8>>>2>>>0]+U()[$+8>>>2>>>0],shaderLocation:U()[$+16>>>2>>>0]}));return C}function b(v){if(v){var I=U()[v+4>>>2>>>0],$=U()[v+16>>>2>>>0];return I===0&&$===0?null:{arrayStride:4294967296*U()[v+4+8>>>2>>>0]+U()[v+8>>>2>>>0],stepMode:q.VertexStepMode[I],attributes:m($,U()[v+20>>>2>>>0])}}}function y(v,I){if(v){for(var $=[],C=0;C>>2>>>0]),vertex:function(v){if(v)return{module:q.getJsObject(U()[v+4>>>2>>>0]),constants:q.makePipelineConstants(U()[v+16>>>2>>>0],U()[v+20>>>2>>>0]),buffers:y(U()[v+24>>>2>>>0],U()[v+28>>>2>>>0]),entryPoint:q.makeStringFromOptionalStringView(v+8)}}(s+16),primitive:function(v){if(v)return{topology:q.PrimitiveTopology[U()[v+4>>>2>>>0]],stripIndexFormat:q.IndexFormat[U()[v+8>>>2>>>0]],frontFace:q.FrontFace[U()[v+12>>>2>>>0]],cullMode:q.CullMode[U()[v+16>>>2>>>0]],unclippedDepth:!!U()[v+20>>>2>>>0]}}(s+48),depthStencil:function(v){if(v)return{format:q.TextureFormat[U()[v+4>>>2>>>0]],depthWriteEnabled:!!U()[v+8>>>2>>>0],depthCompare:q.CompareFunction[U()[v+12>>>2>>>0]],stencilFront:f(v+16),stencilBack:f(v+32),stencilReadMask:U()[v+48>>>2>>>0],stencilWriteMask:U()[v+52>>>2>>>0],depthBias:j()[v+56>>>2>>>0],depthBiasSlopeScale:ze()[v+60>>>2>>>0],depthBiasClamp:ze()[v+64>>>2>>>0]}}(U()[s+72>>>2>>>0]),multisample:function(v){if(v)return{count:U()[v+4>>>2>>>0],mask:U()[v+8>>>2>>>0],alphaToCoverageEnabled:!!U()[v+12>>>2>>>0]}}(s+76),fragment:function(v){if(v)return{module:q.getJsObject(U()[v+4>>>2>>>0]),constants:q.makePipelineConstants(U()[v+16>>>2>>>0],U()[v+20>>>2>>>0]),targets:p(U()[v+24>>>2>>>0],U()[v+28>>>2>>>0]),entryPoint:q.makeStringFromOptionalStringView(v+8)}}(U()[s+92>>>2>>>0])}},fillLimitStruct:(s,u)=>{function c(f,m){var b=s[f];j()[u+m>>>2>>>0]=b}function p(f,m){var b=s[f];oe[u+m>>>3]=BigInt(b)}c("maxTextureDimension1D",4),c("maxTextureDimension2D",8),c("maxTextureDimension3D",12),c("maxTextureArrayLayers",16),c("maxBindGroups",20),c("maxBindGroupsPlusVertexBuffers",24),c("maxBindingsPerBindGroup",28),c("maxDynamicUniformBuffersPerPipelineLayout",32),c("maxDynamicStorageBuffersPerPipelineLayout",36),c("maxSampledTexturesPerShaderStage",40),c("maxSamplersPerShaderStage",44),c("maxStorageBuffersPerShaderStage",48),c("maxStorageTexturesPerShaderStage",52),c("maxUniformBuffersPerShaderStage",56),c("minUniformBufferOffsetAlignment",80),c("minStorageBufferOffsetAlignment",84),p("maxUniformBufferBindingSize",64),p("maxStorageBufferBindingSize",72),c("maxVertexBuffers",88),p("maxBufferSize",96),c("maxVertexAttributes",104),c("maxVertexBufferArrayStride",108),c("maxInterStageShaderVariables",112),c("maxColorAttachments",116),c("maxColorAttachmentBytesPerSample",120),c("maxComputeWorkgroupStorageSize",124),c("maxComputeInvocationsPerWorkgroup",128),c("maxComputeWorkgroupSizeX",132),c("maxComputeWorkgroupSizeY",136),c("maxComputeWorkgroupSizeZ",140),c("maxComputeWorkgroupsPerDimension",144)},Int_BufferMapState:{unmapped:1,pending:2,mapped:3},Int_CompilationMessageType:{error:1,warning:2,info:3},Int_DeviceLostReason:{undefined:1,unknown:1,destroyed:2},Int_PreferredFormat:{rgba8unorm:18,bgra8unorm:23},WGSLLanguageFeatureName:{1:"readonly_and_readwrite_storage_textures",2:"packed_4x8_integer_dot_product",3:"unrestricted_pointer_parameters",4:"pointer_composite_access",5:"sized_binding_array"},AddressMode:[,"clamp-to-edge","repeat","mirror-repeat"],BlendFactor:[,"zero","one","src","one-minus-src","src-alpha","one-minus-src-alpha","dst","one-minus-dst","dst-alpha","one-minus-dst-alpha","src-alpha-saturated","constant","one-minus-constant","src1","one-minus-src1","src1alpha","one-minus-src1alpha"],BlendOperation:[,"add","subtract","reverse-subtract","min","max"],BufferBindingType:["binding-not-used",,"uniform","storage","read-only-storage"],BufferMapState:{1:"unmapped",2:"pending",3:"mapped"},CompareFunction:[,"never","less","equal","less-equal","greater","not-equal","greater-equal","always"],CompilationInfoRequestStatus:{1:"success",2:"callback-cancelled"},CompositeAlphaMode:[,"opaque","premultiplied","unpremultiplied","inherit"],CullMode:[,"none","front","back"],ErrorFilter:{1:"validation",2:"out-of-memory",3:"internal"},FeatureLevel:[,"compatibility","core"],FeatureName:{1:"depth-clip-control",2:"depth32float-stencil8",3:"timestamp-query",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"indirect-first-instance",10:"shader-f16",11:"rg11b10ufloat-renderable",12:"bgra8unorm-storage",13:"float32-filterable",14:"float32-blendable",15:"clip-distances",16:"dual-source-blending",17:"subgroups",18:"core-features-and-limits",327688:"subgroups-f16",327693:"chromium-experimental-unorm16-texture-formats",327694:"chromium-experimental-snorm16-texture-formats",327733:"chromium-experimental-multi-draw-indirect"},FilterMode:[,"nearest","linear"],FrontFace:[,"ccw","cw"],IndexFormat:[,"uint16","uint32"],LoadOp:[,"load","clear"],MipmapFilterMode:[,"nearest","linear"],OptionalBool:["false","true"],PowerPreference:[,"low-power","high-performance"],PredefinedColorSpace:{1:"srgb",2:"display-p3"},PrimitiveTopology:[,"point-list","line-list","line-strip","triangle-list","triangle-strip"],QueryType:{1:"occlusion",2:"timestamp"},SamplerBindingType:["binding-not-used",,"filtering","non-filtering","comparison"],Status:{1:"success",2:"error"},StencilOperation:[,"keep","zero","replace","invert","increment-clamp","decrement-clamp","increment-wrap","decrement-wrap"],StorageTextureAccess:["binding-not-used",,"write-only","read-only","read-write"],StoreOp:[,"store","discard"],SurfaceGetCurrentTextureStatus:{1:"success-optimal",2:"success-suboptimal",3:"timeout",4:"outdated",5:"lost",6:"error"},TextureAspect:[,"all","stencil-only","depth-only"],TextureDimension:[,"1d","2d","3d"],TextureFormat:[,"r8unorm","r8snorm","r8uint","r8sint","r16uint","r16sint","r16float","rg8unorm","rg8snorm","rg8uint","rg8sint","r32float","r32uint","r32sint","rg16uint","rg16sint","rg16float","rgba8unorm","rgba8unorm-srgb","rgba8snorm","rgba8uint","rgba8sint","bgra8unorm","bgra8unorm-srgb","rgb10a2uint","rgb10a2unorm","rg11b10ufloat","rgb9e5ufloat","rg32float","rg32uint","rg32sint","rgba16uint","rgba16sint","rgba16float","rgba32float","rgba32uint","rgba32sint","stencil8","depth16unorm","depth24plus","depth24plus-stencil8","depth32float","depth32float-stencil8","bc1-rgba-unorm","bc1-rgba-unorm-srgb","bc2-rgba-unorm","bc2-rgba-unorm-srgb","bc3-rgba-unorm","bc3-rgba-unorm-srgb","bc4-r-unorm","bc4-r-snorm","bc5-rg-unorm","bc5-rg-snorm","bc6h-rgb-ufloat","bc6h-rgb-float","bc7-rgba-unorm","bc7-rgba-unorm-srgb","etc2-rgb8unorm","etc2-rgb8unorm-srgb","etc2-rgb8a1unorm","etc2-rgb8a1unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","eac-r11unorm","eac-r11snorm","eac-rg11unorm","eac-rg11snorm","astc-4x4-unorm","astc-4x4-unorm-srgb","astc-5x4-unorm","astc-5x4-unorm-srgb","astc-5x5-unorm","astc-5x5-unorm-srgb","astc-6x5-unorm","astc-6x5-unorm-srgb","astc-6x6-unorm","astc-6x6-unorm-srgb","astc-8x5-unorm","astc-8x5-unorm-srgb","astc-8x6-unorm","astc-8x6-unorm-srgb","astc-8x8-unorm","astc-8x8-unorm-srgb","astc-10x5-unorm","astc-10x5-unorm-srgb","astc-10x6-unorm","astc-10x6-unorm-srgb","astc-10x8-unorm","astc-10x8-unorm-srgb","astc-10x10-unorm","astc-10x10-unorm-srgb","astc-12x10-unorm","astc-12x10-unorm-srgb","astc-12x12-unorm","astc-12x12-unorm-srgb"],TextureSampleType:["binding-not-used",,"float","unfilterable-float","depth","sint","uint"],TextureViewDimension:[,"1d","2d","2d-array","cube","cube-array","3d"],ToneMappingMode:{1:"standard",2:"extended"},VertexFormat:{1:"uint8",2:"uint8x2",3:"uint8x4",4:"sint8",5:"sint8x2",6:"sint8x4",7:"unorm8",8:"unorm8x2",9:"unorm8x4",10:"snorm8",11:"snorm8x2",12:"snorm8x4",13:"uint16",14:"uint16x2",15:"uint16x4",16:"sint16",17:"sint16x2",18:"sint16x4",19:"unorm16",20:"unorm16x2",21:"unorm16x4",22:"snorm16",23:"snorm16x2",24:"snorm16x4",25:"float16",26:"float16x2",27:"float16x4",28:"float32",29:"float32x2",30:"float32x3",31:"float32x4",32:"uint32",33:"uint32x2",34:"uint32x3",35:"uint32x4",36:"sint32",37:"sint32x2",38:"sint32x3",39:"sint32x4",40:"unorm10-10-10-2",41:"unorm8x4-bgra"},VertexStepMode:[,"vertex","instance"],FeatureNameString2Enum:{"depth-clip-control":"1","depth32float-stencil8":"2","timestamp-query":"3","texture-compression-bc":"4","texture-compression-bc-sliced-3d":"5","texture-compression-etc2":"6","texture-compression-astc":"7","texture-compression-astc-sliced-3d":"8","indirect-first-instance":"9","shader-f16":"10","rg11b10ufloat-renderable":"11","bgra8unorm-storage":"12","float32-filterable":"13","float32-blendable":"14","clip-distances":"15","dual-source-blending":"16",subgroups:"17","core-features-and-limits":"18","subgroups-f16":"327688","chromium-experimental-unorm16-texture-formats":"327693","chromium-experimental-snorm16-texture-formats":"327694","chromium-experimental-multi-draw-indirect":"327733"},WGSLLanguageFeatureNameString2Enum:{readonly_and_readwrite_storage_textures:"1",packed_4x8_integer_dot_product:"2",unrestricted_pointer_parameters:"3",pointer_composite_access:"4",sized_binding_array:"5"}};function I$(s,u,c,p,f,m){s>>>=0,u=It(u),c=It(c),p>>>=0,f>>>=0,m>>>=0;var b=q.getJsObject(s),y={};if(m){var v=U()[m+12>>>2>>>0];if(v){var I=U()[m+16>>>2>>>0];y.requiredFeatures=Array.from(U().subarray(I>>>2>>>0,I+4*v>>>2>>>0),Q=>q.FeatureName[Q])}var $=U()[m+20>>>2>>>0];if($){let Q=function(le,$e){var De=$+$e,tt=U()[De>>>2>>>0];tt!=4294967295&&(C[le]=tt)},re=function(le,$e){var De=$+$e,tt=U()[De>>>2>>>0],ht=U()[De+4>>>2>>>0];tt==4294967295&&ht==4294967295||(C[le]=4294967296*U()[De+4>>>2>>>0]+U()[De>>>2>>>0])};var X=Q,Y=re,C={};Q("maxTextureDimension1D",4),Q("maxTextureDimension2D",8),Q("maxTextureDimension3D",12),Q("maxTextureArrayLayers",16),Q("maxBindGroups",20),Q("maxBindGroupsPlusVertexBuffers",24),Q("maxDynamicUniformBuffersPerPipelineLayout",32),Q("maxDynamicStorageBuffersPerPipelineLayout",36),Q("maxSampledTexturesPerShaderStage",40),Q("maxSamplersPerShaderStage",44),Q("maxStorageBuffersPerShaderStage",48),Q("maxStorageTexturesPerShaderStage",52),Q("maxUniformBuffersPerShaderStage",56),Q("minUniformBufferOffsetAlignment",80),Q("minStorageBufferOffsetAlignment",84),re("maxUniformBufferBindingSize",64),re("maxStorageBufferBindingSize",72),Q("maxVertexBuffers",88),re("maxBufferSize",96),Q("maxVertexAttributes",104),Q("maxVertexBufferArrayStride",108),Q("maxInterStageShaderVariables",112),Q("maxColorAttachments",116),Q("maxColorAttachmentBytesPerSample",120),Q("maxComputeWorkgroupStorageSize",124),Q("maxComputeInvocationsPerWorkgroup",128),Q("maxComputeWorkgroupSizeX",132),Q("maxComputeWorkgroupSizeY",136),Q("maxComputeWorkgroupSizeZ",140),Q("maxComputeWorkgroupsPerDimension",144),y.requiredLimits=C}var k=U()[m+24>>>2>>>0];if(k){var R={label:q.makeStringFromOptionalStringView(k+4)};y.defaultQueue=R}y.label=q.makeStringFromOptionalStringView(m+4)}Rn(),q.Internals.futureInsert(u,b.requestDevice(y).then(Q=>{mr(),q.Internals.jsObjectInsert(f,Q.queue),q.Internals.jsObjectInsert(p,Q),c&&(Rn(),q.Internals.futureInsert(c,Q.lost.then(re=>{mr(),Q.onuncapturederror=De=>{};var le=F(),$e=gr(re.message);Us(c,q.Int_DeviceLostReason[re.reason],$e),V(le)}))),Q.onuncapturederror=re=>{var le=5;re.error instanceof GPUValidationError?le=2:re.error instanceof GPUOutOfMemoryError?le=3:re.error instanceof GPUInternalError&&(le=4);var $e=F(),De=gr(re.error.message);Np(p,le,De),V($e)},qs(u,1,p,0)},Q=>{mr();var re=F(),le=gr(Q.message);qs(u,3,p,le),c&&Us(c,4,le),V(re)}))}function S$(s){s>>>=0;var u=q.getJsObject(s),c=q.Internals.bufferOnUnmaps[s];if(c){for(var p=0;p>>=0,u>>>=0,c>>>=0;var p,f=q.getJsObject(s);c===0&&Eo("getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE"),c==4294967295&&(c=void 0);try{p=f.getMappedRange(u,c)}catch{return 0}var m=Js(16,p.byteLength);return Ue().set(new Uint8Array(p),m>>>0),q.Internals.bufferOnUnmaps[s].push(()=>Ut(m)),m}function A$(s,u,c){s>>>=0,u>>>=0,c>>>=0;var p,f=q.getJsObject(s);c===0&&Eo("getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE"),c==4294967295&&(c=void 0);try{p=f.getMappedRange(u,c)}catch{return 0}var m=Js(16,p.byteLength);return Ue().fill(0,m,p.byteLength),q.Internals.bufferOnUnmaps[s].push(()=>{new Uint8Array(p).set(Ue().subarray(m>>>0,m+p.byteLength>>>0)),Ut(m)}),m}var O$=function(s,u,c,p,f){s>>>=0,u=It(u),c=It(c),p>>>=0,f>>>=0;var m=q.getJsObject(s);q.Internals.bufferOnUnmaps[s]=[],f==4294967295&&(f=void 0),Rn(),q.Internals.futureInsert(u,m.mapAsync(c,p,f).then(()=>{mr(),Ws(u,1,0)},b=>{mr(),F();var y=gr(b.message),v=b.name==="AbortError"?4:b.name==="OperationError"?3:0;Ws(u,v,y),delete q.Internals.bufferOnUnmaps[s]}))};function C$(s){s>>>=0;var u=q.getJsObject(s),c=q.Internals.bufferOnUnmaps[s];if(c){for(var p=0;p>>=0,delete q.Internals.jsObjects[s]}function E$(s,u,c){s>>>=0,u>>>=0,c>>>=0;var p,f=!!U()[u+32>>>2>>>0],m={label:q.makeStringFromOptionalStringView(u+4),usage:U()[u+16>>>2>>>0],size:4294967296*U()[u+4+24>>>2>>>0]+U()[u+24>>>2>>>0],mappedAtCreation:f},b=q.getJsObject(s);try{p=b.createBuffer(m)}catch{return!1}return q.Internals.jsObjectInsert(c,p),f&&(q.Internals.bufferOnUnmaps[c]=[]),!0}function D$(s,u,c){s>>>=0,u>>>=0,c>>>=0;var p=U()[u>>>2>>>0],f=U()[p+4>>>2>>>0],m={label:q.makeStringFromOptionalStringView(u+4),code:""};f===2&&(m.code=q.makeStringFromStringView(p+8));var b=q.getJsObject(s);q.Internals.jsObjectInsert(c,b.createShaderModule(m))}var k$=s=>{q.getJsObject(s).destroy()},N$=function(s,u){s>>>=0,u=It(u);var c=q.getJsObject(s);Rn(),q.Internals.futureInsert(u,c.popErrorScope().then(p=>{mr();var f=5;p?p instanceof GPUValidationError?f=2:p instanceof GPUOutOfMemoryError?f=3:p instanceof GPUInternalError&&(f=4):f=1;var m=F(),b=p?gr(p.message):0;Hs(u,1,f,b),V(m)},p=>{mr();var f=F(),m=gr(p.message);Hs(u,1,5,m),V(f)}))};function L$(s,u,c,p){var f;if(u=It(u),p>>>=0,c>>>=0){var m=U()[c+4>>>2>>>0];f={featureLevel:q.FeatureLevel[m],powerPreference:q.PowerPreference[U()[c+8>>>2>>>0]],forceFallbackAdapter:!!U()[c+12>>>2>>>0]};var b=U()[c>>>2>>>0];if(b!==0){U()[b+4>>>2>>>0];var y=b;f.xrCompatible=!!U()[y+8>>>2>>>0]}}if(!("gpu"in navigator)){var v=F(),I=gr("WebGPU not available on this browser (navigator.gpu is not available)");return ko(u,3,p,I),void V(v)}Rn(),q.Internals.futureInsert(u,navigator.gpu.requestAdapter(f).then($=>{if(mr(),$)q.Internals.jsObjectInsert(p,$),ko(u,1,p,0);else{var C=F(),k=gr("WebGPU not available on this browser (requestAdapter returned null)");ko(u,3,p,k),V(C)}},$=>{mr();var C=F(),k=gr($.message);ko(u,4,p,k),V(C)}))}var cp=function(s,u,c){return s>>>=0,u>>>=0,c>>>=0,ye.handleAsync(async()=>{var p=[];if(c){var f=(4294967296*U()[c+4>>>2>>>0]+U()[c>>>2>>>0])/1e6;p.length=u+1,p[u]=new Promise(v=>setTimeout(v,f,0))}else p.length=u;for(var m=0;m>>2>>>0]+U()[s+8*m>>>2>>>0];if(!(b in q.Internals.futures))return b;p[m]=q.Internals.futures[b]}let y=await Promise.race(p);return delete q.Internals.futures[y],y})};cp.isAsync=!0;var Ns={},Do=()=>{if(!Do.strings){var s={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:"./this.program"};for(var u in Ns)Ns[u]===void 0?delete s[u]:s[u]=Ns[u];var c=[];for(var u in s)c.push(`${u}=${s[u]}`);Do.strings=c}return Do.strings},dp=function(s,u){if(l)return st(19,0,1,s,u);s>>>=0,u>>>=0;var c=0;return Do().forEach((p,f)=>{var m=u+c;U()[s+4*f>>>2>>>0]=m,((b,y)=>{for(var v=0;v>>0]=b.charCodeAt(v);Te()[y>>>0]=0})(p,m),c+=p.length+1}),0},pp=function(s,u){if(l)return st(20,0,1,s,u);s>>>=0,u>>>=0;var c=Do();U()[s>>>2>>>0]=c.length;var p=0;return c.forEach(f=>p+=f.length+1),U()[u>>>2>>>0]=p,0};function fp(s){return l?st(21,0,1,s):52}function hp(s,u,c,p){return l?st(22,0,1,s,u,c,p):(u>>>=0,c>>>=0,p>>>=0,52)}function mp(s,u,c,p){return l?st(23,0,1,s,u,c,p):(u=It(u),p>>>=0,70)}var R$=[null,[],[]],z$=(s,u)=>{var c=R$[s];u===0||u===10?((s===1?O:E)(kd(c)),c.length=0):c.push(u)};function gp(s,u,c,p){if(l)return st(24,0,1,s,u,c,p);u>>>=0,c>>>=0,p>>>=0;for(var f=0,m=0;m>>2>>>0],y=U()[u+4>>>2>>>0];u+=8;for(var v=0;v>>0]);f+=y}return U()[p>>>2>>>0]=f,0}function M$(s){return s>>>0}function B$(s,u){s>>>=0,u>>>=0;var c=q.getJsObject(s);return q.fillLimitStruct(c.limits,u),1}function F$(s,u){return s>>>=0,q.getJsObject(s).features.has(q.FeatureName[u])}var V$=function(s){s>>>=0;var u=q.getJsObject(s).size;return BigInt(u)},j$=function(s){s>>>=0;var u=q.getJsObject(s).usage;return BigInt(u)};function G$(s,u){var c;s>>>=0,(u>>>=0)&&(c={label:q.makeStringFromOptionalStringView(u+4),timestampWrites:q.makePassTimestampWrites(U()[u+12>>>2>>>0])});var p=q.getJsObject(s),f=Fs(0);return q.Internals.jsObjectInsert(f,p.beginComputePass(c)),f}function U$(s,u,c,p,f,m){s>>>=0,u>>>=0,c=It(c),p>>>=0,f=It(f),m=It(m);var b=q.getJsObject(s),y=q.getJsObject(u),v=q.getJsObject(p);b.copyBufferToBuffer(y,c,v,f,m)}function W$(s,u){s>>>=0;var c=q.getJsObject(s),p=Ms(0);return q.Internals.jsObjectInsert(p,c.finish()),p}function H$(s,u,c,p,f,m){s>>>=0,u>>>=0,f>>>=0,m=It(m);var b=q.getJsObject(s),y=q.getJsObject(u),v=q.getJsObject(f);b.resolveQuerySet(y,c,p,v,m)}function q$(s,u,c,p){s>>>=0,q.getJsObject(s).dispatchWorkgroups(u,c,p)}function K$(s){s>>>=0,q.getJsObject(s).end()}function X$(s,u,c,p,f){s>>>=0,c>>>=0,p>>>=0,f>>>=0;var m=q.getJsObject(s),b=q.getJsObject(c);if(p==0)m.setBindGroup(u,b);else{for(var y=[],v=0;v>>2>>>0]);m.setBindGroup(u,b,y)}}function J$(s,u){s>>>=0,u>>>=0;var c=q.getJsObject(s),p=q.getJsObject(u);c.setPipeline(p)}function Z$(s,u,c){s>>>=0,u>>>=0;var p=q.getJsObject(s),f=q.getJsObject(u);p.writeTimestamp(f,c)}function Q$(s,u){s>>>=0;var c=q.getJsObject(s),p=zs(0);return q.Internals.jsObjectInsert(p,c.getBindGroupLayout(u)),p}var Y$=s=>U()[s>>>2>>>0]+4294967296*j()[s+4>>>2>>>0];function eA(s,u){function c(b){var y=U()[b+8>>>2>>>0],v=U()[b+32>>>2>>>0],I=U()[b+36>>>2>>>0],$=U()[b+4>>>2>>>0];if(y){var C=Y$(b+24);return C==-1&&(C=void 0),{binding:$,resource:{buffer:q.getJsObject(y),offset:4294967296*U()[b+4+16>>>2>>>0]+U()[b+16>>>2>>>0],size:C}}}return v?{binding:$,resource:q.getJsObject(v)}:{binding:$,resource:q.getJsObject(I)}}s>>>=0,u>>>=0;var p={label:q.makeStringFromOptionalStringView(u+4),layout:q.getJsObject(U()[u+12>>>2>>>0]),entries:function(b,y){for(var v=[],I=0;I>>2>>>0],U()[u+20>>>2>>>0])},f=q.getJsObject(s),m=Rs(0);return q.Internals.jsObjectInsert(m,f.createBindGroup(p)),m}function tA(s,u){var c;s>>>=0,(u>>>=0)&&(c={label:q.makeStringFromOptionalStringView(u+4)});var p=q.getJsObject(s),f=Bs(0);return q.Internals.jsObjectInsert(f,p.createCommandEncoder(c)),f}function rA(s,u){s>>>=0,u>>>=0;var c=q.makeComputePipelineDesc(u),p=q.getJsObject(s),f=Vs(0);return q.Internals.jsObjectInsert(f,p.createComputePipeline(c)),f}function nA(s,u){s>>>=0,u>>>=0;var c={type:q.QueryType[U()[u+12>>>2>>>0]],count:U()[u+16>>>2>>>0]},p=q.getJsObject(s),f=js(0);return q.Internals.jsObjectInsert(f,p.createQuerySet(c)),f}var oA=s=>{var u=gn(s)+1,c=so(u);return c&&bn(s,c,u),c};function iA(s,u){s>>>=0,u>>>=0;var c=q.getJsObject(s),p=c.adapterInfo.vendor+c.adapterInfo.architecture+c.adapterInfo.device+c.adapterInfo.description,f=oA(p),m=gn(c.adapterInfo.vendor);q.setStringView(u+4,f,m),f+=m;var b=gn(c.adapterInfo.architecture);q.setStringView(u+12,f,b),f+=b;var y=gn(c.adapterInfo.device);q.setStringView(u+20,f,y),f+=y;var v=gn(c.adapterInfo.description);q.setStringView(u+28,f,v),f+=v,j()[u+36>>>2>>>0]=2;var I=c.adapterInfo.isFallbackAdapter?3:4;return j()[u+40>>>2>>>0]=I,j()[u+44>>>2>>>0]=0,j()[u+48>>>2>>>0]=0,1}var aA=function(s,u){s>>>=0,u>>>=0;var c=q.getJsObject(s),p=so(4*c.features.size),f=0,m=0;c.features.forEach(b=>{var y=q.FeatureNameString2Enum[b];y!==void 0&&(j()[p+f>>>2>>>0]=y,f+=4,m++)}),U()[u+4>>>2>>>0]=p,U()[u>>>2>>>0]=m};function sA(s,u){s>>>=0,u>>>=0;var c=q.getJsObject(s);return q.fillLimitStruct(c.limits,u),1}function uA(s,u){return s>>>=0,q.getJsObject(s).features.has(q.FeatureName[u])}function lA(s,u){s>>>=0,q.getJsObject(s).pushErrorScope(q.ErrorFilter[u])}var cA=function(s,u,c){s>>>=0,u>>>=0,c>>>=0;var p=q.getJsObject(s),f=Array.from(j().subarray(c>>>2>>>0,c+4*u>>>2>>>0),m=>q.getJsObject(m));p.submit(f)};function dA(s,u,c,p,f){s>>>=0,u>>>=0,c=It(c),p>>>=0,f>>>=0;var m=q.getJsObject(s),b=q.getJsObject(u),y=Ue().subarray(p>>>0,p+f>>>0);m.writeBuffer(b,c,y,0,f)}Fe.init(),(()=>{for(var s=new Array(256),u=0;u<256;++u)s[u]=String.fromCharCode(u);qd=s})(),Kd=t.BindingError=class extends Error{constructor(s){super(s),this.name="BindingError"}},t.InternalError=class extends Error{constructor(s){super(s),this.name="InternalError"}},cn.push(0,1,void 0,1,null,1,!0,1,!1,1),t.count_emval_handles=()=>cn.length/2-5-As.length;var pA=[ws,Cd,Pd,Nd,Ld,Rd,zd,Md,Bd,Fd,Vd,jd,Gd,Ud,Wd,Hd,rp,np,op,dp,pp,fp,hp,mp,gp],D=await async function(){function s(f,m){return D=f.exports,D=function(y){var v,I=C=>k=>C(k)>>>0,$=C=>()=>C()>>>0;return(y=Object.assign({},y)).rf=I(y.rf),y.Wf=$(y.Wf),y.Yf=I(y.Yf),y.Jg=(v=y.Jg,(C,k)=>v(C,k)>>>0),y.Og=I(y.Og),y.Pg=$(y.Pg),y.Tg=I(y.Tg),y}(D=ye.instrumentWasmExports(D)),b=D.Ag,Fe.tlsInitFunctions.push(b),D.Bg,z=m,vd(),D;var b}_d();var u,c,p=wd();if(t.instantiateWasm)return new Promise((f,m)=>{t.instantiateWasm(p,(b,y)=>{s(b,y),f(b.exports)})});if(l)return new Promise(f=>{Et=m=>{var b=new WebAssembly.Instance(m,wd());f(s(b,m))}});mn??=t.locateFile?(u="ort-wasm-simd-threaded.jsep.wasm",t.locateFile?t.locateFile(u,S):S+u):new URL("ort-wasm-simd-threaded.jsep.wasm",import.meta.url).href;try{return s((c=await WI(ue,mn,p)).instance,c.module)}catch(f){return r(f),Promise.reject(f)}}(),bp=s=>(bp=D.rf)(s),yp=()=>(yp=D.sf)(),Ls=(t._OrtInit=(s,u)=>(t._OrtInit=D.tf)(s,u),t._OrtGetLastError=(s,u)=>(t._OrtGetLastError=D.uf)(s,u),t._OrtCreateSessionOptions=(s,u,c,p,f,m,b,y,v,I)=>(t._OrtCreateSessionOptions=D.vf)(s,u,c,p,f,m,b,y,v,I),t._OrtAppendExecutionProvider=(s,u,c,p,f)=>(t._OrtAppendExecutionProvider=D.wf)(s,u,c,p,f),t._OrtAddFreeDimensionOverride=(s,u,c)=>(t._OrtAddFreeDimensionOverride=D.xf)(s,u,c),t._OrtAddSessionConfigEntry=(s,u,c)=>(t._OrtAddSessionConfigEntry=D.yf)(s,u,c),t._OrtReleaseSessionOptions=s=>(t._OrtReleaseSessionOptions=D.zf)(s),t._OrtCreateSession=(s,u,c)=>(t._OrtCreateSession=D.Af)(s,u,c),t._OrtReleaseSession=s=>(t._OrtReleaseSession=D.Bf)(s),t._OrtGetInputOutputCount=(s,u,c)=>(t._OrtGetInputOutputCount=D.Cf)(s,u,c),t._OrtGetInputOutputMetadata=(s,u,c,p)=>(t._OrtGetInputOutputMetadata=D.Df)(s,u,c,p),t._OrtFree=s=>(t._OrtFree=D.Ef)(s),t._OrtCreateTensor=(s,u,c,p,f,m)=>(t._OrtCreateTensor=D.Ff)(s,u,c,p,f,m),t._OrtGetTensorData=(s,u,c,p,f)=>(t._OrtGetTensorData=D.Gf)(s,u,c,p,f),t._OrtReleaseTensor=s=>(t._OrtReleaseTensor=D.Hf)(s),t._OrtCreateRunOptions=(s,u,c,p)=>(t._OrtCreateRunOptions=D.If)(s,u,c,p),t._OrtAddRunConfigEntry=(s,u,c)=>(t._OrtAddRunConfigEntry=D.Jf)(s,u,c),t._OrtReleaseRunOptions=s=>(t._OrtReleaseRunOptions=D.Kf)(s),t._OrtCreateBinding=s=>(t._OrtCreateBinding=D.Lf)(s),t._OrtBindInput=(s,u,c)=>(t._OrtBindInput=D.Mf)(s,u,c),t._OrtBindOutput=(s,u,c,p)=>(t._OrtBindOutput=D.Nf)(s,u,c,p),t._OrtClearBoundOutputs=s=>(t._OrtClearBoundOutputs=D.Of)(s),t._OrtReleaseBinding=s=>(t._OrtReleaseBinding=D.Pf)(s),t._OrtRunWithBinding=(s,u,c,p,f)=>(t._OrtRunWithBinding=D.Qf)(s,u,c,p,f),t._OrtRun=(s,u,c,p,f,m,b,y)=>(t._OrtRun=D.Rf)(s,u,c,p,f,m,b,y),t._OrtEndProfiling=s=>(t._OrtEndProfiling=D.Sf)(s),t._OrtGetWebGpuDevice=s=>(Ls=t._OrtGetWebGpuDevice=D.Tf)(s)),vi=(t._JsepOutput=(s,u,c)=>(t._JsepOutput=D.Uf)(s,u,c),t._JsepGetNodeName=s=>(t._JsepGetNodeName=D.Vf)(s),()=>(vi=D.Wf)()),Ut=t._free=s=>(Ut=t._free=D.Xf)(s),so=t._malloc=s=>(so=t._malloc=D.Yf)(s),_p=t._wgpuBufferRelease=s=>(_p=t._wgpuBufferRelease=D.Zf)(s),vp=t._wgpuCreateInstance=s=>(vp=t._wgpuCreateInstance=D._f)(s),Rs=s=>(Rs=D.$f)(s),zs=s=>(zs=D.ag)(s),Ms=s=>(Ms=D.bg)(s),Bs=s=>(Bs=D.cg)(s),Fs=s=>(Fs=D.dg)(s),Vs=s=>(Vs=D.eg)(s),wp=s=>(wp=D.fg)(s),js=s=>(js=D.gg)(s),xp=s=>(xp=D.hg)(s),Tp=s=>(Tp=D.ig)(s),Ip=s=>(Ip=D.jg)(s),Sp=s=>(Sp=D.kg)(s),$p=s=>($p=D.lg)(s),Ap=s=>(Ap=D.mg)(s),Op=s=>(Op=D.ng)(s),Cp=s=>(Cp=D.og)(s),Pp=s=>(Pp=D.pg)(s),Ep=(s,u)=>(Ep=D.qg)(s,u),Dp=(s,u)=>(Dp=D.rg)(s,u),Gs=s=>(Gs=D.sg)(s),kp=s=>(kp=D.tg)(s),Us=(s,u,c)=>(Us=D.ug)(s,u,c),Ws=(s,u,c)=>(Ws=D.vg)(s,u,c),Hs=(s,u,c,p)=>(Hs=D.wg)(s,u,c,p),ko=(s,u,c,p)=>(ko=D.xg)(s,u,c,p),qs=(s,u,c,p)=>(qs=D.yg)(s,u,c,p),Np=(s,u,c)=>(Np=D.zg)(s,u,c),Ks=(s,u,c,p,f,m)=>(Ks=D.Cg)(s,u,c,p,f,m),Lp=()=>(Lp=D.Dg)(),Rp=(s,u,c,p,f)=>(Rp=D.Eg)(s,u,c,p,f),zp=s=>(zp=D.Fg)(s),Xs=s=>(Xs=D.Gg)(s),Mp=(s,u)=>(Mp=D.Hg)(s,u),Bp=()=>(Bp=D.Ig)(),Js=(s,u)=>(Js=D.Jg)(s,u),G=(s,u)=>(G=D.Kg)(s,u),Fp=s=>(Fp=D.Lg)(s),Vp=(s,u)=>(Vp=D.Mg)(s,u),jp=s=>(jp=D.Ng)(s),Gp=s=>(Gp=D.Og)(s),Up=()=>(Up=D.Pg)(),Wp=s=>(Wp=D.Qg)(s),Hp=s=>(Hp=D.Rg)(s),qp=(s,u,c)=>(qp=D.Sg)(s,u,c),Kp=s=>(Kp=D.Tg)(s),Xp=t.dynCall_vii=(s,u,c)=>(Xp=t.dynCall_vii=D.Ug)(s,u,c),Jp=t.dynCall_iiii=(s,u,c,p)=>(Jp=t.dynCall_iiii=D.Vg)(s,u,c,p),Zp=t.dynCall_iii=(s,u,c)=>(Zp=t.dynCall_iii=D.Wg)(s,u,c),Zs=t.dynCall_ii=(s,u)=>(Zs=t.dynCall_ii=D.Xg)(s,u),Qp=t.dynCall_iiiiiii=(s,u,c,p,f,m,b)=>(Qp=t.dynCall_iiiiiii=D.Yg)(s,u,c,p,f,m,b),Yp=t.dynCall_vi=(s,u)=>(Yp=t.dynCall_vi=D.Zg)(s,u),ef=t.dynCall_v=s=>(ef=t.dynCall_v=D._g)(s),tf=t.dynCall_iiiiii=(s,u,c,p,f,m)=>(tf=t.dynCall_iiiiii=D.$g)(s,u,c,p,f,m),Qs=t.dynCall_viii=(s,u,c,p)=>(Qs=t.dynCall_viii=D.ah)(s,u,c,p),rf=t.dynCall_i=s=>(rf=t.dynCall_i=D.bh)(s),nf=t.dynCall_iiiii=(s,u,c,p,f)=>(nf=t.dynCall_iiiii=D.ch)(s,u,c,p,f),of=t.dynCall_viiii=(s,u,c,p,f)=>(of=t.dynCall_viiii=D.dh)(s,u,c,p,f),af=t.dynCall_viiiii=(s,u,c,p,f,m)=>(af=t.dynCall_viiiii=D.eh)(s,u,c,p,f,m),sf=t.dynCall_vijii=(s,u,c,p,f)=>(sf=t.dynCall_vijii=D.fh)(s,u,c,p,f),uf=t.dynCall_vijjiii=(s,u,c,p,f,m,b)=>(uf=t.dynCall_vijjiii=D.gh)(s,u,c,p,f,m,b),lf=t.dynCall_vijj=(s,u,c,p)=>(lf=t.dynCall_vijj=D.hh)(s,u,c,p),cf=t.dynCall_vijji=(s,u,c,p,f)=>(cf=t.dynCall_vijji=D.ih)(s,u,c,p,f),df=t.dynCall_diii=(s,u,c,p)=>(df=t.dynCall_diii=D.jh)(s,u,c,p),pf=t.dynCall_viiij=(s,u,c,p,f)=>(pf=t.dynCall_viiij=D.kh)(s,u,c,p,f),ff=t.dynCall_iiij=(s,u,c,p)=>(ff=t.dynCall_iiij=D.lh)(s,u,c,p),hf=t.dynCall_viijii=(s,u,c,p,f,m)=>(hf=t.dynCall_viijii=D.mh)(s,u,c,p,f,m),mf=t.dynCall_iif=(s,u,c)=>(mf=t.dynCall_iif=D.nh)(s,u,c),gf=t.dynCall_jiii=(s,u,c,p)=>(gf=t.dynCall_jiii=D.oh)(s,u,c,p),bf=t.dynCall_viijijj=(s,u,c,p,f,m,b)=>(bf=t.dynCall_viijijj=D.ph)(s,u,c,p,f,m,b),yf=t.dynCall_vij=(s,u,c)=>(yf=t.dynCall_vij=D.qh)(s,u,c),_f=t.dynCall_viij=(s,u,c,p)=>(_f=t.dynCall_viij=D.rh)(s,u,c,p),vf=t.dynCall_iiiiid=(s,u,c,p,f,m)=>(vf=t.dynCall_iiiiid=D.sh)(s,u,c,p,f,m),wf=t.dynCall_viijj=(s,u,c,p,f)=>(wf=t.dynCall_viijj=D.th)(s,u,c,p,f),xf=t.dynCall_iij=(s,u,c)=>(xf=t.dynCall_iij=D.uh)(s,u,c),Tf=t.dynCall_iiiiij=(s,u,c,p,f,m)=>(Tf=t.dynCall_iiiiij=D.vh)(s,u,c,p,f,m),If=t.dynCall_j=s=>(If=t.dynCall_j=D.wh)(s),Sf=t.dynCall_viiiiiii=(s,u,c,p,f,m,b,y)=>(Sf=t.dynCall_viiiiiii=D.xh)(s,u,c,p,f,m,b,y),$f=t.dynCall_iiiiiiiii=(s,u,c,p,f,m,b,y,v)=>($f=t.dynCall_iiiiiiiii=D.yh)(s,u,c,p,f,m,b,y,v),Af=t.dynCall_iiiiijiiiii=(s,u,c,p,f,m,b,y,v,I,$)=>(Af=t.dynCall_iiiiijiiiii=D.zh)(s,u,c,p,f,m,b,y,v,I,$),Of=t.dynCall_iiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$)=>(Of=t.dynCall_iiiiiiiiiii=D.Ah)(s,u,c,p,f,m,b,y,v,I,$),Cf=t.dynCall_vijjjiiiiij=(s,u,c,p,f,m,b,y,v,I,$)=>(Cf=t.dynCall_vijjjiiiiij=D.Bh)(s,u,c,p,f,m,b,y,v,I,$),Pf=t.dynCall_viiiiii=(s,u,c,p,f,m,b)=>(Pf=t.dynCall_viiiiii=D.Ch)(s,u,c,p,f,m,b),Ef=t.dynCall_viji=(s,u,c,p)=>(Ef=t.dynCall_viji=D.Dh)(s,u,c,p),Df=t.dynCall_viiiiiiiii=(s,u,c,p,f,m,b,y,v,I)=>(Df=t.dynCall_viiiiiiiii=D.Eh)(s,u,c,p,f,m,b,y,v,I),kf=t.dynCall_fi=(s,u)=>(kf=t.dynCall_fi=D.Fh)(s,u),Nf=t.dynCall_fii=(s,u,c)=>(Nf=t.dynCall_fii=D.Gh)(s,u,c),Lf=t.dynCall_ji=(s,u)=>(Lf=t.dynCall_ji=D.Hh)(s,u),Rf=t.dynCall_di=(s,u)=>(Rf=t.dynCall_di=D.Ih)(s,u),zf=t.dynCall_jii=(s,u,c)=>(zf=t.dynCall_jii=D.Jh)(s,u,c),Mf=t.dynCall_dii=(s,u,c)=>(Mf=t.dynCall_dii=D.Kh)(s,u,c),Bf=t.dynCall_viijiii=(s,u,c,p,f,m,b)=>(Bf=t.dynCall_viijiii=D.Lh)(s,u,c,p,f,m,b),Ff=t.dynCall_viiiiiiii=(s,u,c,p,f,m,b,y,v)=>(Ff=t.dynCall_viiiiiiii=D.Mh)(s,u,c,p,f,m,b,y,v),Vf=t.dynCall_iiiiiiiij=(s,u,c,p,f,m,b,y,v)=>(Vf=t.dynCall_iiiiiiiij=D.Nh)(s,u,c,p,f,m,b,y,v),jf=t.dynCall_iiiiiiii=(s,u,c,p,f,m,b,y)=>(jf=t.dynCall_iiiiiiii=D.Oh)(s,u,c,p,f,m,b,y),Gf=t.dynCall_viiji=(s,u,c,p,f)=>(Gf=t.dynCall_viiji=D.Ph)(s,u,c,p,f),Uf=t.dynCall_viiiiij=(s,u,c,p,f,m,b)=>(Uf=t.dynCall_viiiiij=D.Qh)(s,u,c,p,f,m,b),Wf=t.dynCall_viijjjiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Wf=t.dynCall_viijjjiiiiii=D.Rh)(s,u,c,p,f,m,b,y,v,I,$,C),Hf=t.dynCall_viiijiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Hf=t.dynCall_viiijiiiiiii=D.Sh)(s,u,c,p,f,m,b,y,v,I,$,C),qf=t.dynCall_iiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(qf=t.dynCall_iiiiiiiiiiiii=D.Th)(s,u,c,p,f,m,b,y,v,I,$,C,k),Kf=t.dynCall_viiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$)=>(Kf=t.dynCall_viiiiiiiiii=D.Uh)(s,u,c,p,f,m,b,y,v,I,$),Xf=t.dynCall_viiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)=>(Xf=t.dynCall_viiiiiiiiiiiiiiii=D.Vh)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q),Jf=t.dynCall_viid=(s,u,c,p)=>(Jf=t.dynCall_viid=D.Wh)(s,u,c,p),Zf=t.dynCall_vid=(s,u,c)=>(Zf=t.dynCall_vid=D.Xh)(s,u,c),Qf=t.dynCall_viiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Qf=t.dynCall_viiiiiiiiiii=D.Yh)(s,u,c,p,f,m,b,y,v,I,$,C),Yf=t.dynCall_viiijjjii=(s,u,c,p,f,m,b,y,v)=>(Yf=t.dynCall_viiijjjii=D.Zh)(s,u,c,p,f,m,b,y,v),eh=t.dynCall_iid=(s,u,c)=>(eh=t.dynCall_iid=D._h)(s,u,c),th=t.dynCall_viiiij=(s,u,c,p,f,m)=>(th=t.dynCall_viiiij=D.$h)(s,u,c,p,f,m),rh=t.dynCall_viiijiiiii=(s,u,c,p,f,m,b,y,v,I)=>(rh=t.dynCall_viiijiiiii=D.ai)(s,u,c,p,f,m,b,y,v,I),nh=t.dynCall_jj=(s,u)=>(nh=t.dynCall_jj=D.bi)(s,u),oh=t.dynCall_iiiijii=(s,u,c,p,f,m,b)=>(oh=t.dynCall_iiiijii=D.ci)(s,u,c,p,f,m,b),ih=t.dynCall_iiijii=(s,u,c,p,f,m)=>(ih=t.dynCall_iiijii=D.di)(s,u,c,p,f,m),ah=t.dynCall_viiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)=>(ah=t.dynCall_viiiiiiiiiiiiiii=D.ei)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y),sh=t.dynCall_iiijjj=(s,u,c,p,f,m)=>(sh=t.dynCall_iiijjj=D.fi)(s,u,c,p,f,m),uh=t.dynCall_ij=(s,u)=>(uh=t.dynCall_ij=D.gi)(s,u),lh=t.dynCall_viiiiji=(s,u,c,p,f,m,b)=>(lh=t.dynCall_viiiiji=D.hi)(s,u,c,p,f,m,b),ch=t.dynCall_iijjji=(s,u,c,p,f,m)=>(ch=t.dynCall_iijjji=D.ii)(s,u,c,p,f,m),dh=t.dynCall_vjiiiiii=(s,u,c,p,f,m,b,y)=>(dh=t.dynCall_vjiiiiii=D.ji)(s,u,c,p,f,m,b,y),ph=t.dynCall_vijjiiiii=(s,u,c,p,f,m,b,y,v)=>(ph=t.dynCall_vijjiiiii=D.ki)(s,u,c,p,f,m,b,y,v),fh=t.dynCall_jiij=(s,u,c,p)=>(fh=t.dynCall_jiij=D.li)(s,u,c,p),hh=t.dynCall_iijijjijiji=(s,u,c,p,f,m,b,y,v,I,$)=>(hh=t.dynCall_iijijjijiji=D.mi)(s,u,c,p,f,m,b,y,v,I,$),mh=t.dynCall_iijijji=(s,u,c,p,f,m,b)=>(mh=t.dynCall_iijijji=D.ni)(s,u,c,p,f,m,b),gh=t.dynCall_ijijji=(s,u,c,p,f,m)=>(gh=t.dynCall_ijijji=D.oi)(s,u,c,p,f,m),bh=t.dynCall_iiiiiiij=(s,u,c,p,f,m,b,y)=>(bh=t.dynCall_iiiiiiij=D.pi)(s,u,c,p,f,m,b,y),yh=t.dynCall_viiijjiii=(s,u,c,p,f,m,b,y,v)=>(yh=t.dynCall_viiijjiii=D.qi)(s,u,c,p,f,m,b,y,v),_h=t.dynCall_vif=(s,u,c)=>(_h=t.dynCall_vif=D.ri)(s,u,c),vh=t.dynCall_viif=(s,u,c,p)=>(vh=t.dynCall_viif=D.si)(s,u,c,p),wh=t.dynCall_iiiiijji=(s,u,c,p,f,m,b,y)=>(wh=t.dynCall_iiiiijji=D.ti)(s,u,c,p,f,m,b,y),xh=t.dynCall_iiiiji=(s,u,c,p,f,m)=>(xh=t.dynCall_iiiiji=D.ui)(s,u,c,p,f,m),Th=t.dynCall_iiiifi=(s,u,c,p,f,m)=>(Th=t.dynCall_iiiifi=D.vi)(s,u,c,p,f,m),Ih=t.dynCall_iiiiiiiiijii=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Ih=t.dynCall_iiiiiiiiijii=D.wi)(s,u,c,p,f,m,b,y,v,I,$,C),Sh=t.dynCall_iiiijjii=(s,u,c,p,f,m,b,y)=>(Sh=t.dynCall_iiiijjii=D.xi)(s,u,c,p,f,m,b,y),$h=t.dynCall_iiiiiijjjii=(s,u,c,p,f,m,b,y,v,I,$)=>($h=t.dynCall_iiiiiijjjii=D.yi)(s,u,c,p,f,m,b,y,v,I,$),Ah=t.dynCall_iiijiii=(s,u,c,p,f,m,b)=>(Ah=t.dynCall_iiijiii=D.zi)(s,u,c,p,f,m,b),Oh=t.dynCall_iiiiiiiijjjfi=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Oh=t.dynCall_iiiiiiiijjjfi=D.Ai)(s,u,c,p,f,m,b,y,v,I,$,C,k),Ch=t.dynCall_iijiiii=(s,u,c,p,f,m,b)=>(Ch=t.dynCall_iijiiii=D.Bi)(s,u,c,p,f,m,b),Ph=t.dynCall_viiiijj=(s,u,c,p,f,m,b)=>(Ph=t.dynCall_viiiijj=D.Ci)(s,u,c,p,f,m,b),Eh=t.dynCall_iijjjii=(s,u,c,p,f,m,b)=>(Eh=t.dynCall_iijjjii=D.Di)(s,u,c,p,f,m,b),Dh=t.dynCall_jij=(s,u,c)=>(Dh=t.dynCall_jij=D.Ei)(s,u,c),kh=t.dynCall_jjj=(s,u,c)=>(kh=t.dynCall_jjj=D.Fi)(s,u,c),Nh=t.dynCall_iiji=(s,u,c,p)=>(Nh=t.dynCall_iiji=D.Gi)(s,u,c,p),Lh=t.dynCall_viffiii=(s,u,c,p,f,m,b)=>(Lh=t.dynCall_viffiii=D.Hi)(s,u,c,p,f,m,b),Rh=t.dynCall_viifiii=(s,u,c,p,f,m,b)=>(Rh=t.dynCall_viifiii=D.Ii)(s,u,c,p,f,m,b),zh=t.dynCall_viiiiidiidi=(s,u,c,p,f,m,b,y,v,I,$)=>(zh=t.dynCall_viiiiidiidi=D.Ji)(s,u,c,p,f,m,b,y,v,I,$),Mh=t.dynCall_viiiiiiiiidi=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Mh=t.dynCall_viiiiiiiiidi=D.Ki)(s,u,c,p,f,m,b,y,v,I,$,C),Bh=t.dynCall_viiiiiiiiiiiiiifi=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)=>(Bh=t.dynCall_viiiiiiiiiiiiiifi=D.Li)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q),Fh=t.dynCall_ijii=(s,u,c,p)=>(Fh=t.dynCall_ijii=D.Mi)(s,u,c,p),Vh=t.dynCall_viijiiiijiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>(Vh=t.dynCall_viijiiiijiii=D.Ni)(s,u,c,p,f,m,b,y,v,I,$,C),jh=t.dynCall_vijjjjjjjjjjjjji=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)=>(jh=t.dynCall_vijjjjjjjjjjjjji=D.Oi)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y),Gh=t.dynCall_viiijii=(s,u,c,p,f,m,b)=>(Gh=t.dynCall_viiijii=D.Pi)(s,u,c,p,f,m,b),Uh=t.dynCall_vijjjiiji=(s,u,c,p,f,m,b,y,v)=>(Uh=t.dynCall_vijjjiiji=D.Qi)(s,u,c,p,f,m,b,y,v),Wh=t.dynCall_iiiijiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(Wh=t.dynCall_iiiijiiiiiiiiii=D.Ri)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),Hh=t.dynCall_iiiiiiiiii=(s,u,c,p,f,m,b,y,v,I)=>(Hh=t.dynCall_iiiiiiiiii=D.Si)(s,u,c,p,f,m,b,y,v,I),qh=t.dynCall_vj=(s,u)=>(qh=t.dynCall_vj=D.Ti)(s,u),Kh=t.dynCall_vfiii=(s,u,c,p,f)=>(Kh=t.dynCall_vfiii=D.Ui)(s,u,c,p,f),Xh=t.dynCall_viiiiff=(s,u,c,p,f,m,b)=>(Xh=t.dynCall_viiiiff=D.Vi)(s,u,c,p,f,m,b),Jh=t.dynCall_viiiiiff=(s,u,c,p,f,m,b,y)=>(Jh=t.dynCall_viiiiiff=D.Wi)(s,u,c,p,f,m,b,y),Zh=t.dynCall_viiff=(s,u,c,p,f)=>(Zh=t.dynCall_viiff=D.Xi)(s,u,c,p,f),Qh=t.dynCall_viiiiiiiiifiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(Qh=t.dynCall_viiiiiiiiifiiii=D.Yi)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),Yh=t.dynCall_viiiiiiiijj=(s,u,c,p,f,m,b,y,v,I,$)=>(Yh=t.dynCall_viiiiiiiijj=D.Zi)(s,u,c,p,f,m,b,y,v,I,$),em=t.dynCall_iiiiiiiiiiiiiifii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)=>(em=t.dynCall_iiiiiiiiiiiiiifii=D._i)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q),tm=t.dynCall_viiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(tm=t.dynCall_viiiiiiiiiiiii=D.$i)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),rm=t.dynCall_iiiiiiiiiiiiiiiiiiifii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt)=>(rm=t.dynCall_iiiiiiiiiiiiiiiiiiifii=D.aj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt),nm=t.dynCall_vijjiiiiiii=(s,u,c,p,f,m,b,y,v,I,$)=>(nm=t.dynCall_vijjiiiiiii=D.bj)(s,u,c,p,f,m,b,y,v,I,$),om=t.dynCall_iiiijjj=(s,u,c,p,f,m,b)=>(om=t.dynCall_iiiijjj=D.cj)(s,u,c,p,f,m,b),im=t.dynCall_fffffff=(s,u,c,p,f,m,b)=>(im=t.dynCall_fffffff=D.dj)(s,u,c,p,f,m,b),am=t.dynCall_viiiiiijiifiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(am=t.dynCall_viiiiiijiifiii=D.ej)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),sm=t.dynCall_vjjjjjjffjifiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re)=>(sm=t.dynCall_vjjjjjjffjifiiiiii=D.fj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re),um=t.dynCall_viiiiiiffjifiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)=>(um=t.dynCall_viiiiiiffjifiiiii=D.gj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q),lm=t.dynCall_viiiiiiffjfiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)=>(lm=t.dynCall_viiiiiiffjfiiiii=D.hj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y),cm=t.dynCall_viiiiiiffjiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(cm=t.dynCall_viiiiiiffjiiiii=D.ij)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),dm=t.dynCall_vjjjjjjjjfffjifiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)=>(dm=t.dynCall_vjjjjjjjjfffjifiiiiii=D.jj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De),pm=t.dynCall_vjjjjjjfffifijiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le)=>(pm=t.dynCall_vjjjjjjfffifijiiiii=D.kj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le),fm=t.dynCall_vjjjjjjfffifiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re)=>(fm=t.dynCall_vjjjjjjfffifiiiiii=D.lj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re),hm=t.dynCall_vjjjjjjjjfffiiifiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)=>(hm=t.dynCall_vjjjjjjjjfffiiifiiiii=D.mj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De),mm=t.dynCall_vijiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(mm=t.dynCall_vijiiiiiiiiii=D.nj)(s,u,c,p,f,m,b,y,v,I,$,C,k),gm=t.dynCall_vijjfffiii=(s,u,c,p,f,m,b,y,v,I)=>(gm=t.dynCall_vijjfffiii=D.oj)(s,u,c,p,f,m,b,y,v,I),bm=t.dynCall_jiijjiif=(s,u,c,p,f,m,b,y)=>(bm=t.dynCall_jiijjiif=D.pj)(s,u,c,p,f,m,b,y),ym=t.dynCall_vijjjjjjifiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(ym=t.dynCall_vijjjjjjifiiiii=D.qj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),_m=t.dynCall_vjjjjjiiii=(s,u,c,p,f,m,b,y,v,I)=>(_m=t.dynCall_vjjjjjiiii=D.rj)(s,u,c,p,f,m,b,y,v,I),vm=t.dynCall_vjjjjfiii=(s,u,c,p,f,m,b,y,v)=>(vm=t.dynCall_vjjjjfiii=D.sj)(s,u,c,p,f,m,b,y,v),wm=t.dynCall_viiiiiijiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(wm=t.dynCall_viiiiiijiiiiii=D.tj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),xm=t.dynCall_vijjii=(s,u,c,p,f,m)=>(xm=t.dynCall_vijjii=D.uj)(s,u,c,p,f,m),Tm=t.dynCall_viiiiijjiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Tm=t.dynCall_viiiiijjiiiii=D.vj)(s,u,c,p,f,m,b,y,v,I,$,C,k),Im=t.dynCall_iiiiiji=(s,u,c,p,f,m,b)=>(Im=t.dynCall_iiiiiji=D.wj)(s,u,c,p,f,m,b),Sm=t.dynCall_viiiiijiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Sm=t.dynCall_viiiiijiiiiii=D.xj)(s,u,c,p,f,m,b,y,v,I,$,C,k),$m=t.dynCall_iiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>($m=t.dynCall_iiiiiiiiiiii=D.yj)(s,u,c,p,f,m,b,y,v,I,$,C),Am=t.dynCall_viiijiiiiii=(s,u,c,p,f,m,b,y,v,I,$)=>(Am=t.dynCall_viiijiiiiii=D.zj)(s,u,c,p,f,m,b,y,v,I,$),Om=t.dynCall_viiiijii=(s,u,c,p,f,m,b,y)=>(Om=t.dynCall_viiiijii=D.Aj)(s,u,c,p,f,m,b,y),Cm=t.dynCall_viijjiii=(s,u,c,p,f,m,b,y)=>(Cm=t.dynCall_viijjiii=D.Bj)(s,u,c,p,f,m,b,y),Pm=t.dynCall_viiiji=(s,u,c,p,f,m)=>(Pm=t.dynCall_viiiji=D.Cj)(s,u,c,p,f,m),Em=t.dynCall_viiiiiijii=(s,u,c,p,f,m,b,y,v,I)=>(Em=t.dynCall_viiiiiijii=D.Dj)(s,u,c,p,f,m,b,y,v,I),Dm=t.dynCall_viiiiijjji=(s,u,c,p,f,m,b,y,v,I)=>(Dm=t.dynCall_viiiiijjji=D.Ej)(s,u,c,p,f,m,b,y,v,I),km=t.dynCall_vijiii=(s,u,c,p,f,m)=>(km=t.dynCall_vijiii=D.Fj)(s,u,c,p,f,m),Nm=t.dynCall_iiijiiii=(s,u,c,p,f,m,b,y)=>(Nm=t.dynCall_iiijiiii=D.Gj)(s,u,c,p,f,m,b,y),Lm=t.dynCall_viiiiiijjiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(Lm=t.dynCall_viiiiiijjiiiii=D.Hj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),Rm=t.dynCall_viiiiiiijiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(Rm=t.dynCall_viiiiiiijiiiiii=D.Ij)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),zm=t.dynCall_viiiiiji=(s,u,c,p,f,m,b,y)=>(zm=t.dynCall_viiiiiji=D.Jj)(s,u,c,p,f,m,b,y),Mm=t.dynCall_fiif=(s,u,c,p)=>(Mm=t.dynCall_fiif=D.Kj)(s,u,c,p),Bm=t.dynCall_viijjjiii=(s,u,c,p,f,m,b,y,v)=>(Bm=t.dynCall_viijjjiii=D.Lj)(s,u,c,p,f,m,b,y,v),Fm=t.dynCall_viiiiiifiii=(s,u,c,p,f,m,b,y,v,I,$)=>(Fm=t.dynCall_viiiiiifiii=D.Mj)(s,u,c,p,f,m,b,y,v,I,$),Vm=t.dynCall_viijji=(s,u,c,p,f,m)=>(Vm=t.dynCall_viijji=D.Nj)(s,u,c,p,f,m),jm=t.dynCall_iiiiiiiiiiijijji=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)=>(jm=t.dynCall_iiiiiiiiiiijijji=D.Oj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y),Gm=t.dynCall_jiijjiii=(s,u,c,p,f,m,b,y)=>(Gm=t.dynCall_jiijjiii=D.Pj)(s,u,c,p,f,m,b,y),Um=t.dynCall_viifiifijjjii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Um=t.dynCall_viifiifijjjii=D.Qj)(s,u,c,p,f,m,b,y,v,I,$,C,k),Wm=t.dynCall_viiiiiiiiiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt,ht,rr)=>(Wm=t.dynCall_viiiiiiiiiiiiiiiiiiiiiii=D.Rj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt,ht,rr),Hm=t.dynCall_viiiiifiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Hm=t.dynCall_viiiiifiiiiii=D.Sj)(s,u,c,p,f,m,b,y,v,I,$,C,k),qm=t.dynCall_vijjiiiiii=(s,u,c,p,f,m,b,y,v,I)=>(qm=t.dynCall_vijjiiiiii=D.Tj)(s,u,c,p,f,m,b,y,v,I),Km=t.dynCall_vijiiiiiiijjii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(Km=t.dynCall_vijiiiiiiijjii=D.Uj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),Xm=t.dynCall_viiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Xm=t.dynCall_viiiiiiiiiiii=D.Vj)(s,u,c,p,f,m,b,y,v,I,$,C,k),Jm=t.dynCall_viiiiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le)=>(Jm=t.dynCall_viiiiiiiiiiiiiiiiii=D.Wj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le),Zm=t.dynCall_viiiiiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e)=>(Zm=t.dynCall_viiiiiiiiiiiiiiiiiii=D.Xj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e),Qm=t.dynCall_viiijiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e)=>(Qm=t.dynCall_viiijiiiiiiiiiiiiiii=D.Yj)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e),Ym=t.dynCall_viiiijjj=(s,u,c,p,f,m,b,y)=>(Ym=t.dynCall_viiiijjj=D.Zj)(s,u,c,p,f,m,b,y),eg=t.dynCall_viiiiiiijjj=(s,u,c,p,f,m,b,y,v,I,$)=>(eg=t.dynCall_viiiiiiijjj=D._j)(s,u,c,p,f,m,b,y,v,I,$),tg=t.dynCall_iiiiiiiiiiiiiiiiiiiifi=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt)=>(tg=t.dynCall_iiiiiiiiiiiiiiiiiiiifi=D.$j)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt),rg=t.dynCall_viiijiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(rg=t.dynCall_viiijiiiiiiiiii=D.ak)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),ng=t.dynCall_viiiiif=(s,u,c,p,f,m,b)=>(ng=t.dynCall_viiiiif=D.bk)(s,u,c,p,f,m,b),og=t.dynCall_viiif=(s,u,c,p,f)=>(og=t.dynCall_viiif=D.ck)(s,u,c,p,f),ig=t.dynCall_viiiiiiiiifi=(s,u,c,p,f,m,b,y,v,I,$,C)=>(ig=t.dynCall_viiiiiiiiifi=D.dk)(s,u,c,p,f,m,b,y,v,I,$,C),ag=t.dynCall_viiiiid=(s,u,c,p,f,m,b)=>(ag=t.dynCall_viiiiid=D.ek)(s,u,c,p,f,m,b),sg=t.dynCall_viiid=(s,u,c,p,f)=>(sg=t.dynCall_viiid=D.fk)(s,u,c,p,f),ug=t.dynCall_iiif=(s,u,c,p)=>(ug=t.dynCall_iiif=D.gk)(s,u,c,p),lg=t.dynCall_iiiij=(s,u,c,p,f)=>(lg=t.dynCall_iiiij=D.hk)(s,u,c,p,f),cg=t.dynCall_iiiiiif=(s,u,c,p,f,m,b)=>(cg=t.dynCall_iiiiiif=D.ik)(s,u,c,p,f,m,b),dg=t.dynCall_vijij=(s,u,c,p,f)=>(dg=t.dynCall_vijij=D.jk)(s,u,c,p,f),pg=t.dynCall_viiijji=(s,u,c,p,f,m,b)=>(pg=t.dynCall_viiijji=D.kk)(s,u,c,p,f,m,b),fg=t.dynCall_viiiiiiffii=(s,u,c,p,f,m,b,y,v,I,$)=>(fg=t.dynCall_viiiiiiffii=D.lk)(s,u,c,p,f,m,b,y,v,I,$),hg=t.dynCall_iifii=(s,u,c,p,f)=>(hg=t.dynCall_iifii=D.mk)(s,u,c,p,f),mg=t.dynCall_viiiiifi=(s,u,c,p,f,m,b,y)=>(mg=t.dynCall_viiiiifi=D.nk)(s,u,c,p,f,m,b,y),gg=t.dynCall_iifjii=(s,u,c,p,f,m)=>(gg=t.dynCall_iifjii=D.ok)(s,u,c,p,f,m),bg=t.dynCall_vidi=(s,u,c,p)=>(bg=t.dynCall_vidi=D.pk)(s,u,c,p),yg=t.dynCall_viiijiji=(s,u,c,p,f,m,b,y)=>(yg=t.dynCall_viiijiji=D.qk)(s,u,c,p,f,m,b,y),_g=t.dynCall_viiijij=(s,u,c,p,f,m,b)=>(_g=t.dynCall_viiijij=D.rk)(s,u,c,p,f,m,b),vg=t.dynCall_vijjj=(s,u,c,p,f)=>(vg=t.dynCall_vijjj=D.sk)(s,u,c,p,f),wg=t.dynCall_vjiij=(s,u,c,p,f)=>(wg=t.dynCall_vjiij=D.tk)(s,u,c,p,f),xg=t.dynCall_diiiii=(s,u,c,p,f,m)=>(xg=t.dynCall_diiiii=D.uk)(s,u,c,p,f,m),Tg=t.dynCall_diiii=(s,u,c,p,f)=>(Tg=t.dynCall_diiii=D.vk)(s,u,c,p,f),Ig=t.dynCall_iiiji=(s,u,c,p,f)=>(Ig=t.dynCall_iiiji=D.wk)(s,u,c,p,f),Sg=t.dynCall_ijiijji=(s,u,c,p,f,m,b)=>(Sg=t.dynCall_ijiijji=D.xk)(s,u,c,p,f,m,b),$g=t.dynCall_viiijjiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C)=>($g=t.dynCall_viiijjiiiiii=D.yk)(s,u,c,p,f,m,b,y,v,I,$,C),Ag=t.dynCall_viijjijjjjiii=(s,u,c,p,f,m,b,y,v,I,$,C,k)=>(Ag=t.dynCall_viijjijjjjiii=D.zk)(s,u,c,p,f,m,b,y,v,I,$,C,k),Og=t.dynCall_ijiii=(s,u,c,p,f)=>(Og=t.dynCall_ijiii=D.Ak)(s,u,c,p,f),Cg=t.dynCall_ijiiiiji=(s,u,c,p,f,m,b,y)=>(Cg=t.dynCall_ijiiiiji=D.Bk)(s,u,c,p,f,m,b,y),Pg=t.dynCall_iiifii=(s,u,c,p,f,m)=>(Pg=t.dynCall_iiifii=D.Ck)(s,u,c,p,f,m),Eg=t.dynCall_ijiij=(s,u,c,p,f)=>(Eg=t.dynCall_ijiij=D.Dk)(s,u,c,p,f),Dg=t.dynCall_viijiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R)=>(Dg=t.dynCall_viijiiiiiiiiii=D.Ek)(s,u,c,p,f,m,b,y,v,I,$,C,k,R),kg=t.dynCall_fiiii=(s,u,c,p,f)=>(kg=t.dynCall_fiiii=D.Fk)(s,u,c,p,f),Ng=t.dynCall_jfi=(s,u,c)=>(Ng=t.dynCall_jfi=D.Gk)(s,u,c),Lg=t.dynCall_viiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)=>(Lg=t.dynCall_viiiiiiiiiiiiii=D.Hk)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X),Rg=t.dynCall_viiiiiiiiiiiiiiiiiiii=(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)=>(Rg=t.dynCall_viiiiiiiiiiiiiiiiiiii=D.Ik)(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De),zg=t.dynCall_fiii=(s,u,c,p)=>(zg=t.dynCall_fiii=D.Jk)(s,u,c,p),Mg=s=>(Mg=D.Kk)(s),Bg=()=>(Bg=D.Lk)(),Fg=s=>(Fg=D.Mk)(s),Vg=()=>(Vg=D.Nk)();function fA(s,u,c,p){var f=F();try{return Jp(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function hA(s,u,c){var p=F();try{return Zp(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function mA(s,u,c){var p=F();try{Xp(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function gA(s,u){var c=F();try{return Zs(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function bA(s,u){var c=F();try{Yp(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function yA(s){var u=F();try{ef(s)}catch(c){if(V(u),c!==c+0)throw c;G(1,0)}}function _A(s,u,c,p,f,m,b){var y=F();try{return Qp(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function vA(s,u,c,p,f){var m=F();try{sf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function wA(s,u,c,p,f,m){var b=F();try{return tf(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function xA(s,u,c,p){var f=F();try{Qs(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function TA(s,u,c,p,f,m,b){var y=F();try{uf(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function IA(s,u,c,p,f){var m=F();try{of(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function SA(s,u,c,p,f){var m=F();try{return nf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function $A(s,u,c,p,f,m,b){var y=F();try{Pf(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function AA(s,u,c,p,f,m){var b=F();try{af(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function OA(s){var u=F();try{return rf(s)}catch(c){if(V(u),c!==c+0)throw c;G(1,0)}}function CA(s,u,c,p){var f=F();try{return ff(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function PA(s,u,c,p,f,m){var b=F();try{hf(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function EA(s,u,c,p){var f=F();try{return gf(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;return G(1,0),0n}}function DA(s,u,c,p,f,m,b){var y=F();try{bf(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function kA(s,u,c){var p=F();try{yf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function NA(s,u,c,p){var f=F();try{_f(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function LA(s,u,c){var p=F();try{return mf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function RA(s,u,c){var p=F();try{return xf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function zA(s,u,c,p,f){var m=F();try{wf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function MA(s,u,c,p,f,m,b,y){var v=F();try{Sf(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function BA(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{return Af(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function FA(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{return Of(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function VA(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{Cf(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function jA(s,u,c,p,f,m,b,y,v,I){var $=F();try{Df(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function GA(s,u,c,p,f,m,b,y,v){var I=F();try{return $f(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function UA(s,u){var c=F();try{return kf(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function WA(s,u){var c=F();try{return Lf(s,u)}catch(p){if(V(c),p!==p+0)throw p;return G(1,0),0n}}function HA(s,u){var c=F();try{return Rf(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function qA(s,u,c,p){var f=F();try{lf(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function KA(s,u,c,p,f,m,b){var y=F();try{Gh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function XA(s,u,c,p,f,m,b){var y=F();try{Bf(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function JA(s,u,c,p,f,m,b,y){var v=F();try{Om(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function ZA(s,u,c,p,f,m,b,y,v){var I=F();try{Ff(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function QA(s,u,c,p){var f=F();try{Ef(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function YA(s,u,c,p,f,m,b,y,v){var I=F();try{return Vf(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function eO(s,u,c,p,f,m,b,y){var v=F();try{return jf(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function tO(s,u,c,p,f){var m=F();try{Gf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function rO(s,u,c){var p=F();try{return zf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;return G(1,0),0n}}function nO(s,u,c,p,f,m,b){var y=F();try{Uf(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function oO(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{Wf(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function iO(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{Hf(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function aO(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{return qf(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function sO(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{Kf(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function uO(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q){var re=F();try{Xf(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)}catch(le){if(V(re),le!==le+0)throw le;G(1,0)}}function lO(s,u,c,p){var f=F();try{Jf(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function cO(s,u,c){var p=F();try{Zf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function dO(s,u,c,p,f){var m=F();try{pf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function pO(s,u,c,p,f){var m=F();try{cf(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function fO(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{Qf(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function hO(s,u,c){var p=F();try{return eh(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function mO(s,u,c,p,f,m){var b=F();try{th(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function gO(s,u,c,p,f,m,b,y,v,I){var $=F();try{rh(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function bO(s,u,c,p,f,m,b,y,v){var I=F();try{Yf(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function yO(s,u){var c=F();try{return uh(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function _O(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{Dg(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function vO(s,u,c,p,f,m){var b=F();try{return ih(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function wO(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y){var Q=F();try{ah(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)}catch(re){if(V(Q),re!==re+0)throw re;G(1,0)}}function xO(s,u,c,p){var f=F();try{return fh(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;return G(1,0),0n}}function TO(s,u,c,p,f,m){var b=F();try{return sh(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function IO(s,u,c,p,f,m,b,y){var v=F();try{dh(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function SO(s,u,c,p,f,m,b,y,v){var I=F();try{ph(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function $O(s,u,c,p,f,m,b){var y=F();try{lh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function AO(s,u,c,p,f,m){var b=F();try{return ch(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function OO(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{return hh(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function CO(s,u,c,p,f,m,b){var y=F();try{return mh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function PO(s,u,c,p,f,m){var b=F();try{return gh(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function EO(s,u){var c=F();try{return nh(s,u)}catch(p){if(V(c),p!==p+0)throw p;return G(1,0),0n}}function DO(s,u,c,p,f,m,b){var y=F();try{return oh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function kO(s,u,c){var p=F();try{_h(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function NO(s,u,c,p,f,m,b,y){var v=F();try{return bh(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function LO(s,u,c,p,f,m,b,y,v){var I=F();try{yh(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function RO(s,u,c,p){var f=F();try{vh(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function zO(s,u,c,p,f,m,b,y){var v=F();try{return wh(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function MO(s,u,c,p,f,m){var b=F();try{return xh(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function BO(s,u,c,p,f,m){var b=F();try{return Th(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function FO(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{return Ih(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function VO(s,u,c,p,f,m,b,y){var v=F();try{return Sh(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function jO(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{return $h(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function GO(s,u,c,p,f,m,b){var y=F();try{return Ah(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function UO(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{return Oh(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function WO(s,u,c,p,f,m,b){var y=F();try{return Ch(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function HO(s,u,c,p,f,m,b){var y=F();try{Ph(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function qO(s,u,c,p,f,m,b){var y=F();try{return Eh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function KO(s,u,c){var p=F();try{return Dh(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;return G(1,0),0n}}function XO(s,u,c){var p=F();try{return kh(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;return G(1,0),0n}}function JO(s,u,c,p){var f=F();try{return Nh(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function ZO(s,u,c,p,f,m,b){var y=F();try{Lh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function QO(s,u,c,p,f,m,b){var y=F();try{Rh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function YO(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{zh(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function eC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q){var re=F();try{Bh(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)}catch(le){if(V(re),le!==le+0)throw le;G(1,0)}}function tC(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{Vh(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function rC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y){var Q=F();try{jh(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)}catch(re){if(V(Q),re!==re+0)throw re;G(1,0)}}function nC(s,u,c,p,f,m,b,y,v){var I=F();try{Uh(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function oC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{return Wh(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function iC(s,u,c,p,f,m,b,y,v,I){var $=F();try{return Hh(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function aC(s,u){var c=F();try{qh(s,u)}catch(p){if(V(c),p!==p+0)throw p;G(1,0)}}function sC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{Qh(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function uC(s,u,c,p,f){var m=F();try{Kh(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function lC(s,u,c,p,f,m,b){var y=F();try{Xh(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function cC(s,u,c,p,f){var m=F();try{Zh(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function dC(s,u,c,p,f,m,b,y){var v=F();try{Jh(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function pC(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{Yh(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function fC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q){var re=F();try{return em(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)}catch(le){if(V(re),le!==le+0)throw le;G(1,0)}}function hC(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{tm(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function mC(s,u,c,p,f){var m=F();try{return kg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function gC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt){var ht=F();try{return rm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt)}catch(rr){if(V(ht),rr!==rr+0)throw rr;G(1,0)}}function bC(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{nm(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function yC(s,u,c,p,f,m,b){var y=F();try{return om(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function _C(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{am(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function vC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re){var le=F();try{sm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re)}catch($e){if(V(le),$e!==$e+0)throw $e;G(1,0)}}function wC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q){var re=F();try{um(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q)}catch(le){if(V(re),le!==le+0)throw le;G(1,0)}}function xC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y){var Q=F();try{lm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)}catch(re){if(V(Q),re!==re+0)throw re;G(1,0)}}function TC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{cm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function IC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De){var tt=F();try{dm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)}catch(ht){if(V(tt),ht!==ht+0)throw ht;G(1,0)}}function SC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le){var $e=F();try{pm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le)}catch(De){if(V($e),De!==De+0)throw De;G(1,0)}}function $C(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re){var le=F();try{fm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re)}catch($e){if(V(le),$e!==$e+0)throw $e;G(1,0)}}function AC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De){var tt=F();try{hm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)}catch(ht){if(V(tt),ht!==ht+0)throw ht;G(1,0)}}function OC(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{mm(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function CC(s,u,c,p,f,m,b,y,v,I){var $=F();try{gm(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function PC(s,u,c,p,f,m,b,y){var v=F();try{return bm(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;return G(1,0),0n}}function EC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{ym(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function DC(s,u,c,p,f,m,b,y,v,I){var $=F();try{_m(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function kC(s,u,c,p,f,m,b,y,v){var I=F();try{vm(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function NC(s,u,c,p,f,m,b){var y=F();try{return im(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function LC(s,u,c){var p=F();try{return Ng(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;return G(1,0),0n}}function RC(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{wm(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function zC(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Tm(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function MC(s,u,c,p,f,m,b){var y=F();try{return Im(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function BC(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Sm(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function FC(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{return $m(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function VC(s,u,c,p,f,m){var b=F();try{xm(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function jC(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{Am(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function GC(s,u,c,p,f,m,b,y){var v=F();try{Cm(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function UC(s,u,c,p,f,m){var b=F();try{Pm(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function WC(s,u,c,p,f,m,b,y,v,I){var $=F();try{Em(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function HC(s,u,c,p){var f=F();try{return Fh(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function qC(s,u,c,p,f,m,b,y,v,I){var $=F();try{Dm(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function KC(s,u,c,p,f,m){var b=F();try{km(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function XC(s,u,c){var p=F();try{return Nf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function JC(s,u,c,p,f,m,b,y){var v=F();try{return Nm(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function ZC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{Lg(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function QC(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{Lm(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function YC(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{Rm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function eP(s,u,c,p,f,m,b,y){var v=F();try{zm(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function tP(s,u,c,p){var f=F();try{return Mm(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function rP(s,u,c){var p=F();try{return Mf(s,u,c)}catch(f){if(V(p),f!==f+0)throw f;G(1,0)}}function nP(s,u,c,p,f,m,b,y,v){var I=F();try{Bm(s,u,c,p,f,m,b,y,v)}catch($){if(V(I),$!==$+0)throw $;G(1,0)}}function oP(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{Fm(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function iP(s,u,c,p,f,m){var b=F();try{Vm(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function aP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y){var Q=F();try{return jm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y)}catch(re){if(V(Q),re!==re+0)throw re;G(1,0)}}function sP(s,u,c,p,f,m,b,y){var v=F();try{return Gm(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;return G(1,0),0n}}function uP(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Um(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function lP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt,ht,rr){var n3=F();try{Wm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt,ht,rr)}catch(Ys){if(V(n3),Ys!==Ys+0)throw Ys;G(1,0)}}function cP(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Hm(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function dP(s,u,c,p,f,m,b,y,v,I){var $=F();try{qm(s,u,c,p,f,m,b,y,v,I)}catch(C){if(V($),C!==C+0)throw C;G(1,0)}}function pP(s,u,c,p,f,m,b,y,v,I,$,C,k,R){var X=F();try{Km(s,u,c,p,f,m,b,y,v,I,$,C,k,R)}catch(Y){if(V(X),Y!==Y+0)throw Y;G(1,0)}}function fP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e){var De=F();try{Qm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e)}catch(tt){if(V(De),tt!==tt+0)throw tt;G(1,0)}}function hP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De){var tt=F();try{Rg(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De)}catch(ht){if(V(tt),ht!==ht+0)throw ht;G(1,0)}}function mP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e){var De=F();try{Zm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e)}catch(tt){if(V(De),tt!==tt+0)throw tt;G(1,0)}}function gP(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Xm(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function bP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le){var $e=F();try{Jm(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le)}catch(De){if(V($e),De!==De+0)throw De;G(1,0)}}function yP(s,u,c,p,f,m,b,y){var v=F();try{Ym(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function _P(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{eg(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function vP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt){var ht=F();try{return tg(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X,Y,Q,re,le,$e,De,tt)}catch(rr){if(V(ht),rr!==rr+0)throw rr;G(1,0)}}function wP(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X){var Y=F();try{rg(s,u,c,p,f,m,b,y,v,I,$,C,k,R,X)}catch(Q){if(V(Y),Q!==Q+0)throw Q;G(1,0)}}function xP(s,u,c,p,f,m,b){var y=F();try{ng(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function TP(s,u,c,p,f){var m=F();try{og(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function IP(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{ig(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function SP(s,u,c,p,f,m,b){var y=F();try{ag(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function $P(s,u,c,p,f){var m=F();try{sg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function AP(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{Mh(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function OP(s,u,c,p,f,m,b){var y=F();try{return cg(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function CP(s,u,c,p,f){var m=F();try{dg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function PP(s,u,c,p,f,m,b){var y=F();try{pg(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function EP(s,u,c,p,f,m,b,y,v,I,$){var C=F();try{fg(s,u,c,p,f,m,b,y,v,I,$)}catch(k){if(V(C),k!==k+0)throw k;G(1,0)}}function DP(s,u,c,p,f){var m=F();try{return hg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function kP(s,u,c,p,f,m,b,y){var v=F();try{mg(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function NP(s,u,c,p,f,m){var b=F();try{return gg(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function LP(s,u,c,p){var f=F();try{bg(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function RP(s,u,c,p,f,m,b,y){var v=F();try{yg(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function zP(s,u,c,p,f,m,b){var y=F();try{_g(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function MP(s,u,c,p,f){var m=F();try{vg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function BP(s,u,c,p,f){var m=F();try{return lg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function FP(s,u,c,p){var f=F();try{return ug(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function VP(s,u,c,p){var f=F();try{return zg(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function jP(s,u,c,p,f){var m=F();try{wg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function GP(s,u,c,p){var f=F();try{return df(s,u,c,p)}catch(m){if(V(f),m!==m+0)throw m;G(1,0)}}function UP(s,u,c,p,f,m){var b=F();try{return xg(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function WP(s,u,c,p,f){var m=F();try{return Tg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function HP(s,u,c,p,f){var m=F();try{return Ig(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function qP(s,u,c,p,f,m,b){var y=F();try{return Sg(s,u,c,p,f,m,b)}catch(v){if(V(y),v!==v+0)throw v;G(1,0)}}function KP(s,u,c,p,f,m,b,y,v,I,$,C){var k=F();try{$g(s,u,c,p,f,m,b,y,v,I,$,C)}catch(R){if(V(k),R!==R+0)throw R;G(1,0)}}function XP(s,u,c,p,f){var m=F();try{return Og(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function JP(s,u,c,p,f,m,b,y,v,I,$,C,k){var R=F();try{Ag(s,u,c,p,f,m,b,y,v,I,$,C,k)}catch(X){if(V(R),X!==X+0)throw X;G(1,0)}}function ZP(s,u,c,p,f,m,b,y){var v=F();try{return Cg(s,u,c,p,f,m,b,y)}catch(I){if(V(v),I!==I+0)throw I;G(1,0)}}function QP(s,u,c,p,f,m){var b=F();try{return Pg(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function YP(s,u,c,p,f){var m=F();try{return Eg(s,u,c,p,f)}catch(b){if(V(m),b!==b+0)throw b;G(1,0)}}function e3(s){var u=F();try{return If(s)}catch(c){if(V(u),c!==c+0)throw c;return G(1,0),0n}}function t3(s,u,c,p,f,m){var b=F();try{return Tf(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}function r3(s,u,c,p,f,m){var b=F();try{return vf(s,u,c,p,f,m)}catch(y){if(V(b),y!==y+0)throw y;G(1,0)}}return t.stackSave=F,t.stackRestore=V,t.stackAlloc=vs,t.setValue=function(s,u,c="i8"){switch(c.endsWith("*")&&(c="*"),c){case"i1":case"i8":Te()[s>>>0]=u;break;case"i16":rt()[s>>>1>>>0]=u;break;case"i32":j()[s>>>2>>>0]=u;break;case"i64":oe[s>>>3]=BigInt(u);break;case"float":ze()[s>>>2>>>0]=u;break;case"double":lt()[s>>>3>>>0]=u;break;case"*":U()[s>>>2>>>0]=u;break;default:fr(`invalid type for setValue: ${c}`)}},t.getValue=function(s,u="i8"){switch(u.endsWith("*")&&(u="*"),u){case"i1":case"i8":return Te()[s>>>0];case"i16":return rt()[s>>>1>>>0];case"i32":return j()[s>>>2>>>0];case"i64":return oe[s>>>3];case"float":return ze()[s>>>2>>>0];case"double":return lt()[s>>>3>>>0];case"*":return U()[s>>>2>>>0];default:fr(`invalid type for getValue: ${u}`)}},t.UTF8ToString=ut,t.stringToUTF8=bn,t.lengthBytesUTF8=gn,function s(){if(kn>0)io=s;else{if(l)return e(t),void tr();(u=>{for(;u.length>0;)u.shift()(t)})($d),kn>0?io=s:(t.calledRun=!0,Ee||(tr(),e(t)))}}(),t.PTR_SIZE=4,t.webgpuInit=s=>{let u=new WeakMap,c=1,p=s,f,m;t.webgpuRegisterDevice=v=>{if(m!==void 0)throw new Error("another WebGPU EP inference session is being created.");if(v){let I=u.get(v);if(!I){let $=vp(0),C=q.importJsDevice(v,$);I=[c++,$,C],u.set(v,I)}return f=v,m=I[0],I}return f=void 0,void(m=0)};let b=new Map;t.webgpuOnCreateSession=v=>{if(m===void 0)return;let I=m;if(m=void 0,v){let $=Ls(I);if(b.set(v,$),I===0){let C=f??q.getJsObject($);p(C)}}f=void 0},t.webgpuOnReleaseSession=v=>{b.delete(v)};let y=Symbol("gpuBufferMetadata");t.webgpuRegisterBuffer=(v,I,$)=>{if($)return v[y]=[$,NaN],$;{let C=v[y];if(C)return C[1]++,C[0];let k=b.get(I);if(k===void 0)throw new Error("Invalid session handle passed to webgpuRegisterBuffer");let R=q.importJsBuffer(v,k);return v[y]=[R,1],R}},t.webgpuUnregisterBuffer=v=>{let I=v[y];if(!I)throw new Error("Buffer is not registered");I[1]--,I[1]===0&&(_p(I[0]),delete v[y])},t.webgpuGetBuffer=v=>q.getJsObject(v),t.webgpuCreateDownloader=(v,I,$)=>{let C=b.get($);if(C===void 0)throw new Error("Invalid session handle passed to webgpuRegisterBuffer");let k=v,R=q.getJsObject(C),X=I,Y=16*Math.ceil(Number(X)/16);return async()=>{let Q={size:Y,usage:9},re=R.createBuffer(Q);try{let le=R.createCommandEncoder();return le.copyBufferToBuffer(k,0,re,0,Y),R.queue.submit([le.finish()]),await re.mapAsync(GPUMapMode.READ),re.getMappedRange().slice(0,X)}finally{re.destroy()}}},t.webgpuUploadExternalBuffer=(v,I)=>{let $=I.buffer,C=I.byteOffset,k=I.byteLength,R=16*Math.ceil(Number(k)/16),X=q.getJsObject(v);if(!f){let $e=Ls(m);f=q.getJsObject($e)}let Y={mappedAtCreation:!0,size:R,usage:6},Q=f.createBuffer(Y),re=Q.getMappedRange();new Uint8Array(re).set(new Uint8Array($,C,k)),Q.unmap();let le=f.createCommandEncoder();le.copyBufferToBuffer(Q,0,X,0,R),f.queue.submit([le.finish()]),Q.destroy()}},o}),iR=Yw,aR=globalThis.self?.name?.startsWith("em-pthread");aR&&Yw()});var ox,Dc,sR,jt,ix,Ec,uR,lR,ax,cR,rx,sx,nx,ux,Oa=H(()=>{"use strict";Aa();ox=typeof location>"u"?void 0:location.origin,Dc=import.meta.url>"file:"&&import.meta.url<"file;",sR=()=>{if(!!1){if(Dc){let n=URL;return new URL(new n("ort.all.bundle.min.mjs",import.meta.url).href,ox).href}return import.meta.url}},jt=sR(),ix=()=>{if(jt&&!jt.startsWith("blob:"))return jt.substring(0,jt.lastIndexOf("/")+1)},Ec=(n,e)=>{try{let r=e??jt;return(r?new URL(n,r):new URL(n)).origin===ox}catch{return!1}},uR=(n,e)=>{let r=e??jt;try{return(r?new URL(n,r):new URL(n)).href}catch{return}},lR=(n,e)=>`${e??"./"}${n}`,ax=async n=>{let r=await(await fetch(n,{credentials:"same-origin"})).blob();return URL.createObjectURL(r)},cR=async n=>(await import(/*webpackIgnore:true*/n)).default,rx=(Qw(),uo(Zw)).default,sx=async()=>{if(!jt)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(Ec(jt))return[void 0,rx()];let n=await ax(jt);return[n,rx(n)]},nx=(tx(),uo(ex)).default,ux=async(n,e,r)=>{if(!n&&!e&&nx&&jt&&Ec(jt))return[void 0,nx];{let t="ort-wasm-simd-threaded.jsep.mjs",o=n??uR(t,e),i=!!1&&r&&o&&!Ec(o,e),a=i?await ax(o):o??lR(t,e);return[i?a:void 0,await cR(a)]}}});var kc,Nc,za,lx,dR,pR,fR,Ca,Qe,On=H(()=>{"use strict";Oa();Nc=!1,za=!1,lx=!1,dR=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},pR=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},fR=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}},Ca=async n=>{if(Nc)return Promise.resolve();if(za)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(lx)throw new Error("previous call to 'initializeWebAssembly()' failed.");za=!0;let e=n.initTimeout,r=n.numThreads;if(n.simd!==!1){if(n.simd==="relaxed"){if(!fR())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!pR())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let t=dR();r>1&&!t&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),n.numThreads=r=1);let o=n.wasmPaths,i=typeof o=="string"?o:void 0,a=o?.mjs,l=a?.href??a,d=o?.wasm,h=d?.href??d,g=n.wasmBinary,[_,w]=await ux(l,i,r>1),x=!1,T=[];if(e>0&&T.push(new Promise(S=>{setTimeout(()=>{x=!0,S()},e)})),T.push(new Promise((S,P)=>{let A={numThreads:r};if(g)A.wasmBinary=g;else if(h||i)A.locateFile=O=>h??i+O;else if(l&&l.indexOf("blob:")!==0)A.locateFile=O=>new URL(O,l).href;else if(_){let O=ix();O&&(A.locateFile=E=>O+E)}w(A).then(O=>{za=!1,Nc=!0,kc=O,S(),_&&URL.revokeObjectURL(_)},O=>{za=!1,lx=!0,P(O)})})),await Promise.race(T),x)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},Qe=()=>{if(Nc&&kc)return kc;throw new Error("WebAssembly is not initialized yet.")}});var Gt,ti,qe,Ma=H(()=>{"use strict";On();Gt=(n,e)=>{let r=Qe(),t=r.lengthBytesUTF8(n)+1,o=r._malloc(t);return r.stringToUTF8(n,o,t),e.push(o),o},ti=(n,e,r,t)=>{if(typeof n=="object"&&n!==null){if(r.has(n))throw new Error("Circular reference in options");r.add(n)}Object.entries(n).forEach(([o,i])=>{let a=e?e+o:o;if(typeof i=="object")ti(i,a+".",r,t);else if(typeof i=="string"||typeof i=="number")t(a,i.toString());else if(typeof i=="boolean")t(a,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},qe=n=>{let e=Qe(),r=e.stackSave();try{let t=e.PTR_SIZE,o=e.stackAlloc(2*t);e._OrtGetLastError(o,o+t);let i=Number(e.getValue(o,t===4?"i32":"i64")),a=e.getValue(o+t,"*"),l=a?e.UTF8ToString(a):"";throw new Error(`${n} ERROR_CODE: ${i}, ERROR_MESSAGE: ${l}`)}finally{e.stackRestore(r)}}});var cx,dx=H(()=>{"use strict";On();Ma();cx=n=>{let e=Qe(),r=0,t=[],o=n||{};try{if(n?.logSeverityLevel===void 0)o.logSeverityLevel=2;else if(typeof n.logSeverityLevel!="number"||!Number.isInteger(n.logSeverityLevel)||n.logSeverityLevel<0||n.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${n.logSeverityLevel}`);if(n?.logVerbosityLevel===void 0)o.logVerbosityLevel=0;else if(typeof n.logVerbosityLevel!="number"||!Number.isInteger(n.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${n.logVerbosityLevel}`);n?.terminate===void 0&&(o.terminate=!1);let i=0;return n?.tag!==void 0&&(i=Gt(n.tag,t)),r=e._OrtCreateRunOptions(o.logSeverityLevel,o.logVerbosityLevel,!!o.terminate,i),r===0&&qe("Can't create run options."),n?.extra!==void 0&&ti(n.extra,"",new WeakSet,(a,l)=>{let d=Gt(a,t),h=Gt(l,t);e._OrtAddRunConfigEntry(r,d,h)!==0&&qe(`Can't set a run config entry: ${a} - ${l}.`)}),[r,t]}catch(i){throw r!==0&&e._OrtReleaseRunOptions(r),t.forEach(a=>e._free(a)),i}}});var hR,mR,gR,Ba,bR,px,fx=H(()=>{"use strict";On();Ma();hR=n=>{switch(n){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${n}`)}},mR=n=>{switch(n){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${n}`)}},gR=n=>{n.extra||(n.extra={}),n.extra.session||(n.extra.session={});let e=n.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),n.executionProviders&&n.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(n.enableMemPattern=!1)},Ba=(n,e,r,t)=>{let o=Gt(e,t),i=Gt(r,t);Qe()._OrtAddSessionConfigEntry(n,o,i)!==0&&qe(`Can't set a session config entry: ${e} - ${r}.`)},bR=async(n,e,r)=>{for(let t of e){let o=typeof t=="string"?t:t.name,i=[];switch(o){case"webnn":if(o="WEBNN",typeof t!="string"){let _=t?.deviceType;_&&Ba(n,"deviceType",_,r)}break;case"webgpu":if(o="JS",typeof t!="string"){let g=t;if(g?.preferredLayout){if(g.preferredLayout!=="NCHW"&&g.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${g.preferredLayout}`);Ba(n,"preferredLayout",g.preferredLayout,r)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${o}`)}let a=Gt(o,r),l=i.length,d=0,h=0;if(l>0){d=Qe()._malloc(l*Qe().PTR_SIZE),r.push(d),h=Qe()._malloc(l*Qe().PTR_SIZE),r.push(h);for(let g=0;g{let e=Qe(),r=0,t=[],o=n||{};gR(o);try{let i=hR(o.graphOptimizationLevel??"all"),a=mR(o.executionMode??"sequential"),l=typeof o.logId=="string"?Gt(o.logId,t):0,d=o.logSeverityLevel??2;if(!Number.isInteger(d)||d<0||d>4)throw new Error(`log serverity level is not valid: ${d}`);let h=o.logVerbosityLevel??0;if(!Number.isInteger(h)||h<0||h>4)throw new Error(`log verbosity level is not valid: ${h}`);let g=typeof o.optimizedModelFilePath=="string"?Gt(o.optimizedModelFilePath,t):0;if(r=e._OrtCreateSessionOptions(i,!!o.enableCpuMemArena,!!o.enableMemPattern,a,!!o.enableProfiling,0,l,d,h,g),r===0&&qe("Can't create session options."),o.executionProviders&&await bR(r,o.executionProviders,t),o.enableGraphCapture!==void 0){if(typeof o.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${o.enableGraphCapture}`);Ba(r,"enableGraphCapture",o.enableGraphCapture.toString(),t)}if(o.freeDimensionOverrides)for(let[_,w]of Object.entries(o.freeDimensionOverrides)){if(typeof _!="string")throw new Error(`free dimension override name must be a string: ${_}`);if(typeof w!="number"||!Number.isInteger(w)||w<0)throw new Error(`free dimension override value must be a non-negative integer: ${w}`);let x=Gt(_,t);e._OrtAddFreeDimensionOverride(r,x,w)!==0&&qe(`Can't set a free dimension override: ${_} - ${w}.`)}return o.extra!==void 0&&ti(o.extra,"",new WeakSet,(_,w)=>{Ba(r,_,w,t)}),[r,t]}catch(i){throw r!==0&&e._OrtReleaseSessionOptions(r)!==0&&qe("Can't release session options."),t.forEach(a=>e._free(a)),i}}});var Cn,en,Pn,xo,ri,Fa,Va,Lc,ve=H(()=>{"use strict";Cn=n=>{switch(n){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${n}`)}},en=n=>{switch(n){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${n}`)}},Pn=(n,e)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][n],t=typeof e=="number"?e:e.reduce((o,i)=>o*i,1);return r>0?Math.ceil(t*r):void 0},xo=n=>{switch(n){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${n}`)}},ri=n=>{switch(n){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${n}`)}},Fa=n=>n==="float32"||n==="float16"||n==="int32"||n==="int64"||n==="uint32"||n==="uint8"||n==="bool"||n==="uint4"||n==="int4",Va=n=>n==="float32"||n==="float16"||n==="int32"||n==="int64"||n==="uint32"||n==="uint64"||n==="int8"||n==="uint8"||n==="bool"||n==="uint4"||n==="int4",Lc=n=>{switch(n){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${n}`)}}});var ni,Rc=H(()=>{"use strict";Aa();ni=async n=>{if(typeof n=="string")if(!1)try{let{readFile:e}=eu("node:fs/promises");return new Uint8Array(await e(n))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:r}=eu("node:fs"),t=r(n),o=[];for await(let i of t)o.push(i);return new Uint8Array(Buffer.concat(o))}throw e}else{let e=await fetch(n);if(!e.ok)throw new Error(`failed to load external data file: ${n}`);let r=e.headers.get("Content-Length"),t=r?parseInt(r,10):0;if(t<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${n}, no response body.`);let o=e.body.getReader(),i;try{i=new ArrayBuffer(t)}catch(l){if(l instanceof RangeError){let d=Math.ceil(t/65536);i=new WebAssembly.Memory({initial:d,maximum:d}).buffer}else throw l}let a=0;for(;;){let{done:l,value:d}=await o.read();if(l)break;let h=d.byteLength;new Uint8Array(i,a,h).set(d),a+=h}return new Uint8Array(i,0,t)}}else return n instanceof Blob?new Uint8Array(await n.arrayBuffer()):n instanceof Uint8Array?n:new Uint8Array(n)}});var yR,_R,hx,mx,ja,vR,ke,tn=H(()=>{"use strict";ve();yR=["V","I","W","E","F"],_R=(n,e)=>{console.log(`[${yR[n]},${new Date().toISOString()}]${e}`)},ja=(n,e)=>{hx=n,mx=e},vR=(n,e)=>{let r=ri(n),t=ri(hx);r>=t&&_R(r,typeof e=="function"?e():e)},ke=(...n)=>{mx&&vR(...n)}});var zc,rn,W,eo,Ga,gx,bx,Oe=H(()=>{"use strict";zc=class{static calcMatMulShape(e,r){return e[1]!==r[0]?void 0:[e[0],r[1]]}},rn=class{static calcShape(e,r,t=!1){let o=e.length,i=r.length;if(o===0)return r;if(i===0)return e;let a=Math.max(e.length,r.length),l=new Array(a);if(t){if(o<2||i<2)return;let d=zc.calcMatMulShape([e[o-2],e[o-1]],[r[i-2],r[i-1]]);if(d===void 0)return;[l[a-2],l[a-1]]=d}for(let d=t?3:1;d<=a;d++){let h=o-d<0?1:e[o-d],g=i-d<0?1:r[i-d];if(h!==g&&h>1&&g>1)return;let _=Math.max(h,g);if(h&&g)l[a-d]=Math.max(h,g);else{if(_>1)return;l[a-d]=0}}return l}static isValidBroadcast(e,r){let t=e.length,o=r.length;if(t>o)return!1;for(let i=1;i<=t;i++)if(e[t-i]!==1&&e[t-i]!==r[o-i])return!1;return!0}},W=class n{static size(e){return n.getSizeFromDimensionRange(e,0,e.length)}static convertShape(e,r=4){let t=e.length;if(t===0)return[];let o=new Array(t),i=t-1;for(;i>=0;){if(e[i]%r===0){o[i]=e[i]/r;break}if(r%e[i]!==0)throw new Error("cannot convert shape");o[i]=1,r/=e[i],i--}for(i--;i>=0;i--)o[i]=e[i];return o}static sizeFromDimension(e,r){if(r<0||r>e.length)throw new Error(`invalid dimension of ${r} for sizeFromDimension as Tensor has ${e.length} dimensions.`);return n.getSizeFromDimensionRange(e,r,e.length)}static sizeToDimension(e,r){if(r<0||r>e.length)throw new Error(`invalid dimension of ${r} for sizeToDimension as Tensor has ${e.length} dimensions.`);return n.getSizeFromDimensionRange(e,0,r)}static getSizeFromDimensionRange(e,r,t){let o=1;for(let i=r;i=0;--o)t[o]=t[o+1]*e[o+1];return t}static normalizeAxis(e,r){if(e<-r&&e>=r)throw new Error("unsupported axis for this operation.");return e<0?e+r:e}static normalizeAxes(e,r){return e.map(t=>this.normalizeAxis(t,r??e.length))}static sortBasedOnPerm(e,r){return r?r.map(t=>e[t]):e.slice().reverse()}static padShape(e,r){let t=e.length;return e.map((o,i)=>o+r[i]+r[i+t])}static areEqual(e,r){return e.length!==r.length?!1:e.every((t,o)=>t===r[o])}},eo=class n{static adjustPoolAttributes(e,r,t,o,i,a){if(!e&&t.length!==r.length-2)throw new Error("length of specified kernel shapes should be 2 less than length of input dimensions");if(e)for(let l=0;l=t.length?t.push(r[l+2]):t[l]=r[l+2];for(let l=0;l=t[l]||a[l+t.length]>=t[l])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(e,r,t,o,i,a,l){if(l){if(i.length!==2*(e.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(r.length!==e.length-2)throw new Error("length of strides should be the length of data dimensions");if(o.length!==e.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let d=0;d{"use strict";ve();Ua=(n,e)=>new(xo(e))(n)});var _x,Fc,vx,wR,yx,xR,wx,Wa,Ha,Bc,xx,Tx=H(()=>{"use strict";ve();tn();_x=new Map([["float32",32],["float16",16],["int32",32],["uint32",32],["int64",64],["uint64",64],["int8",8],["uint8",8],["int4",4],["uint4",4]]),Fc=(n,e)=>{if(e==="int32")return n;let r=_x.get(e);if(!r)throw new Error(`WebNN backend does not support data type: ${e}`);let t=r/8;if(n.byteLength%t!==0)throw new Error(`Invalid Uint8Array length - must be a multiple of ${t}.`);let o=n.byteLength/t,i=new(xo(e))(n.buffer,n.byteOffset,o);switch(e){case"int64":case"uint64":{let a=new Int32Array(o);for(let l=0;l2147483647n||d<-2147483648n)throw new Error("Can not convert int64 data to int32 - value out of range.");a[l]=Number(d)}return new Uint8Array(a.buffer)}case"int8":case"uint8":case"uint32":{if(e==="uint32"&&i.some(l=>l>2147483647))throw new Error("Can not convert uint32 data to int32 - value out of range.");let a=Int32Array.from(i,Number);return new Uint8Array(a.buffer)}default:throw new Error(`Unsupported data conversion from ${e} to 'int32'`)}},vx=(n,e)=>{if(e==="int32")return n;if(n.byteLength%4!==0)throw new Error("Invalid Uint8Array length - must be a multiple of 4 (int32).");let r=n.byteLength/4,t=new Int32Array(n.buffer,n.byteOffset,r);switch(e){case"int64":{let o=BigInt64Array.from(t,BigInt);return new Uint8Array(o.buffer)}case"uint64":{if(t.some(i=>i<0))throw new Error("Can not convert int32 data to uin64 - negative value found.");let o=BigUint64Array.from(t,BigInt);return new Uint8Array(o.buffer)}case"int8":{if(t.some(i=>i<-128||i>127))throw new Error("Can not convert int32 data to int8 - value out of range.");let o=Int8Array.from(t,Number);return new Uint8Array(o.buffer)}case"uint8":{if(t.some(o=>o<0||o>255))throw new Error("Can not convert int32 data to uint8 - value out of range.");return Uint8Array.from(t,Number)}case"uint32":{if(t.some(i=>i<0))throw new Error("Can not convert int32 data to uint32 - negative value found.");let o=Uint32Array.from(t,Number);return new Uint8Array(o.buffer)}default:throw new Error(`Unsupported data conversion from 'int32' to ${e}`)}},wR=1,yx=()=>wR++,xR=new Map([["int8","int32"],["uint8","int32"],["uint32","int32"],["int64","int32"]]),wx=(n,e)=>{let r=_x.get(n);if(!r)throw new Error(`WebNN backend does not support data type: ${n}`);return e.length>0?Math.ceil(e.reduce((t,o)=>t*o)*r/8):0},Wa=class{constructor(e){this.isDataConverted=!1;let{sessionId:r,context:t,tensor:o,dataType:i,shape:a,fallbackDataType:l}=e;this.sessionId=r,this.mlContext=t,this.mlTensor=o,this.dataType=i,this.tensorShape=a,this.fallbackDataType=l}get tensor(){return this.mlTensor}get type(){return this.dataType}get fallbackType(){return this.fallbackDataType}get shape(){return this.tensorShape}get byteLength(){return wx(this.dataType,this.tensorShape)}destroy(){ke("verbose",()=>"[WebNN] TensorWrapper.destroy"),this.mlTensor.destroy()}write(e){this.mlContext.writeTensor(this.mlTensor,e)}async read(e){if(this.fallbackDataType){let r=await this.mlContext.readTensor(this.mlTensor),t=vx(new Uint8Array(r),this.dataType);if(e){(e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)).set(t);return}else return t.buffer}else return e?this.mlContext.readTensor(this.mlTensor,e):this.mlContext.readTensor(this.mlTensor)}canReuseTensor(e,r,t){return this.mlContext===e&&this.dataType===r&&this.tensorShape.length===t.length&&this.tensorShape.every((o,i)=>o===t[i])}setIsDataConverted(e){this.isDataConverted=e}},Ha=class{constructor(e,r){this.tensorManager=e;this.wrapper=r}get tensorWrapper(){return this.wrapper}releaseTensor(){this.tensorWrapper&&(this.tensorManager.releaseTensor(this.tensorWrapper),this.wrapper=void 0)}async ensureTensor(e,r,t,o){let i=this.tensorManager.getMLContext(e),a;if(!i.opSupportLimits().input.dataTypes.includes(r)){if(a=xR.get(r),!a||!i.opSupportLimits().input.dataTypes.includes(a))throw new Error(`WebNN backend does not support data type: ${r}`);ke("verbose",()=>`[WebNN] TensorIdTracker.ensureTensor: fallback dataType from ${r} to ${a}`)}if(this.wrapper){if(this.wrapper.canReuseTensor(i,r,t))return this.wrapper.tensor;if(o){if(this.wrapper.byteLength!==wx(r,t))throw new Error("Unable to copy data to tensor with different size.");this.activeUpload=new Uint8Array(await this.wrapper.read())}this.tensorManager.releaseTensor(this.wrapper)}let l=typeof MLTensorUsage>"u"?void 0:MLTensorUsage.READ|MLTensorUsage.WRITE;return this.wrapper=await this.tensorManager.getCachedTensor(e,r,t,l,!0,!0,a),o&&this.activeUpload&&(this.wrapper.write(this.activeUpload),this.activeUpload=void 0),this.wrapper.tensor}upload(e){let r=e;if(this.wrapper){if(this.wrapper.fallbackType)if(this.wrapper.fallbackType==="int32")r=Fc(e,this.wrapper.type),this.wrapper.setIsDataConverted(!0);else throw new Error(`Unsupported fallback data type: ${this.wrapper.fallbackType}`);if(e.byteLength===this.wrapper.byteLength){this.wrapper.write(r);return}else ke("verbose",()=>"Data size does not match tensor size. Releasing tensor."),this.releaseTensor()}this.activeUpload?this.activeUpload.set(r):this.activeUpload=new Uint8Array(r)}async download(e){if(this.activeUpload){let r=this.wrapper?.isDataConverted?vx(this.activeUpload,this.wrapper?.type):this.activeUpload;if(e){e instanceof ArrayBuffer?new Uint8Array(e).set(r):new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(r);return}else return r.buffer}if(!this.wrapper)throw new Error("Tensor has not been created.");return e?this.wrapper.read(e):this.wrapper.read()}},Bc=class{constructor(e){this.backend=e;this.tensorTrackersById=new Map;this.freeTensors=[];this.externalTensors=new Set}getMLContext(e){let r=this.backend.getMLContext(e);if(!r)throw new Error("MLContext not found for session.");return r}reserveTensorId(){let e=yx();return this.tensorTrackersById.set(e,new Ha(this)),e}releaseTensorId(e){let r=this.tensorTrackersById.get(e);r&&(this.tensorTrackersById.delete(e),r.tensorWrapper&&this.releaseTensor(r.tensorWrapper))}async ensureTensor(e,r,t,o,i){ke("verbose",()=>`[WebNN] TensorManager.ensureTensor {tensorId: ${r}, dataType: ${t}, shape: ${o}, copyOld: ${i}}`);let a=this.tensorTrackersById.get(r);if(!a)throw new Error("Tensor not found.");return a.ensureTensor(e,t,o,i)}upload(e,r){let t=this.tensorTrackersById.get(e);if(!t)throw new Error("Tensor not found.");t.upload(r)}async download(e,r){ke("verbose",()=>`[WebNN] TensorManager.download {tensorId: ${e}, dstBuffer: ${r?.byteLength}}`);let t=this.tensorTrackersById.get(e);if(!t)throw new Error("Tensor not found.");return t.download(r)}releaseTensorsForSession(e){for(let r of this.freeTensors)r.sessionId===e&&r.destroy();this.freeTensors=this.freeTensors.filter(r=>r.sessionId!==e)}registerTensor(e,r,t,o){let i=this.getMLContext(e),a=yx(),l=new Wa({sessionId:e,context:i,tensor:r,dataType:t,shape:o});return this.tensorTrackersById.set(a,new Ha(this,l)),this.externalTensors.add(l),a}async getCachedTensor(e,r,t,o,i,a,l){let d=this.getMLContext(e);for(let[g,_]of this.freeTensors.entries())if(_.canReuseTensor(d,r,t)){ke("verbose",()=>`[WebNN] Reusing tensor {dataType: ${r}, ${l?`fallbackDataType: ${l},`:""} shape: ${t}`);let w=this.freeTensors.splice(g,1)[0];return w.sessionId=e,w}ke("verbose",()=>`[WebNN] MLContext.createTensor {dataType: ${r}, ${l?`fallbackDataType: ${l},`:""} shape: ${t}}`);let h=await d.createTensor({dataType:l??r,shape:t,dimensions:t,usage:o,writable:i,readable:a});return new Wa({sessionId:e,context:d,tensor:h,dataType:r,shape:t,fallbackDataType:l})}releaseTensor(e){this.externalTensors.has(e)&&this.externalTensors.delete(e),this.freeTensors.push(e)}},xx=(...n)=>new Bc(...n)});var qa,TR,Ka,Ix=H(()=>{"use strict";ve();On();Mc();Tx();tn();qa=new Map([[1,"float32"],[10,"float16"],[6,"int32"],[12,"uint32"],[7,"int64"],[13,"uint64"],[22,"int4"],[21,"uint4"],[3,"int8"],[2,"uint8"],[9,"uint8"]]),TR=(n,e)=>{if(n===e)return!0;if(n===void 0||e===void 0)return!1;let r=Object.keys(n).sort(),t=Object.keys(e).sort();return r.length===t.length&&r.every((o,i)=>o===t[i]&&n[o]===e[o])},Ka=class{constructor(e){this.tensorManager=xx(this);this.mlContextBySessionId=new Map;this.sessionIdsByMLContext=new Map;this.mlContextCache=[];this.sessionGraphInputs=new Map;this.sessionGraphOutputs=new Map;this.temporaryGraphInputs=[];this.temporaryGraphOutputs=[];this.temporarySessionTensorIds=new Map;ja(e.logLevel,!!e.debug)}get currentSessionId(){if(this.activeSessionId===void 0)throw new Error("No active session");return this.activeSessionId}onRunStart(e){ke("verbose",()=>`[WebNN] onRunStart {sessionId: ${e}}`),this.activeSessionId=e}onRunEnd(e){ke("verbose",()=>`[WebNN] onRunEnd {sessionId: ${e}}`);let r=this.temporarySessionTensorIds.get(e);if(r){for(let t of r)ke("verbose",()=>`[WebNN] releasing temporary tensor {tensorId: ${t}}`),this.tensorManager.releaseTensorId(t);this.temporarySessionTensorIds.delete(e),this.activeSessionId=void 0}}async createMLContext(e){if(e instanceof GPUDevice){let t=this.mlContextCache.findIndex(o=>o.gpuDevice===e);if(t!==-1)return this.mlContextCache[t].mlContext;{let o=await navigator.ml.createContext(e);return this.mlContextCache.push({gpuDevice:e,mlContext:o}),o}}else if(e===void 0){let t=this.mlContextCache.findIndex(o=>o.options===void 0&&o.gpuDevice===void 0);if(t!==-1)return this.mlContextCache[t].mlContext;{let o=await navigator.ml.createContext();return this.mlContextCache.push({mlContext:o}),o}}let r=this.mlContextCache.findIndex(t=>TR(t.options,e));if(r!==-1)return this.mlContextCache[r].mlContext;{let t=await navigator.ml.createContext(e);return this.mlContextCache.push({options:e,mlContext:t}),t}}registerMLContext(e,r){this.mlContextBySessionId.set(e,r);let t=this.sessionIdsByMLContext.get(r);t||(t=new Set,this.sessionIdsByMLContext.set(r,t)),t.add(e),this.temporaryGraphInputs.length>0&&(this.sessionGraphInputs.set(e,this.temporaryGraphInputs),this.temporaryGraphInputs=[]),this.temporaryGraphOutputs.length>0&&(this.sessionGraphOutputs.set(e,this.temporaryGraphOutputs),this.temporaryGraphOutputs=[])}onReleaseSession(e){this.sessionGraphInputs.delete(e),this.sessionGraphOutputs.delete(e);let r=this.mlContextBySessionId.get(e);if(!r)return;this.tensorManager.releaseTensorsForSession(e),this.mlContextBySessionId.delete(e);let t=this.sessionIdsByMLContext.get(r);if(t.delete(e),t.size===0){this.sessionIdsByMLContext.delete(r);let o=this.mlContextCache.findIndex(i=>i.mlContext===r);o!==-1&&this.mlContextCache.splice(o,1)}}getMLContext(e){return this.mlContextBySessionId.get(e)}reserveTensorId(){return this.tensorManager.reserveTensorId()}releaseTensorId(e){ke("verbose",()=>`[WebNN] releaseTensorId {tensorId: ${e}}`),this.tensorManager.releaseTensorId(e)}async ensureTensor(e,r,t,o,i){let a=qa.get(t);if(!a)throw new Error(`Unsupported ONNX data type: ${t}`);return this.tensorManager.ensureTensor(e??this.currentSessionId,r,a,o,i)}async createTemporaryTensor(e,r,t){ke("verbose",()=>`[WebNN] createTemporaryTensor {onnxDataType: ${r}, shape: ${t}}`);let o=qa.get(r);if(!o)throw new Error(`Unsupported ONNX data type: ${r}`);let i=this.tensorManager.reserveTensorId();await this.tensorManager.ensureTensor(e,i,o,t,!1);let a=this.temporarySessionTensorIds.get(e);return a?a.push(i):this.temporarySessionTensorIds.set(e,[i]),i}uploadTensor(e,r){if(!Qe().shouldTransferToMLTensor)throw new Error("Trying to upload to a MLTensor while shouldTransferToMLTensor is false");ke("verbose",()=>`[WebNN] uploadTensor {tensorId: ${e}, data: ${r.byteLength}}`),this.tensorManager.upload(e,r)}async downloadTensor(e,r){return this.tensorManager.download(e,r)}createMLTensorDownloader(e,r){return async()=>{let t=await this.tensorManager.download(e);return Ua(t,r)}}registerMLTensor(e,r,t,o){let i=qa.get(t);if(!i)throw new Error(`Unsupported ONNX data type: ${t}`);let a=this.tensorManager.registerTensor(e,r,i,o);return ke("verbose",()=>`[WebNN] registerMLTensor {tensor: ${r}, dataType: ${i}, dimensions: ${o}} -> {tensorId: ${a}}`),a}registerMLConstant(e,r,t,o,i,a,l=!1){if(!a)throw new Error("External mounted files are not available.");let d=e;e.startsWith("./")&&(d=e.substring(2));let h=a.get(d);if(!h)throw new Error(`File with name ${d} not found in preloaded files.`);if(r+t>h.byteLength)throw new Error("Out of bounds: data offset and length exceed the external file data size.");let g=h.slice(r,r+t).buffer,_;switch(i.dataType){case"float32":_=new Float32Array(g);break;case"float16":_=typeof Float16Array<"u"&&Float16Array.from?new Float16Array(g):new Uint16Array(g);break;case"int32":_=new Int32Array(g);break;case"uint32":_=new Uint32Array(g);break;case"int64":if(l){let w=Fc(new Uint8Array(g),"int64");_=new Int32Array(w.buffer),i.dataType="int32"}else _=new BigInt64Array(g);break;case"uint64":_=new BigUint64Array(g);break;case"int8":_=new Int8Array(g);break;case"int4":case"uint4":case"uint8":_=new Uint8Array(g);break;default:throw new Error(`Unsupported data type: ${i.dataType} in creating WebNN Constant from external data.`)}return ke("verbose",()=>`[WebNN] registerMLConstant {dataType: ${i.dataType}, shape: ${i.shape}}} ${l?"(Note: it was int64 data type and registered to int32 as workaround)":""}`),o.constant(i,_)}registerGraphInput(e){this.temporaryGraphInputs.push(e)}registerGraphOutput(e){this.temporaryGraphOutputs.push(e)}isGraphInput(e,r){let t=this.sessionGraphInputs.get(e);return t?t.includes(r):!1}isGraphOutput(e,r){let t=this.sessionGraphOutputs.get(e);return t?t.includes(r):!1}isGraphInputOutputTypeSupported(e,r,t=!0){let o=this.mlContextBySessionId.get(e),i=qa.get(Cn(r));return typeof i>"u"?!1:t?!!o?.opSupportLimits().input.dataTypes.includes(i):!!o?.opSupportLimits().output.dataTypes.includes(i)}flush(){}}});var Xa=H(()=>{"use strict"});var Sx,Vc,jc,IR,SR,$x,Uc,Gc,Ox,Cx=H(()=>{"use strict";tn();Xa();Sx=new Map([[64,250],[128,200],[256,200],[512,200],[2048,230],[4096,200],[8192,50],[16384,50],[32768,50],[65536,50],[131072,50],[262144,50],[524288,50],[1048576,50],[2097152,30],[4194304,20],[8388608,10],[12582912,10],[16777216,10],[26214400,15],[33554432,22],[44236800,2],[58982400,6],[67108864,6],[134217728,6],[167772160,6]]),Vc=[],jc=n=>Math.ceil(Number(n)/16)*16,IR=n=>{for(let e=0;eSR++,Uc=async(n,e,r,t)=>{let o=jc(r),i=n.device.createBuffer({size:o,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});try{let a=n.getCommandEncoder();n.endComputePass(),a.copyBufferToBuffer(e,0,i,0,o),n.flush(),await i.mapAsync(GPUMapMode.READ);let l=i.getMappedRange();if(t){let d=t();return d.set(new Uint8Array(l,0,r)),d}else return new Uint8Array(l.slice(0,r))}finally{i.destroy()}},Gc=class{constructor(e){this.backend=e;this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.buffersPending=[],this.capturedPendingBuffers=new Map;for(let[r]of Sx)Vc.push(r),this.freeBuffers.set(r,[]),this.freeUniformBuffers.set(r,[]);this.sessionCount=0}upload(e,r){let t=r.buffer,o=r.byteOffset,i=r.byteLength,a=jc(i),l=this.storageCache.get(e);if(!l)throw new Error("gpu data for uploading does not exist");if(Number(l.originalSize)!==i)throw new Error(`inconsistent data size. gpu data size=${l.originalSize}, data size=${i}`);let d=this.backend.device.createBuffer({mappedAtCreation:!0,size:a,usage:GPUBufferUsage.MAP_WRITE|GPUBufferUsage.COPY_SRC}),h=d.getMappedRange();new Uint8Array(h).set(new Uint8Array(t,o,i)),d.unmap();let g=this.backend.device.createCommandEncoder();g.copyBufferToBuffer(d,0,l.gpuData.buffer,0,a),this.backend.device.queue.submit([g.finish()]),d.destroy(),ke("verbose",()=>`[WebGPU] GpuDataManager.upload(id=${e})`)}memcpy(e,r){let t=this.storageCache.get(e);if(!t)throw new Error("source gpu data for memcpy does not exist");let o=this.storageCache.get(r);if(!o)throw new Error("destination gpu data for memcpy does not exist");if(t.originalSize!==o.originalSize)throw new Error("inconsistent source and destination gpu data size");let i=jc(t.originalSize),a=this.backend.getCommandEncoder();this.backend.endComputePass(),a.copyBufferToBuffer(t.gpuData.buffer,0,o.gpuData.buffer,0,i)}registerExternalBuffer(e,r,t){let o;if(t){if(o=t[0],e===t[1])return ke("verbose",()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${r}) => id=${o}, buffer is the same, skip.`),o;if(this.backend.capturedCommandList.has(this.backend.currentSessionId))throw new Error(`Registering a different external buffer under graph capture mode is not supported yet. + Please use the previous external buffer!`)}else o=$x();return this.storageCache.set(o,{gpuData:{id:o,type:0,buffer:e},originalSize:r}),ke("verbose",()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${r}) => id=${o}, registered.`),o}unregisterExternalBuffer(e){e!==void 0&&(this.storageCache.delete(e),ke("verbose",()=>`[WebGPU] GpuDataManager.unregisterExternalBuffer() => id=${e}`))}create(e,r=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST){let t=IR(e),o,i=(r&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE,a=(r&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM;if(i||a){let h=(i?this.freeBuffers:this.freeUniformBuffers).get(t);h?h.length>0?o=h.pop():o=this.backend.device.createBuffer({size:t,usage:r}):o=this.backend.device.createBuffer({size:t,usage:r})}else o=this.backend.device.createBuffer({size:t,usage:r});let l={id:$x(),type:0,buffer:o};return this.storageCache.set(l.id,{gpuData:l,originalSize:Number(e)}),ke("verbose",()=>`[WebGPU] GpuDataManager.create(size=${e}) => id=${l.id}`),l}get(e){return this.storageCache.get(e)?.gpuData}release(e){let r=typeof e=="bigint"?Number(e):e,t=this.storageCache.get(r);if(!t){if(this.storageCache.size===0)return 0;throw new Error("releasing data does not exist")}return ke("verbose",()=>`[WebGPU] GpuDataManager.release(id=${r}), gpuDataId=${t.gpuData.id}`),this.storageCache.delete(r),this.buffersPending.push(t.gpuData.buffer),t.originalSize}async download(e,r){let t=this.storageCache.get(Number(e));if(!t)throw new Error("data does not exist");await Uc(this.backend,t.gpuData.buffer,t.originalSize,r)}refreshPendingBuffers(){if(this.buffersPending.length!==0)if(this.backend.sessionStatus==="default"){for(let e of this.buffersPending){let r=Sx.get(e.size);if((e.usage&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE){let t=this.freeBuffers.get(e.size)||[];r===void 0||t.length>=r?e.destroy():t.push(e)}else if((e.usage&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM){let t=this.freeUniformBuffers.get(e.size)||[];r===void 0||t.length>=r?e.destroy():t.push(e)}else e.destroy()}this.buffersPending=[]}else{let e=this.capturedPendingBuffers.get(this.backend.currentSessionId);e||(e=[],this.capturedPendingBuffers.set(this.backend.currentSessionId,e));for(let r of this.buffersPending)e.push(r);this.buffersPending=[]}}dispose(){this.freeBuffers.forEach(e=>{e.forEach(r=>{r.destroy()})}),this.freeUniformBuffers.forEach(e=>{e.forEach(r=>{r.destroy()})}),this.storageCache.forEach(e=>{e.gpuData.buffer.destroy()}),this.capturedPendingBuffers.forEach(e=>{e.forEach(r=>{r.destroy()})}),this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.capturedPendingBuffers=new Map}onCreateSession(){this.sessionCount+=1}onReleaseSession(e){let r=this.capturedPendingBuffers.get(e);r&&(r.forEach(t=>{t.destroy()}),this.capturedPendingBuffers.delete(e)),this.sessionCount-=1,this.sessionCount===0&&(ke("warning",()=>"[WebGPU] Clearing webgpu buffer cache"),this.storageCache.forEach(t=>{t.gpuData.buffer.destroy()}),this.storageCache=new Map)}},Ox=(...n)=>new Gc(...n)});var Wc,we,ft=H(()=>{"use strict";Wc=class{constructor(e){Object.assign(this,e)}get cacheKey(){return this.key||(this.key=Object.getOwnPropertyNames(this).sort().map(e=>`${this[e]}`).join(";")),this.key}},we=n=>new Wc(n)});var to,qc,et,vt,ne,Ge,Kc,ro,lr,de,Ja,J,te,Px,Za,Hc,Ex,Pe=H(()=>{"use strict";ve();Oe();to=64,qc=(n,e)=>{if(e===3)throw new Error("vec3 has same alignment as vec4, use vec4 instead");switch(Number(n)){case 10:return e>1?`vec${e}`:"f16";case 1:return e>1?`vec${e}`:"f32";case 6:return e>1?`vec${e}`:"i32";case 12:return e>1?`vec${e}`:"u32";case 7:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2","i32"];case 13:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2","u32"];case 9:if(e!==4)throw new Error("bool must be vec4");return["u32","vec4"];case 22:return"i32";case 21:return"u32";default:throw new Error(`Unknown data type: ${n}`)}},et=(n,e=1)=>{let r=qc(n,e);return typeof r=="string"?r:r[0]},vt=(n,e=1)=>{let r=qc(n,e);return typeof r=="string"?r:r[1]},ne=(...n)=>{let e=[];return n.forEach(r=>{r.length!==0&&e.push({type:12,data:r},{type:12,data:W.computeStrides(r)})}),e},Ge=n=>n%4===0?4:n%2===0?2:1,Kc=(n="f32",e,r="0")=>!e||e===1?`${n}(${r})`:`vec${e}<${n}>(${r})`,ro=(n,e,r)=>n==="f32"?r:e===1?`f32(${r})`:`vec${e}(${r})`,lr=(n,e)=>e===4?`(${n}.x + ${n}.y + ${n}.z + ${n}.w)`:e===2?`(${n}.x + ${n}.y)`:e===3?`(${n}.x + ${n}.y + ${n}.z)`:n,de=(n,e,r,t)=>n.startsWith("uniforms.")&&r>4?typeof e=="string"?t==="f16"?`${n}[(${e}) / 8][(${e}) % 8 / 4][(${e}) % 8 % 4]`:`${n}[(${e}) / 4][(${e}) % 4]`:t==="f16"?`${n}[${Math.floor(e/8)}][${Math.floor(e%8/4)}][${e%8%4}]`:`${n}[${Math.floor(e/4)}][${e%4}]`:r>1?`${n}[${e}]`:n,Ja=(n,e,r,t,o)=>{let i=typeof r=="number",a=i?r:r.length,l=[...new Array(a).keys()],d=a<2?"u32":a<=4?`vec${a}`:`array`,h=qc(e,o),g=typeof h=="string"?h:h[1],_=typeof h=="string"?h:h[0],w={indices:d,value:g,storage:_,tensor:e},x=j=>typeof j=="string"?j:`${j}u`,T={offsetToIndices:!1,indicesToOffset:!1,broadcastedIndicesToOffset:!1,set:!1,setByIndices:!1,get:!1,getByIndices:!1},S=i?"uniforms.":"",P=`${S}${n}_shape`,A=`${S}${n}_strides`,O="";for(let j=0;j ${w.indices} { + var indices: ${w.indices}; + var current = offset; + ${O} + return indices; + }`,L=j=>(T.offsetToIndices=!0,a<2?j:`o2i_${n}(${j})`),z=[];if(a>=2)for(let j=a-1;j>=0;j--)z.push(`${de(A,j,a)} * (indices[${j}])`);let B=a<2?"":` + fn i2o_${n}(indices: ${w.indices}) -> u32 { + return ${z.join("+")}; + }`,K=j=>(T.indicesToOffset=!0,a<2?j:`i2o_${n}(${j})`),Z=(...j)=>a===0?"0u":`${w.indices}(${j.map(x).join(",")})`,ee=(j,U)=>a<2?`${j}`:`${de(j,U,a)}`,ae=(j,U,ze)=>a<2?`${j}=${ze};`:`${de(j,U,a)}=${ze};`,pe={},he=(j,U)=>{T.broadcastedIndicesToOffset=!0;let ze=`${U.name}broadcastedIndicesTo${n}Offset`;if(ze in pe)return`${ze}(${j})`;let lt=[];for(let Et=a-1;Et>=0;Et--){let ct=U.indicesGet("outputIndices",Et+U.rank-a);lt.push(`${ee(A,Et)} * (${ct} % ${ee(P,Et)})`)}return pe[ze]=`fn ${ze}(outputIndices: ${U.type.indices}) -> u32 { + return ${lt.length>0?lt.join("+"):"0u"}; + }`,`${ze}(${j})`},Se=(j,U)=>(()=>{if(w.storage===w.value)return`${n}[${j}]=${U};`;if(w.storage==="vec2"&&w.value==="i32")return`${n}[${j}]=vec2(u32(${U}), select(0u, 0xFFFFFFFFu, ${U} < 0));`;if(w.storage==="vec2"&&w.value==="u32")return`${n}[${j}]=vec2(u32(${U}), 0u);`;if(w.storage==="u32"&&w.value==="vec4")return`${n}[${j}]=dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(${U}));`;throw new Error(`not supported combination of storage type ${w.storage} and value type ${w.value} yet`)})(),oe=j=>(()=>{if(w.storage===w.value)return`${n}[${j}]`;if(w.storage==="vec2"&&w.value==="i32")return`i32(${n}[${j}].x)`;if(w.storage==="vec2"&&w.value==="u32")return`u32(${n}[${j}].x)`;if(w.storage==="u32"&&w.value==="vec4")return`vec4(bool(${n}[${j}] & 0xFFu), bool(${n}[${j}] & 0xFF00u), bool(${n}[${j}] & 0xFF0000u), bool(${n}[${j}] & 0xFF000000u))`;throw new Error(`not supported combination of storage type ${w.storage} and value type ${w.value} yet`)})(),Be=a<2?"":` + fn get_${n}ByIndices(indices: ${w.indices}) -> ${g} { + return ${oe(`i2o_${n}(indices)`)}; + }`,xe=a<2?"":(()=>{let j=l.map(ze=>`d${ze}: u32`).join(", "),U=l.map(ze=>`d${ze}`).join(", ");return` + fn get_${n}(${j}) -> ${g} { + return get_${n}ByIndices(${Z(U)}); + }`})(),ue=(...j)=>{if(j.length!==a)throw new Error(`indices length must be ${a}`);let U=j.map(x).join(",");return a===0?oe("0u"):a===1?oe(U[0]):(T.get=!0,T.getByIndices=!0,T.indicesToOffset=!0,`get_${n}(${U})`)},Ee=j=>a<2?oe(j):(T.getByIndices=!0,T.indicesToOffset=!0,`get_${n}ByIndices(${j})`),me=a<2?"":` + fn set_${n}ByIndices(indices: ${w.indices}, value: ${g}) { + ${Se(`i2o_${n}(indices)`,"value")} + }`,Te=a<2?"":(()=>{let j=l.map(ze=>`d${ze}: u32`).join(", "),U=l.map(ze=>`d${ze}`).join(", ");return` + fn set_${n}(${j}, value: ${g}) { + set_${n}ByIndices(${Z(U)}, value); + }`})();return{impl:()=>{let j=[],U=!1;return T.offsetToIndices&&(j.push(E),U=!0),T.indicesToOffset&&(j.push(B),U=!0),T.broadcastedIndicesToOffset&&(Object.values(pe).forEach(ze=>j.push(ze)),U=!0),T.set&&(j.push(Te),U=!0),T.setByIndices&&(j.push(me),U=!0),T.get&&(j.push(xe),U=!0),T.getByIndices&&(j.push(Be),U=!0),!i&&U&&j.unshift(`const ${P} = ${w.indices}(${r.join(",")});`,`const ${A} = ${w.indices}(${W.computeStrides(r).join(",")});`),j.join(` +`)},type:w,offsetToIndices:L,indicesToOffset:K,broadcastedIndicesToOffset:he,indices:Z,indicesGet:ee,indicesSet:ae,set:(...j)=>{if(j.length!==a+1)throw new Error(`indices length must be ${a}`);let U=j[a];if(typeof U!="string")throw new Error("value must be string");let ze=j.slice(0,a).map(x).join(",");return a===0?Se("0u",U):a===1?Se(ze[0],U):(T.set=!0,T.setByIndices=!0,T.indicesToOffset=!0,`set_${n}(${ze}, ${U})`)},setByOffset:Se,setByIndices:(j,U)=>a<2?Se(j,U):(T.setByIndices=!0,T.indicesToOffset=!0,`set_${n}ByIndices(${j}, ${U});`),get:ue,getByOffset:oe,getByIndices:Ee,usage:t,name:n,strides:A,shape:P,rank:a}},J=(n,e,r,t=1)=>Ja(n,e,r,"input",t),te=(n,e,r,t=1)=>Ja(n,e,r,"output",t),Px=(n,e,r)=>Ja(n,e,r,"atomicOutput",1),Za=(n,e,r,t=1)=>Ja(n,e,r,"internal",t),Hc=class{constructor(e,r){this.normalizedDispatchGroup=e;this.limits=r;this.internalVariables=[];this.variables=[];this.uniforms=[];this.variableIndex=0}guardAgainstOutOfBoundsWorkgroupSizes(e){return`if (global_idx >= ${typeof e=="number"?`${e}u`:e}) { return; }`}mainStart(e=to){let r=typeof e=="number"?e:e[0],t=typeof e=="number"?1:e[1],o=typeof e=="number"?1:e[2];if(r>this.limits.maxComputeWorkgroupSizeX||t>this.limits.maxComputeWorkgroupSizeY||o>this.limits.maxComputeWorkgroupSizeZ)throw new Error(`workgroup size [${r}, ${t}, ${o}] exceeds the maximum workgroup size [${this.limits.maxComputeWorkgroupSizeX}, ${this.limits.maxComputeWorkgroupSizeY}, ${this.limits.maxComputeWorkgroupSizeZ}].`);if(r*t*o>this.limits.maxComputeInvocationsPerWorkgroup)throw new Error(`workgroup size [${r}, ${t}, ${o}] exceeds the maximum workgroup invocations ${this.limits.maxComputeInvocationsPerWorkgroup}.`);let i=this.normalizedDispatchGroup[1]===1&&this.normalizedDispatchGroup[2]===1,a=i?`@builtin(global_invocation_id) global_id : vec3, + @builtin(workgroup_id) workgroup_id : vec3, + @builtin(local_invocation_index) local_idx : u32, + @builtin(local_invocation_id) local_id : vec3`:`@builtin(global_invocation_id) global_id : vec3, + @builtin(local_invocation_id) local_id : vec3, + @builtin(local_invocation_index) local_idx : u32, + @builtin(workgroup_id) workgroup_id : vec3, + @builtin(num_workgroups) num_workgroups : vec3`,l=i?`let global_idx = global_id.x; + let workgroup_index = workgroup_id.x;`:`let workgroup_index = workgroup_id.z * num_workgroups[0] * num_workgroups[1] + + workgroup_id.y * num_workgroups[0] + workgroup_id.x; + let global_idx = workgroup_index * ${r*t*o}u + local_idx;`;return`@compute @workgroup_size(${r}, ${t}, ${o}) + fn main(${a}) { + ${l} + `}appendVariableUniforms(e){e.rank!==0&&(e.shape.startsWith("uniforms.")&&this.uniforms.push({name:e.shape.replace("uniforms.",""),type:"u32",length:e.rank}),e.strides.startsWith("uniforms.")&&this.uniforms.push({name:e.strides.replace("uniforms.",""),type:"u32",length:e.rank}))}declareVariable(e,r){if(e.usage==="internal")throw new Error("cannot use internal variable with declareVariable(). use registerInternalVariables() instead.");this.variables.push(e),this.appendVariableUniforms(e);let t=e.usage==="input"?"read":"read_write",o=e.usage==="atomicOutput"?"atomic":e.type.storage;return`@group(0) @binding(${r}) var ${e.name}: array<${o}>;`}declareVariables(...e){return e.map(r=>this.declareVariable(r,this.variableIndex++)).join(` +`)}registerInternalVariable(e){if(e.usage!=="internal")throw new Error("cannot use input or output variable with registerInternalVariable(). use declareVariables() instead.");this.internalVariables.push(e),this.appendVariableUniforms(e)}registerInternalVariables(...e){return e.forEach(r=>this.registerInternalVariable(r)),this}registerUniform(e,r,t=1){return this.uniforms.push({name:e,type:r,length:t}),this}registerUniforms(e){return this.uniforms=this.uniforms.concat(e),this}uniformDeclaration(){if(this.uniforms.length===0)return"";let e=[];for(let{name:r,type:t,length:o}of this.uniforms)if(o&&o>4)t==="f16"?e.push(`@align(16) ${r}:array, ${Math.ceil(o/8)}>`):e.push(`${r}:array, ${Math.ceil(o/4)}>`);else{let i=o==null||o===1?t:`vec${o}<${t}>`;e.push(`${r}:${i}`)}return` + struct Uniforms { ${e.join(", ")} }; + @group(0) @binding(${this.variableIndex}) var uniforms: Uniforms;`}get additionalImplementations(){return this.uniformDeclaration()+this.variables.map(e=>e.impl()).join(` +`)+this.internalVariables.map(e=>e.impl()).join(` +`)}get variablesInfo(){if(this.uniforms.length===0)return;let e=r=>[12,10,1,6][["u32","f16","f32","i32"].indexOf(r)];return this.uniforms.map(r=>[e(r.type),r.length??1])}},Ex=(n,e)=>new Hc(n,e)});var $R,Dx,AR,OR,CR,PR,wt,kx,Nx,fn=H(()=>{"use strict";ve();Oe();ft();Pe();$R=(n,e)=>{if(!n||n.length!==1)throw new Error("Transpose requires 1 input.");if(e.length!==0&&e.length!==n[0].dims.length)throw new Error(`perm size ${e.length} does not match input rank ${n[0].dims.length}`)},Dx=(n,e)=>e.length!==0?e:[...new Array(n).keys()].reverse(),AR=(n,e)=>W.sortBasedOnPerm(n,Dx(n.length,e)),OR=(n,e,r,t)=>{let o=`fn perm(i: ${t.type.indices}) -> ${r.type.indices} { + var a: ${r.type.indices};`;for(let i=0;i{let r=[],t=[];for(let o=0;o{let r=0;for(let t=0;t{let r=n.dataType,t=n.dims.length,o=Dx(t,e),i=AR(n.dims,o),a=n.dims,l=i,d=t<2||PR(o,n.dims),h;if(d)return h=S=>{let P=J("input",r,a,4),A=te("output",r,l,4);return` + ${S.registerUniform("output_size","u32").declareVariables(P,A)} + ${S.mainStart()} + ${S.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + output[global_idx] = input[global_idx]; + }`},{name:"TransposeCopy",shaderCache:{inputDependencies:["type"]},getRunData:()=>{let S=W.size(i);return{outputs:[{dims:i,dataType:n.dataType}],dispatchGroup:{x:Math.ceil(S/64/4)},programUniforms:[{type:12,data:Math.ceil(S/4)}]}},getShaderSource:h};let{newShape:g,newPerm:_}=CR(n.dims,o),w=W.areEqual(_,[2,3,1]),x=W.areEqual(_,[3,1,2]);if(g.length===2||w||x){a=w?[g[0],g[1]*g[2]]:x?[g[0]*g[1],g[2]]:g,l=[a[1],a[0]];let S=16;return h=P=>{let A=J("a",r,a.length),O=te("output",r,l.length);return` + ${P.registerUniform("output_size","u32").declareVariables(A,O)} + var tile : array, ${S}>; + ${P.mainStart([S,S,1])} + let stride = (uniforms.output_shape[1] - 1) / ${S} + 1; + let workgroup_id_x = workgroup_index % stride; + let workgroup_id_y = workgroup_index / stride; + let input_col = workgroup_id_y * ${S}u + local_id.x; + let input_row = workgroup_id_x * ${S}u + local_id.y; + if (input_row < uniforms.a_shape[0] && input_col < uniforms.a_shape[1]) { + tile[local_id.y][local_id.x] = ${A.getByIndices(`${A.type.indices}(input_row, input_col)`)}; + } + workgroupBarrier(); + + let output_col = workgroup_id_x * ${S}u + local_id.x; + let output_row = workgroup_id_y * ${S}u + local_id.y; + if (output_row < uniforms.output_shape[0] && output_col < uniforms.output_shape[1]) { + ${O.setByIndices(`${O.type.indices}(output_row, output_col)`,"tile[local_id.x][local_id.y]")} + } + }`},{name:"TransposeShared",shaderCache:{inputDependencies:["type"]},getRunData:()=>{let P=W.size(i);return{outputs:[{dims:i,dataType:n.dataType}],dispatchGroup:{x:Math.ceil(l[1]/S),y:Math.ceil(l[0]/S)},programUniforms:[{type:12,data:P},...ne(a,l)]}},getShaderSource:h}}return h=S=>{let P=J("a",r,a.length),A=te("output",r,l.length);return` + ${S.registerUniform("output_size","u32").declareVariables(P,A)} + + ${OR(o,t,P,A)} + + ${S.mainStart()} + ${S.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + + let indices = ${A.offsetToIndices("global_idx")}; + let aIndices = perm(indices); + + ${A.setByOffset("global_idx",P.getByIndices("aIndices"))} + }`},{name:"Transpose",shaderCache:{hint:`${e}`,inputDependencies:["rank"]},getRunData:()=>{let S=W.size(i);return{outputs:[{dims:i,dataType:n.dataType}],dispatchGroup:{x:Math.ceil(S/64)},programUniforms:[{type:12,data:S},...ne(a,l)]}},getShaderSource:h}},kx=(n,e)=>{$R(n.inputs,e.perm),n.compute(wt(n.inputs[0],e.perm))},Nx=n=>we({perm:n.perm})});var ER,DR,kR,NR,LR,RR,zR,MR,BR,FR,nn,Lx,Rx,zx,Mx,Bx,Fx,Vx,jx,Gx,Ux,Wx=H(()=>{"use strict";ve();Oe();Pe();Qa();fn();ER={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate * candidate",logSumExp:"bestValue + exp(candidate)",l1:"bestValue + abs(candidate)",l2:"bestValue + candidate * candidate",logSum:"bestValue + candidate"},DR={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate",logSumExp:"bestValue + candidate",l1:"bestValue + candidate",l2:"bestValue + candidate",logSum:"bestValue + candidate"},kR={max:"_A[offset]",min:"_A[offset]",mean:"0",sum:"0",prod:"1",sumSquare:"0",logSumExp:"0",l1:"0",l2:"0",logSum:"0"},NR={max:"bestValue",min:"bestValue",sum:"bestValue",prod:"bestValue",sumSquare:"bestValue",logSumExp:"log(bestValue)",l1:"bestValue",l2:"sqrt(bestValue)",logSum:"log(bestValue)"},LR=(n,e)=>{let r=[];for(let t=e-n;t{let r=[],t=n.length;for(let i=0;in[i]);return[r,o]},zR=(n,e)=>{let r=n.length+e.length,t=[],o=0;for(let i=0;i{for(let r=0;r{let r=[];if(!MR(n,e)){for(let t=0;tr.push(t))}return r},FR=(n,e,r,t,o,i,a)=>{let l=r[0].dims,d=W.size(i),h=W.size(a),g=J("_A",r[0].dataType,l),_=te("output",o,i),w=64;d===1&&(w=256);let x=` + var aBestValues : array; + `,T=S=>` + ${S.registerUniform("reduceSize","u32").declareVariables(g,_)} + ${x} + fn DIV_CEIL(a : u32, b : u32) -> u32 { + return ((a - 1u) / b + 1u); + } + ${S.mainStart(w)} + + let outputIndex = global_idx / ${w}; + let offset = outputIndex * uniforms.reduceSize; + + var bestValue = f32(${kR[t]}); + let Length = uniforms.reduceSize; + for (var k = local_idx; k < Length; k = k + ${w}) { + let candidate = f32(${g.getByOffset("offset + k")}); + bestValue = ${ER[t]}; + } + aBestValues[local_idx] = bestValue; + workgroupBarrier(); + + var reduceSize = min(Length, ${w}u); + for (var currentSize = reduceSize / 2u; reduceSize > 1u; + currentSize = reduceSize / 2u) { + let interval = DIV_CEIL(reduceSize, 2u); + if (local_idx < currentSize) { + let candidate = aBestValues[local_idx + interval]; + bestValue = ${DR[t]}; + aBestValues[local_idx] = bestValue; + } + reduceSize = interval; + workgroupBarrier(); + } + + if (local_idx == 0u) { + ${_.setByOffset("outputIndex",`${t==="mean"?`${_.type.storage}(bestValue / f32(uniforms.reduceSize))`:`${_.type.storage}(${NR[t]})`}`)}; + } + }`;return{name:n,shaderCache:{hint:`${e};${w}`,inputDependencies:["type"]},getShaderSource:T,getRunData:()=>({outputs:[{dims:i,dataType:o}],dispatchGroup:{x:d},programUniforms:[{type:12,data:h}]})}},nn=(n,e,r,t)=>{let o=n.inputs.length===1?r:Xc(n.inputs,r),i=o.axes;i.length===0&&!o.noopWithEmptyAxes&&(i=n.inputs[0].dims.map((x,T)=>T));let a=W.normalizeAxes(i,n.inputs[0].dims.length),l=a,d=n.inputs[0],h=BR(l,n.inputs[0].dims.length);h.length>0&&(d=n.compute(wt(n.inputs[0],h),{inputs:[0],outputs:[-1]})[0],l=LR(l.length,d.dims.length));let[g,_]=RR(d.dims,l),w=g;o.keepDims&&(w=zR(g,a)),n.compute(FR(e,o.cacheKey,[d],t,n.inputs[0].dataType,w,_),{inputs:[d]})},Lx=(n,e)=>{nn(n,"ReduceMeanShared",e,"mean")},Rx=(n,e)=>{nn(n,"ReduceL1Shared",e,"l1")},zx=(n,e)=>{nn(n,"ReduceL2Shared",e,"l2")},Mx=(n,e)=>{nn(n,"ReduceLogSumExpShared",e,"logSumExp")},Bx=(n,e)=>{nn(n,"ReduceMaxShared",e,"max")},Fx=(n,e)=>{nn(n,"ReduceMinShared",e,"min")},Vx=(n,e)=>{nn(n,"ReduceProdShared",e,"prod")},jx=(n,e)=>{nn(n,"ReduceSumShared",e,"sum")},Gx=(n,e)=>{nn(n,"ReduceSumSquareShared",e,"sumSquare")},Ux=(n,e)=>{nn(n,"ReduceLogSumShared",e,"logSum")}});var on,VR,Ya,Xc,an,jR,GR,UR,WR,HR,qR,KR,XR,JR,ZR,sn,Hx,qx,Kx,Xx,Jx,Zx,Qx,Yx,eT,tT,Qa=H(()=>{"use strict";ve();Oe();ft();Pe();Wx();on=n=>{if(!n||n.length===0||n.length>2)throw new Error("Reduce op requires 1 or 2 inputs.");if(n.length===2&&n[1].dims.length!==1)throw new Error("Invalid axes input dims.")},VR=n=>["","",`var value = ${n.getByIndices("input_indices")};`,""],Ya=(n,e,r,t,o,i,a=!1,l=!1)=>{let d=[],h=r[0].dims,g=h.length,_=W.normalizeAxes(o,g),w=!l&&_.length===0;h.forEach((P,A)=>{w||_.indexOf(A)>=0?a&&d.push(1):d.push(P)});let x=d.length,T=W.size(d);return{name:n,shaderCache:e,getShaderSource:P=>{let A=[],O=J("_A",r[0].dataType,g),E=te("output",i,x),L=t(O,E,_),z=L[2];for(let B=0,K=0;B=0?(a&&K++,z=`for(var j${B}: u32 = 0; j${B} < ${h[B]}; j${B}++) { + ${L[2].includes("last_index")?`let last_index = j${B};`:""} + ${O.indicesSet("input_indices",B,`j${B}`)} + ${z} + }`):(A.push(`${O.indicesSet("input_indices",B,E.indicesGet("output_indices",K))};`),K++);return` + + ${P.registerUniform("output_size","u32").declareVariables(O,E)} + + ${P.mainStart()} + ${P.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + var input_indices: ${O.type.indices}; + let output_indices = ${E.offsetToIndices("global_idx")}; + + ${A.join(` +`)} + ${L[0]} // init ops for reduce max/min + ${L[1]} + ${z} + ${L[3]} + ${L.length===4?E.setByOffset("global_idx","value"):L.slice(4).join(` +`)} + }`},getRunData:()=>({outputs:[{dims:d,dataType:i}],dispatchGroup:{x:Math.ceil(T/64)},programUniforms:[{type:12,data:T},...ne(h,d)]})}},Xc=(n,e)=>{let r=[];return n[1].dims[0]>0&&n[1].getBigInt64Array().forEach(t=>r.push(Number(t))),we({axes:r,keepDims:e.keepDims,noopWithEmptyAxes:e.noopWithEmptyAxes})},an=(n,e,r,t)=>{let o=n.inputs,i=o.length===1?r:Xc(o,r);n.compute(Ya(e,{hint:i.cacheKey,inputDependencies:["rank"]},[o[0]],i.noopWithEmptyAxes&&i.axes.length===0?VR:t,i.axes,o[0].dataType,i.keepDims,i.noopWithEmptyAxes),{inputs:[0]})},jR=(n,e)=>{on(n.inputs),an(n,"ReduceLogSum",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,"value = log(value);"])},GR=(n,e)=>{on(n.inputs),an(n,"ReduceL1",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += abs(${t.getByIndices("input_indices")});`,""])},UR=(n,e)=>{on(n.inputs),an(n,"ReduceL2",e,(t,o)=>[`var t = ${o.type.value}(0); var value = ${o.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += (t * t);`,"value = sqrt(value);"])},WR=(n,e)=>{on(n.inputs),an(n,"ReduceLogSumExp",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += exp(${t.getByIndices("input_indices")});`,"value = log(value);"])},HR=(n,e)=>{on(n.inputs),an(n,"ReduceMax",e,(t,o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(t.indicesSet("input_indices",l,0));return[`${a.join(` +`)}`,`var value = ${t.getByIndices("input_indices")};`,`value = max(value, ${t.getByIndices("input_indices")});`,""]})},qR=(n,e)=>{on(n.inputs),an(n,"ReduceMean",e,(t,o,i)=>{let a=1;for(let l=0;l=0||i.length===0)&&(a*=n.inputs[0].dims[l]);return["var sum = f32(0);","",`sum += f32(${t.getByIndices("input_indices")});`,`let value = ${o.type.value}(sum / ${a});`]})},KR=(n,e)=>{on(n.inputs),an(n,"ReduceMin",e,(t,o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(`input_indices[${l}] = 0;`);return[`${a.join(` +`)}`,`var value = ${t.getByIndices("input_indices")};`,`value = min(value, ${t.getByIndices("input_indices")});`,""]})},XR=(n,e)=>{on(n.inputs),an(n,"ReduceProd",e,(t,o)=>[`var value = ${o.type.storage}(1);`,"",`value *= ${t.getByIndices("input_indices")};`,""])},JR=(n,e)=>{on(n.inputs),an(n,"ReduceSum",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,""])},ZR=(n,e)=>{on(n.inputs),an(n,"ReduceSumSquare",e,(t,o)=>[`var t = ${o.type.value}(0); var value = ${o.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += t * t;`,""])},sn=(n,e,r)=>{if(e.length===0)return r;let t=1,o=1;for(let i=0;i1024},Hx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?qR(n,e):Lx(n,e)},qx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?GR(n,e):Rx(n,e)},Kx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?UR(n,e):zx(n,e)},Xx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?WR(n,e):Mx(n,e)},Jx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?HR(n,e):Bx(n,e)},Zx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?KR(n,e):Fx(n,e)},Qx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?XR(n,e):Vx(n,e)},Yx=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?JR(n,e):jx(n,e)},eT=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?ZR(n,e):Gx(n,e)},tT=(n,e)=>{sn(n.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?jR(n,e):Ux(n,e)}});var rT,nT,oT,Jc,iT=H(()=>{"use strict";ve();ft();Qa();rT=n=>{if(!n||n.length===0||n.length>2)throw new Error("ArgMinMaxOp op requires 1 or 2 inputs.");if(n[0].dataType!==1)throw new Error("Invalid input type.")},nT=(n,e)=>{rT(n.inputs);let r=(t,o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(`input_indices[${l}] = 0;`);return[`${a.join(` +`)}`,`var value = ${t.getByIndices("input_indices")}; +var best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?"<=":"<"} value) { + value = ${t.getByIndices("input_indices")}; + best_index = i32(last_index); + }`,"",o.setByOffset("global_idx","best_index")]};n.compute(Ya("ArgMin",{hint:e.cacheKey,inputDependencies:["rank"]},[n.inputs[0]],r,[e.axis],7,e.keepDims),{inputs:[0]})},oT=(n,e)=>{rT(n.inputs);let r=(t,o,i)=>{let a=[];for(let l=0;l=0||i.length===0)&&a.push(`input_indices[${l}] = 0;`);return[`${a.join(` +`)}`,`var value = ${t.getByIndices("input_indices")}; +var best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?">=":">"} value) { + value = ${t.getByIndices("input_indices")}; + best_index = i32(last_index); + }`,"",o.setByOffset("global_idx","best_index")]};n.compute(Ya("argMax",{hint:e.cacheKey,inputDependencies:["rank"]},[n.inputs[0]],r,[e.axis],7,e.keepDims),{inputs:[0]})},Jc=n=>we(n)});var QR,Zc,YR,ez,tz,To,rz,aT,es=H(()=>{"use strict";ve();Oe();Xa();Pe();QR=(n,e)=>{let r=n[0],t=n[1],o=n[2],i=n[3],a=n[4],l=n[5];if(a&&l)throw new Error("Attention cannot have both past and attention_bias");if(r.dims.length!==3)throw new Error('Input "input" must have 3 dimensions');let d=r.dims[0],h=r.dims[1],g=r.dims[2];if(o.dims.length!==1)throw new Error('Input "bias" is expected to have 1 dimensions');if(t.dims.length!==2)throw new Error('Input "weights" is expected to have 2 dimensions');if(t.dims[0]!==g)throw new Error("Input 1 dimension 0 should have same length as dimension 2 of input 0");if(o.dims[0]!==t.dims[1])throw new Error('Input "bias" dimension 0 should have same length as dimension 1 of input "weights"');let _=o.dims[0]/3,w=_,x=w;if(e.qkvHiddenSizes.length>0){if(e.qkvHiddenSizes.length!==3)throw new Error("qkv_hidden_sizes attribute should have 3 elements");for(let E of e.qkvHiddenSizes)if(E%e.numHeads!==0)throw new Error("qkv_hidden_sizes should be divisible by num_heads");_=e.qkvHiddenSizes[0],w=e.qkvHiddenSizes[1],x=e.qkvHiddenSizes[2]}let T=h;if(_!==w)throw new Error("qkv_hidden_sizes first element should be same as the second");if(o.dims[0]!==_+w+x)throw new Error('Input "bias" dimension 0 should have same length as sum of Q/K/V hidden sizes');let S=0;if(a){if(w!==x)throw new Error('Input "past" expect k_hidden_size == v_hidden_size');if(a.dims.length!==5)throw new Error('Input "past" must have 5 dimensions');if(a.dims[0]!==2)throw new Error('Input "past" first dimension must be 2');if(a.dims[1]!==d)throw new Error('Input "past" second dimension must be batch_size');if(a.dims[2]!==e.numHeads)throw new Error('Input "past" third dimension must be num_heads');if(a.dims[4]!==w/e.numHeads)throw new Error('Input "past" fifth dimension must be k_hidden_size / num_heads');e.pastPresentShareBuffer||(S=a.dims[3])}let P=T+S,A=-1,O=0;if(i)throw new Error("Mask not supported");if(a)throw new Error("past is not supported");if(l){if(l.dims.length!==4)throw new Error('Input "attention_bias" must have 4 dimensions');if(l.dims[0]!==d||l.dims[1]!==e.numHeads||l.dims[2]!==h||l.dims[3]!==P)throw new Error('Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)')}return{batchSize:d,sequenceLength:h,pastSequenceLength:S,kvSequenceLength:T,totalSequenceLength:P,maxSequenceLength:A,inputHiddenSize:g,hiddenSize:_,vHiddenSize:x,headSize:Math.floor(_/e.numHeads),vHeadSize:Math.floor(x/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:O,scale:e.scale,broadcastResPosBias:!1,passPastInKv:!1,qkvFormat:1}},Zc=(n,e,r)=>e&&n?` + let total_sequence_length_input = u32(${e.getByOffset("0")}); + let present_sequence_length = max(total_sequence_length_input, uniforms.past_sequence_length); + let is_subsequent_prompt: bool = sequence_length > 1 && sequence_length != total_sequence_length_input; + let is_first_prompt: bool = is_subsequent_prompt == false && sequence_length == total_sequence_length_input; + total_sequence_length = u32(${n?.getByOffset("batchIdx")}) + 1; + var past_sequence_length: u32 = 0; + if (is_first_prompt == false) { + past_sequence_length = total_sequence_length - sequence_length; + } + `:` + ${r?"let past_sequence_length = uniforms.past_sequence_length":""}; + let present_sequence_length = total_sequence_length; + `,YR=(n,e,r,t,o,i,a,l)=>{let d=Ge(a?1:i),h=64,g=i/d;g{let O=te("x",n.dataType,n.dims,d),E=[O],L=a?J("seq_lens",a.dataType,a.dims):void 0;L&&E.push(L);let z=l?J("total_sequence_length_input",l.dataType,l.dims):void 0;z&&E.push(z);let B=vt(n.dataType),K=[{name:"batch_size",type:"u32"},{name:"num_heads",type:"u32"},{name:"past_sequence_length",type:"u32"},{name:"sequence_length",type:"u32"},{name:"total_sequence_length",type:"u32"},{name:"elements_per_thread",type:"u32"}];return` + var thread_max: array; + var thread_sum: array; + ${A.registerUniforms(K).declareVariables(...E)} + ${A.mainStart([h,1,1])} + let batchIdx = workgroup_id.z / uniforms.num_heads; + let headIdx = workgroup_id.z % uniforms.num_heads; + let sequence_length = uniforms.sequence_length; + var total_sequence_length = uniforms.total_sequence_length; + ${Zc(L,z,!1)} + let local_offset = local_idx * uniforms.elements_per_thread; + let offset = (global_idx / ${h}) * uniforms.total_sequence_length + local_offset; + let seq_causal_length = ${a?"u32(past_sequence_length + workgroup_id.y + 1)":"total_sequence_length"}; + var thread_max_vector = ${T}(-3.402823e+38f); + for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { + thread_max_vector = max(${T}(x[offset + i]), thread_max_vector); + } + thread_max[local_idx] = ${(()=>{switch(d){case 1:return"thread_max_vector";case 2:return"max(thread_max_vector.x, thread_max_vector.y)";case 4:return"max(max(thread_max_vector.x, thread_max_vector.y), max(thread_max_vector.z, thread_max_vector.w))";default:throw new Error(`Unsupported components: ${d}`)}})()}; + workgroupBarrier(); + + var max_value = f32(-3.402823e+38f); + for (var i = 0u; i < ${h}; i++) { + max_value = max(thread_max[i], max_value); + } + + var sum_vector = ${T}(0); + for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { + sum_vector += exp(${T}(x[offset + i]) - max_value); + } + thread_sum[local_idx] = ${(()=>{switch(d){case 1:return"sum_vector";case 2:return"sum_vector.x + sum_vector.y";case 4:return"sum_vector.x + sum_vector.y + sum_vector.z + sum_vector.w";default:throw new Error(`Unsupported components: ${d}`)}})()}; + workgroupBarrier(); + + var sum: f32 = 0; + for (var i = 0u; i < ${h}; i++) { + sum += thread_sum[i]; + } + + if (sum == 0) { + for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { + x[offset + i] = ${O.type.value}(${B}(1.0) / ${B}(seq_causal_length)); + } + } else { + for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { + var f32input = ${T}(x[offset + i]); + x[offset + i] = ${O.type.value}(exp(f32input - max_value) / sum); + } + } + ${a?` + for (var total_seq_id: u32 = seq_causal_length; total_seq_id + local_offset < uniforms.total_sequence_length; total_seq_id++) { + x[offset + total_seq_id] = ${O.type.value}(${B}(0)); + }`:""}; + }`};return{name:"AttentionProbsSoftmax",shaderCache:{hint:`${h};${x};${d}`,inputDependencies:S},getShaderSource:P,getRunData:()=>({outputs:[],dispatchGroup:{x:1,y:o,z:e*r},programUniforms:w})}},ez=(n,e,r,t,o,i,a,l,d)=>{let h=a+i.kvSequenceLength,g=[i.batchSize,i.numHeads,i.sequenceLength,h],_=n>1&&t,w=i.kvNumHeads?i.kvNumHeads:i.numHeads,x=_?[i.batchSize,w,h,i.headSize]:void 0,T=i.nReps?i.nReps:1,S=i.scale===0?1/Math.sqrt(i.headSize):i.scale,P=Ge(i.headSize),A=i.headSize/P,O=12,E={x:Math.ceil(h/O),y:Math.ceil(i.sequenceLength/O),z:i.batchSize*i.numHeads},L=[{type:12,data:i.sequenceLength},{type:12,data:A},{type:12,data:h},{type:12,data:i.numHeads},{type:12,data:i.headSize},{type:1,data:S},{type:12,data:a},{type:12,data:i.kvSequenceLength},{type:12,data:T}],z=_&&t&&W.size(t.dims)>0,B=["type","type"];z&&B.push("type"),o&&B.push("type"),l&&B.push("type"),d&&B.push("type");let K=[{dims:g,dataType:e.dataType,gpuDataType:0}];_&&K.push({dims:x,dataType:e.dataType,gpuDataType:0});let Z=ee=>{let ae=J("q",e.dataType,e.dims,P),pe=J("key",r.dataType,r.dims,P),he=[ae,pe];if(z){let me=J("past_key",t.dataType,t.dims,P);he.push(me)}o&&he.push(J("attention_bias",o.dataType,o.dims));let Se=l?J("seq_lens",l.dataType,l.dims):void 0;Se&&he.push(Se);let oe=d?J("total_sequence_length_input",d.dataType,d.dims):void 0;oe&&he.push(oe);let Be=te("output",e.dataType,g),xe=[Be];_&&xe.push(te("present_key",e.dataType,x,P));let ue=vt(1,P),Ee=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"alpha",type:"f32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"},{name:"n_reps",type:"u32"}];return` + const TILE_SIZE = ${O}u; + + var tileQ: array<${ae.type.storage}, ${O*O}>; + var tileK: array<${ae.type.storage}, ${O*O}>; + ${ee.registerUniforms(Ee).declareVariables(...he,...xe)} + ${ee.mainStart([O,O,1])} + // x holds the N and y holds the M + let headIdx = workgroup_id.z % uniforms.num_heads; + let kvHeadIdx = ${T===1?"headIdx":"headIdx / uniforms.n_reps"}; + let kv_num_heads = ${T===1?"uniforms.num_heads":"uniforms.num_heads / uniforms.n_reps"}; + let batchIdx = workgroup_id.z / uniforms.num_heads; + let m = workgroup_id.y * TILE_SIZE; + let n = workgroup_id.x * TILE_SIZE; + let sequence_length = uniforms.M; + var total_sequence_length = uniforms.N; + ${Zc(Se,oe,!0)} + let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx; + let qOffset = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K; + ${z&&_?"let pastKeyOffset = absKvHeadIdx * uniforms.past_sequence_length * uniforms.K;":""}; + let kOffset = absKvHeadIdx * uniforms.kv_sequence_length * uniforms.K; + ${_?"let presentKeyOffset = absKvHeadIdx * uniforms.N * uniforms.K;":""} + var value = ${ue}(0); + for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { + if (global_id.y < uniforms.M && w + local_id.x < uniforms.K) { + tileQ[TILE_SIZE * local_id.y + local_id.x] = q[qOffset + local_id.y * uniforms.K + w + local_id.x]; + } + if (n + local_id.y < uniforms.N && w + local_id.x < uniforms.K) { + var idx = TILE_SIZE * local_id.y + local_id.x; + ${z&&_?` + if (n + local_id.y < past_sequence_length) { + tileK[idx] = past_key[pastKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x]; + } else if (n + local_id.y - past_sequence_length < uniforms.kv_sequence_length) { + tileK[idx] = key[kOffset + (n + local_id.y - past_sequence_length) * uniforms.K + w + local_id.x]; + }`:` + if (n + local_id.y < uniforms.kv_sequence_length) { + tileK[idx] = key[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x]; + }`} + ${_?`if (n + local_id.y < present_sequence_length) { + present_key[presentKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x] = tileK[idx]; + }`:""} + } + workgroupBarrier(); + + for (var k: u32 = 0u; k < TILE_SIZE && w+k < uniforms.K; k++) { + value += ${ue}(tileQ[TILE_SIZE * local_id.y + k] * tileK[TILE_SIZE * local_id.x + k]); + } + + workgroupBarrier(); + } + + if (global_id.y < uniforms.M && global_id.x < total_sequence_length) { + let headOffset = workgroup_id.z * uniforms.M * uniforms.N; + let outputIdx = headOffset + global_id.y * uniforms.N + global_id.x; + var sum: f32 = ${(()=>{switch(P){case 1:return"value";case 2:return"value.x + value.y";case 4:return"value.x + value.y + value.z + value.w";default:throw new Error(`Unsupported components: ${P}`)}})()}; + output[outputIdx] = ${Be.type.value} (sum * uniforms.alpha) + ${o?"attention_bias[outputIdx]":"0.0"}; + } + }`};return{name:"AttentionProbs",shaderCache:{hint:`${P};${o!==void 0};${t!==void 0};${n}`,inputDependencies:B},getRunData:()=>({outputs:K,dispatchGroup:E,programUniforms:L}),getShaderSource:Z}},tz=(n,e,r,t,o,i,a=void 0,l=void 0)=>{let d=i+o.kvSequenceLength,h=o.nReps?o.nReps:1,g=o.vHiddenSize*h,_=n>1&&t,w=o.kvNumHeads?o.kvNumHeads:o.numHeads,x=_?[o.batchSize,w,d,o.headSize]:void 0,T=[o.batchSize,o.sequenceLength,g],S=12,P={x:Math.ceil(o.vHeadSize/S),y:Math.ceil(o.sequenceLength/S),z:o.batchSize*o.numHeads},A=[{type:12,data:o.sequenceLength},{type:12,data:d},{type:12,data:o.vHeadSize},{type:12,data:o.numHeads},{type:12,data:o.headSize},{type:12,data:g},{type:12,data:i},{type:12,data:o.kvSequenceLength},{type:12,data:h}],O=_&&t&&W.size(t.dims)>0,E=["type","type"];O&&E.push("type"),a&&E.push("type"),l&&E.push("type");let L=[{dims:T,dataType:e.dataType,gpuDataType:0}];_&&L.push({dims:x,dataType:e.dataType,gpuDataType:0});let z=B=>{let K=J("probs",e.dataType,e.dims),Z=J("v",r.dataType,r.dims),ee=[K,Z];O&&ee.push(J("past_value",t.dataType,t.dims));let ae=a?J("seq_lens",a.dataType,a.dims):void 0;a&&ee.push(ae);let pe=l?J("total_sequence_length_input",l.dataType,l.dims):void 0;l&&ee.push(pe);let Se=[te("output",e.dataType,T)];_&&Se.push(te("present_value",e.dataType,x));let oe=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"v_hidden_size",type:"u32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"},{name:"n_reps",type:"u32"}];return` + const TILE_SIZE = ${S}u; + var tileQ: array<${K.type.value}, ${S*S}>; + var tileV: array<${K.type.value}, ${S*S}>; + ${B.registerUniforms(oe).declareVariables(...ee,...Se)} + ${B.mainStart([S,S,1])} + let headIdx = workgroup_id.z % uniforms.num_heads; + let batchIdx = workgroup_id.z / uniforms.num_heads; + let kvHeadIdx = ${h===1?"headIdx":"headIdx / uniforms.n_reps"}; + let kv_num_heads = ${h===1?"uniforms.num_heads":"uniforms.num_heads / uniforms.n_reps"}; + let m = global_id.y; + let n = global_id.x; + let sequence_length = uniforms.M; + var total_sequence_length = uniforms.K; + ${Zc(ae,pe,!0)} + let offsetA = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K; + let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx; // kvHeadIdx is relative to the batch + ${O&&_?"let pastValueOffset = absKvHeadIdx * uniforms.N * uniforms.past_sequence_length + n;":""}; + let vOffset = absKvHeadIdx * uniforms.N * uniforms.kv_sequence_length + n; + ${_?"let presentValueOffset = absKvHeadIdx * uniforms.N * uniforms.K + n;":""} + var value = ${K.type.storage}(0); + for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { + if (m < uniforms.M && w + local_id.x < uniforms.K) { + tileQ[TILE_SIZE * local_id.y + local_id.x] = probs[offsetA + w + local_id.x]; + } + if (n < uniforms.N && w + local_id.y < uniforms.K) { + var idx = TILE_SIZE * local_id.y + local_id.x; + ${O&&_?` + if (w + local_id.y < past_sequence_length) { + tileV[idx] = past_value[pastValueOffset + (w + local_id.y) * uniforms.N]; + } else if (w + local_id.y - past_sequence_length < uniforms.kv_sequence_length) { + tileV[idx] = v[vOffset + (w + local_id.y - past_sequence_length) * uniforms.N]; + } + `:` + if (w + local_id.y < uniforms.kv_sequence_length) { + tileV[idx] = v[vOffset + (w + local_id.y) * uniforms.N]; + }`} + ${_?` + if (w + local_id.y < present_sequence_length) { + present_value[presentValueOffset + (w + local_id.y) * uniforms.N] = tileV[idx]; + }`:""} + } + workgroupBarrier(); + for (var k: u32 = 0u; k < TILE_SIZE && w+k < total_sequence_length; k++) { + value += tileQ[TILE_SIZE * local_id.y + k] * tileV[TILE_SIZE * k + local_id.x]; + } + workgroupBarrier(); + } + + // we need to transpose output from BNSH_v to BSND_v + if (m < uniforms.M && n < uniforms.N) { + let outputIdx = batchIdx * uniforms.M * uniforms.v_hidden_size + m * uniforms.v_hidden_size + + headIdx * uniforms.N + n; + output[outputIdx] = value; + } + }`};return{name:"AttentionScore",shaderCache:{hint:`${t!==void 0};${n}`,inputDependencies:E},getRunData:()=>({outputs:L,dispatchGroup:P,programUniforms:A}),getShaderSource:z}},To=(n,e,r,t,o,i,a,l,d,h,g=void 0,_=void 0)=>{let w=Math.min(n.outputCount,1+(a?1:0)+(l?1:0)),x=w>1?h.pastSequenceLength:0,T=x+h.kvSequenceLength,S=d&&W.size(d.dims)>0?d:void 0,P=[e,r];w>1&&a&&W.size(a.dims)>0&&P.push(a),S&&P.push(S),g&&P.push(g),_&&P.push(_);let A=n.compute(ez(w,e,r,a,S,h,x,g,_),{inputs:P,outputs:w>1?[-1,1]:[-1]})[0];n.compute(YR(A,h.batchSize,h.numHeads,x,h.sequenceLength,T,g,_),{inputs:g&&_?[A,g,_]:[A],outputs:[]});let O=[A,t];w>1&&l&&W.size(l.dims)>0&&O.push(l),g&&O.push(g),_&&O.push(_),n.compute(tz(w,A,t,l,h,x,g,_),{inputs:O,outputs:w>1?[0,2]:[0]})},rz=(n,e)=>{let r=[e.batchSize,e.numHeads,e.sequenceLength,e.headSize],t=e.sequenceLength,o=e.inputHiddenSize,i=e.headSize,a=12,l={x:Math.ceil(e.headSize/a),y:Math.ceil(e.sequenceLength/a),z:e.batchSize*e.numHeads},d=[n.inputs[0],n.inputs[1],n.inputs[2]],h=[{type:12,data:t},{type:12,data:o},{type:12,data:i},{type:12,data:e.numHeads},{type:12,data:e.headSize},{type:12,data:e.hiddenSize},{type:12,data:e.hiddenSize+e.hiddenSize+e.vHiddenSize}],g=_=>{let w=te("output_q",d[0].dataType,r),x=te("output_k",d[0].dataType,r),T=te("output_v",d[0].dataType,r),S=J("input",d[0].dataType,d[0].dims),P=J("weight",d[1].dataType,d[1].dims),A=J("bias",d[2].dataType,d[2].dims),O=S.type.storage,E=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"hidden_size",type:"u32"},{name:"ldb",type:"u32"}];return` + const TILE_SIZE = ${a}u; + var tileInput: array<${O}, ${a*a}>; + var tileWeightQ: array<${O}, ${a*a}>; + var tileWeightK: array<${O}, ${a*a}>; + var tileWeightV: array<${O}, ${a*a}>; + ${_.registerUniforms(E).declareVariables(S,P,A,w,x,T)} + ${_.mainStart([a,a,1])} + let batchIndex = workgroup_id.z / uniforms.num_heads; + let headNumber = workgroup_id.z % uniforms.num_heads; + let m = global_id.y; + let n = global_id.x; + + let inputOffset = batchIndex * (uniforms.M * uniforms.K) + m * uniforms.K; + let biasOffsetQ = headNumber * uniforms.head_size; + let biasOffsetK = uniforms.hidden_size + biasOffsetQ; + let biasOffsetV = uniforms.hidden_size + biasOffsetK; + + var valueQ = ${O}(0); + var valueK = ${O}(0); + var valueV = ${O}(0); + for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { + if (m < uniforms.M && w + local_id.x < uniforms.K) { + tileInput[TILE_SIZE * local_id.y + local_id.x] = input[inputOffset + w + local_id.x]; + } + if (n < uniforms.N && w + local_id.y < uniforms.K) { + let offset = n + (w + local_id.y) * uniforms.ldb; + tileWeightQ[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetQ + offset]; + tileWeightK[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetK + offset]; + tileWeightV[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetV + offset]; + } + workgroupBarrier(); + for (var k: u32 = 0u; k({outputs:[{dims:r,dataType:n.inputs[0].dataType,gpuDataType:0},{dims:r,dataType:n.inputs[0].dataType,gpuDataType:0},{dims:r,dataType:n.inputs[0].dataType,gpuDataType:0}],dispatchGroup:l,programUniforms:h}),getShaderSource:g},{inputs:d,outputs:[-1,-1,-1]})},aT=(n,e)=>{let r=QR(n.inputs,e),[t,o,i]=rz(n,r);return To(n,t,o,i,n.inputs[4],void 0,void 0,void 0,n.inputs[5],r)}});var nz,oz,iz,sT,uT=H(()=>{"use strict";At();ve();Oe();ft();Pe();nz=(n,e)=>{if(!n||n.length!==5)throw new Error("BatchNormalization requires 5 inputs");let r=(t,o,i)=>{let a=o.length;if(a!==t.length)throw new Error(`${i}: num dimensions != ${a}`);o.forEach((l,d)=>{if(l!==t[d])throw new Error(`${i}: dim[${d}] do not match`)})};if(n[0].dims.length>1){let t=e.format==="NHWC"?e.spatial?n[0].dims.slice(-1):n[0].dims.slice(-1).concat(n[0].dims.slice(1,n[0].dims.length-1)):n[0].dims.slice(1,e.spatial?2:void 0);r(n[1].dims,t,"Invalid input scale"),r(n[2].dims,t,"Invalid input B"),r(n[3].dims,t,"Invalid input mean"),r(n[4].dims,t,"Invalid input var")}else r(n[1].dims,[1],"Invalid input scale"),r(n[2].dims,[1],"Invalid input B"),r(n[3].dims,[1],"Invalid input mean"),r(n[4].dims,[1],"Invalid input var")},oz=(n,e)=>{let{epsilon:r,spatial:t,format:o}=e,i=n[0].dims,a=t?Ge(i[i.length-1]):1,l=o==="NHWC"&&i.length>1?a:1,d=W.size(i)/a,h=t,g=h?i.length:i,_=J("x",n[0].dataType,n[0].dims,a),w=J("scale",n[1].dataType,n[1].dims,l),x=J("bias",n[2].dataType,n[2].dims,l),T=J("inputMean",n[3].dataType,n[3].dims,l),S=J("inputVar",n[4].dataType,n[4].dims,l),P=te("y",n[0].dataType,g,a),A=()=>{let E="";if(t)E=`let cOffset = ${i.length===1?"0u":o==="NHWC"?`outputIndices[${i.length-1}] / ${a}`:"outputIndices[1]"};`;else if(o==="NCHW")E=` + ${P.indicesSet("outputIndices","0","0")} + let cOffset = ${P.indicesToOffset("outputIndices")};`;else{E=`var cIndices = ${w.type.indices}(0); + cIndices[0] = outputIndices[${i.length-1}];`;for(let L=1;L` + const epsilon = ${r}; + ${E.registerUniform("outputSize","u32").declareVariables(_,w,x,T,S,P)} + ${E.mainStart()} + ${E.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + var outputIndices = ${P.offsetToIndices(`global_idx * ${a}`)}; + ${A()} + let scale = ${w.getByOffset("cOffset")}; + let bias = ${x.getByOffset("cOffset")}; + let inputMean = ${T.getByOffset("cOffset")}; + let inputVar = ${S.getByOffset("cOffset")}; + let x = ${_.getByOffset("global_idx")}; + let value = (x - inputMean) * inverseSqrt(inputVar + epsilon) * scale + bias; + ${P.setByOffset("global_idx","value")} + }`;return{name:"BatchNormalization",shaderCache:{hint:`${e.epsilon}_${e.format}_${t}_${a}`,inputDependencies:h?["rank","type","type","type","type"]:void 0},getShaderSource:O,getRunData:()=>({outputs:[{dims:n[0].dims,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:h?[{type:12,data:d},...ne(i)]:[{type:12,data:d}]})}},iz=n=>we(n),sT=(n,e)=>{let{inputs:r,outputCount:t}=n,o=iz({...e,outputCount:t});if(Ae.webgpu.validateInputContent&&nz(r,o),e.trainingMode)throw new Error("BatchNormalization trainingMode is not supported yet.");n.compute(oz(r,o))}});var az,sz,lT,cT=H(()=>{"use strict";Oe();Pe();az=n=>{if(n[0].dims.length!==3)throw new Error("input should have 3 dimensions");if(![320,640,1280].includes(n[0].dims[2]))throw new Error("number of channels should be 320, 640 or 1280");if(n[1].dims.length!==1)throw new Error("bias is expected to have 1 dimensions");if(n[0].dims[2]!==n[1].dims[0])throw new Error("last dimension of input and bias are not the same")},sz=n=>{let e=n[0].dims,r=n[0].dims[2],t=W.size(e)/4,o=n[0].dataType,i=J("input",o,e,4),a=J("bias",o,[r],4),l=J("residual",o,e,4),d=te("output",o,e,4);return{name:"BiasAdd",getRunData:()=>({outputs:[{dims:e,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(t/64)}}),getShaderSource:g=>` + const channels = ${r}u / 4; + ${g.declareVariables(i,a,l,d)} + + ${g.mainStart()} + ${g.guardAgainstOutOfBoundsWorkgroupSizes(t)} + let value = ${i.getByOffset("global_idx")} + + ${a.getByOffset("global_idx % channels")} + ${l.getByOffset("global_idx")}; + ${d.setByOffset("global_idx","value")} + }`}},lT=n=>{az(n.inputs),n.compute(sz(n.inputs))}});var uz,Ke,dT,pT,fT,hT,mT,gT,bT,yT,_T,lz,vT,wT,xT,TT,oi,IT,ts,ST,$T,AT,OT,CT,PT,ET,DT,kT,NT,LT,RT,zT,MT,BT,FT,VT,jT,Qc,Yc,GT,UT,WT,cz,dz,HT,rs=H(()=>{"use strict";ve();Oe();ft();Pe();uz=(n,e,r,t,o,i,a)=>{let l=Math.ceil(e/4),d="";typeof o=="string"?d=`${o}(a)`:d=o("a");let h=J("inputData",r,[l],4),g=te("outputData",t,[l],4),_=[{name:"vec_size",type:"u32"}];return a&&_.push(...a),` + ${n.registerUniforms(_).declareVariables(h,g)} + + ${i??""} + + ${n.mainStart()} + ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} + + let a = ${h.getByOffset("global_idx")}; + ${g.setByOffset("global_idx",d)} + }`},Ke=(n,e,r,t,o,i=n.dataType,a,l)=>{let d=[{type:12,data:Math.ceil(W.size(n.dims)/4)}];return a&&d.push(...a),{name:e,shaderCache:{hint:o,inputDependencies:["type"]},getShaderSource:h=>uz(h,W.size(n.dims),n.dataType,i,r,t,l),getRunData:h=>({outputs:[{dims:n.dims,dataType:i}],dispatchGroup:{x:Math.ceil(W.size(h[0].dims)/64/4)},programUniforms:d})}},dT=n=>{n.compute(Ke(n.inputs[0],"Abs","abs"))},pT=n=>{n.compute(Ke(n.inputs[0],"Acos","acos"))},fT=n=>{n.compute(Ke(n.inputs[0],"Acosh","acosh"))},hT=n=>{n.compute(Ke(n.inputs[0],"Asin","asin"))},mT=n=>{n.compute(Ke(n.inputs[0],"Asinh","asinh"))},gT=n=>{n.compute(Ke(n.inputs[0],"Atan","atan"))},bT=n=>{n.compute(Ke(n.inputs[0],"Atanh","atanh"))},yT=n=>we(n),_T=(n,e)=>{let r;switch(e.to){case 10:r="vec4";break;case 1:r="vec4";break;case 12:r="vec4";break;case 6:r="vec4";break;case 9:r="vec4";break;default:throw new RangeError(`not supported type (specified in attribute 'to' from 'Cast' operator): ${e.to}`)}n.compute(Ke(n.inputs[0],"Cast",r,void 0,e.cacheKey,e.to))},lz=n=>{let e,r,t=n.length>=2&&n[1].data!==0,o=n.length>=3&&n[2].data!==0;switch(n[0].dataType){case 1:e=t?n[1].getFloat32Array()[0]:-34028234663852886e22,r=o?n[2].getFloat32Array()[0]:34028234663852886e22;break;case 10:e=t?n[1].getUint16Array()[0]:64511,r=o?n[2].getUint16Array()[0]:31743;break;default:throw new Error("Unsupport data type")}return we({min:e,max:r})},vT=(n,e)=>{let r=e||lz(n.inputs),t=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"Clip",o=>`clamp(${o}, vec4<${t}>(uniforms.min), vec4<${t}>(uniforms.max))`,void 0,r.cacheKey,void 0,[{type:n.inputs[0].dataType,data:r.min},{type:n.inputs[0].dataType,data:r.max}],[{name:"min",type:t},{name:"max",type:t}]),{inputs:[0]})},wT=n=>{n.compute(Ke(n.inputs[0],"Ceil","ceil"))},xT=n=>{n.compute(Ke(n.inputs[0],"Cos","cos"))},TT=n=>{n.compute(Ke(n.inputs[0],"Cosh","cosh"))},oi=n=>we(n),IT=(n,e)=>{let r=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"Elu",t=>`elu_vf32(${t})`,` + const elu_alpha_ = ${r}(${e.alpha}); + + fn elu_f32(a: ${r}) -> ${r} { + return select((exp(a) - 1.0) * elu_alpha_, a, a >= 0.0); + } + + fn elu_vf32(v: vec4<${r}>) -> vec4<${r}> { + return vec4(elu_f32(v.x), elu_f32(v.y), elu_f32(v.z), elu_f32(v.w)); + }`,e.cacheKey))},ts=(n="f32")=>` +const r0: ${n} = 0.3275911; +const r1: ${n} = 0.254829592; +const r2: ${n} = -0.284496736; +const r3: ${n} = 1.421413741; +const r4: ${n} = -1.453152027; +const r5: ${n} = 1.061405429; + +fn erf_vf32(v: vec4<${n}>) -> vec4<${n}> { + let absv = abs(v); + let x = 1.0 / (1.0 + r0 * absv); + return sign(v) * (1.0 - ((((r5 * x + r4) * x + r3) * x + r2) * x + r1) * x * exp(-absv * absv)); +}`,ST=n=>{let e=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"Erf",r=>`erf_vf32(${r})`,ts(e)))},$T=n=>{n.compute(Ke(n.inputs[0],"Exp","exp"))},AT=n=>{n.compute(Ke(n.inputs[0],"Floor","floor"))},OT=n=>{let e=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"Gelu",r=>`0.5 * ${r} * (1.0 + erf_vf32(${r} * 0.7071067811865475))`,ts(e)))},CT=(n,e)=>{let r=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"LeakyRelu",t=>`select(leaky_relu_alpha_ * ${t}, ${t}, ${t} >= vec4<${r}>(0.0))`,`const leaky_relu_alpha_ = ${r}(${e.alpha});`,e.cacheKey))},PT=n=>{n.compute(Ke(n.inputs[0],"Not",e=>`!${e}`))},ET=n=>{n.compute(Ke(n.inputs[0],"Neg",e=>`-${e}`))},DT=n=>{n.compute(Ke(n.inputs[0],"Reciprocal",e=>`1.0/${e}`))},kT=n=>{let e=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"Relu",r=>`select(vec4<${e}>(0.0), ${r}, ${r} > vec4<${e}>(0.0))`))},NT=n=>{n.compute(Ke(n.inputs[0],"Sigmoid",e=>`(1.0 / (1.0 + exp(-${e})))`))},LT=n=>we(n),RT=(n,e)=>{let r=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"HardSigmoid",t=>`max(vec4<${r}>(0.0), min(vec4<${r}>(1.0), ${e.alpha} * ${t} + vec4<${r}>(${e.beta})))`,void 0,e.cacheKey))},zT=n=>{n.compute(Ke(n.inputs[0],"Sin","sin"))},MT=n=>{n.compute(Ke(n.inputs[0],"Sinh","sinh"))},BT=n=>{n.compute(Ke(n.inputs[0],"Sqrt","sqrt"))},FT=n=>{n.compute(Ke(n.inputs[0],"Tan","tan"))},VT=n=>`sign(${n}) * (1 - exp(-2 * abs(${n}))) / (1 + exp(-2 * abs(${n})))`,jT=n=>{n.compute(Ke(n.inputs[0],"Tanh",VT))},Qc=(n="f32")=>` +const fast_gelu_a: ${n} = 0.5; +const fast_gelu_b: ${n} = 0.7978845608028654; +const fast_gelu_c: ${n} = 0.035677408136300125; + +fn tanh_v(v: vec4<${n}>) -> vec4<${n}> { + return ${VT("v")}; +} +`,Yc=n=>`(fast_gelu_a + fast_gelu_a * tanh_v(${n} * (fast_gelu_c * ${n} * ${n} + fast_gelu_b))) * ${n}`,GT=n=>{let e=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"FastGelu",Yc,Qc(e),void 0,n.inputs[0].dataType))},UT=(n,e)=>{let r=vt(n.inputs[0].dataType);return n.compute(Ke(n.inputs[0],"ThresholdedRelu",t=>`select(vec4<${r}>(0.0), ${t}, ${t} > thresholded_relu_alpha_)`,`const thresholded_relu_alpha_ = vec4<${r}>(${e.alpha});`,e.cacheKey)),0},WT=n=>{n.compute(Ke(n.inputs[0],"Log","log"))},cz=(n,e)=>` +const alpha = vec4<${n}>(${e}); +const one = ${n}(1.0); +const zero = ${n}(0.0); + +fn quick_gelu_impl(x: vec4<${n}>) -> vec4<${n}> { + let v = x *alpha; + var x1 : vec4<${n}>; + for (var i = 0; i < 4; i = i + 1) { + if (v[i] >= zero) { + x1[i] = one / (one + exp(-v[i])); + } else { + x1[i] = one - one / (one + exp(v[i])); + } + } + return x * x1; +} +`,dz=n=>`quick_gelu_impl(${n})`,HT=(n,e)=>{let r=vt(n.inputs[0].dataType);n.compute(Ke(n.inputs[0],"QuickGelu",dz,cz(r,e.alpha),e.cacheKey,n.inputs[0].dataType))}});var pz,fz,KT,XT=H(()=>{"use strict";Oe();Pe();rs();pz=n=>{if(n[0].dims.length!==3)throw new Error("input should have 3 dimensions");if(![2560,5120,10240].includes(n[0].dims[2]))throw new Error("hidden state should be 2560, 5120 or 10240");if(n[1].dims.length!==1)throw new Error("bias is expected to have 1 dimensions");if(n[0].dims[2]!==n[1].dims[0])throw new Error("last dimension of input and bias are not the same")},fz=n=>{let e=n[0].dims.slice();e[2]=e[2]/2;let r=J("input",n[0].dataType,n[0].dims,4),t=J("bias",n[0].dataType,[n[0].dims[2]],4),o=te("output",n[0].dataType,e,4),i=W.size(e)/4,a=et(n[0].dataType);return{name:"BiasSplitGelu",getRunData:()=>({outputs:[{dims:e,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(i/64)}}),getShaderSource:d=>` + const M_SQRT2 = sqrt(2.0); + const halfChannels = ${n[0].dims[2]/4/2}u; + + ${d.declareVariables(r,t,o)} + + ${ts(a)} + + ${d.mainStart()} + ${d.guardAgainstOutOfBoundsWorkgroupSizes(i)} + let biasIdx = global_idx % halfChannels; + let batchIndex = global_idx / halfChannels; + let inputOffset = biasIdx + batchIndex * halfChannels * 2; + let valueLeft = input[inputOffset] + bias[biasIdx]; + let valueRight = input[inputOffset + halfChannels] + bias[biasIdx + halfChannels]; + let geluRight = valueRight * 0.5 * (erf_vf32(valueRight / M_SQRT2) + 1); + + ${o.setByOffset("global_idx","valueLeft * geluRight")} + }`}},KT=n=>{pz(n.inputs),n.compute(fz(n.inputs))}});var hz,mz,un,JT,ZT,QT,YT,e1,t1,r1,n1,o1,i1,a1=H(()=>{"use strict";ve();Oe();Pe();hz=(n,e,r,t,o,i,a,l,d,h,g,_)=>{let w,x;typeof l=="string"?w=x=(O,E)=>`${l}((${O}),(${E}))`:typeof l=="function"?w=x=l:(w=l.scalar,x=l.vector);let T=te("outputData",g,t.length,4),S=J("aData",d,e.length,4),P=J("bData",h,r.length,4),A;if(o)if(i){let O=W.size(e)===1,E=W.size(r)===1,L=e.length>0&&e[e.length-1]%4===0,z=r.length>0&&r[r.length-1]%4===0;O||E?A=T.setByOffset("global_idx",x(O?`${S.type.value}(${S.getByOffset("0")}.x)`:S.getByOffset("global_idx"),E?`${P.type.value}(${P.getByOffset("0")}.x)`:P.getByOffset("global_idx"))):A=` + let outputIndices = ${T.offsetToIndices("global_idx * 4u")}; + let offsetA = ${S.broadcastedIndicesToOffset("outputIndices",T)}; + let offsetB = ${P.broadcastedIndicesToOffset("outputIndices",T)}; + ${T.setByOffset("global_idx",x(a||L?S.getByOffset("offsetA / 4u"):`${S.type.value}(${S.getByOffset("offsetA / 4u")}[offsetA % 4u])`,a||z?P.getByOffset("offsetB / 4u"):`${P.type.value}(${P.getByOffset("offsetB / 4u")}[offsetB % 4u])`))} + `}else A=T.setByOffset("global_idx",x(S.getByOffset("global_idx"),P.getByOffset("global_idx")));else{if(!i)throw new Error("no necessary to use scalar implementation for element-wise binary op implementation.");let O=(E,L,z="")=>{let B=`aData[indexA${L}][componentA${L}]`,K=`bData[indexB${L}][componentB${L}]`;return` + let outputIndices${L} = ${T.offsetToIndices(`global_idx * 4u + ${L}u`)}; + let offsetA${L} = ${S.broadcastedIndicesToOffset(`outputIndices${L}`,T)}; + let offsetB${L} = ${P.broadcastedIndicesToOffset(`outputIndices${L}`,T)}; + let indexA${L} = offsetA${L} / 4u; + let indexB${L} = offsetB${L} / 4u; + let componentA${L} = offsetA${L} % 4u; + let componentB${L} = offsetB${L} % 4u; + ${E}[${L}] = ${z}(${w(B,K)}); + `};g===9?A=` + var data = vec4(0); + ${O("data",0,"u32")} + ${O("data",1,"u32")} + ${O("data",2,"u32")} + ${O("data",3,"u32")} + outputData[global_idx] = dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(data));`:A=` + ${O("outputData[global_idx]",0)} + ${O("outputData[global_idx]",1)} + ${O("outputData[global_idx]",2)} + ${O("outputData[global_idx]",3)} + `}return` + ${n.registerUniform("vec_size","u32").declareVariables(S,P,T)} + + ${_??""} + + ${n.mainStart()} + ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} + ${A} + }`},mz=(n,e,r,t,o,i,a=r.dataType)=>{let l=r.dims.map(S=>Number(S)??1),d=t.dims.map(S=>Number(S)??1),h=!W.areEqual(l,d),g=l,_=W.size(l),w=!1,x=!1,T=[h];if(h){let S=rn.calcShape(l,d,!1);if(!S)throw new Error("Can't perform binary op on the given tensors");g=S.slice(),_=W.size(g);let P=W.size(l)===1,A=W.size(d)===1,O=l.length>0&&l[l.length-1]%4===0,E=d.length>0&&d[d.length-1]%4===0;T.push(P),T.push(A),T.push(O),T.push(E);let L=1;for(let z=1;zS.toString()).join("_"),inputDependencies:["rank","rank"]},getShaderSource:S=>hz(S,l,d,g,w,h,x,o,r.dataType,t.dataType,a,i),getRunData:()=>({outputs:[{dims:g,dataType:a}],dispatchGroup:{x:Math.ceil(_/64/4)},programUniforms:[{type:12,data:Math.ceil(W.size(g)/4)},...ne(l,d,g)]})}},un=(n,e,r,t,o,i)=>{n.compute(mz(e,o??"",n.inputs[0],n.inputs[1],r,t,i))},JT=n=>{un(n,"Add",(e,r)=>`${e}+${r}`)},ZT=n=>{un(n,"Div",(e,r)=>`${e}/${r}`)},QT=n=>{un(n,"Equal",{scalar:(e,r)=>`u32(${e}==${r})`,vector:(e,r)=>`vec4(${e}==${r})`},void 0,void 0,9)},YT=n=>{un(n,"Mul",(e,r)=>`${e}*${r}`)},e1=n=>{let e=J("input",n.inputs[0].dataType,n.inputs[0].dims).type.value;un(n,"Pow",{scalar:(t,o)=>`pow_custom(${t},${o})`,vector:(t,o)=>`pow_vector_custom(${t},${o})`},` + fn pow_custom(a : ${e}, b : ${e}) -> ${e} { + if (b == ${e}(0.0)) { + return ${e}(1.0); + } else if (a < ${e}(0.0) && f32(b) != floor(f32(b))) { + return ${e}(pow(f32(a), f32(b))); // NaN + } + return select(sign(a), ${e}(1.0), round(f32(abs(b) % ${e}(2.0))) != 1.0) * ${e}(${e==="i32"?"round":""}(pow(f32(abs(a)), f32(b)))); + } + fn pow_vector_custom(a : vec4<${e}>, b : vec4<${e}>) -> vec4<${e}> { + // TODO: implement vectorized pow + return vec4<${e}>(pow_custom(a.x, b.x), pow_custom(a.y, b.y), pow_custom(a.z, b.z), pow_custom(a.w, b.w)); + } + `)},t1=n=>{un(n,"Sub",(e,r)=>`${e}-${r}`)},r1=n=>{un(n,"Greater",{scalar:(e,r)=>`u32(${e}>${r})`,vector:(e,r)=>`vec4(${e}>${r})`},void 0,void 0,9)},n1=n=>{un(n,"Less",{scalar:(e,r)=>`u32(${e}<${r})`,vector:(e,r)=>`vec4(${e}<${r})`},void 0,void 0,9)},o1=n=>{un(n,"GreaterOrEqual",{scalar:(e,r)=>`u32(${e}>=${r})`,vector:(e,r)=>`vec4(${e}>=${r})`},void 0,void 0,9)},i1=n=>{un(n,"LessOrEqual",{scalar:(e,r)=>`u32(${e}<=${r})`,vector:(e,r)=>`vec4(${e}<=${r})`},void 0,void 0,9)}});var bz,yz,_z,vz,s1,u1,l1=H(()=>{"use strict";ve();Oe();ft();Pe();bz=(n,e)=>{if(!n||n.length<1)throw new Error("too few inputs");let r=0,t=n[r],o=t.dataType,i=t.dims.length;n.forEach((a,l)=>{if(l!==r){if(a.dataType!==o)throw new Error("input tensors should be one type");if(a.dims.length!==i)throw new Error("input tensors should have the same shape");a.dims.forEach((d,h)=>{if(h!==e&&d!==t.dims[h])throw new Error("non concat dimensions must match")})}})},yz=(n,e)=>` + fn calculateInputIndex(index: u32) -> u32 { + let sizeInConcatAxis = array(${e}); + for (var i: u32 = 0u; i < ${n}; i += 1u ) { + if (index < sizeInConcatAxis[i]) { + return i; + } + } + return ${n}u; + }`,_z=(n,e)=>{let r=n.length,t=[];for(let o=0;o{let o=W.size(r),i=new Array(n.length),a=new Array(n.length),l=0,d=[],h=[],g=[{type:12,data:o}];for(let S=0;S`uniforms.sizeInConcatAxis${S}`).join(","),T=S=>` + + ${(()=>{S.registerUniform("outputSize","u32");for(let P=0;P(${x}); + ${w} -= sizeInConcatAxis[inputIndex - 1u]; + } + + ${_z(a,_)} + }`;return{name:"Concat",shaderCache:{hint:`${e}`,inputDependencies:d},getRunData:()=>({outputs:[{dims:r,dataType:t}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:g}),getShaderSource:T}},s1=(n,e)=>{let r=n.inputs,t=r[0].dims,o=W.normalizeAxis(e.axis,t.length);bz(r,o);let i=t.slice();i[o]=r.reduce((l,d)=>l+(d.dims.length>o?d.dims[o]:0),0);let a=r.filter(l=>W.size(l.dims)>0);n.compute(vz(a,o,i,r[0].dataType),{inputs:a})},u1=n=>we({axis:n.axis})});var cr,dr,pr,ns,En=H(()=>{"use strict";ve();Oe();cr=(n,e,r="f32")=>{switch(n.activation){case"Relu":return`value = max(value, ${e}(0.0));`;case"Sigmoid":return`value = (${e}(1.0) / (${e}(1.0) + exp(-value)));`;case"Clip":return`value = clamp(value, ${e}(${r}(uniforms.clip_min)), ${e}(${r}(uniforms.clip_max)));`;case"HardSigmoid":return`value = max(${e}(0.0), min(${e}(1.0), ${r}(uniforms.alpha) * value + ${r}(uniforms.beta)));`;case"LeakyRelu":return`value = select(${r}(uniforms.alpha) * value, value, value >= ${e}(0.0));`;case"Tanh":return`let e2x = exp(-2.0 * abs(value)); + value = sign(value) * (1.0 - e2x) / (1.0 + e2x); + `;case"":return"";default:throw new Error(`Unsupported activation ${n.activation}`)}},dr=(n,e)=>{n.activation==="Clip"?e.push({type:1,data:n.clipMax},{type:1,data:n.clipMin}):n.activation==="HardSigmoid"?e.push({type:1,data:n.alpha},{type:1,data:n.beta}):n.activation==="LeakyRelu"&&e.push({type:1,data:n.alpha})},pr=(n,e)=>{n.activation==="Clip"?e.push({name:"clip_max",type:"f32"},{name:"clip_min",type:"f32"}):n.activation==="HardSigmoid"?e.push({name:"alpha",type:"f32"},{name:"beta",type:"f32"}):n.activation==="LeakyRelu"&&e.push({name:"alpha",type:"f32"})},ns=n=>{let e=n?.activation||"";if(e==="HardSigmoid"){let[r,t]=n?.activation_params||[.2,.5];return{activation:e,alpha:r,beta:t}}else if(e==="Clip"){let[r,t]=n?.activation_params||[gx,bx];return{activation:e,clipMax:t,clipMin:r}}else if(e==="LeakyRelu"){let[r]=n?.activation_params||[.01];return{activation:e,alpha:r}}return{activation:e}}});var _t,c1,os=H(()=>{"use strict";_t=(n,e)=>{switch(n){case 1:return e;case 2:return`vec2<${e}>`;case 3:return`vec3<${e}>`;case 4:return`vec4<${e}>`;default:throw new Error(`${n}-component is not supported.`)}},c1=n=>` + ${n?"value = value + getBiasByOutputCoords(coords);":""} + `});var d1,p1=H(()=>{"use strict";d1=n=>` +fn getIndexFromCoords4D(coords : vec4, shape : vec4) -> i32 { + return dot(coords, vec4( + shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1)); +} +fn getOutputIndexFromCoords(coords : vec4) -> i32 { + return dot(coords, vec4( + i32(${n}.x), i32(${n}.y), i32(${n}.z), 1)); +} +`});var ii,is,as=H(()=>{"use strict";ve();Oe();Pe();En();ii=(n,e,r,t,o)=>{let i=t-r;return` + ${Array.from({length:r}).map((a,l)=>` + if (${de(e.shape,l,e.rank)} != 1) { + ${e.indicesSet(n,l,de(o,l+i,t))} + } else { + ${e.indicesSet(n,l,0)} + }`).join("")} +`},is=(n,e,r,t,o=!1,i)=>{let a=n[0].dims,l=n[1].dims,d=a[a.length-2],h=l[l.length-1],g=a[a.length-1],_=Ge(h),w=Ge(g),x=Ge(d),T=W.size(r)/_/x,S=n.length>2,P=t?t.slice(0,-2):r.slice(0,-2),O=[W.size(P),d,h],E=[{type:12,data:T},{type:12,data:d},{type:12,data:h},{type:12,data:g}];dr(e,E),E.push(...ne(P,a,l)),S&&E.push(...ne(n[2].dims)),E.push(...ne(O));let L=z=>{let B=Za("batch_dims",n[0].dataType,P.length),K=J("a",n[0].dataType,a.length,w),Z=J("b",n[1].dataType,l.length,_),ee=te("output",n[0].dataType,O.length,_),ae=et(ee.type.tensor),pe=cr(e,ee.type.value,ae),he=[K,Z],Se="";if(S){let xe=o?_:1;he.push(J("bias",n[2].dataType,n[2].dims.length,xe)),Se=`${o?`value += bias[col / ${xe}];`:`value += ${ee.type.value}(bias[row + i]);`}`}let oe=[{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"}];pr(e,oe);let Be=()=>{let xe=`var a_data: ${K.type.value};`;for(let ue=0;ue; + for (var k: u32 = 0u; k < uniforms.K; k = k + ${w}) { + ${Be()} + } + for (var i = 0u; i < ${x}u; i++) { + var value = values[i]; + ${Se} + ${pe} + let cur_indices = ${ee.type.indices}(batch, row + i, col); + let offset = ${ee.indicesToOffset("cur_indices")}; + ${ee.setByOffset(`offset / ${_}`,"value")}; + } + } + `};return{name:"MatMulNaive",shaderCache:{hint:`${e.activation};${_};${w};${x};${o}`,inputDependencies:S?["rank","rank","rank"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:i?i(r):r,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(T/64)},programUniforms:E}),getShaderSource:L}}});var wz,xz,ed,f1,Tz,td,Iz,ai,ss=H(()=>{"use strict";ve();Oe();Pe();En();as();os();wz=(n,e)=>n?` + mm_Asub[inputRow][inputCol] = mm_readA(batch, + kStart + inputRow, + globalRowStart / innerElementSize + inputCol${e?", batchIndices":""}); + `:` + mm_Asub[inputRow][inputCol] = mm_readA(batch, + globalRow + innerRow, + kStart / innerElementSize + inputCol${e?", batchIndices":""}); + `,xz=(n,e)=>n?` + let ACached0 = mm_Asub[k * innerElementSize][localRow]; + let ACached1 = mm_Asub[k * innerElementSize + 1][localRow]; + let ACached2 = mm_Asub[k * innerElementSize + 2][localRow]; + ${e===3?"":"let ACached3 = mm_Asub[k * innerElementSize + 3][localRow];"} + for (var i = 0; i < rowPerThread; i = i + 1) { + acc[i] = BCached0 * ACached0[i] + acc[i]; + acc[i] = BCached1 * ACached1[i] + acc[i]; + acc[i] = BCached2 * ACached2[i] + acc[i]; + ${e===3?"":"acc[i] = BCached3 * ACached3[i] + acc[i];"} + }`:` + for (var i = 0; i < rowPerThread; i = i + 1) { + let ACached = mm_Asub[tileRow + i][k]; + acc[i] = BCached0 * ACached.x + acc[i]; + acc[i] = BCached1 * ACached.y + acc[i]; + acc[i] = BCached2 * ACached.z + acc[i]; + ${e===3?"":"acc[i] = BCached3 * ACached.w + acc[i];"} + }`,ed=(n,e,r="f32",t,o=!1,i=32,a=!1,l=32)=>{let d=e[1]*n[1],h=e[0]*n[0],g=o?d:i,_=o?i:d,w=g/e[0],x=i/e[1];if(!((o&&w===4&&n[1]===4||!o&&(w===3||w===4))&&g%e[0]===0&&i%e[1]===0&&n[0]===4))throw new Error(`If transposeA ${o} is true, innerElementSize ${w} and workPerThread[1] ${n[1]} must be 4. + Otherwise, innerElementSize ${w} must be 3 or 4. + tileAWidth ${g} must be divisible by workgroupSize[0]${e[0]}. tileInner ${i} must be divisible by workgroupSize[1] ${e[1]}. colPerThread ${n[0]} must be 4.`);return` +var mm_Asub: array, ${g/w}>, ${_}>; +var mm_Bsub: array, ${h/n[0]}>, ${i}>; + +const rowPerThread = ${n[1]}; +const colPerThread = ${n[0]}; +const innerElementSize = ${w}; +const tileInner = ${i}; + +@compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]}) +fn main(@builtin(local_invocation_id) localId : vec3, + @builtin(global_invocation_id) globalId : vec3, + @builtin(workgroup_id) workgroupId : vec3) { + let localRow = i32(localId.y); + let tileRow = localRow * rowPerThread; + let tileCol = i32(localId.x); + + let globalRow =i32(globalId.y) * rowPerThread; + let globalCol = i32(globalId.x); + let batch = ${a?"0":"i32(globalId.z)"}; + ${t?`let batchIndices = ${t.offsetToIndices("u32(batch)")};`:""} + let globalRowStart = i32(workgroupId.y) * ${d}; + + let num_tiles = ${a?`${Math.ceil(l/i)}`:"(uniforms.dim_inner - 1) / tileInner + 1"}; + var kStart = ${a?`i32(globalId.z) * ${l}`:"0"}; + + var acc: array, rowPerThread>; + + // Loop over shared dimension. + let tileRowB = localRow * ${x}; + for (var t = 0; t < num_tiles; t = t + 1) { + // Load one tile of A into local memory. + for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + let inputRow = tileRow + innerRow; + let inputCol = tileCol; + ${wz(o,t)} + } + + // Load one tile of B into local memory. + for (var innerRow = 0; innerRow < ${x}; innerRow = innerRow + 1) { + let inputRow = tileRowB + innerRow; + let inputCol = tileCol; + mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalCol${t?", batchIndices":""}); + } + kStart = kStart + tileInner; + workgroupBarrier(); + + // Compute acc values for a single thread. + for (var k = 0; k < tileInner / innerElementSize; k = k + 1) { + let BCached0 = mm_Bsub[k * innerElementSize][tileCol]; + let BCached1 = mm_Bsub[k * innerElementSize + 1][tileCol]; + let BCached2 = mm_Bsub[k * innerElementSize + 2][tileCol]; + ${w===3?"":"let BCached3 = mm_Bsub[k * innerElementSize + 3][tileCol];"} + + ${xz(o,w)} + } + + workgroupBarrier(); + } + + for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + mm_write(batch, globalRow + innerRow, globalCol, acc[innerRow]); + } +}`},f1=(n,e)=>n?` + mm_Asub[inputRow][inputCol] = mm_readA(batch, + kStart + inputRow, + globalRowStart + inputCol${e?", batchIndices":""}); + `:` + mm_Asub[inputRow][inputCol] = mm_readA(batch, + globalRowStart + inputRow, + kStart + inputCol${e?", batchIndices":""}); + `,Tz=n=>n?"let ACached = mm_Asub[k][tileRow + innerRow];":"let ACached = mm_Asub[tileRow + innerRow][k];",td=(n,e,r="f32",t,o=!1,i=32,a=!1,l=32,d=!1)=>{let h=n[1]*e[1],g=n[0]*e[0],_=o?h:i,w=o?i:h;if(!(w%e[1]===0&&_%e[0]===0&&i%e[1]===0))throw new Error(`tileAHight ${w} must be divisible by workgroupSize[1]${e[1]}, tileAWidth ${_} must be divisible by workgroupSize[0]${e[0]}, tileInner ${i} must be divisible by workgroupSize[1]${e[1]}`);let x=w/e[1],T=_/e[0],S=i/e[1],P=d?` + let localRow = i32(localId.y); + let localCol = i32(localId.x); + let globalRowStart = i32(workgroupId.y) * ${h}; + let globalColStart = i32(workgroupId.x) * ${g}; + + // Loop over shared dimension. + for (var t = 0; t < num_tiles; t = t + 1) { + // Load one tile of A into local memory. + for (var inputRow = localRow; inputRow < ${w}; inputRow = inputRow + ${e[1]}) { + for (var inputCol = localCol; inputCol < ${_}; inputCol = inputCol + ${e[0]}) { + ${f1(o,t)} + } + } + // Load one tile of B into local memory. + for (var inputRow = localRow; inputRow < ${i}; inputRow = inputRow + ${e[1]}) { + for (var inputCol = localCol; inputCol < ${g}; inputCol = inputCol + ${e[0]}) { + mm_Bsub[inputRow][inputCol] = mm_readB(batch, + kStart + inputRow, + globalColStart + inputCol${t?", batchIndices":""}); + } + } + kStart = kStart + tileInner; + workgroupBarrier(); + + // Compute acc values for a single thread. + var BCached : array<${r}, colPerThread>; + for (var k = 0; k < tileInner; k = k + 1) { + for (var inner = 0; inner < colPerThread; inner = inner + 1) { + BCached[inner] = mm_Bsub[k][localCol + inner * ${e[0]}]; + } + for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + let ACached = ${o?`mm_Asub[k][localRow + innerRow * ${e[1]}];`:`mm_Asub[localRow + innerRow * ${e[1]}][k];`} + for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { + acc[innerRow][innerCol] = acc[innerRow][innerCol] + + ACached * BCached[innerCol]; + } + } + } + workgroupBarrier(); + } + for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + let gRow = globalRowStart + localRow + innerRow * ${e[1]}; + for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { + let gCol = globalColStart + localCol + innerCol * ${e[0]}; + mm_write(batch, gRow, gCol, acc[innerRow][innerCol]); + } + } + `:` +let tileRow = i32(localId.y) * rowPerThread; +let tileCol = i32(localId.x) * colPerThread; + +let globalRow = i32(globalId.y) * rowPerThread; +let globalCol = i32(globalId.x) * colPerThread; +let globalRowStart = i32(workgroupId.y) * ${h}; + +let tileRowA = i32(localId.y) * ${x}; +let tileColA = i32(localId.x) * ${T}; +let tileRowB = i32(localId.y) * ${S}; +// Loop over shared dimension. +for (var t = 0; t < num_tiles; t = t + 1) { + // Load one tile of A into local memory. + for (var innerRow = 0; innerRow < ${x}; innerRow = innerRow + 1) { + for (var innerCol = 0; innerCol < ${T}; innerCol = innerCol + 1) { + let inputRow = tileRowA + innerRow; + let inputCol = tileColA + innerCol; + ${f1(o,t)} + } + } + + // Load one tile of B into local memory. + for (var innerRow = 0; innerRow < ${S}; innerRow = innerRow + 1) { + for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { + let inputRow = tileRowB + innerRow; + let inputCol = tileCol + innerCol; + mm_Bsub[inputRow][inputCol] = mm_readB(batch, + kStart + inputRow, + globalCol + innerCol${t?", batchIndices":""}); + } + } + kStart = kStart + tileInner; + workgroupBarrier(); + + // Compute acc values for a single thread. + var BCached : array<${r}, colPerThread>; + for (var k = 0; k < tileInner; k = k + 1) { + for (var inner = 0; inner < colPerThread; inner = inner + 1) { + BCached[inner] = mm_Bsub[k][tileCol + inner]; + } + + for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + ${Tz(o)} + for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { + acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol]; + } + } + } + + workgroupBarrier(); +} + +for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { + for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { + mm_write(batch, globalRow + innerRow, globalCol + innerCol, + acc[innerRow][innerCol]); + } +} +`;return` + var mm_Asub : array, ${w}>; + var mm_Bsub : array, ${i}>; + const rowPerThread = ${n[1]}; + const colPerThread = ${n[0]}; + const tileInner = ${i}; + +@compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]}) +fn main(@builtin(local_invocation_id) localId : vec3, + @builtin(global_invocation_id) globalId : vec3, + @builtin(workgroup_id) workgroupId : vec3) { + let batch = ${a?"0":"i32(globalId.z)"}; + ${t?`let batchIndices = ${t.offsetToIndices("u32(batch)")};`:""} + let num_tiles = ${a?`${Math.ceil(l/i)}`:"(uniforms.dim_inner - 1) / tileInner + 1"}; + var kStart = ${a?`i32(globalId.z) * ${l}`:"0"}; + + var acc : array, rowPerThread>; + ${P} + } +`},Iz=(n,e,r,t,o=!1)=>{let[i,a,l,d]=t,h=et(t[0].type.tensor);return` + fn mm_readA(batch: i32, row: i32, colIn: i32, batchIndices: ${i.type.indices}) -> ${_t(n,h)} { + var value = ${_t(n,h)}(0.0); + let col = colIn * ${n}; + if(row < uniforms.dim_a_outer && col < uniforms.dim_inner) + { + var aIndices: ${a.type.indices}; + ${ii("aIndices",a,a.rank-2,i.rank,"batchIndices")} + ${a.indicesSet("aIndices",a.rank-2,"u32(row)")} + ${a.indicesSet("aIndices",a.rank-1,"u32(colIn)")} + value = ${a.getByIndices("aIndices")}; + } + return value; + } + + fn mm_readB(batch: i32, row: i32, colIn: i32, batchIndices: ${i.type.indices}) -> ${_t(n,h)} { + var value = ${_t(n,h)}(0.0); + let col = colIn * ${n}; + if(row < uniforms.dim_inner && col < uniforms.dim_b_outer) + { + var bIndices: ${l.type.indices}; + ${ii("bIndices",l,l.rank-2,i.rank,"batchIndices")} + ${l.indicesSet("bIndices",l.rank-2,"u32(row)")} + ${l.indicesSet("bIndices",l.rank-1,"u32(colIn)")} + value = ${l.getByIndices("bIndices")}; + } + return value; + } + + fn mm_write(batch: i32, row: i32, colIn: i32, valueIn: ${_t(n,h)}) { + let col = colIn * ${n}; + if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) { + var value = valueIn; + let coords = vec3(batch, row, colIn); + ${e?`value = value + ${o?"bias[colIn]":`${_t(n,h)}(bias[row])`};`:""} + ${r} + ${d.setByIndices("vec3(coords)","value")} + } + } + `},ai=(n,e,r,t,o=!1,i)=>{let a=n[0].dims,l=n[1].dims,d=a.slice(0,-2),h=l.slice(0,-2),g=t?t.slice(0,-2):r.slice(0,-2),_=W.size(g),w=a[a.length-2],x=a[a.length-1],T=l[l.length-1],S=x%4===0&&T%4===0,P=w<=8?[4,1,1]:[4,4,1],A=[8,8,1],O=[Math.ceil(T/A[0]/P[0]),Math.ceil(w/A[1]/P[1]),Math.ceil(_/A[2]/P[2])],E=S?4:1,L=[...d,w,x/E],z=L.length,B=[...h,x,T/E],K=B.length,Z=[_,w,T/E],ee=[{type:6,data:w},{type:6,data:T},{type:6,data:x}];dr(e,ee),ee.push(...ne(g,L,B));let ae=["rank","rank"],pe=n.length>2;pe&&(ee.push(...ne(n[2].dims)),ae.push("rank")),ee.push(...ne(Z));let he=Se=>{let oe=g.length,Be=Za("batchDims",n[0].dataType,oe,1),xe=et(n[0].dataType),ue=J("a",n[0].dataType,z,E),Ee=J("b",n[1].dataType,K,E),me=te("result",n[0].dataType,Z.length,E),Te=[ue,Ee];if(pe){let U=o?E:1;Te.push(J("bias",n[2].dataType,n[2].dims.length,U))}let Ue=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"}];pr(e,Ue);let rt=et(me.type.tensor),Ie=cr(e,me.type.value,rt),j=Iz(E,pe,Ie,[Be,ue,Ee,me],o);return` + ${Se.registerUniforms(Ue).registerInternalVariables(Be).declareVariables(...Te,me)} + ${j} + ${S?ed(P,A,xe,Be):td(P,A,xe,Be)} + `};return{name:"MatMul",shaderCache:{hint:`${P};${e.activation};${S};${o}`,inputDependencies:ae},getRunData:()=>({outputs:[{dims:i?i(r):r,dataType:n[0].dataType}],dispatchGroup:{x:O[0],y:O[1],z:O[2]},programUniforms:ee}),getShaderSource:he}}});var Sz,h1,m1=H(()=>{"use strict";ve();tn();Pe();En();os();p1();ss();Sz=(n,e,r,t,o=!1,i,a=4,l=4,d=4,h="f32")=>{let g=ae=>{switch(ae){case 1:return"resData = x[xIndex];";case 3:return`resData = vec3<${h}>(x[xIndex], x[xIndex + 1], x[xIndex + 2]);`;case 4:return"resData = x[xIndex / 4];";default:throw new Error(`innerElementSize ${ae} is not supported.`)}},_=ae=>{switch(ae){case 1:return"return w[row * i32(uniforms.w_shape[3]) + colIn];";case 4:return"return w[row * i32(uniforms.w_shape[3]) / 4 + colIn];";default:throw new Error(`innerElementSize ${ae} is not supported.`)}},w=n?` + let coord = vec4(batch, xRow, xCol, xCh); + `:` + let coord = vec4(batch, xCh, xRow, xCol); + `,x=n?` + let coords = vec4( + batch, + row / outWidth, + row % outWidth, + col); + `:` + let coords = vec4( + batch, + row, + col / outWidth, + col % outWidth); + `,T=n?"i32(uniforms.x_shape[1])":"i32(uniforms.x_shape[2])",S=n?"i32(uniforms.x_shape[2])":"i32(uniforms.x_shape[3])",P=n?"row":"col",A=n?"col":"row",O=` + let inChannels = i32(uniforms.w_shape[2]); + let outWidth = ${n?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"}; + let outRow = ${P} / outWidth; + let outCol = ${P} % outWidth; + + let WRow = ${A} / (i32(uniforms.w_shape[1]) * inChannels); + let WCol = ${A} / inChannels % i32(uniforms.w_shape[1]); + let xRow = outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0]; + let xCol = outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1]; + let xCh = ${A} % inChannels; + var resData = ${_t(a,h)}(0.0); + // The bounds checking is always needed since we use it to pad zero for + // the 'same' padding type. + if (xRow >= 0 && xRow < ${T} && xCol >= 0 && xCol < ${S}) { + ${w} + let xIndex = getIndexFromCoords4D(coord, vec4(uniforms.x_shape)); + ${g(a)} + } + return resData;`,E=n?e&&t?` + let col = colIn * ${a}; + ${O}`:` + let col = colIn * ${a}; + if (row < uniforms.dim_a_outer && col < uniforms.dim_inner) { + ${O} + } + return ${_t(a,h)}(0.0);`:t&&r?` + let col = colIn * ${a}; + ${O}`:` + let col = colIn * ${a}; + if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) { + ${O} + } + return ${_t(a,h)}(0.0);`,L=n?t&&r?_(l):` + let col = colIn * ${l}; + if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) { + ${_(l)} + } + return ${_t(l,h)}(0.0);`:` + let col = colIn * ${l}; + if (row < uniforms.dim_inner && col < uniforms.dim_a_outer) { + ${_(l)} + } + return ${_t(l,h)}(0.0);`,z=_t(d,h),B=n?_t(a,h):_t(l,h),K=n?_t(l,h):_t(a,h),Z=cr(i,z,h);return` + fn mm_readA(batch: i32, row : i32, colIn : i32) -> ${B} { + ${n?E:L} + } + + fn mm_readB(batch: i32, row : i32, colIn : i32) -> ${K} { + ${n?L:E} + } + + fn mm_write(batch: i32, row : i32, colIn : i32, valueIn : ${z}) { + let col = colIn * ${d}; + if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) + { + var value = valueIn; + let outWidth = ${n?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"}; + ${x} + ${c1(o)} + ${Z} + setOutputAtCoords(coords[0], coords[1], coords[2], coords[3], value); + } + }`},h1=(n,e,r,t,o,i,a,l,d)=>{let h=e.format==="NHWC",g=h?n[0].dims[3]:n[0].dims[1],_=r[0],w=h?r[2]:r[3],x=h?r[1]:r[2],T=h?r[3]:r[1],S=h&&(g%4===0||g%3===0)&&T%4===0,P=h?T:w*x,A=h?w*x:T,O=[8,8,1],E=t<=8?[4,1,1]:[4,4,1],L=[Math.ceil(P/O[0]/E[0]),Math.ceil(A/O[1]/E[1]),Math.ceil(_/O[2]/E[2])];ke("verbose",()=>`[conv2d_mm_webgpu] dispatch = ${L}`);let z=S?h&&g%4!==0?3:4:1,B=O[1]*E[1],K=O[0]*E[0],Z=Math.max(O[0]*z,O[1]),ee=t%B===0,ae=o%K===0,pe=i%Z===0,he=S?[z,4,4]:[1,1,1],Se=[{type:6,data:t},{type:6,data:o},{type:6,data:i},{type:6,data:[e.pads[0],e.pads[1]]},{type:6,data:e.strides},{type:6,data:e.dilations}];dr(e,Se),Se.push(...ne(n[0].dims,n[1].dims));let oe=["rank","rank"];a&&(Se.push(...ne(n[2].dims)),oe.push("rank")),Se.push(...ne(r));let Be=xe=>{let ue=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"},{name:"pad",type:"i32",length:2},{name:"stride",type:"i32",length:2},{name:"dilation",type:"i32",length:2}];pr(e,ue);let Ee=S?4:1,me=et(n[0].dataType),Te=` + fn setOutputAtIndex(flatIndex : i32, value : ${S?`vec4<${me}>`:me}) { + result[flatIndex] = ${S?`vec4<${me}>`:me}(value); + } + fn setOutputAtCoords(d0 : i32, d1 : i32, d2 : i32, d3 : i32, value : ${S?`vec4<${me}>`:me}) { + let flatIndex = getOutputIndexFromCoords(vec4(d0, d1, d2, d3)); + setOutputAtIndex(flatIndex ${S?"/ 4":""}, value); + }`,Ue=J("x",n[0].dataType,n[0].dims.length,z===3?1:z),rt=J("w",n[1].dataType,n[1].dims.length,Ee),Ie=[Ue,rt],j=te("result",n[0].dataType,r.length,Ee);if(a){let U=J("bias",n[2].dataType,n[2].dims.length,Ee);Ie.push(U),Te+=` + fn getBiasByOutputCoords(coords : vec4) -> ${S?`vec4<${me}>`:me} { + return bias[coords.${h?"w":"y"}${S?"/ 4":""}]; + }`}return` + ${d1("uniforms.result_strides")} + //struct Uniforms { xShape : vec4, wShape : vec4, outShape : vec4, + // outShapeStrides: vec3, filterDims : vec2, pad : vec2, stride : vec2, + // dilation : vec2, dimAOuter : i32, dimBOuter : i32, dimInner : i32 }; + ${xe.registerUniforms(ue).declareVariables(...Ie,j)} + ${Te} + ${Sz(h,ee,ae,pe,a,e,he[0],he[1],he[2],me)} + ${S?ed(E,O,me,void 0,!h,Z):td(E,O,me,void 0,!h,Z,!1,void 0,l)}`};return{name:"Conv2DMatMul",shaderCache:{hint:`${e.cacheKey};${z};${S};${ee};${ae};${pe};${B};${K};${Z}`,inputDependencies:oe},getRunData:()=>({outputs:[{dims:d?d(r):r,dataType:n[0].dataType}],dispatchGroup:{x:L[0],y:L[1],z:L[2]},programUniforms:Se}),getShaderSource:Be}}});var $z,g1,us,Az,b1,Oz,y1,_1,v1=H(()=>{"use strict";ve();tn();Oe();Pe();En();os();$z=n=>{let e=1;for(let r=0;rtypeof n=="number"?[n,n,n]:n,us=(n,e)=>e<=1?n:n+(n-1)*(e-1),Az=(n,e,r,t=1)=>{let o=us(e,t);return Math.floor((n[0]*(r-1)-r+o)/2)},b1=(n,e,r,t,o)=>{o==null&&(o=Az(n,e[0],t[0]));let i=[0,0,0,r];for(let a=0;a<3;a++)n[a]+2*o>=e[a]&&(i[a]=Math.trunc((n[a]-e[a]+2*o)/t[a]+1));return i},Oz=(n,e,r,t,o,i,a,l,d,h)=>{let g,_,w,x;if(n==="VALID"&&(n=0),typeof n=="number"){g={top:n,bottom:n,left:n,right:n,front:n,back:n};let T=b1([e,r,t,1],[l,d,h],1,[o,i,a],n);_=T[0],w=T[1],x=T[2]}else if(Array.isArray(n)){if(!n.every((S,P,A)=>S===A[0]))throw Error(`Unsupported padding parameter: ${n}`);g={top:n[0],bottom:n[1],left:n[2],right:n[3],front:n[4],back:n[5]};let T=b1([e,r,t,1],[l,d,h],1,[o,i,a],n[0]);_=T[0],w=T[1],x=T[2]}else if(n==="SAME_UPPER"){_=Math.ceil(e/o),w=Math.ceil(r/i),x=Math.ceil(t/a);let T=(_-1)*o+l-e,S=(w-1)*i+d-r,P=(x-1)*a+h-t,A=Math.floor(T/2),O=T-A,E=Math.floor(S/2),L=S-E,z=Math.floor(P/2),B=P-z;g={top:E,bottom:L,left:z,right:B,front:A,back:O}}else throw Error(`Unknown padding parameter: ${n}`);return{padInfo:g,outDepth:_,outHeight:w,outWidth:x}},y1=(n,e,r,t,o,i=!1,a="channelsLast")=>{let l,d,h,g,_;if(a==="channelsLast")[l,d,h,g,_]=n;else if(a==="channelsFirst")[l,_,d,h,g]=n;else throw new Error(`Unknown dataFormat ${a}`);let[w,,x,T,S]=e,[P,A,O]=g1(r),[E,L,z]=g1(t),B=us(x,E),K=us(T,L),Z=us(S,z),{padInfo:ee,outDepth:ae,outHeight:pe,outWidth:he}=Oz(o,d,h,g,P,A,O,B,K,Z),Se=i?w*_:w,oe=[0,0,0,0,0];return a==="channelsFirst"?oe=[l,Se,ae,pe,he]:a==="channelsLast"&&(oe=[l,ae,pe,he,Se]),{batchSize:l,dataFormat:a,inDepth:d,inHeight:h,inWidth:g,inChannels:_,outDepth:ae,outHeight:pe,outWidth:he,outChannels:Se,padInfo:ee,strideDepth:P,strideHeight:A,strideWidth:O,filterDepth:x,filterHeight:T,filterWidth:S,effectiveFilterDepth:B,effectiveFilterHeight:K,effectiveFilterWidth:Z,dilationDepth:E,dilationHeight:L,dilationWidth:z,inShape:n,outShape:oe,filterShape:e}},_1=(n,e,r,t,o,i)=>{let a=i==="channelsLast",l=a?n[0].dims[3]:n[0].dims[1],d=!1,h=[64,1,1],g={x:r.map((O,E)=>E)},_=[Math.ceil($z(g.x.map(O=>r[O]))/h[0]),1,1];ke("verbose",()=>`[conv3d_naive_webgpu] dispatch = ${_}`);let w=d?a&&l%4!==0?3:4:1,x=W.size(r),T=[{type:12,data:x},{type:12,data:t},{type:12,data:o},{type:12,data:e.strides},{type:12,data:e.dilations}];dr(e,T),T.push(...ne(n[0].dims,n[1].dims));let S=["rank","rank"],P=n.length===3;P&&(T.push(...ne(n[2].dims)),S.push("rank")),T.push(...ne(r));let A=O=>{let E=[{name:"output_size",type:"u32"},{name:"filter_dims",type:"u32",length:t.length},{name:"pads",type:"u32",length:o.length},{name:"strides",type:"u32",length:e.strides.length},{name:"dilations",type:"u32",length:e.dilations.length}];pr(e,E);let L=d?4:1,z=et(n[0].dataType),B=J("x",n[0].dataType,n[0].dims.length,w===3?1:w),K=J("W",n[1].dataType,n[1].dims.length,L),Z=[B,K],ee=te("result",n[0].dataType,r.length,L),ae="";if(P){let Se=J("bias",n[2].dataType,n[2].dims.length,L);Z.push(Se),ae+=` + fn getBiasByOutputCoords(coords : array) -> ${d?`vec4<${z}>`:z} { + return bias[${a?de("coords",4,5):de("coords",1,5)}${d?"/ 4":""}]; + }`}let pe=_t(w,z),he=cr(e,pe,z);return` + ${ae} + fn getX(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 { + let aIndices = array(d0, d1, d2, d3, d4); + return ${B.getByIndices("aIndices")}; + } + fn getW(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 { + let aIndices = array(d0, d1, d2, d3, d4); + return ${K.getByIndices("aIndices")}; + } + ${O.registerUniforms(E).declareVariables(...Z,ee)} + ${O.mainStart()} + ${O.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let coords = ${ee.offsetToIndices("global_idx")}; + let batch = ${de("coords",0,B.rank)}; + let d2 = ${a?de("coords",B.rank-1,B.rank):de("coords",1,B.rank)}; + let xFRCCorner = vec3(${a?de("coords",1,B.rank):de("coords",2,B.rank)}, + ${a?de("coords",2,B.rank):de("coords",3,B.rank)}, + ${a?de("coords",3,B.rank):de("coords",4,B.rank)}) * uniforms.strides - uniforms.pads; + let xFCorner = xFRCCorner.x; + let xRCorner = xFRCCorner.y; + let xCCorner = xFRCCorner.z; + let xShapeY = ${a?de("uniforms.x_shape",1,B.rank):de("uniforms.x_shape",2,B.rank)}; + let xShapeZ = ${a?de("uniforms.x_shape",2,B.rank):de("uniforms.x_shape",3,B.rank)}; + let xShapeW = ${a?de("uniforms.x_shape",3,B.rank):de("uniforms.x_shape",4,B.rank)}; + let xShapeU = ${a?de("uniforms.x_shape",4,B.rank):de("uniforms.x_shape",1,B.rank)}; + let inputDepthNearestVec4 = (xShapeU / 4) * 4; + let inputDepthVec4Remainder = xShapeU % 4; + + var value = 0.0; + for (var wF = 0u; wF < uniforms.filter_dims[0]; wF++) { + let xF = xFCorner + wF * uniforms.dilations[0]; + if (xF < 0 || xF >= xShapeY) { + continue; + } + + for (var wR = 0u; wR < uniforms.filter_dims[1]; wR++) { + let xR = xRCorner + wR * uniforms.dilations[1]; + if (xR < 0 || xR >= xShapeZ) { + continue; + } + + for (var wC = 0u; wC < uniforms.filter_dims[2]; wC++) { + let xC = xCCorner + wC * uniforms.dilations[2]; + if (xC < 0 || xC >= xShapeW) { + continue; + } + + for (var d1 = 0u; d1 < inputDepthNearestVec4; d1 += 4) { + ${a?`let xValues = vec4( + getX(batch, xF, xR, xC, d1), + getX(batch, xF, xR, xC, d1 + 1), + getX(batch, xF, xR, xC, d1 + 2), + getX(batch, xF, xR, xC, d1 + 3)); + `:`let xValues = vec4( + getX(batch, d1, xF, xR, xC), + getX(batch, d1 + 1, xF, xR, xC), + getX(batch, d1 + 2, xF, xR, xC), + getX(batch, d1 + 3, xF, xR, xC)); + `} + let wValues = vec4( + getW(d2, d1, wF, wR, wC), + getW(d2, d1 + 1, wF, wR, wC), + getW(d2, d1 + 2, wF, wR, wC), + getW(d2, d1 + 3, wF, wR, wC)); + value += dot(xValues, wValues); + } + if (inputDepthVec4Remainder == 1) { + ${a?`value += getX(batch, xF, xR, xC, inputDepthNearestVec4) + * getW(d2, inputDepthNearestVec4, wF, wR, wC);`:`value += getX(batch, inputDepthNearestVec4, xF, xR, xC) + * getW(d2, inputDepthNearestVec4, wF, wR, wC);`} + } else if (inputDepthVec4Remainder == 2) { + ${a?`let xValues = vec2( + getX(batch, xF, xR, xC, inputDepthNearestVec4), + getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1)); + `:`let xValues = vec2( + getX(batch, inputDepthNearestVec4, xF, xR, xC), + getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC)); + `} + let wValues = vec2( + getW(d2, inputDepthNearestVec4, wF, wR, wC), + getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC)); + value += dot(xValues, wValues); + } else if (inputDepthVec4Remainder == 3) { + ${a?`let xValues = vec3( + getX(batch, xF, xR, xC, inputDepthNearestVec4), + getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1), + getX(batch, xF, xR, xC, inputDepthNearestVec4 + 2)); + `:`let xValues = vec3( + getX(batch, inputDepthNearestVec4, xF, xR, xC), + getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC), + getX(batch, inputDepthNearestVec4 + 2, xF, xR, xC)); + `} + let wValues = vec3( + getW(d2, inputDepthNearestVec4, wF, wR, wC), + getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC), + getW(d2, inputDepthNearestVec4 + 2, wF, wR, wC)); + value += dot(xValues, wValues); + } + } + } + } + ${P?"value = value + getBiasByOutputCoords(coords)":""}; + ${he} + result[global_idx] = f32(value); + }`};return{name:"Conv3DNaive",shaderCache:{hint:`${e.cacheKey};${a};${w};${P}`,inputDependencies:S},getRunData:()=>({outputs:[{dims:r,dataType:n[0].dataType}],dispatchGroup:{x:_[0],y:_[1],z:_[2]},programUniforms:T}),getShaderSource:A}}});var w1,x1,T1=H(()=>{"use strict";ve();Oe();Pe();En();w1=(n,e,r,t)=>{let o=n.length>2,i=o?"value += b[output_channel];":"",a=n[0].dims,l=n[1].dims,d=e.format==="NHWC",h=d?r[3]:r[1],g=h/e.group,_=d&&g>=4?Ge(h):1,w=W.size(r)/_,x=[{type:12,data:w},{type:12,data:e.dilations},{type:12,data:[e.strides[0],e.strides[1]]},{type:12,data:[e.pads[0],e.pads[1]]},{type:12,data:g}];dr(e,x),x.push(...ne(a,[l[0],l[1],l[2],l[3]/_]));let T=o?["rank","rank","rank"]:["rank","rank"];x.push(...ne([r[0],r[1],r[2],r[3]/_]));let S=P=>{let A=te("output",n[0].dataType,r.length,_),O=et(A.type.tensor),E=cr(e,A.type.value,O),L=J("x",n[0].dataType,a.length),z=J("w",n[1].dataType,l.length,_),B=[L,z];o&&B.push(J("b",n[2].dataType,n[2].dims,_));let K=[{name:"output_size",type:"u32"},{name:"dilations",type:"u32",length:e.dilations.length},{name:"strides",type:"u32",length:2},{name:"pads",type:"u32",length:2},{name:"output_channels_per_group",type:"u32"}];pr(e,K);let Z=d?` + for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[0]; wHeight++) { + let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0]; + + if (xHeight < 0u || xHeight >= uniforms.x_shape[1]) { + continue; + } + + for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[1]; wWidth++) { + let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1]; + if (xWidth < 0u || xWidth >= uniforms.x_shape[2]) { + continue; + } + + for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[2]; wInChannel++) { + let input_channel = in_channel_offset + wInChannel; + let xVal = ${L.get("batch","xHeight","xWidth","input_channel")}; + let wVal = ${z.get("wHeight","wWidth","wInChannel","output_channel")}; + value += xVal * wVal; + } + } + } + `:` + for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[1]; wInChannel++) { + let input_channel = in_channel_offset + wInChannel; + for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[2]; wHeight++) { + let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0]; + + if (xHeight < 0u || xHeight >= uniforms.x_shape[2]) { + continue; + } + + for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[3]; wWidth++) { + let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1]; + if (xWidth < 0u || xWidth >= uniforms.x_shape[3]) { + continue; + } + + let xVal = ${L.get("batch","input_channel","xHeight","xWidth")}; + let wVal = ${z.get("output_channel","wInChannel","wHeight","wWidth")}; + value += xVal * wVal; + } + } + } + `;return` + ${P.registerUniforms(K).declareVariables(...B,A)} + + ${P.mainStart()} + ${P.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + + let outputIndices = ${A.offsetToIndices("global_idx")}; + let batch: u32 = outputIndices[0]; + let output_channel: u32 = outputIndices[${d?3:1}]; + let xRCCorner: vec2 = vec2(outputIndices[${d?1:2}], outputIndices[${d?2:3}]) * uniforms.strides - uniforms.pads; + let group_id: u32 = output_channel * ${_} / uniforms.output_channels_per_group; + var in_channel_offset = group_id * uniforms.w_shape[${d?2:1}]; + + var value: ${A.type.value} = ${A.type.value}(0); + ${Z} + ${i} + ${E} + ${A.setByOffset("global_idx","value")} + }`};return{name:"GroupedConv",shaderCache:{hint:`${e.cacheKey}_${_}`,inputDependencies:T},getRunData:()=>({outputs:[{dims:t?t(r):r,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(w/64)},programUniforms:x}),getShaderSource:S}},x1=(n,e,r,t)=>{let o=n.length>2,i=Ge(r[3]),a=Ge(r[2]),l=W.size(r)/i/a,d=[n[0].dims[0],n[0].dims[1],n[0].dims[2],n[0].dims[3]/i],h=[n[1].dims[0],n[1].dims[1],n[1].dims[2],n[1].dims[3]/i],g=[r[0],r[1],r[2],r[3]/i],_=[{type:12,data:l},{type:6,data:[e.strides[0],e.strides[1]]},{type:6,data:[e.pads[0],e.pads[1]]}];dr(e,_),_.push(...ne(d,h,g));let w=(a-1)*e.strides[1]+h[1],x=T=>{let S=te("output",n[0].dataType,g.length,i),P=et(S.type.tensor),A=cr(e,S.type.value,P),O=J("x",n[0].dataType,d.length,i),E=J("w",n[1].dataType,h.length,i),L=[O,E];o&&L.push(J("b",n[2].dataType,n[2].dims,i));let z=o?"value += b[output_channel];":"",B=[{name:"output_size",type:"u32"},{name:"strides",type:"i32",length:2},{name:"pads",type:"i32",length:2}];return pr(e,B),` + ${T.registerUniforms(B).declareVariables(...L,S)} + ${T.mainStart()} + ${T.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let width0 = uniforms.output_shape[3]; + let output_channel = global_idx % width0; + var index1 = global_idx / width0; + let width1 = uniforms.output_shape[2] / ${a}u; + let col = (index1 % width1) * ${a}u; + index1 = index1 / width1; + let row = index1 % uniforms.output_shape[1]; + let batch = index1 / uniforms.output_shape[1]; + + let x_corner = vec2(i32(row), i32(col)) * uniforms.strides - uniforms.pads; + + var x_vals: array<${O.type.value}, ${w}>; + var values: array<${S.type.value}, ${a}>; + let input_channel = output_channel; + // Use constant instead of uniform can give better performance for w's height/width. + for (var w_height: u32 = 0u; w_height < ${h[0]}; w_height++) { + let x_height = x_corner.x + i32(w_height); + if (x_height >= 0 && u32(x_height) < uniforms.x_shape[1]) { + for (var i = 0; i < ${w}; i++) { + let x_width = x_corner.y + i; + if (x_width >= 0 && u32(x_width) < uniforms.x_shape[2]) { + x_vals[i] = ${O.get("batch","u32(x_height)","u32(x_width)","input_channel")}; + } else { + x_vals[i] = ${O.type.value}(0); + } + } + for (var w_width: u32 = 0u; w_width < ${h[1]}; w_width++) { + let w_val = ${E.get("w_height","w_width","0","output_channel")}; + for (var i = 0u; i < ${a}u; i++) { + values[i] = fma(x_vals[i * u32(uniforms.strides[1]) + w_width], w_val, values[i]); + } + } + } + } + + for (var i = 0u; i < ${a}u; i++) { + var value = values[i]; + ${z} + ${A} + ${S.set("batch","row","col + i","output_channel","value")}; + } + }`};return{name:"GroupedConv-Vectorize",shaderCache:{hint:`${e.cacheKey};${i};${a};${w};${h[0]};${h[1]}`,inputDependencies:o?["rank","rank","type"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:t?t(r):r,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:_}),getShaderSource:x}}});var Cz,rd,Pz,nd,od,I1,Ez,Dz,id,S1=H(()=>{"use strict";Oe();m1();v1();ss();T1();En();as();fn();Cz=(n,e,r,t,o,i)=>{let a=n[0],l=n.slice(i?1:2,i?3:4),d=l.length,h=e[0],_=e.slice(2).map((T,S)=>T+(T-1)*(r[S]-1)),x=l.map((T,S)=>T+t[S]+t[S+d]).map((T,S)=>Math.floor((T-_[S]+o[S])/o[S]));return x.splice(0,0,a),x.splice(i?3:1,0,h),x},rd=[2,3,1,0],Pz=(n,e)=>{if(!n||n.length!==2&&n.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(n[0].dims.length>5)throw new Error("greater than 5D is not supported");if(n[0].dims.length!==n[1].dims.length)throw new Error("filter does not have same dimension as input");let r=n[0].dims[e.format==="NHWC"?n[0].dims.length-1:1],t=n[1].dims[1]*e.group;if(r!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(n.length===3&&(n[2].dims.length!==1||n[1].dims[0]!==n[2].dims[0]))throw new Error("invalid bias");let o=n[0].dims.length-2;if(e.dilations.length!==o)throw new Error(`dilations should be ${o}D`);if(e.strides.length!==o)throw new Error(`strides should be ${o}D`);if(e.pads.length!==o*2)throw new Error(`pads should be ${o*2}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==n[1].dims.length-2)throw new Error("invalid kernel shape")},nd=(n,e)=>{let r=n.kernelShape.slice();r.length{let e=ns(n),r=n.format,t=["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][n.auto_pad],o=n.dilations,i=n.group,a=n.kernel_shape,l=n.pads,d=n.strides,h=n.w_is_const();return{autoPad:t,format:r,dilations:o,group:i,kernelShape:a,pads:l,strides:d,wIsConst:h,...e,cacheKey:`${n.format};${e.activation};`}},I1=(n,e,r,t)=>{let o=r.format==="NHWC",i=Cz(e[0].dims,e[1].dims,r.dilations,r.pads,r.strides,o);if(r.group!==1){let B=[e[0]];if(o){let Z=n.kernelCustomData.wT??n.compute(wt(e[1],rd),{inputs:[1],outputs:[r.wIsConst?-2:-1]})[0];r.wIsConst&&!n.kernelCustomData.wT&&(n.kernelCustomData.wT=Z),B.push(Z)}else B.push(e[1]);e.length===3&&B.push(e[2]),!n.adapterInfo.isArchitecture("ampere")&&o&&e[1].dims[0]===r.group&&e[1].dims[1]===1&&r.dilations[0]===1&&r.dilations[1]===1?n.compute(x1(B,r,i,t),{inputs:B}):n.compute(w1(B,r,i,t),{inputs:B});return}let a=e.length===3,l=e[0].dims[o?1:2],d=e[0].dims[o?2:3],h=e[0].dims[o?3:1],g=e[1].dims[2],_=e[1].dims[3],w=i[o?1:2],x=i[o?2:3],T=i[o?3:1],S=o&&g===l&&_===d&&r.pads[0]===0&&r.pads[1]===0;if(S||g===1&&_===1&&r.dilations[0]===1&&r.dilations[1]===1&&r.strides[0]===1&&r.strides[1]===1&&r.pads[0]===0&&r.pads[1]===0){let B=i[0],K,Z,ee,ae=[];if(o){let Se=n.kernelCustomData.wT??n.compute(wt(e[1],rd),{inputs:[1],outputs:[r.wIsConst?-2:-1]})[0];if(r.wIsConst&&!n.kernelCustomData.wT&&(n.kernelCustomData.wT=Se),S){let oe=l*d*h;K=e[0].reshape([1,B,oe]),Z=Se.reshape([1,oe,T]),ee=[1,B,T]}else K=e[0].reshape([B,l*d,h]),Z=Se.reshape([1,h,T]),ee=[B,w*x,T];ae.push(K),ae.push(Z)}else K=e[0].reshape([B,h,l*d]),Z=e[1].reshape([1,T,h]),ee=[B,T,w*x],ae.push(Z),ae.push(K);a&&ae.push(e[2]);let pe=ee[2],he=ae[0].dims[ae[0].dims.length-1];pe<8&&he<8?n.compute(is(ae,r,i,ee,o,t),{inputs:ae}):n.compute(ai(ae,r,i,ee,o,t),{inputs:ae});return}let P=!0,A=n.kernelCustomData.wT??n.compute(wt(e[1],rd),{inputs:[1],outputs:[r.wIsConst?-2:-1]})[0];r.wIsConst&&!n.kernelCustomData.wT&&(n.kernelCustomData.wT=A);let O=[e[0],A];a&&O.push(e[2]);let E=o?w*x:T,L=o?T:w*x,z=g*_*h;n.compute(h1(O,r,i,E,L,z,a,P,t),{inputs:O})},Ez=(n,e)=>{let r=e.format==="NHWC",t=[n.inputs[0].reshape(r?[n.inputs[0].dims[0],1,n.inputs[0].dims[1],n.inputs[0].dims[2]]:[n.inputs[0].dims[0],n.inputs[0].dims[1],1,n.inputs[0].dims[2]]),n.inputs[1].reshape([n.inputs[1].dims[0],n.inputs[1].dims[1],1,n.inputs[1].dims[2]])];n.inputs.length===3&&t.push(n.inputs[2]);let o=[0,e.pads[0],0,e.pads[1]],i=[1].concat(e.strides),a=[1].concat(e.dilations),l=[1].concat(e.kernelShape),d=nd({...e,pads:o,strides:i,dilations:a,kernelShape:l},t);I1(n,t,d,h=>r?[h[0],h[2],h[3]]:[h[0],h[1],h[3]])},Dz=(n,e,r)=>{let t=r.format==="NHWC"?"channelsLast":"channelsFirst",o=nd(r,e),i=r.autoPad==="NOTSET"?r.pads:r.autoPad,a=y1(e[0].dims,e[1].dims,r.strides,r.dilations,i,!1,t);n.compute(_1(e,o,a.outShape,[a.filterDepth,a.filterHeight,a.filterWidth],[a.padInfo.front,a.padInfo.top,a.padInfo.left],t))},id=(n,e)=>{if(Pz(n.inputs,e),n.inputs[0].dims.length===3)Ez(n,e);else if(n.inputs[0].dims.length===5)Dz(n,n.inputs,e);else{let r=nd(e,n.inputs);I1(n,n.inputs,r)}}});var $1,A1=H(()=>{"use strict";ve();tn();Oe();Pe();$1=(n,e,r)=>{let t=n.length>2,o=e.outputShape,i=e.format==="NHWC",a=e.group,l=n[1].dims,d=l[2]/a,h=l[3],g=i?Ge(d):1,_=i&&h===1&&d>=4,w=_?Math.floor(d/4)*4:Math.floor(d/g)*g,x=d-w,T=i?Ge(h):1,S=i?h===1?g:T:1,P=W.size(o)/T,A=[Math.ceil(P/64),1,1];ke("verbose",()=>`[conv2d_backprop_webgpu] dispatch = ${A}`);let O=["rank","rank"],E=[e.strides[0],e.strides[1]],L=[e.kernelShape[i?1:2],e.kernelShape[i?2:3]],z=[e.dilations[0],e.dilations[1]],B=[L[0]+(e.dilations[0]<=1?0:(e.kernelShape[i?1:2]-1)*(e.dilations[0]-1)),L[1]+(e.dilations[1]<=1?0:(e.kernelShape[i?2:3]-1)*(e.dilations[1]-1))],K=[B[0]-1-Math.floor((e.pads[0]+e.pads[2])/2),B[1]-1-Math.floor((e.pads[1]+e.pads[3])/2)],Z=[{type:12,data:P},{type:12,data:E},{type:12,data:L},{type:12,data:z},{type:12,data:B},{type:6,data:K},{type:12,data:w},{type:12,data:d},{type:12,data:h},...ne(n[0].dims,n[1].dims)];t&&(Z.push(...ne(n[2].dims)),O.push("rank")),Z.push(...ne(o));let ee=ae=>{let pe=[{name:"output_size",type:"u32"},{name:"strides",type:"u32",length:E.length},{name:"filter_dims",type:"u32",length:L.length},{name:"dilations",type:"u32",length:L.length},{name:"effective_filter_dims",type:"u32",length:B.length},{name:"pads",type:"i32",length:K.length},{name:"input_channels_per_group_int",type:"u32"},{name:"input_channels_per_group",type:"u32"},{name:"output_channels_per_group",type:"u32"}],he=et(n[0].dataType),Se=i?1:2,oe=i?2:3,Be=i?3:1,xe=J("W",n[1].dataType,n[1].dims.length,S),ue=J("Dy",n[0].dataType,n[0].dims.length,g),Ee=[ue,xe];t&&Ee.push(J("bias",n[2].dataType,[o[Be]].length,T));let me=te("result",n[0].dataType,o.length,T),Te=()=>{let Ie="";if(_)g===4?Ie+=` + let xValue = ${ue.getByOffset("x_offset")}; + let wValue = ${xe.getByOffset("w_offset")}; + dotProd = dotProd + dot(xValue, wValue); + x_offset += 1u; + w_offset += 1u;`:g===2?Ie+=` + dotProd = dotProd + dot(vec4<${he}>(${ue.getByOffset("x_offset")}, ${ue.getByOffset("x_offset + 1u")}), vec4<${he}>(${xe.getByOffset("w_offset")}, ${xe.getByOffset("w_offset + 1u")})); + x_offset += 2u; + w_offset += 2u;`:g===1&&(Ie+=` + dotProd = dotProd + dot(vec4<${he}>(${ue.getByOffset("x_offset")}, ${ue.getByOffset("x_offset + 1u")}, ${ue.getByOffset("x_offset + 2u")}, ${ue.getByOffset("x_offset + 3u")}), vec4<${he}>(${xe.getByOffset("w_offset")}, ${xe.getByOffset("w_offset + 1u")}, ${xe.getByOffset("w_offset + 2u")}, ${xe.getByOffset("w_offset + 3u")})); + x_offset += 4u; + w_offset += 4u;`);else if(Ie+=` + let xValue = ${i?ue.getByOffset(`${ue.indicesToOffset(`${ue.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${g}`):ue.get("batch","inputChannel","idyR","idyC")}; + `,g===1)Ie+=` + let w_offset = ${xe.indicesToOffset(`${xe.type.indices}(u32(wRPerm), u32(wCPerm), inputChannel, wOutChannel)`)}; + let wValue = ${xe.getByOffset(`w_offset / ${S}`)}; + dotProd = dotProd + xValue * wValue;`;else for(let j=0;j{if(x===0)return"";if(!_)throw new Error(`packInputAs4 ${_} is not true.`);let Ie="";if(g===1){Ie+="dotProd = dotProd";for(let j=0;j(i32(r), i32(c)) - uniforms.pads; + let dyRCorner = dyCorner.x; + let dyCCorner = dyCorner.y; + let groupId = d1 / uniforms.output_channels_per_group; + let wOutChannel = d1 - groupId * uniforms.output_channels_per_group; + // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1). + // ? = to be determined. : = across all values in that axis. + var dotProd = ${me.type.value}(0.0); + var wR: u32 = 0; + if (uniforms.dilations.x == 1) { + // Minimum wR >= 0 that satisfies (dyRCorner + wR) % (uniforms.strides.x) == 0 + wR = u32(((dyRCorner + i32(uniforms.strides.x) - 1) / i32(uniforms.strides.x)) * i32(uniforms.strides.x) - dyRCorner); + } + for (; wR < uniforms.effective_filter_dims.x; wR = wR + 1) { + if (wR % uniforms.dilations.x != 0) { + continue; + } + let dyR = (${he}(dyRCorner) + ${he}(wR)) / ${he}(uniforms.strides[0]); + let wRPerm = uniforms.filter_dims.x - 1 - wR / uniforms.dilations.x; + if (dyR < 0.0 || dyR >= ${he}(uniforms.Dy_shape[${Se}]) || fract(dyR) > 0.0 || + wRPerm < 0) { + continue; + } + let idyR: u32 = u32(dyR); + var wC: u32 = 0; + if (uniforms.dilations.y == 1) { + // Minimum wC >= 0 that satisfies (dyCCorner + wC) % (uniforms.strides.y) == 0 + wC = u32(((dyCCorner + i32(uniforms.strides.y) - 1) / i32(uniforms.strides.y)) * i32(uniforms.strides.y) - dyCCorner); + } + for (; wC < uniforms.effective_filter_dims.y; wC = wC + 1) { + if (wC % uniforms.dilations.y != 0) { + continue; + } + let dyC = (${he}(dyCCorner) + ${he}(wC)) / ${he}(uniforms.strides.y); + let wCPerm = uniforms.filter_dims.y - 1 - wC / uniforms.dilations.y; + if (dyC < 0.0 || dyC >= ${he}(uniforms.Dy_shape[${oe}]) || + fract(dyC) > 0.0 || wCPerm < 0) { + continue; + } + let idyC: u32 = u32(dyC); + var inputChannel = groupId * uniforms.input_channels_per_group; + ${_?` + var x_offset = ${ue.indicesToOffset(`${ue.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${g}; + var w_offset = ${xe.indicesToOffset(`${xe.type.indices}(wRPerm, wCPerm, inputChannel, wOutChannel)`)} / ${S}; + `:""} + for (var d2: u32 = 0; d2 < uniforms.input_channels_per_group_int; d2 = d2 + ${_?4:g}) { + ${Te()} + inputChannel = inputChannel + ${_?4:g}; + } + ${Ue()} + wC = wC + uniforms.strides.y - 1; + } + wR = wR + uniforms.strides[0] - 1; + } + let value = dotProd${t?` + bias[d1 / ${T}]`:""}; + ${me.setByOffset("global_idx","value")}; + `;return` + ${ae.registerUniforms(pe).declareVariables(...Ee,me)} + ${ae.mainStart()} + ${ae.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}; + ${rt}}`};return{name:"ConvTranspose2D",shaderCache:{hint:`${e.cacheKey};${g}${S}${T}${_}${x}`,inputDependencies:O},getRunData:()=>({dispatchGroup:{x:A[0],y:A[1],z:A[2]},outputs:[{dims:r?r(o):o,dataType:n[0].dataType}],programUniforms:Z}),getShaderSource:ee}}});var kz,Nz,Lz,O1,C1,Rz,P1,zz,E1,D1=H(()=>{"use strict";A1();En();fn();kz=(n,e,r,t,o,i)=>(n-1)*e+r+(t-1)*o+1-i,Nz=(n,e,r,t,o)=>{let i=Math.floor(n/2);e==="SAME_UPPER"?(r[t]=i,r[o]=n-i):e==="SAME_LOWER"&&(r[t]=n-i,r[o]=i)},Lz=(n,e,r,t,o,i,a,l,d,h)=>{let g=n.length-2,_=h.length===0;d.length{let r=n.kernelShape.slice();if(n.kernelShape.length===0||n.kernelShape.reduce((_,w)=>_*w,1)===0){r.length=0;for(let _=2;__+w,0)===0){let _=e[0].dims.length-2;d=new Array(_).fill(1)}let h=n.strides.slice();if(h.reduce((_,w)=>_+w,0)===0){let _=e[0].dims.length-2;h=new Array(_).fill(1)}Lz(l,r,d,n.autoPad,n.group,o,h,t,a,i);let g=Object.assign({},n);return Object.assign(g,{kernelShape:r,pads:o,outputPadding:a,outputShape:i,dilations:d,strides:h}),g},C1=n=>{let e=ns(n),r=n.format,t=["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][typeof n.autoPad>"u"?0:n.autoPad],o=n.dilations,i=n.group,a=n.kernelShape,l=n.pads,d=n.strides,h=n.wIsConst(),g=n.outputPadding,_=n.outputShape;return{autoPad:t,format:r,dilations:o,group:i,kernelShape:a,outputPadding:g,outputShape:_,pads:l,strides:d,wIsConst:h,...e,cacheKey:`${n.format};${e.activation};`}},Rz=(n,e)=>{if(!n||n.length!==2&&n.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(n[0].dims.length!==4&&n[0].dims.length!==3)throw new Error("currently only support 2-dimensional conv");if(n[0].dims.length!==n[1].dims.length)throw new Error("filter does not have same dimension as input");let r=n[0].dims[e.format==="NHWC"?n[0].dims.length-1:1],t=n[1].dims[0];if(r!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");let o=n[1].dims[1]*e.group;if(n.length===3&&(n[2].dims.length!==1||n[2].dims[0]!==o))throw new Error("invalid bias");let i=n[0].dims.length-2;if(e.dilations.reduce((g,_)=>g+_,0)>0&&e.dilations.length!==i)throw new Error(`dilations should be ${i}D`);if(e.strides.reduce((g,_)=>g+_,0)>0&&e.strides.length!==i)throw new Error(`strides should be ${i}D`);if(e.pads.reduce((g,_)=>g+_,0)>0&&e.pads.length!==i*2)throw new Error(`pads should be ${i*2}D`);if(e.outputPadding.length!==i&&e.outputPadding.length!==0)throw new Error(`output_padding should be ${i}D`);if(e.kernelShape.reduce((g,_)=>g+_,0)>0&&e.kernelShape.length!==0&&e.kernelShape.length!==n[1].dims.length-2)throw new Error("invalid kernel shape");if(e.outputShape.length!==0&&e.outputShape.length!==n[0].dims.length-2)throw new Error("invalid output shape")},P1=(n,e,r,t)=>{let o=n.kernelCustomData.wT??n.compute(wt(e[1],[2,3,0,1]),{inputs:[1],outputs:[r.wIsConst?-2:-1]})[0];r.wIsConst&&!n.kernelCustomData.wT&&(n.kernelCustomData.wT=o);let i=[e[0],o];e.length===3&&i.push(e[2]),n.compute($1(i,r,t),{inputs:i})},zz=(n,e)=>{let r=e.format==="NHWC",t=[n.inputs[0].reshape(r?[n.inputs[0].dims[0],1,n.inputs[0].dims[1],n.inputs[0].dims[2]]:[n.inputs[0].dims[0],n.inputs[0].dims[1],1,n.inputs[0].dims[2]]),n.inputs[1].reshape([n.inputs[1].dims[0],n.inputs[1].dims[1],1,n.inputs[1].dims[2]])];n.inputs.length===3&&t.push(n.inputs[2]);let o=e.kernelShape;(o.length===0||o[0]===0)&&(o=[n.inputs[1].dims[2]]);let i=e.dilations;(i.length===0||i[0]===0)&&(i=[1]);let a=e.strides;(a.length===0||a[0]===0)&&(a=[1]);let l=e.pads;l.length===0&&(l=[0,0]),l=[0,l[0],0,l[1]],a=[1].concat(a),i=[1].concat(i),o=[1].concat(o);let d=e.outputPadding;d=[0].concat(d);let h=O1({...e,pads:l,strides:a,dilations:i,kernelShape:o,outputPadding:d},t);P1(n,t,h,g=>r?[g[0],g[2],g[3]]:[g[0],g[1],g[3]])},E1=(n,e)=>{if(Rz(n.inputs,e),n.inputs[0].dims.length===3)zz(n,e);else{let r=O1(e,n.inputs);P1(n,n.inputs,r)}}});var Mz,k1,N1,L1=H(()=>{"use strict";ve();Oe();ft();Pe();Mz=(n,e,r,t)=>{let o=W.size(e),i=e.length,a=J("input",n,i),l=te("output",n,i),d=r.dataType===6?r.getInt32Array()[0]:Number(r.getBigInt64Array()[0]),h=W.normalizeAxis(d,i),g=_=>{let w=` i32(${a.indicesGet("inputIndices","uniforms.axis")}) `,x=de("uniforms.input_shape","uniforms.axis",i),T=t.reverse?w+(t.exclusive?" + 1":""):"0",S=t.reverse?x:w+(t.exclusive?"":" + 1");return` + ${_.registerUniform("outputSize","u32").registerUniform("axis","u32").declareVariables(a,l)} + ${_.mainStart()} + ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + var inputIndices = ${l.offsetToIndices("global_idx")}; + var sum = ${l.type.value}(0); + let first : i32 = ${T}; + let last : i32 = ${S}; + for (var i : i32 = first; i < last; i++) { + ${a.indicesSet("inputIndices","uniforms.axis","u32(i)")}; + sum = sum + ${a.getByIndices("inputIndices")}; + } + ${l.setByOffset("global_idx","sum")}; + }`};return{name:"CumSum",shaderCache:{hint:t.cacheKey,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:e,dataType:n}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:[{type:12,data:o},{type:12,data:h},...ne(e,e)]}),getShaderSource:g}},k1=(n,e)=>{let r=n.inputs[0].dims,t=n.inputs[0].dataType,o=n.inputs[1];n.compute(Mz(t,r,o,e),{inputs:[0]})},N1=n=>{let e=n.exclusive===1,r=n.reverse===1;return we({exclusive:e,reverse:r})}});var Bz,Fz,Vz,R1,z1,M1=H(()=>{"use strict";ve();Oe();ft();Pe();Bz=n=>{if(!n||n.length!==1)throw new Error("DepthToSpace requires 1 input.");if(n[0].dims.length!==4)throw new Error("DepthToSpace requires 4D input.")},Fz=(n,e,r,t)=>{let o=[];o.push(`fn perm(i: ${t.type.indices}) -> ${r.type.indices} { + var a: ${r.type.indices};`);for(let i=0;i{let r,t,o,i,a,l,d=e.format==="NHWC",h=e.blocksize,g=e.mode==="DCR";d?([r,t,o,i]=n.dims,a=g?[r,t,o,h,h,i/h**2]:[r,t,o,i/h**2,h,h],l=g?[0,1,3,2,4,5]:[0,1,4,2,5,3]):([r,t,o,i]=[n.dims[0],n.dims[2],n.dims[3],n.dims[1]],a=g?[r,h,h,i/h**2,t,o]:[r,i/h**2,h,h,t,o],l=g?[0,3,4,1,5,2]:[0,1,4,2,5,3]);let _=n.reshape(a),w=_.dims.length,x=n.dataType,T=J("a",x,w),S=te("output",x,w),P=A=>` + ${A.registerUniform("output_size","u32").declareVariables(T,S)} + + ${Fz(l,w,T,S)} + + ${A.mainStart()} + ${A.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + + let indices = ${S.offsetToIndices("global_idx")}; + let aIndices = perm(indices); + + ${S.setByOffset("global_idx",T.getByIndices("aIndices"))} + }`;return{name:"DepthToSpace",shaderCache:{hint:`${n.dims};${e.blocksize};${e.mode}`,inputDependencies:["rank"]},getRunData:A=>{let O=d?[r,t*h,o*h,i/h**2]:[r,i/h**2,t*h,o*h],E=W.size(O),L=_.dims,z=W.sortBasedOnPerm(L,l);return{outputs:[{dims:O,dataType:A[0].dataType}],dispatchGroup:{x:Math.ceil(E/64)},programUniforms:[{type:12,data:E},...ne(L,z)]}},getShaderSource:P}},R1=(n,e)=>{Bz(n.inputs),n.compute(Vz(n.inputs[0],e))},z1=n=>we({blocksize:n.blocksize,mode:n.mode,format:n.format})});var ad,ls,B1,jz,Gz,sd,ud,F1,Uz,V1,j1,G1=H(()=>{"use strict";ve();Oe();ft();Pe();ad="[a-zA-Z]|\\.\\.\\.",ls="("+ad+")+",B1="^"+ls+"$",jz="("+ls+",)*"+ls,Gz="^"+jz+"$",sd=class{constructor(e=-1){this.symbolToIndices=new Map,this.inputIndex=e}addSymbol(e,r){let t=this.symbolToIndices.get(e);t===void 0?t=[r]:t.push(r),this.symbolToIndices.set(e,t)}},ud=class{constructor(e,r){this.equation=r;this.hasEllipsis=!1,this.symbolToInfo=new Map,this.lhs=new Array,this.outputDims=[];let[t,o]=r.includes("->")?r.split("->",2):[r,""];if(!t.match(RegExp(Gz)))throw new Error("Invalid LHS term");if(t.split(",").forEach((l,d)=>{let h=e[d].dims.slice();if(!l.match(RegExp(B1)))throw new Error("Invalid LHS term");let g=this.processTerm(l,!0,h,d);this.lhs.push(g)}),o==="")o+=[...this.symbolToInfo.entries()].filter(([l,d])=>d.count===1||l==="...").map(([l])=>l).join("");else if(!o.match(RegExp(ls)))throw new Error("Invalid RHS");o.match(RegExp(ad,"g"))?.forEach(l=>{if(l==="...")this.outputDims=this.outputDims.concat(this.ellipsisDims);else{let d=this.symbolToInfo.get(l);if(d===void 0)throw new Error("Invalid RHS symbol");this.outputDims.push(d.dimValue)}}),this.rhs=this.processTerm(o,!1,this.outputDims)}addSymbol(e,r,t){let o=this.symbolToInfo.get(e);if(o!==void 0){if(o.dimValue!==r&&o.count!==1)throw new Error("Dimension mismatch");o.count++,o.inputIndices.push(t)}else o={count:1,dimValue:r,inputIndices:[t]};this.symbolToInfo.set(e,o)}processTerm(e,r,t,o=-1){let i=t.length,a=!1,l=[],d=0;if(!e.match(RegExp(B1))&&!r&&e!=="")throw new Error("Invalid LHS term");let h=e.match(RegExp(ad,"g")),g=new sd(o);return h?.forEach((_,w)=>{if(_==="..."){if(a)throw new Error("Only one ellipsis is allowed per input term");a=!0;let x=i-h.length+1;if(x<0)throw new Error("Ellipsis out of bounds");if(l=t.slice(d,d+x),this.hasEllipsis){if(this.ellipsisDims.length!==l.length||this.ellipsisDims.toString()!==l.toString())throw new Error("Ellipsis dimensions mismatch")}else if(r)this.hasEllipsis=!0,this.ellipsisDims=l;else throw new Error("Ellipsis must be specified in the LHS");for(let T=0;Tn+"_max",Uz=(n,e,r,t)=>{let i=n.map(g=>g.length).map((g,_)=>J(`input${_}`,e,g)),a=W.size(t),l=te("output",e,t.length),d=[...r.symbolToInfo.keys()].filter(g=>!r.rhs.symbolToIndices.has(g)),h=g=>{let _=[],w="var prod = 1.0;",x="var sum = 0.0;",T="sum += prod;",S=[],P=[],A=[],O=[],E=r.symbolToInfo.size===r.rhs.symbolToIndices.size;r.symbolToInfo.forEach((z,B)=>{if(r.rhs.symbolToIndices.has(B)){let K=r.rhs.symbolToIndices.get(B)?.[0];K!==void 0&&r.lhs.forEach((Z,ee)=>{if(z.inputIndices.includes(ee)){let ae=Z.symbolToIndices.get(B);if(ae===void 0)throw new Error("Invalid symbol error");ae.forEach(pe=>{_.push(`${i[ee].indicesSet(`input${ee}Indices`,pe,l.indicesGet("outputIndices",K))}`)})}})}else r.lhs.forEach((K,Z)=>{if(z.inputIndices.includes(Z)){let ee=K.symbolToIndices.get(B);if(ee===void 0)throw new Error("Invalid symbol error");ee.forEach(ae=>{S.push(`${i[Z].indicesSet(`input${Z}Indices`,ae,`${B}`)}`)}),O.push(`prod *= ${i[Z].getByIndices(`input${Z}Indices`)};`)}}),P.push(`for(var ${B}: u32 = 0; ${B} < uniforms.${F1(B)}; ${B}++) {`),A.push("}")});let L=E?[..._,`let sum = ${i.map((z,B)=>z.getByIndices(`input${B}Indices`)).join(" * ")};`]:[..._,x,...P,...S,w,...O,T,...A];return` + ${g.registerUniforms(d.map(z=>({name:`${F1(z)}`,type:"u32"}))).registerUniform("outputSize","u32").declareVariables(...i,l)} + + ${g.mainStart()} + ${g.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + var outputIndices = ${l.offsetToIndices("global_idx")}; + ${i.map((z,B)=>`var input${B}Indices: ${i[B].type.indices};`).join(` +`)} + ${L.join(` +`)}; + ${l.setByOffset("global_idx","sum")}; + }`};return{name:"Einsum",shaderCache:{hint:r.equation,inputDependencies:n.map(()=>"rank")},getRunData:()=>{let g=d.filter(w=>r.symbolToInfo.has(w)).map(w=>({type:12,data:r.symbolToInfo.get(w)?.dimValue||0}));g.push({type:12,data:a});let _=n.map((w,x)=>[...ne(w)]).reduce((w,x)=>w.concat(x),g);return _.push(...ne(t)),{outputs:[{dims:t,dataType:e}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:_}},getShaderSource:h}},V1=(n,e)=>{let r=new ud(n.inputs,e.equation),t=r.outputDims,o=n.inputs.map((i,a)=>i.dims);n.compute(Uz(o,n.inputs[0].dataType,r,t))},j1=n=>{let e=n.equation.replace(/\s+/g,"");return we({equation:e})}});var Wz,U1,Hz,qz,W1,H1=H(()=>{"use strict";ve();Oe();Pe();Wz=n=>{if(!n||n.length!==2)throw new Error("Expand requires 2 input.");let e=n[0].dims,r=Array.from(n[1].getBigInt64Array(),Number),t=r.length{let r=n.length-e.length,t=[];for(let o=0;on.length>e.length?U1(n,e):U1(e,n),qz=n=>{let e=n[0].dims,r=Array.from(n[1].getBigInt64Array(),Number),t=Hz(e,r),o=n[0].dataType,i=o===9||W.size(e)===1,a=o===9||e.length>0&&e[e.length-1]%4===0?4:1,l=i||t.length>0&&t[t.length-1]%4===0?4:1,d=Math.ceil(W.size(t)/l),h=_=>{let w=J("input",o,e.length,a),x=te("output",o,t.length,l),T;if(o===9){let S=(P,A,O="")=>` + let outputIndices${A} = ${x.offsetToIndices(`outputOffset + ${A}u`)}; + let offset${A} = ${w.broadcastedIndicesToOffset(`outputIndices${A}`,x)}; + let index${A} = offset${A} / 4u; + let component${A} = offset${A} % 4u; + ${P}[${A}] = ${O}(${w.getByOffset(`index${A}`)}[component${A}]); + `;T=` + let outputOffset = global_idx * ${l}; + var data = vec4(0); + ${S("data",0,"u32")} + ${S("data",1,"u32")} + ${S("data",2,"u32")} + ${S("data",3,"u32")} + ${x.setByOffset("global_idx","data")} + }`}else T=` + let outputIndices = ${x.offsetToIndices(`global_idx * ${l}`)}; + let inputOffset = ${w.broadcastedIndicesToOffset("outputIndices",x)}; + let data = ${x.type.value}(${w.getByOffset(`inputOffset / ${a}`)}); + ${x.setByOffset("global_idx","data")} + }`;return` + ${_.registerUniform("vec_size","u32").declareVariables(w,x)} + ${_.mainStart()} + ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} + ${T}`},g=[{type:12,data:d},...ne(e,t)];return{name:"Expand",shaderCache:{hint:`${t.length};${a}${l}`,inputDependencies:["rank"]},getShaderSource:h,getRunData:()=>({outputs:[{dims:t,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:g})}},W1=n=>{Wz(n.inputs),n.compute(qz(n.inputs),{inputs:[0]})}});var Kz,q1,K1=H(()=>{"use strict";ve();Oe();Pe();rs();Kz=n=>{let e=n[0].dataType,r=W.size(n[0].dims),t=W.size(n[1].dims),o=t%4===0,i=a=>{let l=J("x",e,[1],4),d=J("bias",e,[1],4),h=te("y",e,[1],4),g=[{name:"output_vec_size",type:"u32"},{name:"bias_size",type:"u32"}],_=x=>` + let bias${x}_offset: u32 = (global_idx * 4 + ${x}) % uniforms.bias_size; + let bias${x} = ${d.getByOffset(`bias${x}_offset / 4`)}[bias${x}_offset % 4];`,w=o?` + let bias = ${d.getByOffset("global_idx % (uniforms.bias_size / 4)")};`:`${_(0)}${_(1)}${_(2)}${_(3)} + let bias = ${l.type.value}(bias0, bias1, bias2, bias3);`;return`${a.registerUniforms(g).declareVariables(l,d,h)} + + ${Qc(vt(e))} + + ${a.mainStart(to)} + ${a.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_vec_size")} + + let x = ${l.getByOffset("global_idx")}; + ${w} + let x_in = x + bias; + ${h.setByOffset("global_idx",Yc("x_in"))} + }`};return{name:"FastGeluWithBias",shaderCache:{hint:`${o}`,inputDependencies:["type","type"]},getShaderSource:i,getRunData:a=>({outputs:[{dims:a[0].dims,dataType:a[0].dataType}],programUniforms:[{type:12,data:Math.ceil(r/4)},{type:12,data:t}],dispatchGroup:{x:Math.ceil(r/to/4)}})}},q1=n=>{n.inputs.length<2||W.size(n.inputs[1].dims)===0?GT(n):n.compute(Kz(n.inputs))}});var Xz,Jz,X1,J1,Z1=H(()=>{"use strict";ve();Oe();ft();Pe();Xz=n=>{if(!n||n.length!==2)throw new Error("Gather requires 2 inputs.")},Jz=(n,e)=>{let r=n[0].dims,t=n[1].dims,o=r.length,i=W.normalizeAxis(e.axis,o),a=r.slice(0);a.splice(i,1,...t);let l=r[i],d=n[0].dataType===9?4:1,h=Math.ceil(W.size(a)/d),g=[{type:12,data:h},{type:6,data:l},{type:12,data:i},...ne(n[0].dims,n[1].dims,a)],_=w=>{let x=J("data",n[0].dataType,n[0].dims.length,d),T=J("inputIndices",n[1].dataType,n[1].dims.length),S=te("output",n[0].dataType,a.length,d),P=O=>{let E=t.length,L=`var indicesIndices${O} = ${T.type.indices}(0);`;for(let z=0;z1?`indicesIndices${O}[${z}]`:`indicesIndices${O}`} = ${a.length>1?`outputIndices${O}[uniforms.axis + ${z}]`:`outputIndices${O}`};`;L+=` + var idx${O} = ${T.getByIndices(`indicesIndices${O}`)}; + if (idx${O} < 0) { + idx${O} = idx${O} + uniforms.axisDimLimit; + } + var dataIndices${O} : ${x.type.indices}; + `;for(let z=0,B=0;z1?`dataIndices${O}[${z}]`:`dataIndices${O}`} = u32(idx${O});`,B+=E):(L+=`${o>1?`dataIndices${O}[${z}]`:`dataIndices${O}`} = ${a.length>1?`outputIndices${O}[${B}]`:`outputIndices${O}`};`,B++);return L},A;if(n[0].dataType===9){let O=(E,L,z="")=>` + let outputIndices${L} = ${S.offsetToIndices(`outputOffset + ${L}u`)}; + ${P(L)}; + let offset${L} = ${x.indicesToOffset(`dataIndices${L}`)}; + let index${L} = offset${L} / 4u; + let component${L} = offset${L} % 4u; + ${E}[${L}] = ${z}(${x.getByOffset(`index${L}`)}[component${L}]); + `;A=` + let outputOffset = global_idx * ${d}; + var value = vec4(0); + ${O("value",0,"u32")} + ${O("value",1,"u32")} + ${O("value",2,"u32")} + ${O("value",3,"u32")} + ${S.setByOffset("global_idx","value")} + `}else A=` + let outputIndices = ${S.offsetToIndices("global_idx")}; + ${P("")}; + let value = ${x.getByIndices("dataIndices")}; + ${S.setByOffset("global_idx","value")}; + `;return` + ${w.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(x,T,S)} + ${w.mainStart()} + ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + ${A} + }`};return{name:"Gather",shaderCache:{hint:e.cacheKey,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:a,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:g}),getShaderSource:_}},X1=n=>we({axis:n.axis}),J1=(n,e)=>{let r=n.inputs;Xz(r),n.compute(Jz(n.inputs,e))}});var Zz,Q1,Y1,e2=H(()=>{"use strict";ve();Oe();Pe();Zz=(n,e,r,t,o,i,a,l,d)=>{let h=[{type:12,data:i},{type:12,data:t},{type:12,data:o},{type:12,data:r},{type:12,data:a},{type:12,data:l},{type:12,data:d}],g=[i];h.push(...ne(e.dims,g));let _=w=>{let x=J("indices_data",e.dataType,e.dims.length),T=te("input_slice_offsets_data",12,1,1),S=[x,T],P=[{name:"output_size",type:"u32"},{name:"batch_dims",type:"u32"},{name:"input_dims",type:"u32",length:o.length},{name:"sizes_from_slice_dims_data",type:"u32",length:r.length},{name:"num_slices_per_batch",type:"u32"},{name:"input_batch_stride",type:"u32"},{name:"num_slice_dims",type:"u32"}];return` + ${w.registerUniforms(P).declareVariables(...S)} + ${w.mainStart()} + ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let batch_idx = global_idx / uniforms.num_slices_per_batch; + let base_offset = batch_idx * uniforms.input_batch_stride; + + let slice_indices_base_offset = global_idx * uniforms.num_slice_dims; + var relative_slice_offset = 0; + for (var dim_idx = 0u; dim_idx < uniforms.num_slice_dims; dim_idx ++) { + var index = i32(indices_data[dim_idx + slice_indices_base_offset].x); + let input_dim_idx = uniforms.batch_dims + dim_idx; + if (index < 0) { + ${o.length===1?"index += i32(uniforms.input_dims);":"index += i32(uniforms.input_dims[input_dim_idx]);"} + } + ${r.length===1?"relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data);":"relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data[dim_idx]);"} + } + + input_slice_offsets_data[global_idx] = base_offset + u32(relative_slice_offset); + }`};return n.compute({name:"computeSliceOffsets",shaderCache:{hint:`${o.length}_${r.length}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:g,dataType:n.inputs[1].dataType}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:h}),getShaderSource:_},{inputs:[e],outputs:[-1]})[0]},Q1=(n,e)=>{let r=n.inputs,t=r[0].dims,o=r[0].dataType,i=r[1].dims,a=i[i.length-1],l=W.sizeToDimension(i,i.length-1),d=W.sizeFromDimension(t,e.batchDims+a),h=W.sizeToDimension(t,e.batchDims),g=W.sizeFromDimension(t,e.batchDims),_=l/h,w=new Array(a),x=d;for(let L=0;Lt.length)throw new Error("last dimension of indices must not be larger than rank of input tensor");let P=i.slice(0,-1).concat(t.slice(S)),A=W.size(P),O=[{type:12,data:A},{type:12,data:d},...ne(r[0].dims,T.dims,P)],E=L=>{let z=J("data",r[0].dataType,r[0].dims.length),B=J("slice_offsets",12,T.dims.length),K=te("output",r[0].dataType,P.length);return` + ${L.registerUniform("output_size","u32").registerUniform("slice_size","u32").declareVariables(z,B,K)} + ${L.mainStart()} + ${L.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let slice_offset = slice_offsets[global_idx / uniforms.slice_size]; + output[global_idx] = data[u32(slice_offset) + global_idx % uniforms.slice_size]; + }`};n.compute({name:"GatherND",shaderCache:{hint:e.cacheKey,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:P,dataType:o}],dispatchGroup:{x:Math.ceil(A/64)},programUniforms:O}),getShaderSource:E},{inputs:[r[0],T]})},Y1=n=>({batchDims:n.batch_dims,cacheKey:""})});var Qz,Yz,t2,r2,n2=H(()=>{"use strict";ve();Oe();ft();Pe();Qz=(n,e)=>{if(n.length<3||n.length>4)throw new Error("GatherBlockQuantized requires 3 or 4 inputs.");let r=W.normalizeAxis(e.quantizeAxis,n[0].dims.length),t=e.blockSize,o=n[0],i=n[2],a=n.length===4?n[3]:void 0;if(i.dims.length!==o.dims.length||!o.dims.map((l,d)=>d===r?Math.ceil(l/t)===i.dims[d]:l===i.dims[d]).reduce((l,d)=>l&&d,!0))throw new Error("Scales must have the same rank as the input tensor and the dims should match except on gatherAxis.");if(a){if(a.dataType!==o.dataType)throw new Error("Zero point must have the same data type as the input tensor.");if(a.dims.length!==i.dims.length||!a.dims.map((l,d)=>l===i.dims[d]).reduce((l,d)=>l&&d,!0))throw new Error("Zero point must have the same rank as the input tensor and the dims should match except on quantizeAxis.")}},Yz=(n,e)=>{let r=n[0].dims,t=n[1].dims,o=r.length,i=W.normalizeAxis(e.gatherAxis,o),a=W.normalizeAxis(e.quantizeAxis,o),l=r.slice(0);l.splice(i,1,...t);let d=W.size(l),h=n[2].dataType,_=n[0].dataType===22,w=[{type:12,data:d},{type:12,data:a},{type:12,data:i},{type:12,data:e.blockSize},...ne(...n.map((T,S)=>T.dims),l)],x=T=>{let S=J("data",n[0].dataType,n[0].dims.length),P=J("inputIndices",n[1].dataType,n[1].dims.length),A=J("scales",n[2].dataType,n[2].dims.length),O=n.length>3?J("zeroPoint",n[3].dataType,n[3].dims.length):void 0,E=te("output",h,l.length),L=[S,P,A];O&&L.push(O);let z=[{name:"output_size",type:"u32"},{name:"quantize_axis",type:"u32"},{name:"gather_axis",type:"u32"},{name:"block_size",type:"u32"}];return` + ${T.registerUniforms(z).declareVariables(...L,E)} + ${T.mainStart()} + let output_indices = ${E.offsetToIndices("global_idx")}; + var indices_indices = ${P.type.indices}(0); + ${t.length>1?` + for (var i: u32 = 0; i < ${t.length}; i++) { + let index = ${E.indicesGet("output_indices","uniforms.gather_axis + i")}; + ${P.indicesSet("indices_indices","i","index")}; + }`:`indices_indices = ${E.indicesGet("output_indices","uniforms.gather_axis")};`}; + var data_indices = ${S.type.indices}(0); + for (var i: u32 = 0; i < uniforms.gather_axis; i++) { + let index = ${E.indicesGet("output_indices","i")}; + ${S.indicesSet("data_indices","i","index")}; + } + var index_from_indices = ${P.getByIndices("indices_indices")}; + if (index_from_indices < 0) { + index_from_indices += ${r[i]}; + } + ${S.indicesSet("data_indices","uniforms.gather_axis","u32(index_from_indices)")}; + for (var i = uniforms.gather_axis + 1; i < ${l.length}; i++) { + let index = ${E.indicesGet("output_indices",`i + ${t.length} - 1`)}; + ${S.indicesSet("data_indices","i","index")}; + } + let data_offset = ${S.indicesToOffset("data_indices")}; + let data_index = data_offset % 8; + // Convert 4-bit packed data to 8-bit packed data. + let packed_4bit_quantized_data = ${S.getByOffset("data_offset / 8")}; + let packed_8bit_quantized_data = (packed_4bit_quantized_data >> (4 * (data_index % 2))) & 0x0f0f0f0f; + let quantized_data_vec = ${_?"unpack4xI8":"unpack4xU8"}(u32(packed_8bit_quantized_data)); + let quantized_data = quantized_data_vec[data_index / 2]; + var scale_indices = data_indices; + let quantize_axis_index = ${A.indicesGet("data_indices","uniforms.quantize_axis")} / uniforms.block_size; + ${A.indicesSet("scale_indices","uniforms.quantize_axis","quantize_axis_index")}; + var scale = ${A.getByIndices("scale_indices")}; + ${O?` + let zero_point_indices = scale_indices; + let zero_point_offset = ${O.indicesToOffset("zero_point_indices")}; + let zero_point_index = zero_point_offset % 8; + let packed_4bit_zero_points = ${O.getByOffset("zero_point_offset / 8")}; + let packed_8bit_zero_points = (packed_4bit_zero_points >> (4 * (zero_point_index % 2))) & 0x0f0f0f0f; + let zero_point_vec = ${_?"unpack4xI8":"unpack4xU8"}(u32(packed_8bit_zero_points)); + let zero_point = zero_point_vec[zero_point_index / 2];`:"var zero_point = 0"}; + let dequantized_data = ${vt(h)}(quantized_data - zero_point) * scale; + ${E.setByOffset("global_idx","dequantized_data")}; + }`};return{name:"GatherBlockQuantized",shaderCache:{hint:`${e.cacheKey};${n.filter((T,S)=>S!==1).map(T=>T.dims.join("_")).join(";")}`,inputDependencies:Array.from({length:n.length},(T,S)=>"rank")},getRunData:()=>({outputs:[{dims:l,dataType:h}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:w}),getShaderSource:x}},t2=(n,e)=>{let r=n.inputs;Qz(r,e),n.compute(Yz(n.inputs,e))},r2=n=>we({blockSize:n.blockSize,gatherAxis:n.gatherAxis,quantizeAxis:n.quantizeAxis})});var eM,tM,o2,i2,a2=H(()=>{"use strict";ve();Oe();ft();Pe();eM=n=>{if(!n||n.length!==2)throw new Error("GatherElements requires 2 inputs.");if(n[0].dims.length<1)throw new Error("GatherElements requires that the data input be rank >= 1.");if(n[0].dims.length!==n[1].dims.length)throw new Error(`GatherElements requires that the data input and + indices input tensors be of same rank.`)},tM=(n,e)=>{let r=n[0].dims,t=n[0].dataType,o=r.length,i=n[1].dims,a=n[1].dataType,l=W.normalizeAxis(e.axis,o),d=r[l],h=i.slice(0),g=W.size(h),_=J("input",t,o),w=J("indicesInput",a,i.length),x=te("output",t,h.length),T=[{type:12,data:g},{type:6,data:d},{type:12,data:l}];return T.push(...ne(r,i,h)),{name:"GatherElements",shaderCache:{inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:h,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(g/64)},programUniforms:T}),getShaderSource:A=>` + ${A.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(_,w,x)} + ${A.mainStart()} + ${A.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + + let outputIndices = ${x.offsetToIndices("global_idx")}; + + var idx = ${w.getByOffset("global_idx")}; + if (idx < 0) { + idx = idx + uniforms.axisDimLimit; + } + var inputIndices = ${_.type.indices}(outputIndices); + ${_.indicesSet("inputIndices","uniforms.axis","u32(idx)")}; + let value = ${_.getByIndices("inputIndices")}; + + ${x.setByOffset("global_idx","value")}; + }`}},o2=n=>we({axis:n.axis}),i2=(n,e)=>{let r=n.inputs;eM(r),n.compute(tM(n.inputs,e))}});var rM,nM,s2,u2,l2=H(()=>{"use strict";ve();Oe();Pe();rM=n=>{if(!n)throw new Error("Input is missing");if(n.length<2||n.length>3)throw new Error("Invaid input number.");if(n.length===3&&n[2].dims.length>2)throw new Error("Invalid input shape of C");if(n[0].dataType!==n[1].dataType||n.length===3&&n[0].dataType!==n[2].dataType)throw new Error("Input types are mismatched")},nM=(n,e)=>{let r=n[0].dims.slice(),t=n[1].dims.slice(),[o,i,a]=Ga.getShapeOfGemmResult(r,e.transA,t,e.transB,n.length===3?n[2].dims:void 0),l=[o,i];if(!l)throw new Error("Can't use gemm on the given tensors");let d=16,h=Math.ceil(i/d),g=Math.ceil(o/d),_=!0,w=W.size(l),x=[{type:12,data:_?h:w},{type:12,data:o},{type:12,data:i},{type:12,data:a},{type:1,data:e.alpha},{type:1,data:e.beta}],T=["type","type"];n.length===3&&(x.push(...ne(n[2].dims)),T.push("rank")),x.push(...ne(l));let S=A=>{let O="";e.transA&&e.transB?O="value += a[k * uniforms.M + m] * b[n * uniforms.K + k];":e.transA&&!e.transB?O="value += a[k * uniforms.M + m] * b[k * uniforms.N + n];":!e.transA&&e.transB?O="value += a[m * uniforms.K + k] * b[n * uniforms.K + k];":!e.transA&&!e.transB&&(O="value += a[m * uniforms.K + k] * b[k * uniforms.N + n];");let E=e.alpha===1?"":"value *= uniforms.alpha;",L=J("a",n[0].dataType,n[0].dims),z=J("b",n[1].dataType,n[1].dims),B=L.type.value,K=null,Z=[L,z];n.length===3&&(K=J("c",n[2].dataType,n[2].dims.length),Z.push(K));let ee=te("output",n[0].dataType,l.length);Z.push(ee);let ae=[{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"},{name:"alpha",type:"f32"},{name:"beta",type:"f32"}];return` + ${A.registerUniforms(ae).declareVariables(...Z)} + + ${A.mainStart()} + ${A.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + + let m = global_idx / uniforms.N; + let n = global_idx % uniforms.N; + + var value = ${B}(0); + for (var k: u32 = 0u; k < uniforms.K; k++) { + ${O} + } + + ${E} + ${K!=null?`let cOffset = ${K.broadcastedIndicesToOffset("vec2(m, n)",ee)}; value += ${B}(uniforms.beta) * ${K.getByOffset("cOffset")};`:""} + output[global_idx] = value; + }`},P=A=>{let O=J("a",n[0].dataType,n[0].dims),E=J("b",n[1].dataType,n[1].dims),L=null,z=[O,E];n.length===3&&(L=J("c",n[2].dataType,n[2].dims.length),z.push(L));let B=te("output",n[0].dataType,l.length);z.push(B);let K=[{name:"num_tile_n",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"},{name:"alpha",type:"f32"},{name:"beta",type:"f32"}],Z="",ee="";e.transA&&e.transB?(ee=` + var col = tile_row_start + local_id.x; + var row = k_start + local_id.y; + if (col < uniforms.M && row < uniforms.K) { + tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col]; + } else { + tile_a[local_id.y][local_id.x] = ${O.type.value}(0); + } + + col = k_start + local_id.x; + row = tile_col_start + local_id.y; + if (col < uniforms.K && row < uniforms.N) { + tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col]; + } else { + tile_b[local_id.y][local_id.x] = ${E.type.value}(0); + } + `,Z="value += tile_a[k][local_id.y] * tile_b[local_id.x][k];"):e.transA&&!e.transB?(ee=` + var col = tile_row_start + local_id.x; + var row = k_start + local_id.y; + if (col < uniforms.M && row < uniforms.K) { + tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col]; + } else { + tile_a[local_id.y][local_id.x] = ${O.type.value}(0); + } + + col = tile_col_start + local_id.x; + row = k_start + local_id.y; + if (col < uniforms.N && row < uniforms.K) { + tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col]; + } else { + tile_b[local_id.y][local_id.x] = ${E.type.value}(0); + } + `,Z="value += tile_a[k][local_id.y] * tile_b[k][local_id.x];"):!e.transA&&e.transB?(ee=` + var col = k_start + local_id.x; + var row = tile_row_start + local_id.y; + if (col < uniforms.K && row < uniforms.M) { + tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col]; + } else { + tile_a[local_id.y][local_id.x] = ${O.type.value}(0); + } + + col = k_start + local_id.x; + row = tile_col_start + local_id.y; + if (col < uniforms.K && row < uniforms.N) { + tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col]; + } else { + tile_b[local_id.y][local_id.x] = ${E.type.value}(0); + } + `,Z="value += tile_a[local_id.y][k] * tile_b[local_id.x][k];"):!e.transA&&!e.transB&&(ee=` + var col = k_start + local_id.x; + var row = tile_row_start + local_id.y; + if (col < uniforms.K && row < uniforms.M) { + tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col]; + } else { + tile_a[local_id.y][local_id.x] = ${O.type.value}(0); + } + + col = tile_col_start + local_id.x; + row = k_start + local_id.y; + if (col < uniforms.N && row < uniforms.K) { + tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col]; + } else { + tile_b[local_id.y][local_id.x] = ${E.type.value}(0); + } + `,Z="value += tile_a[local_id.y][k] * tile_b[k][local_id.x];");let ae=e.alpha===1?"":"value *= uniforms.alpha;";return` + ${A.registerUniforms(K).declareVariables(...z)} + var tile_a: array, ${d}>; + var tile_b: array, ${d}>; + ${A.mainStart([d,d,1])} + let tile_col_start = (workgroup_index % uniforms.num_tile_n) * ${d}; + let tile_row_start = (workgroup_index / uniforms.num_tile_n) * ${d}; + let num_tiles = (uniforms.K - 1) / ${d} + 1; + var k_start = 0u; + var value = ${B.type.value}(0); + for (var t: u32 = 0u; t < num_tiles; t++) { + ${ee} + k_start = k_start + ${d}; + workgroupBarrier(); + + for (var k: u32 = 0u; k < ${d}; k++) { + ${Z} + } + workgroupBarrier(); + } + + ${ae} + let m = tile_row_start + local_id.y; + let n = tile_col_start + local_id.x; + ${L!=null?`let cOffset = ${L.broadcastedIndicesToOffset("vec2(m, n)",B)}; value += ${B.type.value}(uniforms.beta) * ${L.getByOffset("cOffset")};`:""} + if (m < uniforms.M && n < uniforms.N) { + output[m * uniforms.N + n] = value; + } + }`};return _?{name:"GemmShared",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:T},getRunData:()=>({outputs:[{dims:l,dataType:n[0].dataType}],dispatchGroup:{x:h*g},programUniforms:x}),getShaderSource:P}:{name:"Gemm",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:T},getRunData:()=>({outputs:[{dims:l,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(w/64)},programUniforms:x}),getShaderSource:S}},s2=n=>{let e=n.transA,r=n.transB,t=n.alpha,o=n.beta;return{transA:e,transB:r,alpha:t,beta:o,cacheKey:`${n.transA};${n.transB};${n.alpha===1}`}},u2=(n,e)=>{rM(n.inputs),n.compute(nM(n.inputs,e))}});var hn,Dn,Io,So,oM,iM,aM,sM,uM,lM,cM,dM,c2,d2,p2=H(()=>{"use strict";ve();Oe();ft();Pe();[hn,Dn,Io,So]=[0,1,2,3],oM=n=>{if(n[0].dims.length!==4)throw new Error("only 4-D tensor is supported.");if(n[0].dims.length!==n[1].dims.length)throw new Error("input dimensions must be equal to grid dimensions");if(n[0].dims.length-2!==n[1].dims[n[1].dims.length-1])throw new Error(`last dimension of grid must be equal to ${n[0].dims.length-2}`);if(n[0].dims[0]!==n[1].dims[0])throw new Error("grid batch size must match input batch size")},iM=` + fn gs_get_cubic_coeffs(x: f32) -> vec4 { + let cubic_alpha = -0.75f; + let x_abs = abs(x); + var coeffs: vec4; + coeffs[0] = (((cubic_alpha * (x_abs + 1) - 5 * cubic_alpha) * (x_abs + 1) + 8 * cubic_alpha) * (x_abs + 1) - 4 * cubic_alpha); + coeffs[1] = (((cubic_alpha + 2) * x_abs - (cubic_alpha + 3)) * x_abs * x_abs + 1); + coeffs[2] = (((cubic_alpha + 2) * (1 - x_abs) - (cubic_alpha + 3)) * (1 - x_abs) * (1 - x_abs) + 1); + coeffs[3] = (((cubic_alpha * (2 - x_abs) - 5 * cubic_alpha) * (2 - x_abs) + 8 * cubic_alpha) * (2 - x_abs) - 4 * cubic_alpha); + return coeffs; + } +`,aM=n=>` + fn gs_bicubic_interpolate(p: mat4x4<${n}>, x: f32, y: f32) -> ${n} { + var v: vec4; + var coeffs = gs_get_cubic_coeffs(x); + for (var i = 0; i < 4; i++) { + v[i] = coeffs[0] * p[i][0] + coeffs[1] * p[i][1] + coeffs[2] * p[i][2] + coeffs[3] * p[i][3]; + } + coeffs = gs_get_cubic_coeffs(y); + let pixel = ${n}(coeffs[0] * v[0] + coeffs[1] * v[1] + coeffs[2] * v[2] + coeffs[3] * v[3]); + return pixel; + } +`,sM=n=>` + fn gs_denormalize(n: f32, length: i32) -> f32 { + ${n.alignCorners===0?` + // alignCorners: false => [-1, 1] to [-0.5, length - 0.5] + return ((n + 1.0) * f32(length) - 1.0) / 2.0; + `:` + // alignCorners: true => [-1, 1] to [0, length - 1] + return (n + 1.0) / 2.0 * (f32(length - 1)); + `} + } +`,uM=n=>` + ${n.paddingMode==="reflection"?` + fn gs_reflect(x: i32, x_min: f32, x_max: f32) -> u32 { + var dx = 0.0; + var fx = f32(x); + let range = x_max - x_min; + if (fx < x_min) { + dx = x_min - fx; + let n = u32(dx / range); + let r = dx - f32(n) * range; + if (n % 2 == 0) { + fx = x_min + r; + } else { + fx = x_max - r; + } + } else if (fx > x_max) { + dx = fx - x_max; + let n = u32(dx / range); + let r = dx - f32(n) * range; + if (n % 2 == 0) { + fx = x_max - r; + } else { + fx = x_min + r; + } + } + return u32(fx); + }`:""} +`,lM=(n,e,r)=>` + fn pixel_at_grid(r: i32, c: i32, H: i32, W: i32, batch: u32, channel: u32, border: vec4) -> ${e} { + var pixel = ${e}(0); + var indices = vec4(0); + indices[${hn}] = batch; + indices[${Dn}] = channel;`+(()=>{switch(r.paddingMode){case"zeros":return` + if (r >= 0 && r < H && c >=0 && c < W) { + indices[${Io}] = u32(r); + indices[${So}] = u32(c); + } else { + return ${e}(0); + } + `;case"border":return` + indices[${Io}] = u32(clamp(r, 0, H - 1)); + indices[${So}] = u32(clamp(c, 0, W - 1)); + `;case"reflection":return` + indices[${Io}] = gs_reflect(r, border[1], border[3]); + indices[${So}] = gs_reflect(c, border[0], border[2]); + `;default:throw new Error(`padding mode ${r.paddingMode} is not supported`)}})()+` + return ${n.getByIndices("indices")}; + } +`,cM=(n,e,r)=>(()=>{switch(r.mode){case"nearest":return` + let result = pixel_at_grid(i32(round(y)), i32(round(x)), H_in, W_in, indices[${hn}], indices[${Dn}], border); + `;case"bilinear":return` + let x1 = i32(floor(x)); + let y1 = i32(floor(y)); + let x2 = x1 + 1; + let y2 = y1 + 1; + + let p11 = pixel_at_grid(y1, x1, H_in, W_in, indices[${hn}], indices[${Dn}], border); + let p12 = pixel_at_grid(y1, x2, H_in, W_in, indices[${hn}], indices[${Dn}], border); + let p21 = pixel_at_grid(y2, x1, H_in, W_in, indices[${hn}], indices[${Dn}], border); + let p22 = pixel_at_grid(y2, x2, H_in, W_in, indices[${hn}], indices[${Dn}], border); + + let dx2 = ${e}(f32(x2) - x); + let dx1 = ${e}(x - f32(x1)); + let dy2 = ${e}(f32(y2) - y); + let dy1 = ${e}(y - f32(y1)); + let result = dy2 * (dx2 * p11 + dx1 * p12) + dy1 * (dx2 * p21 + dx1 * p22); + `;case"bicubic":return` + let x0 = i32(floor(x)) - 1; + let y0 = i32(floor(y)) - 1; + var p: mat4x4<${e}>; + for (var h = 0; h < 4; h++) { + for (var w = 0; w < 4; w++) { + p[h][w] = pixel_at_grid(h + y0, w + x0, H_in, W_in, indices[${hn}], indices[${Dn}], border); + } + } + + let dx = x - f32(x0 + 1); + let dy = y - f32(y0 + 1); + let result = gs_bicubic_interpolate(p, dx, dy); + `;default:throw new Error(`mode ${r.mode} is not supported`)}})()+`${n.setByOffset("global_idx","result")}`,dM=(n,e)=>{let r=J("x",n[0].dataType,n[0].dims.length),t=[n[1].dims[0],n[1].dims[1],n[1].dims[2]],o=J("grid",n[1].dataType,t.length,2),i=[n[0].dims[0],n[0].dims[1],n[1].dims[1],n[1].dims[2]];e.format==="NHWC"&&(i=[n[0].dims[0],n[1].dims[1],n[1].dims[2],n[0].dims[3]],[hn,Dn,Io,So]=[0,3,1,2]);let a=te("output",n[0].dataType,i.length),l=r.type.value,d=W.size(i),h=[{type:12,data:d},...ne(n[0].dims,t,i)],g=_=>` + ${_.registerUniform("output_size","u32").declareVariables(r,o,a)} + ${iM} + ${aM(l)} + ${sM(e)} + ${uM(e)} + ${lM(r,l,e)} + + ${_.mainStart()} + ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let H_in = i32(uniforms.x_shape[${Io}]); + let W_in = i32(uniforms.x_shape[${So}]); + + ${e.alignCorners===0?` + let x_min = -0.5; + let x_max = f32(W_in) - 0.5; + let y_min = -0.5; + let y_max = f32(H_in) - 0.5; + `:` + let x_min = 0.0; + let x_max = f32(W_in) - 1.0; + let y_min = 0.0; + let y_max = f32(H_in) - 1.0; + `}; + let border = vec4(x_min, y_min, x_max, y_max); + + let indices = ${a.offsetToIndices("global_idx")}; + var grid_indices = vec3(indices[${hn}], indices[${Io}], indices[${So}]); + let nxy = ${o.getByIndices("grid_indices")}; + var x = gs_denormalize(f32(nxy[0]), W_in); + var y = gs_denormalize(f32(nxy[1]), H_in); + + ${cM(a,l,e)} + }`;return{name:"GridSample",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:["type","type"]},getRunData:_=>{let w=W.size(i);return{outputs:[{dims:i,dataType:_[0].dataType}],dispatchGroup:{x:Math.ceil(w/64)},programUniforms:h}},getShaderSource:g}},c2=(n,e)=>{oM(n.inputs),n.compute(dM(n.inputs,e))},d2=n=>we({alignCorners:n.align_corners,mode:n.mode,paddingMode:n.padding_mode,format:n.format})});var zt,hM,h2,f2,mM,si,m2,ld=H(()=>{"use strict";ve();Oe();ft();Xa();es();Pe();fn();zt=(n,e)=>n.length>e&&n[e].dims.length>0?n[e]:void 0,hM=(n,e)=>{let r=n[0],t=zt(n,1),o=zt(n,2),i=zt(n,3),a=zt(n,4),l=zt(n,5),d=zt(n,6),h=zt(n,7);if(r.dims.length!==3&&r.dims.length!==5)throw new Error("Input query is expected to have 3 or 5 dimensions");let g=r.dims[0],_=r.dims[1],w=r.dims.length===3?r.dims[2]:e.numHeads*r.dims[4],x=_,T=0,S=0,P=Math.floor(w/e.numHeads);if(d&&h&&W.size(d.dims)&&W.size(h.dims)){if(d.dims.length!==4)throw new Error('Input "past_key" is expected to have 4 dimensions');if(d.dims[0]!==g||d.dims[1]!==e.numHeads||d.dims[3]!==P)throw new Error('Input "past_key" shape (batch_size, num_heads, past_sequence_length, head_size)');if(h.dims[0]!==g||h.dims[1]!==e.numHeads||h.dims[3]!==P)throw new Error('Input "past_value" shape (batch_size, num_heads, past_sequence_length, head_size)');if(d.dims[2]!==h.dims[2])throw new Error('Input "past_key" and "past_value" shall have same dim 2 (past_sequence_length)');if(h.dims.length!==4)throw new Error('Input "past_value" is expected to have 4 dimensions');T=d.dims[2],S=d.dims[2]}else if(d&&W.size(d.dims)||h&&W.size(h.dims))throw new Error('Input "past_key" and "past_value" shall be both present or both absent');let A;if(t&&W.size(t.dims)>0){if(r.dims.length!==3)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(t.dims.length<3||t.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(r.dims[0]!==t.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(t.dims.length===3){if(t.dims[2]!==r.dims[2])throw new Error('Input "query" and "key" shall have same dim 2 (hidden_size)');A=2,x=t.dims[1]}else if(t.dims.length===5){if(t.dims[2]!==e.numHeads||t.dims[3]!==2||t.dims[4]!==P)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(o)throw new Error('Expect "value" be none when "key" has packed kv format.');A=5,x=t.dims[1]}else{if(t.dims[1]!==e.numHeads||t.dims[3]!==P)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');A=0,x=t.dims[2]}}else{if(r.dims.length!==5)throw new Error('Input "query" is expected to have 5 dimensions when key is empty');if(r.dims[2]!==e.numHeads||r.dims[3]!==3)throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');A=3}if(i&&W.size(i.dims)>0){if(i.dims.length!==1)throw new Error('Input "bias" is expected to have 1 dimension');if(t&&t.dims.length===5&&t.dims[3]===2)throw new Error("bias is not allowed for packed kv.")}let O=T+x,E=0;if(a&&W.size(a.dims)>0){E=8;let K=a.dims;throw K.length===1?K[0]===g?E=1:K[0]===3*g+2&&(E=3):K.length===2&&K[0]===g&&K[1]===O&&(E=5),E===8?new Error('Input "key_padding_mask" shape shall be (batch_size) or (batch_size, total_sequence_length)'):new Error("Mask not supported")}let L=!1,z=w;if(o&&W.size(o.dims)>0){if(o.dims.length!==3&&o.dims.length!==4)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(r.dims[0]!==o.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(o.dims.length===3){if(x!==o.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');z=o.dims[2]}else{if(x!==o.dims[2])throw new Error('Input "key" and "value" shall have the same dim 2 (kv_sequence_length)');z=o.dims[1]*o.dims[3],L=!0}}let B=!1;if(a&&W.size(a.dims)>0)throw new Error("Key padding mask is not supported");if(l&&W.size(l.dims)>0){if(l.dims.length!==4)throw new Error('Input "attention_bias" is expected to have 4 dimensions');if(l.dims[0]!==g||l.dims[1]!==e.numHeads||l.dims[2]!==_||l.dims[3]!==O)throw new Error('Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)')}return{batchSize:g,sequenceLength:_,pastSequenceLength:T,kvSequenceLength:x,totalSequenceLength:O,maxSequenceLength:S,inputHiddenSize:0,hiddenSize:w,vHiddenSize:z,headSize:P,vHeadSize:Math.floor(z/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:E,scale:e.scale,broadcastResPosBias:B,passPastInKv:L,qkvFormat:A}},h2=n=>we({...n}),f2=we({perm:[0,2,1,3]}),mM=(n,e,r,t,o,i,a)=>{let l=[t,o,i],d=W.size(l),h=[{type:12,data:d},{type:12,data:a},{type:12,data:i}],g=_=>{let w=te("qkv_with_bias",e.dataType,l),x=J("qkv",e.dataType,l),T=J("bias",r.dataType,l),S=[{name:"output_size",type:"u32"},{name:"bias_offset",type:"u32"},{name:"hidden_size",type:"u32"}];return` + ${_.registerUniforms(S).declareVariables(x,T,w)} + ${_.mainStart()} + ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let bias_offset_idx = (global_idx % uniforms.hidden_size) + uniforms.bias_offset; + + qkv_with_bias[global_idx] = qkv[global_idx] + bias[bias_offset_idx]; + }`};return n.compute({name:"MultiHeadAttentionAddBias",shaderCache:{inputDependencies:["type","type"]},getRunData:()=>({outputs:[{dims:l,dataType:e.dataType,gpuDataType:0}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:h}),getShaderSource:g},{inputs:[e,r],outputs:[-1]})[0]},si=(n,e,r,t,o,i,a,l)=>{let d=i;if(a&&W.size(a.dims)>0){if(t===1)throw new Error("AddBiasReshape is not implemented. Please export your model with packed QKV or KV");return d=mM(n,i,a,e,t,r*o,l),d=d.reshape([e,t,r,o]),r===1||t===1?d:n.compute(wt(d,f2.perm),{inputs:[d],outputs:[-1]})[0]}else return i.dims.length===3&&(d=i.reshape([e,t,r,o])),r===1||t===1?d:n.compute(wt(d,f2.perm),{inputs:[d],outputs:[-1]})[0]},m2=(n,e)=>{let r=hM(n.inputs,e),t=n.inputs[0],o=zt(n.inputs,1),i=zt(n.inputs,2),a=zt(n.inputs,3),l=zt(n.inputs,4),d=zt(n.inputs,5),h=zt(n.inputs,6),g=zt(n.inputs,7);if(t.dims.length===5)throw new Error("Packed QKV is not implemented");if(o?.dims.length===5)throw new Error("Packed KV is not implemented");let _=o&&i&&o.dims.length===4&&i.dims.length===4,w=si(n,r.batchSize,r.numHeads,r.sequenceLength,r.headSize,t,a,0);if(_)return To(n,w,o,i,l,void 0,h,g,d,r);if(!o||!i)throw new Error("key and value must be provided");let x=si(n,r.batchSize,r.numHeads,r.kvSequenceLength,r.headSize,o,a,r.hiddenSize),T=si(n,r.batchSize,r.numHeads,r.kvSequenceLength,r.vHeadSize,i,a,2*r.hiddenSize);To(n,w,x,T,l,void 0,h,g,d,r)}});var gM,bM,yM,_M,cd,g2,b2,dd=H(()=>{"use strict";ve();Oe();ft();Pe();gM=n=>{if(!n||n.length<1)throw new Error("too few inputs")},bM=(n,e)=>{let r=[],t=e.numOutputs;return n[1].dims[0]>0&&(n[1].getBigInt64Array().forEach(o=>r.push(Number(o))),t=r.length),we({numOutputs:t,axis:e.axis,splitSizes:r})},yM=n=>` +fn calculateOutputIndex(index: u32) -> u32 { + for (var i: u32 = 0u; i < ${n}u; i += 1u ) { + if (index < ${de("uniforms.size_in_split_axis","i",n)}) { + return i; + } + } + return ${n}u; +}`,_M=n=>{let e=n.length,r=[];for(let t=0;t{let r=n[0].dims,t=W.size(r),o=n[0].dataType,i=W.normalizeAxis(e.axis,r.length),a=new Array(e.numOutputs),l=J("input",o,r.length),d=new Array(e.numOutputs),h=[],g=[],_=0,w=[{type:12,data:t}];for(let T=0;T` + ${T.registerUniform("input_size","u32").registerUniform("size_in_split_axis","u32",d.length).declareVariables(l,...a)} + ${yM(d.length)} + ${_M(a)} + + ${T.mainStart()} + ${T.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.input_size")} + + var indices = ${l.offsetToIndices("global_idx")}; + var index = ${l.indicesGet("indices",i)}; + let output_number = calculateOutputIndex(index); + if (output_number != 0) { + index -= ${de("uniforms.size_in_split_axis","output_number - 1u",d.length)}; + ${l.indicesSet("indices",i,"index")}; + } + writeBufferData(output_number, indices, global_idx); + }`;return{name:"Split",shaderCache:{hint:e.cacheKey,inputDependencies:["rank"]},getShaderSource:x,getRunData:()=>({outputs:h,dispatchGroup:{x:Math.ceil(t/64)},programUniforms:w})}},g2=(n,e)=>{gM(n.inputs);let r=n.inputs.length===1?e:bM(n.inputs,e);n.compute(cd(n.inputs,r),{inputs:[0]})},b2=n=>{let e=n.axis,r=n.splitSizes,t=n.numOutputs<0?r.length:n.numOutputs;if(t!==r.length)throw new Error("numOutputs and splitSizes lengh must be equal");return we({axis:e,numOutputs:t,splitSizes:r})}});var vM,cs,y2,pd=H(()=>{"use strict";ve();Oe();ft();Pe();vM=(n,e)=>{let[r,t,o,i]=n,{numHeads:a,rotaryEmbeddingDim:l}=e;if(r.dims.length!==3&&r.dims.length!==4)throw new Error(`Input 'x' is expected to have 3 or 4 dimensions, got ${r.dims.length}`);if(!W.areEqual(t.dims,[])&&!W.areEqual(t.dims,[1])&&t.dims.length!==2)throw new Error(`Input 'position_ids' is expected to have 0, 1, or 2 dimensions, got ${t.dims.length}`);if(o.dims.length!==2)throw new Error(`Input 'cos_cache' is expected to have 2 dimensions, got ${o.dims.length}`);if(i.dims.length!==2)throw new Error(`Input 'sin_cache' is expected to have 2 dimensions, got ${i.dims.length}`);if(!W.areEqual(o.dims,i.dims))throw new Error("Inputs 'cos_cache' and 'sin_cache' are expected to have the same shape");if(l>0&&a===0)throw new Error("num_heads must be provided if rotary_embedding_dim is specified");let d=r.dims[0],h=r.dims[r.dims.length-2],g=o.dims[0],_=W.sizeFromDimension(r.dims,1)/h,w=l===0?o.dims[1]*2:_/a;if(l>w)throw new Error("rotary_embedding_dim must be less than or equal to head_size");if(t.dims.length===2){if(d!==t.dims[0])throw new Error(`Input 'position_ids' dimension 0 should be of size batch_size, got ${t.dims[0]}`);if(h!==t.dims[1])throw new Error(`Input 'position_ids' dimension 1 should be of size sequence_length, got ${t.dims[1]}`)}if(w/2!==o.dims[1]&&l/2!==o.dims[1])throw new Error(`Input 'cos_cache' dimension 1 should be same as head_size / 2 or rotary_embedding_dim / 2, got ${o.dims[1]}`);if(h>g)throw new Error("Updating cos_cache and sin_cache in RotaryEmbedding is not currently supported")},cs=(n,e)=>{let{interleaved:r,numHeads:t,rotaryEmbeddingDim:o,scale:i}=e,a=n[0].dims[0],l=W.sizeFromDimension(n[0].dims,1),d=n[0].dims[n[0].dims.length-2],h=l/d,g=n[2].dims[1],_=o===0?g*2:h/t,w=new Array(a,d,h/_,_-g),x=W.computeStrides(w),T=[{type:1,data:i},{type:12,data:w},{type:12,data:x},...n[0].dims.length===3?new Array({type:12,data:[l,h,_,1]}):[],...n[0].dims.length===4?new Array({type:12,data:[l,_,d*_,1]}):[],...ne(n[0].dims,n[1].dims,n[2].dims,n[3].dims,n[0].dims)],S=P=>{let A=J("input",n[0].dataType,n[0].dims.length),O=J("position_ids",n[1].dataType,n[1].dims.length),E=J("cos_cache",n[2].dataType,n[2].dims.length),L=J("sin_cache",n[3].dataType,n[3].dims.length),z=te("output",n[0].dataType,n[0].dims.length);return P.registerUniforms([{name:"scale",type:"f32"},{name:"global_shape",type:"u32",length:w.length},{name:"global_strides",type:"u32",length:x.length},{name:"input_output_strides",type:"u32",length:x.length}]),` + ${P.declareVariables(A,O,E,L,z)} + + ${P.mainStart(to)} + let half_rotary_emb_dim = uniforms.${E.name}_shape[1]; + let bsnh = global_idx / uniforms.global_strides % uniforms.global_shape; + let size = uniforms.global_shape[0] * uniforms.global_strides[0]; + ${P.guardAgainstOutOfBoundsWorkgroupSizes("size")} + + if (bsnh[3] < half_rotary_emb_dim) { + let position_ids_idx = + ${O.broadcastedIndicesToOffset("bsnh.xy",te("",O.type.tensor,2))}; + let position_id = + u32(${O.getByOffset("position_ids_idx")}) + select(0, bsnh[1], position_ids_idx == 0); + let i = dot(bsnh, uniforms.input_output_strides) + select(0, bsnh[3], ${r}); + let j = i + select(half_rotary_emb_dim, 1, ${r}); + let re = ${A.getByOffset("i")} * ${E.get("position_id","bsnh[3]")} - + ${A.getByOffset("j")} * ${L.get("position_id","bsnh[3]")}; + ${z.setByOffset("i","re")} + let im = ${A.getByOffset("i")} * ${L.get("position_id","bsnh[3]")} + + ${A.getByOffset("j")} * ${E.get("position_id","bsnh[3]")}; + ${z.setByOffset("j","im")} + } else { + let k = dot(bsnh, uniforms.input_output_strides) + half_rotary_emb_dim; + ${z.setByOffset("k",A.getByOffset("k"))} + } + }`};return{name:"RotaryEmbedding",shaderCache:{hint:we({interleaved:r}).cacheKey,inputDependencies:["rank","rank","rank","rank"]},getShaderSource:S,getRunData:()=>({outputs:[{dims:n[0].dims,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(W.size(w)/to)},programUniforms:T})}},y2=(n,e)=>{vM(n.inputs,e),n.compute(cs(n.inputs,e))}});var wM,xM,_2,TM,v2,w2=H(()=>{"use strict";ft();ve();es();ld();dd();fn();pd();Pe();wM=(n,e)=>{if(e.doRotary&&n.length<=7)throw new Error("cos_cache and sin_cache inputs are required if do_rotary is specified");let r=n[0],t=n[1],o=n[2],i=n[3],a=n[4];if(e.doRotary!==0&&n.length<=7)throw new Error("cos_cast and sin_cache are expected if do_rotary attribute is non-zero");if(e.localWindowSize!==-1)throw new Error("Local attention is not supported");if(e.softcap!==0)throw new Error("Softcap is not supported");if(e.rotaryInterleaved!==0)throw new Error("Rotary interleaved is not supported");if(e.smoothSoftmax)throw new Error("Smooth softmax is not supported");if(r.dims.length!==3&&r.dims.length!==5)throw new Error("Input query is expected to have 3 or 5 dimensions");let l=!1,d=r.dims[0],h=r.dims[1],g=r.dims.length===3?l?r.dims[2]/3:r.dims[2]:e.numHeads*r.dims[4],_=h,w=0,x=!t||t.dims.length===0,T=Math.floor(x?g/(e.numHeads+2*e.kvNumHeads):g/e.numHeads);x&&(g=T*e.numHeads);let S=i&&i.dims.length!==0,P=a&&a.dims.length!==0;if(S&&i.dims.length===4&&i.dims[0]===d&&i.dims[1]!==e.kvNumHeads&&i.dims[2]===e.kvNumHeads&&i.dims[3]===T)throw new Error("BSNH pastKey/pastValue is not supported");if(S&&P){if(i.dims.length!==4)throw new Error('Input "past_key" is expected to have 4 dimensions');if(a.dims.length!==4)throw new Error('Input "past_value" is expected to have 4 dimensions');w=i.dims[2]}else if(S||P)throw new Error('Input "past_key" and "past_value" shall be both present or both absent');let O=1;if(t&&t.dims.length>0){if(r.dims.length!==3)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(t.dims.length<3||t.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(r.dims[0]!==t.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(t.dims.length===3){if(r.dims[2]%t.dims[2]!==0)throw new Error('Dimension 2 of "query" should be a multiple of "key"');_=t.dims[1]}else if(t.dims.length===5){if(t.dims[2]!==e.numHeads||t.dims[3]!==2||t.dims[4]!==T)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(o)throw new Error('Expect "value" be none when "key" has packed kv format.');_=t.dims[1]}else{if(t.dims[1]!==e.numHeads||t.dims[3]!==T)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');_=t.dims[2]}}else{if(r.dims.length!==3&&r.dims.length!==5)throw new Error('Input "query" is expected to have 3 or 5 dimensions when key is empty');if(r.dims.length===5&&(r.dims[2]!==e.numHeads||r.dims[3]!==3))throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');O=3}let E=0,L=!1,z=e.kvNumHeads?T*e.kvNumHeads:g;if(o&&o.dims.length>0){if(o.dims.length!==3&&o.dims.length!==4)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(r.dims[0]!==o.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(o.dims.length===3){if(_!==o.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');z=o.dims[2]}else{if(_!==o.dims[2])throw new Error('Input "past_key" and "past_value" shall have the same dim 2 (kv_sequence_length)');z=o.dims[1]*o.dims[3],L=!0}}let B=n.length>4?n[5]:void 0;if(B&&B.dims.length!==1&&B.dims[0]!==d)throw new Error('Input "seqlens" is expected to have 1 dimension and the same dim 0 as batch_size');return{batchSize:d,sequenceLength:h,pastSequenceLength:w,kvSequenceLength:_,totalSequenceLength:-1,maxSequenceLength:-1,inputHiddenSize:0,hiddenSize:g,vHiddenSize:z,headSize:T,vHeadSize:Math.floor(z/e.kvNumHeads),numHeads:e.numHeads,kvNumHeads:e.kvNumHeads,nReps:e.numHeads/e.kvNumHeads,pastPresentShareBuffer:!1,maskType:E,scale:e.scale,broadcastResPosBias:!1,passPastInKv:L,qkvFormat:O}},xM=we({perm:[0,2,1,3]}),_2=(n,e,r)=>{let t=e,o=r.kvNumHeads;return e.dims.length===3&&r.kvSequenceLength!==0&&(t=e.reshape([r.batchSize,r.kvSequenceLength,o,r.headSize]),t=n.compute(wt(t,xM.perm),{inputs:[t],outputs:[-1]})[0]),t},TM=(n,e,r,t)=>{let o=7,i=["type","type"],a=[n*e],l=n*e,d=[{type:12,data:l},{type:12,data:e},{type:12,data:n}],h=g=>{let _=J("seq_lens",r.dataType,r.dims),w=J("total_seq_lens",t.dataType,t.dims),x=te("pos_ids",o,a),T=[{name:"output_size",type:"u32"},{name:"sequence_length",type:"u32"},{name:"batch_size",type:"u32"}];return` + ${g.registerUniforms(T).declareVariables(_,w,x)} + ${g.mainStart()} + ${g.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let total_sequence_length = u32(${w.getByOffset("0")}); + let is_subsequent_prompt = uniforms.sequence_length > 1 && uniforms.sequence_length != total_sequence_length; + let is_first_prompt = !is_subsequent_prompt && uniforms.sequence_length == total_sequence_length; + let batch_idx = global_idx / uniforms.sequence_length; + let sequence_idx = i32(global_idx % uniforms.sequence_length); + var pos_id: i32 = 0; + let seqlen = ${_.getByOffset("batch_idx")}; + let total_seqlen = seqlen + 1; + if (is_first_prompt) { + if (sequence_idx < total_seqlen) { + pos_id = sequence_idx; + } else { + pos_id = 1; + } + ${x.setByOffset("global_idx","pos_id")} + } else if (is_subsequent_prompt) { + let past_seqlen = total_seqlen - i32(uniforms.sequence_length); + if (past_seqlen + sequence_idx < total_seqlen) { + pos_id = past_seqlen + sequence_idx; + } else { + pos_id = 1; + } + ${x.setByOffset("global_idx","pos_id")} + } else if (global_idx < uniforms.batch_size) { + ${x.setByOffset("global_idx","seqlen")} + }; + } + `};return{name:"GeneratePositionIds",shaderCache:{hint:`${n};${e}`,inputDependencies:i},getRunData:()=>({outputs:[{dims:a,dataType:o}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:d}),getShaderSource:h}},v2=(n,e)=>{let r=wM(n.inputs,e);if(n.inputs[0].dims.length===5)throw new Error("Packed QKV is not implemented");if(n.inputs[1]?.dims.length===5)throw new Error("Packed KV is not implemented");let t=n.inputs[0],o=n.inputs[1]&&n.inputs[1].dims.length>0?n.inputs[1]:void 0,i=n.inputs[2]&&n.inputs[2].dims.length>0?n.inputs[2]:void 0,a=n.inputs[3]&&n.inputs[3].dims.length!==0?n.inputs[3]:void 0,l=n.inputs[4]&&n.inputs[4].dims.length!==0?n.inputs[4]:void 0,d=n.inputs.length>4?n.inputs[5]:void 0,h=n.inputs.length>5?n.inputs[6]:void 0,g=r.kvNumHeads?r.kvNumHeads:r.numHeads,_=we({axis:2,numOutputs:3,splitSizes:[r.numHeads*r.headSize,g*r.headSize,g*r.headSize]}),[w,x,T]=!o&&!i?n.compute(cd([t],_),{inputs:[t],outputs:[-1,-1,-1]}):[t,o,i],S,P;if(e.doRotary){let L=n.compute(TM(r.batchSize,r.sequenceLength,d,h),{inputs:[d,h],outputs:[-1]})[0],z=n.inputs[7],B=n.inputs[8],K=we({interleaved:e.rotaryInterleaved!==0,numHeads:r.numHeads,rotaryEmbeddingDim:0,scale:e.scale}),Z=[w,L,z,B],ee=[-1];S=n.compute(cs(Z,K),{inputs:Z,outputs:ee})[0],Z.splice(0,1,x);let ae=we({interleaved:e.rotaryInterleaved!==0,numHeads:r.kvNumHeads,rotaryEmbeddingDim:0,scale:e.scale});P=n.compute(cs(Z,ae),{inputs:Z,outputs:ee})[0]}let A=si(n,r.batchSize,r.numHeads,r.sequenceLength,r.headSize,e.doRotary?S:w,void 0,0),O=_2(n,e.doRotary?P:x,r),E=_2(n,T,r);To(n,A,O,E,void 0,void 0,a,l,void 0,r,d,h)}});var x2,IM,SM,T2,I2=H(()=>{"use strict";ve();Oe();fn();Pe();x2=(n,e,r,t,o,i,a,l)=>{let d=Ge(i),h=d===1?"f32":`vec${d}f`,g=d===1?"vec2f":`mat2x${d}f`,_=o*a,w=64;_===1&&(w=256);let x=[o,a,i/d],T=[o,a,2],S=["rank","type","type"],P=[];P.push(...ne(x,T));let A=O=>{let E=J("x",e.dataType,3,d),L=J("scale",r.dataType,r.dims),z=J("bias",t.dataType,t.dims),B=te("output",1,3,2),K=[E,L,z,B];return` + var workgroup_shared : array<${g}, ${w}>; + const workgroup_size = ${w}u; + ${O.declareVariables(...K)} + ${O.mainStart(w)} + let batch = workgroup_index / uniforms.x_shape[1]; + let channel = workgroup_index % uniforms.x_shape[1]; + let hight = uniforms.x_shape[2]; + // initialize workgroup memory + var sum = ${h}(0); + var squared_sum = ${h}(0); + for (var h = local_idx; h < hight; h += workgroup_size) { + let value = ${h}(${E.get("batch","channel","h")}); + sum += value; + squared_sum += value * value; + } + workgroup_shared[local_idx] = ${g}(sum, squared_sum); + workgroupBarrier(); + + for (var currSize = workgroup_size >> 1; currSize > 0; currSize = currSize >> 1) { + if (local_idx < currSize) { + workgroup_shared[local_idx] = workgroup_shared[local_idx] + workgroup_shared[local_idx + currSize]; + } + workgroupBarrier(); + } + if (local_idx == 0) { + let sum_final = ${lr("workgroup_shared[0][0]",d)} / f32(hight * ${d}); + let squared_sum_final = ${lr("workgroup_shared[0][1]",d)} / f32(hight * ${d}); + + let inv_std_dev = inverseSqrt(squared_sum_final - sum_final * sum_final + f32(${l})); + let channel_scale = inv_std_dev * f32(scale[channel]); + let channel_shift = f32(bias[channel]) - sum_final * channel_scale; + output[workgroup_index] = vec2f(channel_scale, channel_shift); + } + }`};return n.compute({name:"InstanceNormComputeChannelScaleShift",shaderCache:{hint:`${d};${l};${w}`,inputDependencies:S},getRunData:()=>({outputs:[{dims:T,dataType:1}],dispatchGroup:{x:_},programUniforms:P}),getShaderSource:A},{inputs:[e,r,t],outputs:[-1]})[0]},IM=(n,e,r)=>{let t=e[0].dims,o=t,i=2,a=t[0],l=t[1],d=W.sizeFromDimension(t,i),h=Ge(d),g=W.size(o)/h,_=x2(n,e[0],e[1],e[2],a,d,l,r.epsilon),w=[a,l,d/h],x=[a,l],T=["type","none"],S=P=>{let A=J("x",e[0].dataType,w.length,h),O=J("scale_shift",1,x.length,2),E=te("output",e[0].dataType,w.length,h),L=[A,O,E];return` + ${P.registerUniform("output_size","u32").declareVariables(...L)} + ${P.mainStart()} + ${P.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let outputIndices = ${E.offsetToIndices("global_idx")}; + let batch = outputIndices[0]; + let channel = outputIndices[1]; + let scale_shift = ${O.getByIndices("vec2(batch, channel)")}; + let value = ${A.getByOffset("global_idx")} * ${E.type.value}(scale_shift.x) + ${E.type.value}(scale_shift.y); + ${E.setByOffset("global_idx","value")}; + }`};n.compute({name:"InstanceNormalization",shaderCache:{hint:`${h}`,inputDependencies:T},getRunData:()=>({outputs:[{dims:o,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(g/64)},programUniforms:[{type:12,data:g},...ne(w,x,w)]}),getShaderSource:S},{inputs:[e[0],_]})},SM=(n,e,r)=>{let t=e[0].dims,o=t,i=t[0],a=t[t.length-1],l=W.sizeFromDimension(t,1)/a,d=Ge(a),h=W.size(o)/d,g=[{type:12,data:l},{type:12,data:Math.floor(a/d)}],_=["type","type"],w=!1,x=[0,t.length-1];for(let A=0;At[x[O]])),S=x2(n,T,e[1],e[2],i,l,a,r.epsilon),P=A=>{let O=et(e[0].dataType),E=d===1?"vec2f":`mat${d}x2f`,L=K=>{let Z=K===0?"x":"y",ee=d===1?"f32":`vec${d}f`;switch(d){case 1:return`${O}(${ee}(scale.${Z}))`;case 2:return`vec2<${O}>(${ee}(scale[0].${Z}, scale[1].${Z}))`;case 4:return`vec4<${O}>(${ee}(scale[0].${Z}, scale[1].${Z}, scale[2].${Z}, scale[3].${Z}))`;default:throw new Error(`Not supported compoents ${d}`)}},z=J("input",e[0].dataType,e[0].dims,d),B=te("output",e[0].dataType,o,d);return` + @group(0) @binding(0) var input : array<${z.type.storage}>; + @group(0) @binding(1) var scale_input : array<${E}>; + @group(0) @binding(2) var output : array<${B.type.storage}>; + struct Uniforms {H: u32, C : u32}; + @group(0) @binding(3) var uniforms: Uniforms; + + ${A.mainStart()} + let current_image_number = global_idx / (uniforms.C * uniforms.H); + let current_channel_number = global_idx % uniforms.C; + + let scale_offset = current_image_number * uniforms.C + current_channel_number; + let scale = scale_input[scale_offset]; + output[global_idx] = fma(input[global_idx], ${L(0)}, ${L(1)}); + }`};n.compute({name:"InstanceNormalizationNHWC",shaderCache:{hint:`${d}`,inputDependencies:_},getRunData:()=>({outputs:[{dims:o,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:g}),getShaderSource:P},{inputs:[e[0],S]})},T2=(n,e)=>{e.format==="NHWC"?SM(n,n.inputs,e):IM(n,n.inputs,e)}});var $M,AM,S2,$2=H(()=>{"use strict";ve();Oe();Pe();$M=n=>{if(!n||n.length<2)throw new Error("layerNorm requires at least 2 inputs.")},AM=(n,e,r)=>{let t=e.simplified,o=n[0].dims,i=n[1],a=!t&&n[2],l=o,d=W.normalizeAxis(e.axis,o.length),h=W.sizeToDimension(o,d),g=W.sizeFromDimension(o,d),_=W.size(i.dims),w=a?W.size(a.dims):0;if(_!==g||a&&w!==g)throw new Error(`Size of X.shape()[axis:] == ${g}. + Size of scale and bias (if provided) must match this. + Got scale size of ${_} and bias size of ${w}`);let x=[];for(let z=0;z1,O=r>2,E=z=>{let B=et(n[0].dataType),K=[J("x",n[0].dataType,n[0].dims,T),J("scale",i.dataType,i.dims,T)];a&&K.push(J("bias",a.dataType,a.dims,T)),K.push(te("output",n[0].dataType,l,T)),A&&K.push(te("mean_data_output",1,x)),O&&K.push(te("inv_std_output",1,x));let Z=[{name:"norm_count",type:"u32"},{name:"norm_size",type:"f32"},{name:"norm_size_vectorized",type:"u32"},{name:"epsilon",type:"f32"}];return` + ${z.registerUniforms(Z).declareVariables(...K)} + ${z.mainStart()} + ${z.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.norm_count")} + let offset = global_idx * uniforms.norm_size_vectorized; + var mean_vector = ${Kc("f32",T)}; + var mean_square_vector = ${Kc("f32",T)}; + + for (var h: u32 = 0u; h < uniforms.norm_size_vectorized; h++) { + let value = ${ro(B,T,"x[h + offset]")}; + mean_vector += value; + mean_square_vector += value * value; + } + let mean = ${lr("mean_vector",T)} / uniforms.norm_size; + let inv_std_dev = inverseSqrt(${lr("mean_square_vector",T)} / uniforms.norm_size ${t?"":"- mean * mean"} + uniforms.epsilon); + + for (var j: u32 = 0; j < uniforms.norm_size_vectorized; j++) { + let f32input = ${ro(B,T,"x[j + offset]")}; + let f32scale = ${ro(B,T,"scale[j]")}; + output[j + offset] = ${K[0].type.value}((f32input ${t?"":"- mean"}) * inv_std_dev * f32scale + ${a?`+ ${ro(B,T,"bias[j]")}`:""} + ); + } + + ${A?"mean_data_output[global_idx] = mean":""}; + ${O?"inv_std_output[global_idx] = inv_std_dev":""}; + }`},L=[{dims:l,dataType:n[0].dataType}];return A&&L.push({dims:x,dataType:1}),O&&L.push({dims:x,dataType:1}),{name:"LayerNormalization",shaderCache:{hint:`${T};${r};${t}`,inputDependencies:S},getRunData:()=>({outputs:L,dispatchGroup:{x:Math.ceil(h/64)},programUniforms:P}),getShaderSource:E}},S2=(n,e)=>{$M(n.inputs),n.compute(AM(n.inputs,e,n.outputCount))}});var OM,A2,O2=H(()=>{"use strict";Oe();as();ss();OM=n=>{if(!n||n.length!==2)throw new Error("MatMul requires 2 inputs.");if(n[0].dims[n[0].dims.length-1]!==n[1].dims[n[1].dims.length-2])throw new Error("shared dimension does not match.")},A2=n=>{OM(n.inputs);let e=rn.calcShape(n.inputs[0].dims,n.inputs[1].dims,!0);if(!e)throw new Error("Can't use matmul on the given tensors");let r=e[e.length-1],t=n.inputs[0].dims[n.inputs[0].dims.length-1];if(r<8&&t<8)n.compute(is(n.inputs,{activation:""},e));else{let o=e[e.length-2],i=W.size(n.inputs[0].dims.slice(0,-2)),a=W.size(n.inputs[1].dims.slice(0,-2));if(i!==1&&o===1&&a===1){let l=n.inputs[0].reshape([1,i,t]),d=n.inputs[1].reshape([1,t,r]),h=[1,i,r],g=[l,d];n.compute(ai(g,{activation:""},e,h),{inputs:g})}else n.compute(ai(n.inputs,{activation:""},e))}}});var CM,PM,EM,C2,P2,E2=H(()=>{"use strict";ve();Oe();ft();Pe();CM=(n,e)=>{if(n.length<3||n.length>4)throw new Error("MatMulNBits requires 3 or 4 inputs");let r=n[0],t=r.dims.length;if(r.dims[t-1]!==e.k)throw new Error("The last dim of input shape does not match the k value");let o=Math.floor((e.k+e.blockSize-1)/e.blockSize),i=e.blockSize/8*e.bits,a=n[1];if(!W.areEqual(a.dims,[e.n,o,i]))throw new Error("The second inputs must be 3D tensor with shape N X nBlocksPerCol X blobSize");let d=n[2].dims;if(W.size(d)!==e.n*o)throw new Error("scales input size error.");if(n.length===4){let g=n[3].dims,_=e.bits>4?e.n*o:e.n*Math.floor((o+1)/2);if(W.size(g)!==_)throw new Error("zeroPoints input size error.")}},PM=(n,e)=>{let r=n[0].dims,t=r.length,o=r[t-2],i=e.k,a=e.n,l=r.slice(0,t-2),d=W.size(l),g=n[1].dims[2]/4,_=n[0].dataType,w=Ge(e.k),x=Ge(g),T=Ge(a),S=l.concat([o,a]),P=o>1&&a/T%2===0?2:1,A=W.size(S)/T/P,O=64,E=[],L=[d,o,i/w],z=W.convertShape(n[1].dims).slice();z.splice(-1,1,g/x),E.push(...ne(L)),E.push(...ne(z)),E.push(...ne(n[2].dims)),n.length===4&&E.push(...ne(W.convertShape(n[3].dims)));let B=[d,o,a/T];E.push(...ne(B));let K=Z=>{let ee=L.length,ae=J("a",n[0].dataType,ee,w),pe=J("b",12,z.length,x),he=J("scales",n[2].dataType,n[2].dims.length),Se=[ae,pe,he],oe=n.length===4?J("zero_points",12,n[3].dims.length):void 0;oe&&Se.push(oe);let Be=B.length,xe=te("output",n[0].dataType,Be,T),ue=et(n[0].dataType),Ee=(()=>{switch(w){case 1:return`array<${ue}, 8>`;case 2:return`mat4x2<${ue}>`;case 4:return`mat2x4<${ue}>`;default:throw new Error(`${w}-component is not supported.`)}})(),me=()=>{let rt=` + // reuse a data + var input_offset = ${ae.indicesToOffset(`${ae.type.indices}(batch, row, word_offset)`)}; + var a_data: ${Ee}; + for (var j: u32 = 0; j < ${8/w}; j++) { + a_data[j] = ${ae.getByOffset("input_offset")}; + input_offset++; + } + `;for(let Ie=0;Ie> 4) & b_mask); + b_quantized_values = ${Ee}(${Array.from({length:4},(j,U)=>`${ue}(b_value_lower[${U}]), ${ue}(b_value_upper[${U}])`).join(", ")}); + b_dequantized_values = ${w===1?`${Ee}(${Array.from({length:8},(j,U)=>`(b_quantized_values[${U}] - ${oe?`zero_point${Ie}`:"zero_point"}) * scale${Ie}`).join(", ")});`:`(b_quantized_values - ${Ee}(${Array(8).fill(`${oe?`zero_point${Ie}`:"zero_point"}`).join(",")})) * scale${Ie};`}; + workgroup_shared[local_id.x * ${P} + ${Math.floor(Ie/T)}]${T>1?`[${Ie%T}]`:""} += ${Array.from({length:8/w},(j,U)=>`${w===1?`a_data[${U}] * b_dequantized_values[${U}]`:`dot(a_data[${U}], b_dequantized_values[${U}])`}`).join(" + ")}; + `;return rt},Te=()=>{let rt=` + var col_index = col * ${T}; + ${oe?` + let zero_point_bytes_per_col = (nBlocksPerCol + 1) / 2; + var zero_point_byte_count: u32; + var zero_point_word_index: u32; + var zero_point_byte_offset: u32; + let zero_point_nibble_offset: u32 = block & 0x1u; + var zero_point_bits_offset: u32; + var zero_point_word: u32;`:` + // The default zero point is 8 for unsigned 4-bit quantization. + let zero_point = ${ue}(8);`} + `;for(let Ie=0;Ie> 0x1u); + zero_point_word_index = zero_point_byte_count >> 0x2u; + zero_point_byte_offset = zero_point_byte_count & 0x3u; + zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_nibble_offset << 2); + zero_point_word = ${oe.getByOffset("zero_point_word_index")} >> zero_point_bits_offset; + let zero_point${Ie} = ${ue}((zero_point_word) & 0xFu);`:""} + col_index += 1;`;return rt},Ue=()=>{let rt=`col_index = col * ${T};`;for(let Ie=0;Ie; + var b_value_upper: vec4; + var b_quantized_values: ${Ee}; + var b_dequantized_values: ${Ee};`,rt};return` + var workgroup_shared: array<${xe.type.value}, ${P*O}>; + ${Z.declareVariables(...Se,xe)} + ${Z.mainStart([O,1,1])} + let output_indices = ${xe.offsetToIndices(`(global_idx / ${O}) * ${P}`)}; + let col = output_indices[2]; + let row = output_indices[1]; + let batch = output_indices[0]; + let nBlocksPerCol = uniforms.b_shape[1]; + + for (var block = local_id.x; block < nBlocksPerCol; block += ${O}) { + //process one block + var word_offset: u32 = block * ${e.blockSize/w}; + ${Te()} + for (var word: u32 = 0; word < ${g}; word += ${x}) { + ${Ue()} + for (var i: u32 = 0; i < ${x}; i++) { + ${me()} + word_offset += ${8/w}; + } + } + } + workgroupBarrier(); + + if (local_id.x < ${P}) { + var output_value: ${xe.type.value} = ${xe.type.value}(0); + var workgroup_shared_offset: u32 = local_id.x; + for (var b: u32 = 0u; b < ${O}u; b++) { + output_value += workgroup_shared[workgroup_shared_offset]; + workgroup_shared_offset += ${P}; + } + ${xe.setByIndices(`${xe.type.indices}(batch, row, col + local_id.x)`,"output_value")}; + } + }`};return{name:"MatMulNBits",shaderCache:{hint:`${e.blockSize};${e.bits};${w};${x};${T};${P};${O}`,inputDependencies:Array(n.length).fill("rank")},getRunData:()=>({outputs:[{dims:S,dataType:_}],dispatchGroup:{x:A},programUniforms:E}),getShaderSource:K}},EM=(n,e)=>{let r=n[0].dims,t=r.length,o=r[t-2],i=e.k,a=e.n,l=r.slice(0,t-2),d=W.size(l),g=n[1].dims[2]/4,_=n[0].dataType,w=Ge(e.k),x=Ge(g),T=l.concat([o,a]),S=128,P=a%8===0?8:a%4===0?4:1,A=S/P,O=A*x*8,E=O/w,L=O/e.blockSize,z=W.size(T)/P,B=[],K=[d,o,i/w],Z=W.convertShape(n[1].dims).slice();Z.splice(-1,1,g/x),B.push(...ne(K)),B.push(...ne(Z)),B.push(...ne(n[2].dims)),n.length===4&&B.push(...ne(W.convertShape(n[3].dims)));let ee=[d,o,a];B.push(...ne(ee));let ae=pe=>{let he=K.length,Se=J("a",n[0].dataType,he,w),oe=J("b",12,Z.length,x),Be=J("scales",n[2].dataType,n[2].dims.length),xe=[Se,oe,Be],ue=n.length===4?J("zero_points",12,n[3].dims.length):void 0;ue&&xe.push(ue);let Ee=ee.length,me=te("output",n[0].dataType,Ee),Te=et(n[0].dataType),Ue=()=>{switch(w){case 1:return` + let a_data0 = vec4<${Te}>(sub_a[word_offset], sub_a[word_offset + 1], sub_a[word_offset + 2], sub_a[word_offset + 3]); + let a_data1 = vec4<${Te}>(sub_a[word_offset + 4], sub_a[word_offset + 5], sub_a[word_offset + 6], sub_a[word_offset + 7]);`;case 2:return` + let a_data0 = vec4<${Te}>(sub_a[word_offset], sub_a[word_offset + 1]); + let a_data1 = vec4<${Te}>(sub_a[word_offset + 2], sub_a[word_offset + 3]);`;case 4:return` + let a_data0 = sub_a[word_offset]; + let a_data1 = sub_a[word_offset + 1];`;default:throw new Error(`${w}-component is not supported.`)}};return` + var sub_a: array<${Se.type.value}, ${E}>; + var inter_results: array, ${P}>; + ${pe.declareVariables(...xe,me)} + ${pe.mainStart([A,P,1])} + let output_indices = ${me.offsetToIndices(`workgroup_index * ${P}`)}; + let col = output_indices[2]; + let row = output_indices[1]; + let batch = output_indices[0]; + let n_blocks_per_col = uniforms.b_shape[1]; + let num_tiles = (n_blocks_per_col - 1) / ${L} + 1; + + // Loop over shared dimension. + for (var tile: u32 = 0; tile < num_tiles; tile += 1) { + let a_col_start = tile * ${E}; + // load one tile A data into shared memory. + for (var a_offset = local_idx; a_offset < ${E}; a_offset += ${S}) + { + let a_col = a_col_start + a_offset; + if (a_col < uniforms.a_shape[2]) + { + sub_a[a_offset] = ${Se.getByIndices(`${Se.type.indices}(batch, row, a_col)`)}; + } else { + sub_a[a_offset] = ${Se.type.value}(0); + } + } + workgroupBarrier(); + + // each thread process one block + let b_row = col + local_id.y; + let block = tile * ${L} + local_id.x; + ${ue?` + let zero_point_bytes_per_col = (n_blocks_per_col + 1) / 2; + let zero_point_byte_count = b_row * zero_point_bytes_per_col + (block >> 0x1u); + let zero_point_word_index = zero_point_byte_count >> 0x2u; + let zero_point_byte_offset = zero_point_byte_count & 0x3u; + let zero_point_nibble_offset: u32 = block & 0x1u; + let zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_nibble_offset << 2); + let zero_point_word = ${ue.getByOffset("zero_point_word_index")} >> zero_point_bits_offset; + let zero_point = ${Te}((zero_point_word) & 0xFu);`:` + // The default zero point is 8 for unsigned 4-bit quantization. + let zero_point = ${Te}(8);`} + let scale = ${Be.getByOffset("b_row * n_blocks_per_col + block")}; + let b_data = ${oe.getByIndices(`${oe.type.indices}(b_row, block, 0)`)}; + var word_offset = local_id.x * ${e.blockSize/w}; + for (var i: u32 = 0; i < ${x}; i++) { + ${Ue()} + let b_value = ${x===1?"b_data":"b_data[i]"}; + let b_value_lower = unpack4xU8(b_value & 0x0F0F0F0Fu); + let b_value_upper = unpack4xU8((b_value >> 4) & 0x0F0F0F0Fu); + let b_quantized_values = mat2x4<${Te}>(${Array.from({length:4},(rt,Ie)=>`${Te}(b_value_lower[${Ie}]), ${Te}(b_value_upper[${Ie}])`).join(", ")}); + let b_dequantized_values = (b_quantized_values - mat2x4<${Te}>(${Array(8).fill("zero_point").join(",")})) * scale; + inter_results[local_id.y][local_id.x] += ${Array.from({length:2},(rt,Ie)=>`${`dot(a_data${Ie}, b_dequantized_values[${Ie}])`}`).join(" + ")}; + word_offset += ${8/w}; + } + workgroupBarrier(); + } + + if (local_idx < ${P}) { + var output_value: ${me.type.value} = ${me.type.value}(0); + for (var b = 0u; b < ${A}; b++) { + output_value += inter_results[local_idx][b]; + } + if (col + local_idx < uniforms.output_shape[2]) + { + ${me.setByIndices(`${me.type.indices}(batch, row, col + local_idx)`,"output_value")} + } + } + }`};return{name:"BlockwiseMatMulNBits32",shaderCache:{hint:`${e.blockSize};${w};${x};${A};${P}`,inputDependencies:Array(n.length).fill("rank")},getRunData:()=>({outputs:[{dims:T,dataType:_}],dispatchGroup:{x:z},programUniforms:B}),getShaderSource:ae}},C2=(n,e)=>{CM(n.inputs,e),e.blockSize===32&&n.adapterInfo.isVendor("intel")&&n.adapterInfo.isArchitecture("gen-12lp")?n.compute(EM(n.inputs,e)):n.compute(PM(n.inputs,e))},P2=n=>we(n)});var DM,kM,NM,LM,RM,zM,MM,BM,D2,k2=H(()=>{"use strict";ve();Oe();Pe();DM=n=>{if(!n||n.length<1)throw new Error("Too few inputs");if(n[0].dataType!==1&&n[0].dataType!==10)throw new Error("Input type must be float or float16.");if(n.length>=2){let e=n[0].dims.length*2===n[1].dims[0];if(n.length===4&&(e=n[3].dims[0]*2===n[1].dims[0]),!e)throw new Error("The pads should be a 1D tensor of shape [2 * input_rank] or [2 * num_axes].")}},kM=(n,e,r)=>{let t="";for(let o=e-1;o>=0;--o)t+=` + k = i32(${n.indicesGet("indices",o)}) - ${de("uniforms.pads",o,r)}; + if (k < 0) { + break; + } + if (k >= i32(${de("uniforms.x_shape",o,e)})) { + break; + } + offset += k * i32(${de("uniforms.x_strides",o,e)}); + `;return` + value = ${n.type.value}(uniforms.constant_value); + for (var i = 0; i < 1; i++) { + var offset = 0; + var k = 0; + ${t} + value = x[offset]; + } + `},NM=(n,e,r)=>{let t="";for(let o=e-1;o>=0;--o)t+=` + k = i32(${n.indicesGet("indices",o)}) - ${de("uniforms.pads",o,r)}; + if (k < 0) { + k = -k; + } + { + let _2n_1 = 2 * (i32(${de("uniforms.x_shape",o,e)}) - 1); + k = k % _2n_1; + if(k >= i32(${de("uniforms.x_shape",o,e)})) { + k = _2n_1 - k; + } + } + offset += k * i32(${de("uniforms.x_strides",o,e)}); + `;return` + var offset = 0; + var k = 0; + ${t} + value = x[offset]; + `},LM=(n,e,r)=>{let t="";for(let o=e-1;o>=0;--o)t+=` + k = i32(${n.indicesGet("indices",o)}) - ${de("uniforms.pads",o,r)}; + if (k < 0) { + k = 0; + } + if (k >= i32(${de("uniforms.x_shape",o,e)})) { + k = i32(${de("uniforms.x_shape",o,e)}) - 1; + } + offset += k * i32(${de("uniforms.x_strides",o,e)}); + `;return` + var offset = 0; + var k = 0; + ${t} + value = x[offset]; + `},RM=(n,e,r)=>{let t="";for(let o=e-1;o>=0;--o)t+=` + k = i32(${n.indicesGet("indices",o)}) - ${de("uniforms.pads",o,r)}; + if (k < 0) { + k += i32(${de("uniforms.x_shape",o,e)}]); + } + if (k >= i32(${de("uniforms.x_shape",o,e)})) { + k -= i32(${de("uniforms.x_shape",o,e)}); + } + offset += k * i32(${de("uniforms.x_strides",o,e)}); + `;return` + var offset = 0; + var k = 0; + ${t} + value = x[offset]; + `},zM=(n,e,r)=>{switch(r.mode){case 0:return kM(n,e,r.pads.length);case 1:return NM(n,e,r.pads.length);case 2:return LM(n,e,r.pads.length);case 3:return RM(n,e,r.pads.length);default:throw new Error("Invalid mode")}},MM=(n,e)=>{let r=W.padShape(n[0].dims.slice(),e.pads),t=n[0].dims,o=W.size(r),i=[{type:12,data:o},{type:6,data:e.pads}],a=n.length>=3&&n[2].data;e.mode===0&&i.push({type:a?n[2].dataType:1,data:e.value}),i.push(...ne(n[0].dims,r));let l=["rank"],d=h=>{let g=te("output",n[0].dataType,r.length),_=J("x",n[0].dataType,t.length),w=_.type.value,x=zM(g,t.length,e),T=[{name:"output_size",type:"u32"},{name:"pads",type:"i32",length:e.pads.length}];return e.mode===0&&T.push({name:"constant_value",type:a?w:"f32"}),` + ${h.registerUniforms(T).declareVariables(_,g)} + ${h.mainStart()} + ${h.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + + let indices = ${g.offsetToIndices("global_idx")}; + + var value = ${w}(0); + ${x} + output[global_idx] = value; + }`};return{name:"Pad",shaderCache:{hint:`${e.mode}${a}`,inputDependencies:l},getRunData:()=>({outputs:[{dims:r,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(W.size(r)/64)},programUniforms:i}),getShaderSource:d}},BM=(n,e)=>{if(n.length>1){let r=n[1].getBigInt64Array(),t=n.length>=3&&n[2].data?n[2].dataType===10?n[2].getUint16Array()[0]:n[2].getFloat32Array()[0]:0,o=n[0].dims.length,i=new Int32Array(2*o).fill(0);if(n.length>=4){let l=n[3].getBigInt64Array();for(let d=0;di[Number(d)]=Number(l));let a=[];return i.forEach(l=>a.push(l)),{mode:e.mode,value:t,pads:a}}else return e},D2=(n,e)=>{DM(n.inputs);let r=BM(n.inputs,e);n.compute(MM(n.inputs,r),{inputs:[0]})}});var ds,N2,L2,R2,z2,FM,VM,M2,B2,F2,V2,j2,G2,U2,W2,H2,q2,K2,X2,J2=H(()=>{"use strict";At();ve();Oe();Pe();ds=n=>{if(Ae.webgpu.validateInputContent&&(!n||n.length!==1))throw new Error("Pool ops requires 1 input.")},N2=(n,e,r)=>{let t=e.format==="NHWC",o=n.dims.slice();t&&o.splice(1,0,o.pop());let i=Object.hasOwnProperty.call(e,"dilations"),a=e.kernelShape.slice(),l=e.strides.slice(),d=i?e.dilations.slice():[],h=e.pads.slice();eo.adjustPoolAttributes(r,o,a,l,d,h);let g=eo.computePoolOutputShape(r,o,l,d,a,h,e.autoPad),_=Object.assign({},e);i?Object.assign(_,{kernelShape:a,strides:l,pads:h,dilations:d,cacheKey:e.cacheKey}):Object.assign(_,{kernelShape:a,strides:l,pads:h,cacheKey:e.cacheKey});let w=g.slice();return w.push(w.splice(1,1)[0]),[_,t?w:g]},L2=(n,e)=>{let r=e.format==="NHWC",t=W.size(n),o=W.size(e.kernelShape),i=[{type:12,data:t},{type:12,data:o}],a=[{name:"outputSize",type:"u32"},{name:"kernelSize",type:"u32"}];if(e.kernelShape.length<=2){let l=e.kernelShape[e.kernelShape.length-1],d=e.strides[e.strides.length-1],h=e.pads[e.pads.length/2-1],g=e.pads[e.pads.length-1],_=!!(h+g);i.push({type:12,data:l},{type:12,data:d},{type:12,data:h},{type:12,data:g}),a.push({name:"kw",type:"u32"},{name:"sw",type:"u32"},{name:"pwStart",type:"u32"},{name:"pwEnd",type:"u32"});let w=!1;if(e.kernelShape.length===2){let x=e.kernelShape[e.kernelShape.length-2],T=e.strides[e.strides.length-2],S=e.pads[e.pads.length/2-2],P=e.pads[e.pads.length-2];w=!!(S+P),i.push({type:12,data:x},{type:12,data:T},{type:12,data:S},{type:12,data:P}),a.push({name:"kh",type:"u32"},{name:"sh",type:"u32"},{name:"phStart",type:"u32"},{name:"phEnd",type:"u32"})}return[i,a,!0,_,w]}else{if(r)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let l=W.computeStrides(e.kernelShape);i.push({type:12,data:l},{type:12,data:e.pads},{type:12,data:e.strides}),a.push({name:"kernelStrides",type:"u32",length:l.length},{name:"pads",type:"u32",length:e.pads.length},{name:"strides",type:"u32",length:e.strides.length});let d=e.pads.reduce((h,g)=>h+g);return[i,a,!!d,!1,!1]}},R2=(n,e,r,t,o,i,a,l,d,h,g,_)=>{let w=o.format==="NHWC",x=e.type.value,T=te("output",e.type.tensor,t);if(o.kernelShape.length<=2){let S="",P="",A="",O=r-(w?2:1);if(g?S=` + for (var i: u32 = 0u; i < uniforms.kw; i++) { + xIndices[${O}] = indices[${O}] * uniforms.sw - uniforms.pwStart + i; + if (xIndices[${O}] < 0 || xIndices[${O}] + >= uniforms.x_shape[${O}]) { + pad++; + continue; + } + let x_val = x[${e.indicesToOffset("xIndices")}]; + ${i} + }`:S=` + for (var i: u32 = 0u; i < uniforms.kw; i++) { + xIndices[${O}] = indices[${O}] * uniforms.sw - uniforms.pwStart + i; + let x_val = x[${e.indicesToOffset("xIndices")}]; + ${i} + }`,o.kernelShape.length===2){let L=r-(w?3:2);_?P=` + for (var j: u32 = 0u; j < uniforms.kh; j++) { + xIndices[${L}] = indices[${L}] * uniforms.sh - uniforms.phStart + j; + if (xIndices[${L}] < 0 || xIndices[${L}] >= uniforms.x_shape[${L}]) { + pad += i32(uniforms.kw); + continue; + } + `:P=` + for (var j: u32 = 0u; j < uniforms.kh; j++) { + xIndices[${L}] = indices[${L}] * uniforms.sh - uniforms.phStart + j; + `,A=` + } + `}return` + ${n.registerUniforms(d).declareVariables(e,T)} + + ${n.mainStart()} + ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + + let indices = ${T.offsetToIndices("global_idx")}; + var xIndices = ${T.offsetToIndices("global_idx")}; + + var value = ${x}(${l}); + var pad = 0; + ${P} + ${S} + ${A} + ${a} + + output[global_idx] = value; + }`}else{if(w)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let S=o.kernelShape.length,P=o.pads.length,A="";return h?A=` + if (xIndices[j] >= uniforms.x_shape[j]) { + pad++; + isPad = true; + break; + } + } + if (!isPad) { + let x_val = x[${e.indicesToOffset("xIndices")}]; + ${i} + }`:A=` + } + let x_val = x[${e.indicesToOffset("xIndices")}]; + ${i} + `,` + ${n.registerUniforms(d).declareVariables(e,T)} + + ${n.mainStart()} + ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + let indices = ${T.offsetToIndices("global_idx")}; + var xIndices = ${T.offsetToIndices("global_idx")}; + + var offsets: array; + + var value = ${x}(${l}); + var pad = 0; + var isPad = false; + + for (var i: u32 = 0u; i < uniforms.kernelSize; i++) { + var offset = i; + for (var j = 0u; j < ${S-1}u; j++) { + offsets[j] = offset / ${de("uniforms.kernelStrides","j",S)}; + offset -= offsets[j] * ${de("uniforms.kernelStrides","j",S)}; + } + offsets[${S-1}] = offset; + + isPad = false; + for (var j = ${r-S}u; j < ${r}u; j++) { + xIndices[j] = indices[j] * ${de("uniforms.strides",`j - ${r-S}u`,S)} + + offsets[j - ${r-S}u] - ${de("uniforms.pads","j - 2u",P)}; + ${A} + } + ${a} + + output[global_idx] = value; + }`}},z2=n=>`${n.format};${n.ceilMode};${n.autoPad};${n.kernelShape.length}`,FM=n=>`${z2(n)};${n.countIncludePad}`,VM=n=>`${z2(n)};${n.storageOrder};${n.dilations}`,M2=n=>({format:n.format,autoPad:["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][n.auto_pad],ceilMode:n.ceil_mode,kernelShape:n.kernel_shape,strides:n.strides,pads:n.pads}),B2=(n,e,r,t)=>{let[o,i]=N2(e,t,r),a=J("x",e.dataType,e.dims.length),l=a.type.value,d="value += x_val;",h="";o.countIncludePad?h+=`value /= ${l}(uniforms.kernelSize);`:h+=`value /= ${l}(i32(uniforms.kernelSize) - pad);`;let[g,_,w,x,T]=L2(i,o);g.push(...ne(e.dims,i));let S=["rank"];return{name:n,shaderCache:{hint:`${t.cacheKey};${w};${x};${T}`,inputDependencies:S},getRunData:()=>({outputs:[{dims:i,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(W.size(i)/64)},programUniforms:g}),getShaderSource:P=>R2(P,a,e.dims.length,i.length,o,d,h,0,_,w,x,T)}},F2=n=>{let e=n.count_include_pad!==0,r=M2(n);if(r.ceilMode!==0)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");let t={countIncludePad:e,...r,cacheKey:""};return{...t,cacheKey:FM(t)}},V2=(n,e)=>{ds(n.inputs),n.compute(B2("AveragePool",n.inputs[0],!1,e))},j2={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[]},G2=n=>{let e=n.format;return{format:e,...j2,cacheKey:e}},U2=(n,e)=>{ds(n.inputs),n.compute(B2("GlobalAveragePool",n.inputs[0],!0,e))},W2=(n,e,r,t)=>{let[o,i]=N2(e,t,r),a=` + value = max(x_val, value); + `,l="",d=J("x",e.dataType,e.dims.length),h=["rank"],[g,_,w,x,T]=L2(i,o);return g.push(...ne(e.dims,i)),{name:n,shaderCache:{hint:`${t.cacheKey};${w};${x};${T}`,inputDependencies:h},getRunData:()=>({outputs:[{dims:i,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(W.size(i)/64)},programUniforms:g}),getShaderSource:S=>R2(S,d,e.dims.length,i.length,o,a,l,e.dataType===10?-65504:-1e5,_,w,x,T)}},H2=(n,e)=>{ds(n.inputs),n.compute(W2("MaxPool",n.inputs[0],!1,e))},q2=n=>{let e=n.storage_order,r=n.dilations,t=M2(n);if(e!==0)throw new Error("column major storage order is not yet supported for MaxPool");if(t.ceilMode!==0)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");let o={storageOrder:e,dilations:r,...t,cacheKey:""};return{...o,cacheKey:VM(o)}},K2=n=>{let e=n.format;return{format:e,...j2,cacheKey:e}},X2=(n,e)=>{ds(n.inputs),n.compute(W2("GlobalMaxPool",n.inputs[0],!0,e))}});var GM,UM,Z2,Q2,Y2=H(()=>{"use strict";ve();Oe();ft();Pe();GM=(n,e)=>{if(n.length<2||n.length>3)throw new Error("DequantizeLinear requires 2 or 3 inputs.");if(n.length===3&&n[1].dims===n[2].dims)throw new Error("x-scale and x-zero-point must have the same shape.");if(n.length===3&&n[0].dataType!==n[2].dataType)throw new Error("x and x-zero-point must have the same data type.");if(n[0].dataType===6&&n.length>2)throw new Error("In the case of dequantizing int32 there is no zero point.");if(n[1].dims.length!==0&&n[1].dims.length!==1&&n[1].dims.length!==n[0].dims.length)throw new Error("scale input must be a scalar, a 1D tensor, or have the same rank as the input tensor.");if(n.length>2){if(n[0].dataType!==n[2].dataType)throw new Error("x and x-zero-point must have the same data type.");if(n[1].dims.length!==n[2].dims.length)throw new Error("scale and zero-point inputs must have the same rank.");if(!n[1].dims.map((r,t)=>r===n[2].dims[t]).reduce((r,t)=>r&&t,!0))throw new Error("scale and zero-point inputs must have the same shape.")}if(e.blockSize>0){if(n[1].dims.length===0||n[1].dims.length===1&&n[1].dims[0]===1)throw new Error("blockSize must be set only for block quantization.");if(!n[1].dims.map((o,i)=>i===e.axis||o===n[0].dims[i]).reduce((o,i)=>o&&i,!0))throw new Error("For block qunatization, scale input shape to match the input shape except for the axis");if(n[1].dims.length!==n[0].dims.length)throw new Error("For block qunatization the scale input rank must be the same as the x rank.");let r=n[0].dims[e.axis],t=n[1].dims[e.axis];if(e.blockSizeMath.ceil(r/(t-1)-1))throw new Error("blockSize must be with in the range [ceil(dI / Si), ceil(dI / (Si - 1) - 1)].")}},UM=(n,e)=>{let r=W.normalizeAxis(e.axis,n[0].dims.length),t=n[0].dataType,o=t===3,i=n[0].dims,a=n[1].dataType,l=W.size(i),d=t===3||t===2,h=d?[Math.ceil(W.size(n[0].dims)/4)]:n[0].dims,g=n[1].dims,_=n.length>2?n[2]:void 0,w=_?d?[Math.ceil(W.size(_.dims)/4)]:_.dims:void 0,x=g.length===0||g.length===1&&g[0]===1,T=x===!1&&g.length===1,S=Ge(l),P=x&&(!d||S===4),A=P?S:1,O=P&&!d?S:1,E=J("input",d?12:t,h.length,O),L=J("scale",a,g.length),z=_?J("zero_point",d?12:t,w.length):void 0,B=te("output",a,i.length,A),K=[E,L];z&&K.push(z);let Z=[h,g];_&&Z.push(w);let ee=[{type:12,data:l/A},{type:12,data:r},{type:12,data:e.blockSize},...ne(...Z,i)],ae=pe=>{let he=[{name:"output_size",type:"u32"},{name:"axis",type:"u32"},{name:"block_size",type:"u32"}];return` + ${pe.registerUniforms(he).declareVariables(...K,B)} + ${pe.mainStart()} + ${pe.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let output_indices = ${B.offsetToIndices("global_idx")}; + + // Set input x + ${d?` + let input = ${E.getByOffset("global_idx / 4")}; + let x_vec = ${o?"unpack4xI8(input)":"unpack4xU8(input)"}; + let x_value = ${A===1?"x_vec[global_idx % 4]":"x_vec"};`:`let x_value = ${E.getByOffset("global_idx")};`}; + + // Set scale input + ${x?`let scale_value= ${L.getByOffset("0")}`:T?` + let scale_index = ${B.indicesGet("output_indices","uniforms.axis")}; + let scale_value= ${L.getByOffset("scale_index")};`:` + var scale_indices: ${L.type.indices} = output_indices; + let index = ${L.indicesGet("scale_indices","uniforms.axis")} / uniforms.block_size; + ${L.indicesSet("scale_indices","uniforms.axis","index")}; + let scale_value= ${L.getByIndices("scale_indices")};`}; + + // Set zero-point input + ${z?x?d?` + let zero_point_input = ${z.getByOffset("0")}; + let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; + let zero_point_value= zero_point_vec[0]`:`let zero_point_value = ${z.getByOffset("0")}`:T?d?` + let zero_point_index = ${B.indicesGet("output_indices","uniforms.axis")}; + let zero_point_input = ${z.getByOffset("zero_point_index / 4")}; + let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; + let zero_point_value = zero_point_vec[zero_point_index % 4]`:` + let zero_point_index = ${B.indicesGet("output_indices","uniforms.axis")}; + let zero_point_value = ${z.getByOffset("zero_point_index")};`:d?` + let zero_point_offset = ${L.indicesToOffset("scale_indices")}; + let zero_point_input = ${z.getByOffset("zero_point_offset / 4")}; + let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; + let zero_point_value = zero_point_vec[zero_point_offset % 4];`:`let zero_point_value = ${z.getByIndices("scale_indices")};`:`let zero_point_value = ${d?o?"i32":"u32":E.type.value}(0);`}; + // Compute and write output + ${B.setByOffset("global_idx",`${B.type.value}(x_value - zero_point_value) * scale_value`)}; + }`};return{name:"DequantizeLinear",shaderCache:{hint:e.cacheKey,inputDependencies:z?["rank","rank","rank"]:["rank","rank"]},getShaderSource:ae,getRunData:()=>({outputs:[{dims:i,dataType:a}],dispatchGroup:{x:Math.ceil(l/A/64),y:1,z:1},programUniforms:ee})}},Z2=(n,e)=>{GM(n.inputs,e),n.compute(UM(n.inputs,e))},Q2=n=>we({axis:n.axis,blockSize:n.blockSize})});var WM,HM,eI,tI=H(()=>{"use strict";At();ve();Pe();WM=(n,e,r)=>{let t=n===e,o=ne&&r>0;if(t||o||i)throw new Error("Range these inputs' contents are invalid.")},HM=(n,e,r,t)=>{let o=Math.abs(Math.ceil((e-n)/r)),i=[o],a=o,l=[{type:12,data:a},{type:t,data:n},{type:t,data:r},...ne(i)],d=h=>{let g=te("output",t,i.length),_=g.type.value,w=[{name:"outputSize",type:"u32"},{name:"start",type:_},{name:"delta",type:_}];return` + ${h.registerUniforms(w).declareVariables(g)} + ${h.mainStart()} + ${h.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + output[global_idx] = uniforms.start + ${_}(global_idx) * uniforms.delta; + }`};return{name:"Range",shaderCache:{hint:`${t}`},getShaderSource:d,getRunData:()=>({outputs:[{dims:i,dataType:t}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:l})}},eI=n=>{let e=0,r=0,t=0;n.inputs[0].dataType===6?(e=n.inputs[0].getInt32Array()[0],r=n.inputs[1].getInt32Array()[0],t=n.inputs[2].getInt32Array()[0]):n.inputs[0].dataType===1&&(e=n.inputs[0].getFloat32Array()[0],r=n.inputs[1].getFloat32Array()[0],t=n.inputs[2].getFloat32Array()[0]),Ae.webgpu.validateInputContent&&WM(e,r,t),n.compute(HM(e,r,t,n.inputs[0].dataType),{inputs:[]})}});var qM,KM,rI,nI,oI=H(()=>{"use strict";ve();Oe();ft();Pe();qM=(n,e,r,t)=>{if(n!=="none"&&t!=="i32"&&t!=="u32"&&t!=="f32")throw new Error(`Input ${t} is not supported with reduction ${n}.`);let o=`{ + var oldValue = 0; + loop { + let newValueF32 =`,i=`; + let newValue = bitcast(newValueF32); + let res = atomicCompareExchangeWeak(&${e}, oldValue, newValue); + if res.exchanged { + break; + } + oldValue = res.old_value; + } + }`;switch(n){case"none":return`${e}=${r};`;case"add":return t==="i32"||t==="u32"?`atomicAdd(&${e}, bitcast<${t}>(${r}));`:` + ${o}bitcast<${t}>(oldValue) + (${r})${i}`;case"max":return t==="i32"||t==="u32"?`atomicMax(&${e}, bitcast<${t}>(${r}));`:` + ${o}max(bitcast(oldValue), (${r}))${i}`;case"min":return t==="i32"||t==="u32"?`atomicMin(&${e}, bitcast<${t}>(${r}));`:`${o}min(bitcast<${t}>(oldValue), (${r}))${i}`;case"mul":return`${o}(bitcast<${t}>(oldValue) * (${r}))${i}`;default:throw new Error(`Reduction ${n} is not supported.`)}},KM=(n,e)=>{let r=n[0].dims,t=n[1].dims,o=r,i=1,a=Math.ceil(W.sizeToDimension(t,t.length-1)/i),l=t[t.length-1],d=W.sizeFromDimension(r,l),h=[{type:12,data:a},{type:12,data:l},{type:12,data:d},...ne(n[1].dims,n[2].dims,o)],g=_=>{let w=J("indices",n[1].dataType,n[1].dims.length),x=J("updates",n[2].dataType,n[2].dims.length,i),T=e.reduction!=="none"&&e.reduction!==""?Px("output",n[0].dataType,o.length):te("output",n[0].dataType,o.length,i);return` + ${_.registerUniform("output_size","u32").registerUniform("last_index_dimension","u32").registerUniform("num_updates_elements","u32").declareVariables(w,x,T)} + ${_.mainStart()} + ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + var data_offset = 0u; + let indices_start = uniforms.last_index_dimension * global_idx; + let indices_end = indices_start + uniforms.last_index_dimension; + for (var i = indices_start; i < indices_end; i++) { + var index = i32(indices[i].x); + ${n[0].dims.length===1?` + let element_count_dim = uniforms.output_strides; + let dim_value = uniforms.output_shape;`:` + let element_count_dim = uniforms.output_strides[i - indices_start]; + let dim_value = uniforms.output_shape[i - indices_start];`} + if (index >= 0) { + if (index >= i32(dim_value)) { + index = i32(dim_value - 1); + } + } else { + if (index < -i32(dim_value)) { + index = 0; + } else { + index += i32(dim_value); + } + } + data_offset += u32((u32(index) * element_count_dim)); + } + + for (var i = 0u; i < uniforms.num_updates_elements; i++) { + let value = updates[uniforms.num_updates_elements * global_idx + i]; + ${qM(e.reduction,"output[data_offset + i]","value",T.type.value)} + } + + }`};return{name:"ScatterND",shaderCache:{hint:`${e.cacheKey}_${e.reduction}`,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:o,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:h}),getShaderSource:g}},rI=n=>we({reduction:n.reduction}),nI=(n,e)=>{n.compute(KM(n.inputs,e),{inputs:[n.inputs[1],n.inputs[2]],outputs:[]})}});var XM,JM,ZM,iI,QM,YM,eB,tB,rB,nB,oB,iB,aI,aB,sB,uB,lB,cB,sI,uI,lI=H(()=>{"use strict";ve();Oe();ft();Pe();XM=(n,e)=>{if(n.every(r=>r>0||(()=>{throw new Error("Resize requires scales input values to be positive")})),n.length>0){if(e.mode==="linear"){if(!(n.length===2||n.length===3||n.length===4&&n[0]===1&&n[1]===1||n.length===4&&n[0]===1&&n[3]===1||n.length===5&&n[0]===1&&n[1]===1))throw new Error(`For linear mode, Resize requires scales to be 2D, 3D, 4D with either two outermost or one innermost and + one outermost scale values equal to 1, or 5D with two outermost scale values equal to 1`)}else if(e.mode==="cubic"&&!(n.length===2||n.length===4&&n[0]===1&&n[1]===1||n.length===4&&n[0]===1&&n[3]===1))throw new Error("Resize requires scales input size to be 2 or 4 for cubic mode")}},JM=(n,e,r)=>{e.every(o=>o>=0&&o{throw new Error("Resize requires axes input values to be positive and less than rank")}));let t=new Array(r).fill(1);return e.forEach((o,i)=>t[o]=n[i]),t},ZM=(n,e,r,t,o,i)=>{let[a,l,d]=r>10?[1,2,3]:[-1,n.length>1?1:-1,-1],h=n[0].dims.length;if(a>0&&n.length>a&&n[a].dims.length>0)n[a].getFloat32Array().forEach(g=>i.push(g));else if(e.coordinateTransformMode==="tf_crop_and_resize")throw new Error("Resize requires RoI input to be specified when coordinateTransformMode is tfCropAndResize");if(l>0&&n.length>l&&n[l].dims.length===1&&n[l].dims[0]>0){if(n[l].getFloat32Array().forEach(g=>t.push(g)),t.length!==0&&t.length!==h&&r>=18&&t.length!==e.axes.length)throw new Error("Resize requires scales input size to be same as input rank or axes size for opset 18 and up");XM(t,e),e.axes.length>0&&JM(t,e.axes,h).forEach((g,_)=>t[_]=g)}if(d>0&&n.length>d&&n[d].dims.length===1&&n[d].dims[0]>0&&(n[d].getBigInt64Array().forEach(g=>o.push(Number(g))),o.length!==0&&o.length!==h&&r>=18&&o.length!==e.axes.length))throw new Error("Resize requires sizes input size to be same as input rank or axes size for opset 18 and up");if(e.axes.length>0){if(t.length!==0&&t.length!==e.axes.length)throw new Error('Resize requires "scales" input size to be of axes rank when axes attributes is specified');if(o.length!==0&&o.length!==e.axes.length)throw new Error('Resize requires "sizes" input size to be of rank axes rank when axes attributes is specified')}if(typeof t<"u"&&typeof o<"u"&&t.length>0&&o.length>h)throw new Error("Resize requires only of scales or sizes to be specified")},iI=(n,e,r,t)=>` + // The whole part and the fractional part are calculated separately due to inaccuracy of floating + // point division. As an example, f32(21) / f32(7) may evaluate to 2.99... instead of 3, causing an + // offset-by-one error later in floor(). + let big = (${n}) * (${e}); + let whole = ${t}(big / (${r})); + let fract = ${t}(big % (${r})) / ${t}(${r}); + return whole + fract; +`,QM=(n,e)=>`fn getOriginalCoordinateFromResizedCoordinate(xResized: u32, xScale: f32, lengthResized: u32, + lengthOriginal: u32, roiStart: f32, roiEnd: f32) -> ${e} { `+(()=>{switch(n){case"asymmetric":return` + if (xScale < 1.0 || floor(xScale) != xScale) { + return ${e}(xResized) / ${e}(xScale); + } else { + ${iI("xResized","lengthOriginal","lengthResized",e)} + } + `;case"pytorch_half_pixel":return`if (lengthResized > 1) { + return (${e}(xResized) + 0.5) / ${e}(xScale) - 0.5; + } else { + return 0.0; + }`;case"tf_half_pixel_for_nn":return`return (${e}(xResized) + 0.5) / ${e}(xScale);`;case"align_corners":return`if (lengthResized == 1) { + return 0.0; + } else { + ${iI("xResized","lengthOriginal - 1","lengthResized - 1",e)} + }`;case"tf_crop_and_resize":return`if (lengthResized > 1) { + return ${e}(roiStart) * ${e}(lengthOriginal - 1) + + (${e}(xResized) * ${e}(roiEnd - roiStart) * ${e}(lengthOriginal - 1)) / + ${e}(lengthResized - 1); + } else { + return 0.5 * ${e}(roiStart + roiEnd) * ${e}(lengthOriginal - 1); + }`;case"half_pixel_symmetric":return`const outputWidth = ${e}xScale * ${e}(lengthResized); + const adjustment = ${e}(lengthResized) / outputWidth; + const center = ${e}(lengthOriginal) / 2; + const offset = center * (1 - adjustment); + return offset + ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;case"half_pixel":return`return ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;default:throw new Error(`Coordinate transform mode ${n} is not supported`)}})()+"}",YM=(n,e,r)=>`fn getNearestPixelFromOriginal(xOriginal: ${r}, isDownSample: bool) -> ${r} {`+(()=>{switch(n){case"round_prefer_ceil":return"if (fract(xOriginal) == 0.5) { return ceil(xOriginal); } else { return round(xOriginal); }";case"floor":return"return floor(xOriginal);";case"ceil":return"return ceil(xOriginal);";case"round_prefer_floor":return"if (fract(xOriginal) == 0.5) { return floor(xOriginal); } else { return round(xOriginal); }";case"simple":default:if(e<11)return"if (isDownSample) { return ceil(xOriginal); } else { return xOriginal; }";throw new Error(`Nearest mode ${n} is not supported`)}})()+"}",eB=(n,e,r)=>{let t=new Array(r).fill(0).concat(new Array(r).fill(1)),o=n.length===0?t:n.slice();return e.length>0?(e.forEach((i,a)=>{t[i]=o[a],t[a+r]=o[e.length+a]}),t):o},tB=(n,e,r,t)=>{let o=[];if(r.length>0)if(t.length>0){if(n.forEach(i=>o.push(i)),Math.max(...t)>n.length)throw new Error("axes is out of bound");t.forEach((i,a)=>o[i]=r[a])}else r.forEach(i=>o.push(i));else{if(e.length===0)throw new Error("Resize requires either scales or sizes.");o=n.map((i,a)=>Math.round(i*e[a]))}return o},rB=(n,e,r)=>{let t=(()=>{switch(r.keepAspectRatioPolicy){case"not_larger":return r.axes.length>0?Math.min(...r.axes.map(i=>e[i]),Number.MAX_VALUE):Math.min(...e,Number.MAX_VALUE);case"not_smaller":return r.axes.length>0?Math.max(...r.axes.map(i=>e[i]),Number.MIN_VALUE):Math.max(...e,Number.MIN_VALUE);default:throw new Error(`Keep aspect ratio policy ${r.keepAspectRatioPolicy} is not supported`)}})();e.fill(1,0,e.length);let o=n.slice();return r.axes.length>0?(r.axes.forEach(i=>e[i]=t),r.axes.forEach(i=>o[i]=Math.round(n[i]*e[i]))):(e.fill(t,0,e.length),o.forEach((i,a)=>o[a]=Math.round(i*e[a]))),o},nB=(n,e,r,t,o)=>` + fn calculateOriginalIndicesFromOutputIndices(output_indices: ${n.type.indices}) -> array<${n.type.value}, ${r.length}> { + var original_indices: array<${n.type.value}, ${r.length}>; + for (var i:u32 = 0; i < ${r.length}; i++) { + var output_index = ${n.indicesGet("output_indices","i")}; + var scale = ${de("uniforms.scales","i",t)}; + var roi_low = ${de("uniforms.roi","i",o)}; + var roi_hi = ${de("uniforms.roi",`i + ${e.length}`,o)}; + if (scale == 1.0) { + original_indices[i] = ${n.type.value}(output_index); + } else { + var input_shape_i = ${de("uniforms.input_shape","i",e.length)}; + var output_shape_i = ${de("uniforms.output_shape","i",r.length)}; + original_indices[i] = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i, + input_shape_i, roi_low, roi_hi); + } + } + return original_indices; + }`,oB=(n,e,r,t,o,i,a)=>` + fn calculateInputIndicesFromOutputIndices(output_indices: ${e.type.indices}) -> ${n.type.indices} { + var input_indices: ${n.type.indices}; + for (var i:u32 = 0; i < ${t.length}; i++) { + var output_index = ${e.indicesGet("output_indices","i")}; + var input_index: u32; + var scale = ${de("uniforms.scales","i",o)}; + if (scale == 1.0) { + input_index = output_index; + } else { + var roi_low = ${de("uniforms.roi","i",i)}; + var roi_hi = ${de("uniforms.roi",`i + ${r.length}`,i)}; + var input_shape_i = ${de("uniforms.input_shape","i",r.length)}; + var output_shape_i = ${de("uniforms.output_shape","i",t.length)}; + var original_idx = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i, + input_shape_i, roi_low, roi_hi); + if (!${a} || (original_idx >= 0 && original_idx < ${e.type.value}(input_shape_i))) { + if (original_idx < 0) { + input_index = 0; + } else if (original_idx > ${e.type.value}(input_shape_i - 1)) { + input_index = input_shape_i - 1; + } else { + input_index = u32(getNearestPixelFromOriginal(original_idx, scale < 1)); + } + } else { + input_index = u32(original_idx); + } + } + ${n.indicesSet("input_indices","i","input_index")} + } + return input_indices; + }`,iB=(n,e)=>` + fn checkInputIndices(input_indices: ${n.type.indices}) -> bool { + for (var i:u32 = 0; i < ${e.length}; i++) { + var input_index = ${n.indicesGet("input_indices","i")}; + if (input_index < 0 || input_index >= ${de("uniforms.input_shape","i",e.length)}) { + return false; + } + } + return true; + }`,aI=(n,e,r,t)=>n.rank>t?` + ${n.indicesSet("input_indices",e,"channel")}; + ${n.indicesSet("input_indices",r,"batch")}; +`:"",aB=(n,e,r,t,o)=>{let[a,l,d,h]=r.length===2?[-1,0,1,-1]:[0,2,3,1],g=n.type.value;return` + fn getInputValue(batch: u32, channel: u32, row: u32, col: u32) -> ${g} { + var input_indices: ${n.type.indices}; + ${n.indicesSet("input_indices",l,`max(0, min(row, ${r[l]} - 1))`)}; + ${n.indicesSet("input_indices",d,`max(0, min(col, ${r[d]} - 1))`)}; + ${aI(n,h,a,2)} + return ${n.getByIndices("input_indices")}; + } + + fn bilinearInterpolation(output_indices: ${e.type.indices}) -> ${g} { + var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices); + var row:${g} = originalIndices[${l}]; + var col:${g} = originalIndices[${d}]; + ${t?`if (row < 0 || row > (${r[l]} - 1) || col < 0 || col > (${r[d]} - 1)) { + return ${o}; + }`:""}; + row = max(0, min(row, ${r[l]} - 1)); + col = max(0, min(col, ${r[d]} - 1)); + var row1: u32 = u32(row); + var col1: u32 = u32(col); + var row2: u32 = u32(row + 1); + var col2: u32 = u32(col + 1); + var channel: u32 = ${r.length>2?`u32(originalIndices[${h}])`:"0"}; + var batch: u32 = ${r.length>2?`u32(originalIndices[${a}])`:"0"}; + var x11: ${g} = getInputValue(batch, channel, row1, col1); + var x12: ${g} = getInputValue(batch, channel, row1, col2); + var x21: ${g} = getInputValue(batch, channel, row2, col1); + var x22: ${g} = getInputValue(batch, channel, row2, col2); + var dx1: ${g} = abs(row - ${g}(row1)); + var dx2: ${g} = abs(${g}(row2) - row); + var dy1: ${g} = abs(col - ${g}(col1)); + var dy2: ${g} = abs(${g}(col2) - col); + if (row1 == row2) { + dx1 = 0.5; + dx2 = 0.5; + } + if (col1 == col2) { + dy1 = 0.5; + dy2 = 0.5; + } + return (x11 * dx2 * dy2 + x12 * dx2 * dy1 + x21 * dx1 * dy2 + x22 * dx1 * dy1); + }`},sB=(n,e,r,t,o,i,a,l,d,h)=>{let g=r.length===2,_=!0,[w,x]=g?[0,1]:_?[2,3]:[1,2],T=n.type.value,S=P=>{let A=P===w?"row":"col";return` + fn ${A}CubicInterpolation(input_indices: ${n.type.indices}, output_indices: ${e.type.indices}) -> ${T} { + var output_index = ${e.indicesGet("output_indices",P)}; + var originalIdx: ${T} = getOriginalCoordinateFromResizedCoordinate(output_index, ${o[P]}, + ${t[P]}, ${r[P]}, ${i[P]}, ${i[P]} + ${r.length}); + var fractOriginalIdx: ${T} = originalIdx - floor(originalIdx); + var coefs = getCubicInterpolationCoefs(fractOriginalIdx); + + if (${l} && (originalIdx < 0 || originalIdx > (${r[P]} - 1))) { + return ${d}; + } + var data: array<${T}, 4> = array<${T}, 4>(0.0, 0.0, 0.0, 0.0); + for (var i: i32 = -1; i < 3; i++) { + var ${A}: ${T} = originalIdx + ${T}(i); + if (${A} < 0 || ${A} >= ${r[P]}) { + ${h?`coefs[i + 1] = 0.0; + continue;`:l?`return ${d};`:`${A} = max(0, min(${A}, ${r[P]} - 1));`}; + } + var input_indices_copy: ${n.type.indices} = input_indices; + ${n.indicesSet("input_indices_copy",P,`u32(${A})`)}; + data[i + 1] = ${P===w?n.getByIndices("input_indices_copy"):"rowCubicInterpolation(input_indices_copy, output_indices)"}; + } + return cubicInterpolation1D(data, coefs); + }`};return` + ${S(w)}; + ${S(x)}; + fn getCubicInterpolationCoefs(s: ${T}) -> array<${T}, 4> { + var absS = abs(s); + var coeffs: array<${T}, 4> = array<${T}, 4>(0.0, 0.0, 0.0, 0.0); + var oneMinusAbsS: ${T} = 1.0 - absS; + var twoMinusAbsS: ${T} = 2.0 - absS; + var onePlusAbsS: ${T} = 1.0 + absS; + coeffs[0] = ((${a} * onePlusAbsS - 5 * ${a}) * onePlusAbsS + 8 * ${a}) * onePlusAbsS - 4 * ${a}; + coeffs[1] = ((${a} + 2) * absS - (${a} + 3)) * absS * absS + 1; + coeffs[2] = ((${a} + 2) * oneMinusAbsS - (${a} + 3)) * oneMinusAbsS * oneMinusAbsS + 1; + coeffs[3] = ((${a} * twoMinusAbsS - 5 * ${a}) * twoMinusAbsS + 8 * ${a}) * twoMinusAbsS - 4 * ${a}; + return coeffs; + } + + fn cubicInterpolation1D(x: array<${T}, 4>, coefs: array<${T}, 4>) -> ${T} { + var coefsSum: ${T} = coefs[0] + coefs[1] + coefs[2] + coefs[3]; + return (x[0] * coefs[0] + x[1] * coefs[1]+ x[2] * coefs[2]+ x[3] * coefs[3]) / coefsSum; + } + + fn bicubicInterpolation(output_indices: ${e.type.indices}) -> ${T} { + var input_indices: ${n.type.indices} = output_indices; + return colCubicInterpolation(input_indices, output_indices); + } + `},uB=(n,e,r,t,o)=>{let[a,l,d,h,g]=r.length===3?[-1,0,1,2,-1]:[0,2,3,4,1],_=n.type.value;return` + fn getInputValue(batch: u32, channel: u32, depth:u32, height: u32, width: u32) -> ${_} { + var input_indices: ${n.type.indices}; + ${n.indicesSet("input_indices",l,`max(0, min(depth, ${r[l]} - 1))`)}; + ${n.indicesSet("input_indices",d,`max(0, min(height, ${r[d]} - 1))`)}; + ${n.indicesSet("input_indices",h,`max(0, min(width, ${r[h]} - 1))`)}; + ${aI(n,g,a,3)} + return ${n.getByIndices("input_indices")}; + } + + fn trilinearInterpolation(output_indices: ${e.type.indices}) -> ${_} { + var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices); + var depth:${_} = originalIndices[${l}]; + var height:${_} = originalIndices[${d}]; + var width:${_} = originalIndices[${h}]; + ${t?`if (depth < 0 || depth > (${r[l]} - 1) || height < 0 || height > (${r[d]} - 1) || width < 0 || (width > ${r[h]} - 1)) { + return ${o}; + }`:""}; + + depth = max(0, min(depth, ${r[l]} - 1)); + height = max(0, min(height, ${r[d]} - 1)); + width = max(0, min(width, ${r[h]} - 1)); + var depth1: u32 = u32(depth); + var height1: u32 = u32(height); + var width1: u32 = u32(width); + var depth2: u32 = u32(depth + 1); + var height2: u32 = u32(height + 1); + var width2: u32 = u32(width + 1); + var channel: u32 = ${r.length>3?`u32(originalIndices[${g}])`:"0"}; + var batch: u32 = ${r.length>3?`u32(originalIndices[${a}])`:"0"}; + + var x111: ${_} = getInputValue(batch, channel, depth1, height1, width1); + var x112: ${_} = getInputValue(batch, channel, depth1, height1, width2); + var x121: ${_} = getInputValue(batch, channel, depth1, height2, width1); + var x122: ${_} = getInputValue(batch, channel, depth1, height2, width2); + var x211: ${_} = getInputValue(batch, channel, depth2, height1, width1); + var x212: ${_} = getInputValue(batch, channel, depth2, height1, width2); + var x221: ${_} = getInputValue(batch, channel, depth2, height2, width1); + var x222: ${_} = getInputValue(batch, channel, depth2, height2, width2); + var dx1: ${_} = abs(depth - ${_}(depth1)); + var dx2: ${_} = abs(${_}(depth2) - depth); + var dy1: ${_} = abs(height - ${_}(height1)); + var dy2: ${_} = abs(${_}(height2) - height); + var dz1: ${_} = abs(width - ${_}(width1)); + var dz2: ${_} = abs(${_}(width2) - width); + if (depth1 == depth2) { + dx1 = 0.5; + dx2 = 0.5; + } + if (height1 == height2) { + dy1 = 0.5; + dy2 = 0.5; + } + if (width1 == width2) { + dz1 = 0.5; + dz2 = 0.5; + } + return (x111 * dx2 * dy2 * dz2 + x112 * dx2 * dy2 * dz1 + x121 * dx2 * dy1 *dz2 + x122 * dx2 * dy1 * dz1 + + x211 * dx1 * dy2 * dz2 + x212 * dx1 * dy2 * dz1 + x221 * dx1 * dy1 *dz2 + x222 * dx1 * dy1 * dz1); + }`},lB=(n,e,r,t,o,i)=>{let a=n.dims,l=eB(i,e.axes,a.length),d=tB(a,t,o,e.axes),h=t.slice();t.length===0&&(h=a.map((O,E)=>O===0?1:d[E]/O),e.keepAspectRatioPolicy!=="stretch"&&(d=rB(a,h,e)));let g=te("output",n.dataType,d.length),_=J("input",n.dataType,a.length),w=W.size(d),x=a.length===d.length&&a.every((O,E)=>O===d[E]),T=e.coordinateTransformMode==="tf_crop_and_resize",S=e.extrapolationValue,P=_.type.value,A=O=>` + ${x?"":` + ${QM(e.coordinateTransformMode,P)}; + ${(()=>{switch(e.mode){case"nearest":return` + ${iB(_,a)}; + ${YM(e.nearestMode,r,P)}; + ${oB(_,g,a,d,h.length,l.length,T)}; + `;case"linear":return` + ${nB(g,a,d,h.length,l.length)}; + ${(()=>{if(a.length===2||a.length===4)return`${aB(_,g,a,T,S)}`;if(a.length===3||a.length===5)return`${uB(_,g,a,T,S)}`;throw Error("Linear mode only supports input dims 2, 3, 4 and 5 are supported in linear mode.")})()}; + `;case"cubic":return` + ${(()=>{if(a.length===2||a.length===4)return`${sB(_,g,a,d,h,l,e.cubicCoeffA,T,e.extrapolationValue,e.excludeOutside)}`;throw Error("Cubic mode only supports input dims 2 and 4 are supported in linear mode.")})()}; + `;default:throw Error("Invalid resize mode")}})()}; + `} + ${O.registerUniform("output_size","u32").registerUniform("scales","f32",h.length).registerUniform("roi","f32",l.length).declareVariables(_,g)} + ${O.mainStart()} + ${O.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + ${x?"output[global_idx] = input[global_idx];":` + let output_indices = ${g.offsetToIndices("global_idx")}; + var input_indices: ${_.type.indices}; + ${(()=>{switch(e.mode){case"nearest":return`input_indices = calculateInputIndicesFromOutputIndices(output_indices); + if (checkInputIndices(input_indices)) { + output[global_idx] = ${_.getByIndices("input_indices")}; + } else { + output[global_idx] = ${e.extrapolationValue}; + }`;case"linear":return`output[global_idx] = ${a.length===2||a.length===4?"bilinearInterpolation":"trilinearInterpolation"}(output_indices);`;case"cubic":return"output[global_idx] = bicubicInterpolation(output_indices);";default:throw Error(`Unsupported resize mode: ${e.mode}`)}})()}; +`} + }`;return{name:"Resize",shaderCache:{hint:`${e.cacheKey}|${r}|${h.length>0?e.mode==="cubic"?h:h.length:""}|${o.length>0?o:""}|${l.length>0?l:""}|${x}|${e.mode==="nearest"?a.length:a}`,inputDependencies:["rank"]},getShaderSource:A,getRunData:()=>({outputs:[{dims:d,dataType:n.dataType}],dispatchGroup:{x:Math.ceil(w/64)},programUniforms:[{type:12,data:w},{type:1,data:h},{type:1,data:l},...ne(a,d)]})}},cB=n=>{let e=n.customDataBuffer;return new Uint32Array(e,e.byteOffset,1)[0]},sI=(n,e)=>{let r=[],t=[],o=[],i=cB(n);if(e.antialias!==0)throw Error("Only default value (0) for Antialias attribute is supported");ZM(n.inputs,e,i,r,t,o),n.compute(lB(n.inputs[0],e,i,r,t,o),{inputs:[0]})},uI=n=>{let e=n.antialias,r=n.axes,t=n.coordinateTransformMode,o=n.cubicCoeffA,i=n.excludeOutside!==0,a=n.extrapolationValue,l=n.keepAspectRatioPolicy,d=n.mode,h=n.nearestMode===""?"simple":n.nearestMode;return we({antialias:e,axes:r,coordinateTransformMode:t,cubicCoeffA:o,excludeOutside:i,extrapolationValue:a,keepAspectRatioPolicy:l,mode:d,nearestMode:h})}});var dB,pB,cI,dI=H(()=>{"use strict";ve();Oe();Pe();dB=n=>{if(!n||n.length<3)throw new Error("layerNorm requires at least 3 inputs.");let e=n[0],r=n[1],t=n[2];if(e.dataType!==r.dataType||e.dataType!==t.dataType)throw new Error("All inputs must have the same data type");if(e.dims.length!==3&&e.dims.length!==2)throw new Error("Input must be 2D or 3D");if(r.dims.length!==3&&r.dims.length!==2)throw new Error("Skip must be 2D or 3D");let o=e.dims[e.dims.length-1],i=e.dims[e.dims.length-2];if(r.dims[r.dims.length-1]!==o)throw new Error("Skip must have the same hidden size as input");if(r.dims[r.dims.length-2]!==i)throw new Error("Skip must have the same sequence length as input");if(t.dims.length!==1)throw new Error("Gamma must be 1D");if(t.dims[t.dims.length-1]!==o)throw new Error("Gamma must have the same hidden size as input");if(n.length>3){let a=n[3];if(a.dims.length!==1)throw new Error("Beta must be 1D");if(a.dims[a.dims.length-1]!==o)throw new Error("Beta must have the same hidden size as input")}if(n.length>4){let a=n[4];if(a.dims.length!==1)throw new Error("Bias must be 1D");if(a.dims[a.dims.length-1]!==o)throw new Error("Bias must have the same hidden size as input")}},pB=(n,e,r,t)=>{let o=e.simplified,i=n[0].dims,a=W.size(i),l=i,d=a,h=i.slice(-1)[0],g=t?i.slice(0,-1).concat(1):[],_=!o&&n.length>3,w=n.length>4,x=t&&r>1,T=t&&r>2,S=r>3,P=64,A=Ge(h),O=[{type:12,data:d},{type:12,data:A},{type:12,data:h},{type:1,data:e.epsilon}],E=z=>{let B=[{name:"output_size",type:"u32"},{name:"components",type:"u32"},{name:"hidden_size",type:"u32"},{name:"epsilon",type:"f32"}],K=[J("x",n[0].dataType,n[0].dims,A),J("skip",n[1].dataType,n[1].dims,A),J("gamma",n[2].dataType,n[2].dims,A)];_&&K.push(J("beta",n[3].dataType,n[3].dims,A)),w&&K.push(J("bias",n[4].dataType,n[4].dims,A)),K.push(te("output",n[0].dataType,l,A)),x&&K.push(te("mean_output",1,g)),T&&K.push(te("inv_std_output",1,g)),S&&K.push(te("input_skip_bias_sum",n[0].dataType,l,A));let Z=et(n[0].dataType),ee=et(1,A);return` + + ${z.registerUniforms(B).declareVariables(...K)} + var sum_shared : array<${ee}, ${P}>; + var sum_squared_shared : array<${ee}, ${P}>; + + ${z.mainStart([P,1,1])} + let ix = local_id.x; + let iy = global_id.x / ${P}; + + let hidden_size_vectorized: u32 = uniforms.hidden_size / uniforms.components; + var stride = hidden_size_vectorized / ${P}; + let offset = ix * stride + iy * hidden_size_vectorized; + let offset1d = stride * ix; + if (ix == ${P-1}) { + stride = hidden_size_vectorized - stride * ix; + } + for (var i: u32 = 0; i < stride; i++) { + let skip_value = skip[offset + i]; + let bias_value = ${w?"bias[offset1d + i]":Z+"(0.0)"}; + let input_value = x[offset + i]; + let value = input_value + skip_value + bias_value; + ${S?"input_skip_bias_sum[offset + i] = value;":""} + output[offset + i] = value; + let f32_value = ${ro(Z,A,"value")}; + sum_shared[ix] += f32_value; + sum_squared_shared[ix] += f32_value * f32_value; + } + workgroupBarrier(); + + var reduce_size : u32 = ${P}; + for (var curr_size = reduce_size >> 1; curr_size > 0; curr_size = reduce_size >> 1) { + reduce_size = curr_size + (reduce_size & 1); + if (ix < curr_size) { + sum_shared[ix] += sum_shared[ix + reduce_size]; + sum_squared_shared[ix] += sum_squared_shared[ix + reduce_size]; + } + workgroupBarrier(); + } + + let sum = sum_shared[0]; + let square_sum = sum_squared_shared[0]; + let mean = ${lr("sum",A)} / f32(uniforms.hidden_size); + let inv_std_dev = inverseSqrt(${lr("square_sum",A)} / f32(uniforms.hidden_size) ${o?"":"- mean * mean"} + uniforms.epsilon); + ${x?"mean_output[global_idx] = mean;":""} + ${T?"inv_std_output[global_idx] = inv_std_dev;":""} + + for (var i: u32 = 0; i < stride; i++) { + output[offset + i] = (output[offset + i] ${o?"":`- ${Z}(mean)`}) * + ${Z}(inv_std_dev) * gamma[offset1d + i] + ${_?"+ beta[offset1d + i]":""}; + } + }`},L=[{dims:l,dataType:n[0].dataType}];return r>1&&L.push({dims:g,dataType:1}),r>2&&L.push({dims:g,dataType:1}),r>3&&L.push({dims:i,dataType:n[0].dataType}),{name:"SkipLayerNormalization",shaderCache:{hint:`${A};${x};${T};${S}`,inputDependencies:n.map((z,B)=>"type")},getShaderSource:E,getRunData:()=>({outputs:L,dispatchGroup:{x:Math.ceil(d/h)},programUniforms:O})}},cI=(n,e)=>{dB(n.inputs);let t=[0];n.outputCount>1&&t.push(-3),n.outputCount>2&&t.push(-3),n.outputCount>3&&t.push(3),n.compute(pB(n.inputs,e,n.outputCount,!1),{outputs:t})}});var fB,ps,hB,pI,mB,gB,fI,hI,mI=H(()=>{"use strict";ve();Oe();ft();Pe();fB=(n,e)=>{if(!n||n.length<1)throw new Error("too few inputs");if(e.axes.length!==0){if(e.axes.length!==e.starts.length||e.axes.length!==e.ends.length)throw new Error("axes, starts and ends must have the same length")}else if(e.starts.length!==e.ends.length)throw new Error("starts and ends must have the same length");n.slice(1).forEach((r,t)=>{if(n[t+1].dataType!==6&&n[t+1].dataType!==7)throw new Error(`Input ${t} must be an array of int32 or int64`)})},ps=(n,e)=>{let r=[];if(n.length>e)if(n[e].dataType===7)n[e].getBigInt64Array().forEach(t=>r.push(Number(t)));else if(n[e].dataType===6)n[e].getInt32Array().forEach(t=>r.push(Number(t)));else throw new Error(`Input ${e} must be an array of int32 or int64`);return r},hB=(n,e)=>{if(n.length>1){let r=ps(n,1),t=ps(n,2),o=ps(n,3);return o.length===0&&(o=[...Array(n[0].dims.length).keys()]),we({starts:r,ends:t,axes:o})}else return e},pI=(n,e,r,t,o)=>{let i=n;return n<0&&(i+=r[t[e]]),o[e]<0?Math.max(0,Math.min(i,r[t[e]]-1)):Math.max(0,Math.min(i,r[t[e]]))},mB=(n,e,r)=>`fn calculateInputIndices(output_indices: ${e.type.indices}) -> ${n.type.indices} { + var input_indices: ${n.type.indices}; + var carry = 0u; + for (var i = ${r.length}; i >= 0; i--) { + let input_shape_i = ${de("uniforms.input_shape","i",r.length)}; + let steps_i = ${de("uniforms.steps","i",r.length)}; + let signs_i = ${de("uniforms.signs","i",r.length)}; + let starts_i = ${de("uniforms.starts","i",r.length)}; + var output_index = ${e.indicesGet("output_indices","i")}; + var input_index = output_index * steps_i + starts_i + carry; + carry = input_index / input_shape_i; + input_index = input_index % input_shape_i; + if (signs_i < 0) { + input_index = input_shape_i - input_index - 1u + starts_i; + } + ${n.indicesSet("input_indices","i","input_index")}; + } + return input_indices; + }`,gB=(n,e)=>{let r=n[0].dims,t=W.size(r),o=e.axes.length>0?W.normalizeAxes(e.axes,r.length):[...Array(r.length).keys()],i=ps(n,4);i.forEach(A=>A!==0||(()=>{throw new Error("step cannot be 0")})),i.length===0&&(i=Array(o.length).fill(1));let a=e.starts.map((A,O)=>pI(A,O,r,o,i)),l=e.ends.map((A,O)=>pI(A,O,r,o,i));if(o.length!==a.length||o.length!==l.length)throw new Error("start, ends and axes should have the same number of elements");if(o.length!==r.length)for(let A=0;AMath.sign(A));i.forEach((A,O,E)=>{if(A<0){let L=(l[O]-a[O])/A,z=a[O],B=z+L*i[O];a[O]=B,l[O]=z,E[O]=-A}});let h=r.slice(0);o.forEach((A,O)=>{h[A]=Math.ceil((l[A]-a[A])/i[A])});let g={dims:h,dataType:n[0].dataType},_=te("output",n[0].dataType,h.length),w=J("input",n[0].dataType,n[0].dims.length),x=W.size(h),T=[{name:"outputSize",type:"u32"},{name:"starts",type:"u32",length:a.length},{name:"signs",type:"i32",length:d.length},{name:"steps",type:"u32",length:i.length}],S=[{type:12,data:x},{type:12,data:a},{type:6,data:d},{type:12,data:i},...ne(n[0].dims,h)],P=A=>` + ${A.registerUniforms(T).declareVariables(w,_)} + ${mB(w,_,r)} + ${A.mainStart()} + ${A.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} + let output_indices = ${_.offsetToIndices("global_idx")}; + let input_indices = calculateInputIndices(output_indices); + ${_.setByOffset("global_idx",w.getByIndices("input_indices"))} + }`;return{name:"Slice",shaderCache:{hint:`${d.length}_${a.length}_${i.length}`,inputDependencies:["rank"]},getShaderSource:P,getRunData:()=>({outputs:[g],dispatchGroup:{x:Math.ceil(t/64)},programUniforms:S})}},fI=(n,e)=>{fB(n.inputs,e);let r=hB(n.inputs,e);n.compute(gB(n.inputs,r),{inputs:[0]})},hI=n=>{let e=n.starts,r=n.ends,t=n.axes;return we({starts:e,ends:r,axes:t})}});var bB,yB,gI,bI,yI=H(()=>{"use strict";ve();Oe();ft();fn();Pe();bB=n=>{if(!n||n.length!==1)throw new Error("Softmax op requires 1 input.")},yB=(n,e)=>{let r=n.inputs[0],t=r.dims,o=W.size(t),i=t.length,a=W.normalizeAxis(e.axis,i),l=aZ),h[a]=i-1,h[i-1]=a,d=n.compute(wt(r,h),{inputs:[r],outputs:[-1]})[0]):d=r;let g=d.dims,_=g[i-1],w=o/_,x=Ge(_),T=_/x,S=64;w===1&&(S=256);let P=(K,Z)=>Z===4?`max(max(${K}.x, ${K}.y), max(${K}.z, ${K}.w))`:Z===2?`max(${K}.x, ${K}.y)`:Z===3?`max(max(${K}.x, ${K}.y), ${K}.z)`:K,A=J("x",d.dataType,d.dims,x),O=te("result",d.dataType,d.dims,x),E=A.type.value,L=et(d.dataType)==="f32"?`var threadMax = ${E}(-3.402823e+38f);`:`var threadMax = ${E}(-65504.0h);`,z=K=>` + var rowMaxShared : ${E}; + var rowSumShared : ${E}; + var threadShared : array<${E}, ${S}>; + + fn getValue(row: i32, col: i32, row_stride: i32) -> ${E} { + let index = row * row_stride + col; + return x[index]; + } + + fn setValue(row: i32, col: i32, row_stride: i32, value: ${E}) { + let index = row * row_stride + col; + result[index] = value; + } + ${K.registerUniform("packedCols","i32").declareVariables(A,O)} + ${K.mainStart(S)} + let gindex = i32(global_idx); + let lindex = i32(local_idx); + const wg = ${S}; + let row = gindex / wg; + let cols = uniforms.packedCols; + let row_stride : i32 = uniforms.packedCols; + + // find the rows max + ${L} + for (var col = lindex; col < cols; col += wg) { + let value = getValue(row, col, row_stride); + threadMax = max(threadMax, value); + } + if (lindex < cols) { + threadShared[lindex] = threadMax; + } + workgroupBarrier(); + + var reduceSize = min(cols, wg); + for (var currSize = reduceSize >> 1; currSize > 0; currSize = reduceSize >> 1) { + reduceSize = currSize + (reduceSize & 1); + if (lindex < currSize) { + threadShared[lindex] = max(threadShared[lindex], threadShared[lindex + reduceSize]); + } + workgroupBarrier(); + } + if (lindex == 0) { + rowMaxShared = ${E}(${P("threadShared[0]",x)}); + } + workgroupBarrier(); + + // find the rows sum + var threadSum = ${E}(0.0); + for (var col = lindex; col < cols; col += wg) { + let subExp = exp(getValue(row, col, row_stride) - rowMaxShared); + threadSum += subExp; + } + threadShared[lindex] = threadSum; + workgroupBarrier(); + + for (var currSize = wg >> 1; currSize > 0; currSize = currSize >> 1) { + if (lindex < currSize) { + threadShared[lindex] = threadShared[lindex] + threadShared[lindex + currSize]; + } + workgroupBarrier(); + } + if (lindex == 0) { + rowSumShared = ${E}(${lr("threadShared[0]",x)}); + } + workgroupBarrier(); + + // calculate final value for each element in the row + for (var col = lindex; col < cols; col += wg) { + let value = exp(getValue(row, col, row_stride) - rowMaxShared) / rowSumShared; + setValue(row, col, row_stride, value); + } + }`,B=n.compute({name:"Softmax",shaderCache:{hint:`${x};${S}`,inputDependencies:["type"]},getRunData:()=>({outputs:[{dims:g,dataType:d.dataType}],dispatchGroup:{x:w},programUniforms:[{type:6,data:T}]}),getShaderSource:z},{inputs:[d],outputs:[l?-1:0]})[0];l&&n.compute(wt(B,h),{inputs:[B]})},gI=(n,e)=>{bB(n.inputs),yB(n,e)},bI=n=>we({axis:n.axis})});var _I,_B,vB,wB,vI,wI=H(()=>{"use strict";ve();Oe();Pe();_I=n=>Array.from(n.getBigInt64Array(),Number),_B=n=>{if(!n||n.length!==2)throw new Error("Tile requires 2 inputs.");if(n[0].dataType!==1&&n[0].dataType!==10&&n[0].dataType!==6&&n[0].dataType!==12)throw new Error("Tile only support float, float16, int32, and uint32 data types");if(n[1].dataType!==7)throw new Error("Tile `repeats` input should be of int64 data type");if(n[1].dims.length!==1)throw new Error("Tile `repeats` input should be 1-D");if(_I(n[1]).length!==n[0].dims.length)throw new Error("Tile `repeats` input should have same number of elements as rank of input data tensor")},vB=(n,e)=>{let r=[];for(let t=0;t{let r=n[0].dims,t=e??_I(n[1]),o=vB(r,t),i=W.size(o),a=n[0].dataType,l=J("input",a,r.length),d=te("output",a,o.length),h=g=>` + const inputShape = ${l.indices(...r)}; + ${g.registerUniform("output_size","u32").declareVariables(l,d)} + ${g.mainStart()} + ${g.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} + let output_indices = ${d.offsetToIndices("global_idx")}; + var input_indices: ${l.type.indices}; + for (var i = 0; i < ${r.length}; i++) { + let input_dim_i = ${l.indicesGet("uniforms.input_shape","i")}; + let input_dim_value = ${d.indicesGet("output_indices","i")} % input_dim_i; + + ${l.indicesSet("input_indices","i","input_dim_value")} + } + ${d.setByOffset("global_idx",l.getByIndices("input_indices"))} + }`;return{name:"Tile",shaderCache:{hint:`${t}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:o,dataType:n[0].dataType}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:[{type:12,data:i},...ne(n[0].dims,o)]}),getShaderSource:h}},vI=n=>{_B(n.inputs),n.compute(wB(n.inputs),{inputs:[0]})}});var xB,TB,xI,TI=H(()=>{"use strict";ve();Oe();Pe();xB=(n,e,r,t,o)=>{let i=te("output_data",o,r.length,4),a=J("a_data",e[1].dataType,e[1].dims.length,4),l=J("b_data",e[2].dataType,e[2].dims.length,4),d=J("c_data",e[0].dataType,e[0].dims.length,4),h,g=(_,w,x)=>`select(${w}, ${_}, ${x})`;if(!t)h=i.setByOffset("global_idx",g(a.getByOffset("global_idx"),l.getByOffset("global_idx"),d.getByOffset("global_idx")));else{let _=(w,x,T="")=>{let S=`a_data[index_a${x}][component_a${x}]`,P=`b_data[index_b${x}][component_b${x}]`,A=`bool(c_data[index_c${x}] & (0xffu << (component_c${x} * 8)))`;return` + let output_indices${x} = ${i.offsetToIndices(`global_idx * 4u + ${x}u`)}; + let offset_a${x} = ${a.broadcastedIndicesToOffset(`output_indices${x}`,i)}; + let offset_b${x} = ${l.broadcastedIndicesToOffset(`output_indices${x}`,i)}; + let offset_c${x} = ${d.broadcastedIndicesToOffset(`output_indices${x}`,i)}; + let index_a${x} = offset_a${x} / 4u; + let index_b${x} = offset_b${x} / 4u; + let index_c${x} = offset_c${x} / 4u; + let component_a${x} = offset_a${x} % 4u; + let component_b${x} = offset_b${x} % 4u; + let component_c${x} = offset_c${x} % 4u; + ${w}[${x}] = ${T}(${g(S,P,A)}); + `};o===9?h=` + var data = vec4(0); + ${_("data",0,"u32")} + ${_("data",1,"u32")} + ${_("data",2,"u32")} + ${_("data",3,"u32")} + output_data[global_idx] = dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(data));`:h=` + ${_("output_data[global_idx]",0)} + ${_("output_data[global_idx]",1)} + ${_("output_data[global_idx]",2)} + ${_("output_data[global_idx]",3)} + `}return` + ${n.registerUniform("vec_size","u32").declareVariables(d,a,l,i)} + ${n.mainStart()} + ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} + ${h} + }`},TB=n=>{let e=n[1].dims,r=n[2].dims,t=n[0].dims,o=n[1].dataType,i=!(W.areEqual(e,r)&&W.areEqual(r,t)),a=e,l=W.size(e);if(i){let h=rn.calcShape(rn.calcShape(e,r,!1),t,!1);if(!h)throw new Error("Can't perform where op on the given tensors");a=h,l=W.size(a)}let d=Math.ceil(l/4);return{name:"Where",shaderCache:{inputDependencies:["rank","rank","rank"]},getShaderSource:h=>xB(h,n,a,i,o),getRunData:()=>({outputs:[{dims:a,dataType:o}],dispatchGroup:{x:Math.ceil(l/64/4)},programUniforms:[{type:12,data:d},...ne(t,e,r,a)]})}},xI=n=>{n.compute(TB(n.inputs))}});var II,SI=H(()=>{"use strict";iT();es();uT();cT();XT();a1();l1();S1();D1();L1();M1();G1();H1();K1();Z1();e2();n2();a2();l2();p2();w2();I2();$2();O2();E2();ld();k2();J2();Y2();tI();oI();Qa();lI();pd();dI();mI();yI();dd();wI();fn();rs();TI();II=new Map([["Abs",[dT]],["Acos",[pT]],["Acosh",[fT]],["Add",[JT]],["ArgMax",[oT,Jc]],["ArgMin",[nT,Jc]],["Asin",[hT]],["Asinh",[mT]],["Atan",[gT]],["Atanh",[bT]],["Attention",[aT]],["AveragePool",[V2,F2]],["BatchNormalization",[sT]],["BiasAdd",[lT]],["BiasSplitGelu",[KT]],["Cast",[_T,yT]],["Ceil",[wT]],["Clip",[vT]],["Concat",[s1,u1]],["Conv",[id,od]],["ConvTranspose",[E1,C1]],["Cos",[xT]],["Cosh",[TT]],["CumSum",[k1,N1]],["DepthToSpace",[R1,z1]],["DequantizeLinear",[Z2,Q2]],["Div",[ZT]],["Einsum",[V1,j1]],["Elu",[IT,oi]],["Equal",[QT]],["Erf",[ST]],["Exp",[$T]],["Expand",[W1]],["FastGelu",[q1]],["Floor",[AT]],["FusedConv",[id,od]],["Gather",[J1,X1]],["GatherElements",[i2,o2]],["GatherBlockQuantized",[t2,r2]],["GatherND",[Q1,Y1]],["Gelu",[OT]],["Gemm",[u2,s2]],["GlobalAveragePool",[U2,G2]],["GlobalMaxPool",[X2,K2]],["Greater",[r1]],["GreaterOrEqual",[o1]],["GridSample",[c2,d2]],["GroupQueryAttention",[v2]],["HardSigmoid",[RT,LT]],["InstanceNormalization",[T2]],["LayerNormalization",[S2]],["LeakyRelu",[CT,oi]],["Less",[n1]],["LessOrEqual",[i1]],["Log",[WT]],["MatMul",[A2]],["MatMulNBits",[C2,P2]],["MaxPool",[H2,q2]],["Mul",[YT]],["MultiHeadAttention",[m2,h2]],["Neg",[ET]],["Not",[PT]],["Pad",[D2]],["Pow",[e1]],["QuickGelu",[HT,oi]],["Range",[eI]],["Reciprocal",[DT]],["ReduceMin",[Zx]],["ReduceMean",[Hx]],["ReduceMax",[Jx]],["ReduceSum",[Yx]],["ReduceProd",[Qx]],["ReduceL1",[qx]],["ReduceL2",[Kx]],["ReduceLogSum",[tT]],["ReduceLogSumExp",[Xx]],["ReduceSumSquare",[eT]],["Relu",[kT]],["Resize",[sI,uI]],["RotaryEmbedding",[y2]],["ScatterND",[nI,rI]],["Sigmoid",[NT]],["Sin",[zT]],["Sinh",[MT]],["Slice",[fI,hI]],["SkipLayerNormalization",[cI]],["Split",[g2,b2]],["Sqrt",[BT]],["Softmax",[gI,bI]],["Sub",[t1]],["Tan",[FT]],["Tanh",[jT]],["ThresholdedRelu",[UT,oi]],["Tile",[vI]],["Transpose",[kx,Nx]],["Where",[xI]]])});var fs,$I=H(()=>{"use strict";At();tn();Pe();fs=class{constructor(e){this.backend=e;this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,r){this.repo.set(e,r)}run(e,r,t,o,i){Ft(e.programInfo.name);let a=this.backend.device,l=this.backend.getComputePassEncoder();this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2);let d=[];for(let g of r)d.push({binding:d.length,resource:{buffer:g.buffer}});for(let g of t)d.push({binding:d.length,resource:{buffer:g.buffer}});i&&d.push({binding:d.length,resource:i});let h=a.createBindGroup({layout:e.computePipeline.getBindGroupLayout(0),entries:d,label:e.programInfo.name});if(this.backend.sessionStatus==="capturing"){let g={kernelId:this.backend.currentKernelId,computePipeline:e.computePipeline,bindGroup:h,dispatchGroup:o};this.backend.capturedCommandList.get(this.backend.currentSessionId).push(g)}l.setPipeline(e.computePipeline),l.setBindGroup(0,h),l.dispatchWorkgroups(...o),this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2+1),this.backend.pendingDispatchNumber++,(this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber||this.backend.queryType==="at-passes")&&this.backend.endComputePass(),this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber&&this.backend.flush(),Dt(e.programInfo.name)}dispose(){}build(e,r){Ft(e.name);let t=this.backend.device,o=[];[{feature:"shader-f16",extension:"f16"},{feature:"subgroups",extension:"subgroups"}].forEach(_=>{t.features.has(_.feature)&&o.push(`enable ${_.extension};`)});let a=Ex(r,this.backend.device.limits),l=e.getShaderSource(a),d=`${o.join(` +`)} +${a.additionalImplementations} +${l}`,h=t.createShaderModule({code:d,label:e.name});ke("verbose",()=>`[WebGPU] ${e.name} shader code: ${d}`);let g=t.createComputePipeline({compute:{module:h,entryPoint:"main"},layout:"auto",label:e.name});return Dt(e.name),{programInfo:e,computePipeline:g,uniformVariablesInfo:a.variablesInfo}}normalizeDispatchGroupSize(e){let r=typeof e=="number"?e:e.x,t=typeof e=="number"?1:e.y||1,o=typeof e=="number"?1:e.z||1,i=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(r<=i&&t<=i&&o<=i)return[r,t,o];let a=r*t*o,l=Math.ceil(Math.sqrt(a));if(l>i){if(l=Math.ceil(Math.cbrt(a)),l>i)throw new Error("Total dispatch size exceeds WebGPU maximum.");return[l,l,l]}else return[l,l,1]}}});var AI={};zn(AI,{WebGpuBackend:()=>hd});var IB,SB,fd,hd,OI=H(()=>{"use strict";At();ve();tn();Mc();Cx();SI();$I();IB=(n,e)=>{if(e.length!==n.length)throw new Error(`inputDependencies length ${e.length} is not equal to inputTensors length ${n.length}.`);let r=[];for(let t=0;t{let t=n.name;return n.shaderCache?.hint&&(t+="["+n.shaderCache.hint+"]"),t+=":"+r+`:${IB(e,n.shaderCache?.inputDependencies??new Array(e.length).fill("dims"))}`,t},fd=class{constructor(e){e&&(this.architecture=e.architecture,this.vendor=e.vendor)}isArchitecture(e){return this.architecture===e}isVendor(e){return this.vendor===e}},hd=class{constructor(){this.currentSessionId=null;this.currentKernelId=null;this.commandEncoder=null;this.computePassEncoder=null;this.maxDispatchNumber=16;this.pendingDispatchNumber=0;this.pendingKernels=[];this.pendingQueries=new Map;this.sessionStatus="default";this.capturedCommandList=new Map;this.capturedPendingKernels=new Map;this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(this.currentKernelId===null)throw new Error("currentKernelCustomData(): currentKernelId is null. (should not happen)");let e=this.kernelCustomData.get(this.currentKernelId);return e||(e={},this.kernelCustomData.set(this.currentKernelId,e)),e}async initialize(e,r){this.env=e;let t=[],o={requiredLimits:{maxComputeWorkgroupStorageSize:r.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:r.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:r.limits.maxStorageBufferBindingSize,maxBufferSize:r.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:r.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:r.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:r.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:r.limits.maxComputeWorkgroupSizeZ},requiredFeatures:t},i=a=>r.features.has(a)&&t.push(a)&&!0;i("chromium-experimental-timestamp-query-inside-passes")||i("timestamp-query"),i("shader-f16"),i("subgroups"),this.device=await r.requestDevice(o),this.adapterInfo=new fd(r.info||await r.requestAdapterInfo()),this.gpuDataManager=Ox(this),this.programManager=new fs(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,ja(e.logLevel,!!e.debug),this.device.onuncapturederror=a=>{a.error instanceof GPUValidationError&&console.error(`An uncaught WebGPU validation error was raised: ${a.error.message}`)},Object.defineProperty(this.env.webgpu,"device",{value:this.device,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(this.env.webgpu,"adapter",{value:r,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<"u"&&this.querySet.destroy(),this.gpuDataManager.dispose()}getCommandEncoder(){return this.commandEncoder||(this.commandEncoder=this.device.createCommandEncoder()),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let e=this.getCommandEncoder(),r={};this.queryType==="at-passes"&&(r.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:this.pendingDispatchNumber*2,endOfPassWriteIndex:this.pendingDispatchNumber*2+1}),this.computePassEncoder=e.beginComputePass(r)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&(this.computePassEncoder.end(),this.computePassEncoder=null)}flush(){if(!this.commandEncoder)return;Ft(),this.endComputePass();let e;this.queryType!=="none"&&(this.commandEncoder.resolveQuerySet(this.querySet,0,this.pendingDispatchNumber*2,this.queryResolveBuffer,0),e=this.device.createBuffer({size:this.pendingDispatchNumber*2*8,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(e,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,e,0,this.pendingDispatchNumber*2*8)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,this.queryType!=="none"&&e.mapAsync(GPUMapMode.READ).then(()=>{let r=new BigUint64Array(e.getMappedRange()),t=this.pendingQueries.get(e);for(let o=0;o"u"&&(this.queryTimeBase=x);let S=Number(x-this.queryTimeBase),P=Number(T-this.queryTimeBase);if(!Number.isSafeInteger(S)||!Number.isSafeInteger(P))throw new RangeError("incorrect timestamp range");if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:_.map(A=>({dims:A.dims,dataType:en(A.dataType)})),outputsMetadata:w.map(A=>({dims:A.dims,dataType:en(A.dataType)})),kernelId:a,kernelType:d,kernelName:h,programName:g,startTime:S,endTime:P});else{let A="";_.forEach((E,L)=>{A+=`input[${L}]: [${E.dims}] | ${en(E.dataType)}, `});let O="";w.forEach((E,L)=>{O+=`output[${L}]: [${E.dims}] | ${en(E.dataType)}, `}),console.log(`[profiling] kernel "${a}|${d}|${h}|${g}" ${A}${O}execution time: ${P-S} ns`)}Ii("GPU",`${g}::${x}::${T}`)}e.unmap(),this.pendingQueries.delete(e)}),Dt()}run(e,r,t,o,i,a){Ft(e.name);let l=[];for(let E=0;EL):t;if(_.length!==d.length)throw new Error(`Output size ${_.length} must be equal to ${d.length}.`);let w=[],x=[];for(let E=0;E=a)throw new Error(`Invalid output index: ${_[E]}`);if(_[E]===-3)continue;let L=_[E]===-1,z=_[E]===-2,B=L||z?i(d[E].dataType,d[E].dims):o(_[E],d[E].dataType,d[E].dims);if(w.push(B),B.data===0)continue;let K=this.gpuDataManager.get(B.data);if(!K)throw new Error(`no GPU data for output: ${B.data}`);if(L&&this.temporaryData.push(K),z){let Z=this.kernelPersistentData.get(this.currentKernelId);Z||(Z=[],this.kernelPersistentData.set(this.currentKernelId,Z)),Z.push(K)}x.push(K)}if(l.length!==r.length||x.length!==w.length){if(x.length===0)return Dt(e.name),w;throw new Error(`Program ${e.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}let T;if(g){let E=0,L=[];g.forEach(Z=>{let ee=typeof Z.data=="number"?[Z.data]:Z.data;if(ee.length===0)return;let ae=Z.type===10?2:4,pe,he;Z.type===10?(he=ee.length>4?16:ee.length>2?8:ee.length*ae,pe=ee.length>4?16:ae*ee.length):(he=ee.length<=2?ee.length*ae:16,pe=16),E=Math.ceil(E/he)*he,L.push(E);let Se=Z.type===10?8:4;E+=ee.length>4?Math.ceil(ee.length/Se)*pe:ee.length*ae});let z=16;E=Math.ceil(E/z)*z;let B=new ArrayBuffer(E);g.forEach((Z,ee)=>{let ae=L[ee],pe=typeof Z.data=="number"?[Z.data]:Z.data;if(Z.type===6)new Int32Array(B,ae,pe.length).set(pe);else if(Z.type===12)new Uint32Array(B,ae,pe.length).set(pe);else if(Z.type===10)new Uint16Array(B,ae,pe.length).set(pe);else if(Z.type===1)new Float32Array(B,ae,pe.length).set(pe);else throw new Error(`Unsupported uniform type: ${en(Z.type)}`)});let K=this.gpuDataManager.create(E,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(K.buffer,0,B,0,E),this.gpuDataManager.release(K.id),T={offset:0,size:E,buffer:K.buffer}}let S=this.programManager.normalizeDispatchGroupSize(h),P=S[1]===1&&S[2]===1,A=SB(e,r,P),O=this.programManager.getArtifact(A);if(O||(O=this.programManager.build(e,S),this.programManager.setArtifact(A,O),ke("info",()=>`[artifact] key: ${A}, programName: ${e.name}`)),g&&O.uniformVariablesInfo){if(g.length!==O.uniformVariablesInfo.length)throw new Error(`Uniform variables count mismatch: expect ${O.uniformVariablesInfo.length}, got ${g.length} in program "${O.programInfo.name}".`);for(let E=0;E`[ProgramManager] run "${e.name}" (key=${A}) with ${S[0]}x${S[1]}x${S[2]}`),this.queryType!=="none"||this.sessionStatus==="capturing"){let E={kernelId:this.currentKernelId,programName:O.programInfo.name,inputTensorViews:r,outputTensorViews:w};this.pendingKernels.push(E),this.sessionStatus==="capturing"&&this.capturedPendingKernels.get(this.currentSessionId).push(E)}return this.programManager.run(O,l,x,S,T),Dt(e.name),w}upload(e,r){this.gpuDataManager.upload(e,r)}memcpy(e,r){this.gpuDataManager.memcpy(e,r)}async download(e,r){await this.gpuDataManager.download(e,r)}alloc(e){return this.gpuDataManager.create(e).id}free(e){return this.gpuDataManager.release(e)}createKernel(e,r,t,o){let i=II.get(e);if(!i)throw new Error(`kernel not implemented: ${e}`);let a={kernelType:e,kernelName:o,kernelEntry:i[0],attributes:[i[1],t]};this.kernels.set(r,a)}releaseKernel(e){let r=this.kernelPersistentData.get(e);if(r){for(let t of r)this.gpuDataManager.release(t.id);this.kernelPersistentData.delete(e)}this.kernelCustomData.delete(e),this.kernels.delete(e)}computeKernel(e,r,t){let o=this.kernels.get(e);if(!o)throw new Error(`kernel not created: ${e}`);let i=o.kernelType,a=o.kernelName,l=o.kernelEntry,d=o.attributes;if(this.currentKernelId!==null)throw new Error(`kernel "[${i}] ${a}" is not allowed to be called recursively`);this.currentKernelId=e,d[0]&&(d[1]=d[0](d[1]),d[0]=void 0),ke("info",()=>`[WebGPU] Start to run kernel "[${i}] ${a}"...`);let h=this.env.debug;this.temporaryData=[];try{return h&&this.device.pushErrorScope("validation"),l(r,d[1]),0}catch(g){return t.push(Promise.resolve(`[WebGPU] Kernel "[${i}] ${a}" failed. ${g}`)),1}finally{h&&t.push(this.device.popErrorScope().then(g=>g?`GPU validation error for kernel "[${i}] ${a}": ${g.message}`:null));for(let g of this.temporaryData)this.gpuDataManager.release(g.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(e,r,t,o){let i=this.sessionExternalDataMapping.get(e);i||(i=new Map,this.sessionExternalDataMapping.set(e,i));let a=i.get(r),l=this.gpuDataManager.registerExternalBuffer(t,o,a);return i.set(r,[l,t]),l}unregisterBuffers(e){let r=this.sessionExternalDataMapping.get(e);r&&(r.forEach(t=>this.gpuDataManager.unregisterExternalBuffer(t[0])),this.sessionExternalDataMapping.delete(e))}getBuffer(e){let r=this.gpuDataManager.get(e);if(!r)throw new Error(`no GPU data for buffer: ${e}`);return r.buffer}createDownloader(e,r,t){return async()=>{let o=await Uc(this,e,r);return Ua(o.buffer,t)}}writeTimestamp(e){this.queryType==="inside-passes"&&this.computePassEncoder.writeTimestamp(this.querySet,e)}setQueryType(){this.queryType="none",(this.env.webgpu.profiling?.mode==="default"||(typeof this.env.trace>"u"?this.env.wasm.trace:this.env.trace))&&(this.device.features.has("chromium-experimental-timestamp-query-inside-passes")?this.queryType="inside-passes":this.device.features.has("timestamp-query")&&(this.queryType="at-passes"),this.queryType!=="none"&&typeof this.querySet>"u"&&(this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxDispatchNumber*2}),this.queryResolveBuffer=this.device.createBuffer({size:this.maxDispatchNumber*2*8,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){ke("info","captureBegin"),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus="capturing"}captureEnd(){ke("info","captureEnd"),this.flush(),this.sessionStatus="default"}replay(){ke("info","replay"),this.sessionStatus="replaying";let e=this.capturedCommandList.get(this.currentSessionId),r=this.capturedPendingKernels.get(this.currentSessionId),t=e.length;this.pendingKernels=[];for(let o=0;o=this.maxDispatchNumber||this.queryType==="at-passes")&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus="default"}onCreateSession(){this.gpuDataManager.onCreateSession()}onReleaseSession(e){this.unregisterBuffers(e),this.capturedCommandList.has(e)&&this.capturedCommandList.delete(e),this.capturedPendingKernels.has(e)&&this.capturedPendingKernels.delete(e),this.gpuDataManager.onReleaseSession(e)}onRunStart(e){this.currentSessionId=e,this.setQueryType()}}});var CI={};zn(CI,{init:()=>$B});var ui,md,$B,PI=H(()=>{"use strict";ve();tn();Oe();Ix();ui=class n{constructor(e,r,t,o){this.module=e;this.dataType=r;this.data=t;this.dims=o}getFloat32Array(){if(this.dataType!==1)throw new Error("Invalid data type");let e=W.size(this.dims);return e===0?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,e)}getBigInt64Array(){if(this.dataType!==7)throw new Error("Invalid data type");let e=W.size(this.dims);return e===0?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,e)}getInt32Array(){if(this.dataType!==6)throw new Error("Invalid data type");let e=W.size(this.dims);return e===0?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,e)}getUint16Array(){if(this.dataType!==10&&this.dataType!==4)throw new Error("Invalid data type");let e=W.size(this.dims);return e===0?new Uint16Array:new Uint16Array(this.module.HEAP8.buffer,this.data,e)}reshape(e){if(W.size(e)!==W.size(this.dims))throw new Error("Invalid new shape");return new n(this.module,this.dataType,this.data,e)}},md=class{constructor(e,r,t){this.module=e;this.backend=r;this.customDataOffset=0;this.customDataSize=0;this.adapterInfo=r.adapterInfo;let o=e.PTR_SIZE,i=t/e.PTR_SIZE,a=o===4?"i32":"i64";this.opKernelContext=Number(e.getValue(o*i++,a));let l=Number(e.getValue(o*i++,a));this.outputCount=Number(e.getValue(o*i++,a)),this.customDataOffset=Number(e.getValue(o*i++,"*")),this.customDataSize=Number(e.getValue(o*i++,a));let d=[];for(let h=0;htypeof l=="number"?this.inputs[l]:l)??this.inputs,o=r?.outputs??[],i=(l,d,h)=>new ui(this.module,d,this.output(l,h),h),a=(l,d)=>{let h=Pn(l,d);if(!h)throw new Error(`Unsupported data type: ${l}`);let g=h>0?this.backend.gpuDataManager.create(h).id:0;return new ui(this.module,l,g,d)};return this.backend.run(e,t,o,i,a,this.outputCount)}output(e,r){let t=this.module.stackSave();try{let o=this.module.PTR_SIZE,i=o===4?"i32":"i64",a=this.module.stackAlloc((1+r.length)*o);this.module.setValue(a,r.length,i);for(let l=0;l{let o=e.jsepInit;if(!o)throw new Error("Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.");if(n==="webgpu"){let i=(OI(),uo(AI)).WebGpuBackend,a=new i;await a.initialize(r,t),o("webgpu",[a,l=>a.alloc(Number(l)),l=>a.free(l),(l,d,h,g=!1)=>{if(g)ke("verbose",()=>`[WebGPU] jsepCopyGpuToGpu: src=${Number(l)}, dst=${Number(d)}, size=${Number(h)}`),a.memcpy(Number(l),Number(d));else{ke("verbose",()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${Number(l)}, gpuDataId=${Number(d)}, size=${Number(h)}`);let _=e.HEAPU8.subarray(Number(l>>>0),Number(l>>>0)+Number(h));a.upload(Number(d),_)}},async(l,d,h)=>{ke("verbose",()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${l}, dataOffset=${d}, size=${h}`),await a.download(Number(l),()=>e.HEAPU8.subarray(Number(d)>>>0,Number(d+h)>>>0))},(l,d,h)=>a.createKernel(l,Number(d),h,e.UTF8ToString(e._JsepGetNodeName(Number(d)))),l=>a.releaseKernel(l),(l,d,h,g)=>{ke("verbose",()=>`[WebGPU] jsepRun: sessionHandle=${h}, kernel=${l}, contextDataOffset=${d}`);let _=new md(e,a,Number(d));return a.computeKernel(Number(l),_,g)},()=>a.captureBegin(),()=>a.captureEnd(),()=>a.replay()])}else{let i=new Ka(r);o("webnn",[i,()=>i.reserveTensorId(),a=>i.releaseTensorId(a),async(a,l,d,h,g)=>i.ensureTensor(a,l,d,h,g),(a,l)=>{i.uploadTensor(a,l)},async(a,l)=>i.downloadTensor(a,l)])}}});var AB,Pa,Ea,no,OB,EI,ei,Da,ka,DI,Na,La,Ra,Cc=H(()=>{"use strict";dx();fx();ve();On();Ma();Rc();AB=(n,e)=>{Qe()._OrtInit(n,e)!==0&&qe("Can't initialize onnxruntime.")},Pa=async n=>{AB(n.wasm.numThreads,ri(n.logLevel))},Ea=async(n,e)=>{Qe().asyncInit?.();{let r=(PI(),uo(CI)).init;if(e==="webgpu"){if(typeof navigator>"u"||!navigator.gpu)throw new Error("WebGPU is not supported in current environment");let t=n.webgpu.adapter;if(t){if(typeof t.limits!="object"||typeof t.features!="object"||typeof t.requestDevice!="function")throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let o=n.webgpu.powerPreference;if(o!==void 0&&o!=="low-power"&&o!=="high-performance")throw new Error(`Invalid powerPreference setting: "${o}"`);let i=n.webgpu.forceFallbackAdapter;if(i!==void 0&&typeof i!="boolean")throw new Error(`Invalid forceFallbackAdapter setting: "${i}"`);if(t=await navigator.gpu.requestAdapter({powerPreference:o,forceFallbackAdapter:i}),!t)throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.')}await r("webgpu",Qe(),n,t)}if(e==="webnn"){if(typeof navigator>"u"||!navigator.ml)throw new Error("WebNN is not supported in current environment");await r("webnn",Qe(),n)}}},no=new Map,OB=n=>{let e=Qe(),r=e.stackSave();try{let t=e.PTR_SIZE,o=e.stackAlloc(2*t);e._OrtGetInputOutputCount(n,o,o+t)!==0&&qe("Can't get session input/output count.");let a=t===4?"i32":"i64";return[Number(e.getValue(o,a)),Number(e.getValue(o+t,a))]}finally{e.stackRestore(r)}},EI=(n,e)=>{let r=Qe(),t=r.stackSave(),o=0;try{let i=r.PTR_SIZE,a=r.stackAlloc(2*i);r._OrtGetInputOutputMetadata(n,e,a,a+i)!==0&&qe("Can't get session input/output metadata.");let d=Number(r.getValue(a,"*"));o=Number(r.getValue(a+i,"*"));let h=r.HEAP32[o/4];if(h===0)return[d,0];let g=r.HEAPU32[o/4+1],_=[];for(let w=0;w{let e=Qe(),r=e._malloc(n.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${n.byteLength}.`);return e.HEAPU8.set(n,r),[r,n.byteLength]},Da=async(n,e)=>{let r,t,o=Qe();Array.isArray(n)?[r,t]=n:n.buffer===o.HEAPU8.buffer?[r,t]=[n.byteOffset,n.byteLength]:[r,t]=ei(n);let i=0,a=0,l=0,d=[],h=[],g=[];try{if([a,d]=await px(e),e?.externalData&&o.mountExternalData){let L=[];for(let z of e.externalData){let B=typeof z=="string"?z:z.path;L.push(ni(typeof z=="string"?z:z.data).then(K=>{o.mountExternalData(B,K)}))}await Promise.all(L)}for(let L of e?.executionProviders??[])if((typeof L=="string"?L:L.name)==="webnn"){if(o.shouldTransferToMLTensor=!1,typeof L!="string"){let B=L,K=B?.context,Z=B?.gpuDevice,ee=B?.deviceType,ae=B?.powerPreference;K?o.currentContext=K:Z?o.currentContext=await o.webnnCreateMLContext(Z):o.currentContext=await o.webnnCreateMLContext({deviceType:ee,powerPreference:ae})}else o.currentContext=await o.webnnCreateMLContext();break}i=await o._OrtCreateSession(r,t,a),o.webgpuOnCreateSession?.(i),i===0&&qe("Can't create a session."),o.jsepOnCreateSession?.(),o.currentContext&&(o.webnnRegisterMLContext(i,o.currentContext),o.currentContext=void 0,o.shouldTransferToMLTensor=!0);let[_,w]=OB(i),x=!!e?.enableGraphCapture,T=[],S=[],P=[],A=[],O=[];for(let L=0;L<_;L++){let[z,B,K]=EI(i,L);z===0&&qe("Can't get an input name."),h.push(z);let Z=o.UTF8ToString(z);T.push(Z),P.push(B===0?{name:Z,isTensor:!1}:{name:Z,isTensor:!0,type:en(B),shape:K})}for(let L=0;LL==="gpu-buffer"||L==="ml-tensor"||L==="ml-tensor-cpu-output")&&(l=o._OrtCreateBinding(i),l===0&&qe("Can't create IO binding."),E={handle:l,outputPreferredLocations:O,outputPreferredLocationsEncoded:O.map(L=>L==="ml-tensor-cpu-output"?"ml-tensor":L).map(L=>Lc(L))}),no.set(i,[i,h,g,E,x,!1]),[i,T,S,P,A]}catch(_){throw h.forEach(w=>o._OrtFree(w)),g.forEach(w=>o._OrtFree(w)),l!==0&&o._OrtReleaseBinding(l)!==0&&qe("Can't release IO binding."),i!==0&&o._OrtReleaseSession(i)!==0&&qe("Can't release session."),_}finally{o._free(r),a!==0&&o._OrtReleaseSessionOptions(a)!==0&&qe("Can't release session options."),d.forEach(_=>o._free(_)),o.unmountExternalData?.()}},ka=n=>{let e=Qe(),r=no.get(n);if(!r)throw new Error(`cannot release session. invalid session id: ${n}`);let[t,o,i,a,l]=r;a&&(l&&e._OrtClearBoundOutputs(a.handle)!==0&&qe("Can't clear bound outputs."),e._OrtReleaseBinding(a.handle)!==0&&qe("Can't release IO binding.")),e.jsepOnReleaseSession?.(n),e.webnnOnReleaseSession?.(n),e.webgpuOnReleaseSession?.(n),o.forEach(d=>e._OrtFree(d)),i.forEach(d=>e._OrtFree(d)),e._OrtReleaseSession(t)!==0&&qe("Can't release session."),no.delete(n)},DI=async(n,e,r,t,o,i,a=!1)=>{if(!n){e.push(0);return}let l=Qe(),d=l.PTR_SIZE,h=n[0],g=n[1],_=n[3],w=_,x,T;if(h==="string"&&(_==="gpu-buffer"||_==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&_!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${i} when enableGraphCapture is true.`);if(_==="gpu-buffer"){let A=n[2].gpuBuffer;T=Pn(Cn(h),g);{let O=l.jsepRegisterBuffer;if(!O)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');x=O(t,i,A,T)}}else if(_==="ml-tensor"){let A=n[2].mlTensor;T=Pn(Cn(h),g);let O=l.webnnRegisterMLTensor;if(!O)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');x=O(t,A,Cn(h),g)}else{let A=n[2];if(Array.isArray(A)){T=d*A.length,x=l._malloc(T),r.push(x);for(let O=0;Ol.setValue(P+E*d,O,d===4?"i32":"i64"));let A=l._OrtCreateTensor(Cn(h),x,T,P,g.length,Lc(w));A===0&&qe(`Can't create tensor for input/output. session=${t}, index=${i}.`),e.push(A)}finally{l.stackRestore(S)}},Na=async(n,e,r,t,o,i)=>{let a=Qe(),l=a.PTR_SIZE,d=no.get(n);if(!d)throw new Error(`cannot run inference. invalid session id: ${n}`);let h=d[0],g=d[1],_=d[2],w=d[3],x=d[4],T=d[5],S=e.length,P=t.length,A=0,O=[],E=[],L=[],z=[],B=a.stackSave(),K=a.stackAlloc(S*l),Z=a.stackAlloc(S*l),ee=a.stackAlloc(P*l),ae=a.stackAlloc(P*l);try{[A,O]=cx(i);for(let oe=0;oect*je,1);me=en(Ie);let Et=w?.outputPreferredLocations[t[oe]];if(me==="string"){if(Et==="gpu-buffer"||Et==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let ct=[];for(let je=0;je0){let ct=a.jsepGetBuffer;if(!ct)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let je=ct(Te),tr=Pn(Ie,lt);if(tr===void 0||!Fa(me))throw new Error(`Unsupported data type: ${me}`);Ee=!0,he.push([me,ze,{gpuBuffer:je,download:a.jsepCreateDownloader(je,tr,me),dispose:()=>{a._OrtReleaseTensor(Be)!==0&&qe("Can't release tensor.")}},"gpu-buffer"])}else if(Et==="ml-tensor"&<>0){let ct=a.webnnEnsureTensor,je=a.webnnIsGraphInputOutputTypeSupported;if(!ct||!je)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(Pn(Ie,lt)===void 0||!Va(me))throw new Error(`Unsupported data type: ${me}`);if(!je(n,me,!1))throw new Error(`preferredLocation "ml-tensor" for ${me} output is not supported by current WebNN Context.`);let mn=await ct(n,Te,Ie,ze,!1);Ee=!0,he.push([me,ze,{mlTensor:mn,download:a.webnnCreateMLTensorDownloader(Te,me),dispose:()=>{a.webnnReleaseTensorId(Te),a._OrtReleaseTensor(Be)}},"ml-tensor"])}else if(Et==="ml-tensor-cpu-output"&<>0){let ct=a.webnnCreateMLTensorDownloader(Te,me)(),je=he.length;Ee=!0,Se.push((async()=>{let tr=[je,await ct];return a.webnnReleaseTensorId(Te),a._OrtReleaseTensor(Be),tr})()),he.push([me,ze,[],"cpu"])}else{let ct=xo(me),je=new ct(lt);new Uint8Array(je.buffer,je.byteOffset,je.byteLength).set(a.HEAPU8.subarray(Te,Te+je.byteLength)),he.push([me,ze,je,"cpu"])}}finally{a.stackRestore(xe),me==="string"&&Te&&a._free(Te),Ee||a._OrtReleaseTensor(Be)}}w&&!x&&(a._OrtClearBoundOutputs(w.handle)!==0&&qe("Can't clear bound outputs."),no.set(n,[h,g,_,w,x,!1]));for(let[oe,Be]of await Promise.all(Se))he[oe][2]=Be;return he}finally{a.webnnOnRunEnd?.(h),a.stackRestore(B),E.forEach(pe=>a._OrtReleaseTensor(pe)),L.forEach(pe=>a._OrtReleaseTensor(pe)),z.forEach(pe=>a._free(pe)),A!==0&&a._OrtReleaseRunOptions(A),O.forEach(pe=>a._free(pe))}},La=n=>{let e=Qe(),r=no.get(n);if(!r)throw new Error("invalid session id");let t=r[0],o=e._OrtEndProfiling(t);o===0&&qe("Can't get an profile file name."),e._OrtFree(o)},Ra=n=>{let e=[];for(let r of n){let t=r[2];!Array.isArray(t)&&"buffer"in t&&e.push(t.buffer)}return e}});var oo,er,li,ms,gs,hs,gd,bd,$o,Ao,PB,kI,NI,LI,RI,zI,MI,BI,yd=H(()=>{"use strict";At();Cc();On();Oa();oo=()=>!!Ae.wasm.proxy&&typeof document<"u",li=!1,ms=!1,gs=!1,bd=new Map,$o=(n,e)=>{let r=bd.get(n);r?r.push(e):bd.set(n,[e])},Ao=()=>{if(li||!ms||gs||!er)throw new Error("worker not ready")},PB=n=>{switch(n.data.type){case"init-wasm":li=!1,n.data.err?(gs=!0,gd[1](n.data.err)):(ms=!0,gd[0]()),hs&&(URL.revokeObjectURL(hs),hs=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=bd.get(n.data.type);n.data.err?e.shift()[1](n.data.err):e.shift()[0](n.data.out);break}default:}},kI=async()=>{if(!ms){if(li)throw new Error("multiple calls to 'initWasm()' detected.");if(gs)throw new Error("previous call to 'initWasm()' failed.");if(li=!0,oo())return new Promise((n,e)=>{er?.terminate(),sx().then(([r,t])=>{try{er=t,er.onerror=i=>e(i),er.onmessage=PB,gd=[n,e];let o={type:"init-wasm",in:Ae};!o.in.wasm.wasmPaths&&(r||Dc)&&(o.in.wasm.wasmPaths={wasm:new URL("ort-wasm-simd-threaded.jsep.wasm",import.meta.url).href}),er.postMessage(o),hs=r}catch(o){e(o)}},e)});try{await Ca(Ae.wasm),await Pa(Ae),ms=!0}catch(n){throw gs=!0,n}finally{li=!1}}},NI=async n=>{if(oo())return Ao(),new Promise((e,r)=>{$o("init-ep",[e,r]);let t={type:"init-ep",in:{epName:n,env:Ae}};er.postMessage(t)});await Ea(Ae,n)},LI=async n=>oo()?(Ao(),new Promise((e,r)=>{$o("copy-from",[e,r]);let t={type:"copy-from",in:{buffer:n}};er.postMessage(t,[n.buffer])})):ei(n),RI=async(n,e)=>{if(oo()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return Ao(),new Promise((r,t)=>{$o("create",[r,t]);let o={type:"create",in:{model:n,options:{...e}}},i=[];n instanceof Uint8Array&&i.push(n.buffer),er.postMessage(o,i)})}else return Da(n,e)},zI=async n=>{if(oo())return Ao(),new Promise((e,r)=>{$o("release",[e,r]);let t={type:"release",in:n};er.postMessage(t)});ka(n)},MI=async(n,e,r,t,o,i)=>{if(oo()){if(r.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(o.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return Ao(),new Promise((a,l)=>{$o("run",[a,l]);let d=r,h={type:"run",in:{sessionId:n,inputIndices:e,inputs:d,outputIndices:t,options:i}};er.postMessage(h,Ra(d))})}else return Na(n,e,r,t,o,i)},BI=async n=>{if(oo())return Ao(),new Promise((e,r)=>{$o("end-profiling",[e,r]);let t={type:"end-profiling",in:n};er.postMessage(t)});La(n)}});var FI,EB,bs,VI=H(()=>{"use strict";At();yd();ve();Aa();Rc();FI=(n,e)=>{switch(n.location){case"cpu":return[n.type,n.dims,n.data,"cpu"];case"gpu-buffer":return[n.type,n.dims,{gpuBuffer:n.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[n.type,n.dims,{mlTensor:n.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${n.location} for ${e()}`)}},EB=n=>{switch(n[3]){case"cpu":return new Bt(n[0],n[2],n[1]);case"gpu-buffer":{let e=n[0];if(!Fa(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:t,dispose:o}=n[2];return Bt.fromGpuBuffer(r,{dataType:e,dims:n[1],download:t,dispose:o})}case"ml-tensor":{let e=n[0];if(!Va(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:r,download:t,dispose:o}=n[2];return Bt.fromMLTensor(r,{dataType:e,dims:n[1],download:t,dispose:o})}default:throw new Error(`invalid data location: ${n[3]}`)}},bs=class{async fetchModelAndCopyToWasmMemory(e){return LI(await ni(e))}async loadModel(e,r){Ft();let t;typeof e=="string"?t=await this.fetchModelAndCopyToWasmMemory(e):t=e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await RI(t,r),Dt()}async dispose(){return zI(this.sessionId)}async run(e,r,t){Ft();let o=[],i=[];Object.entries(e).forEach(w=>{let x=w[0],T=w[1],S=this.inputNames.indexOf(x);if(S===-1)throw new Error(`invalid input '${x}'`);o.push(T),i.push(S)});let a=[],l=[];Object.entries(r).forEach(w=>{let x=w[0],T=w[1],S=this.outputNames.indexOf(x);if(S===-1)throw new Error(`invalid output '${x}'`);a.push(T),l.push(S)});let d=o.map((w,x)=>FI(w,()=>`input "${this.inputNames[i[x]]}"`)),h=a.map((w,x)=>w?FI(w,()=>`output "${this.outputNames[l[x]]}"`):null),g=await MI(this.sessionId,i,d,l,h,t),_={};for(let w=0;wys,initializeFlags:()=>jI,wasmBackend:()=>DB});var jI,ys,DB,UI=H(()=>{"use strict";At();yd();VI();jI=()=>{(typeof Ae.wasm.initTimeout!="number"||Ae.wasm.initTimeout<0)&&(Ae.wasm.initTimeout=0);let n=Ae.wasm.simd;if(typeof n!="boolean"&&n!==void 0&&n!=="fixed"&&n!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${n}". Reset it to \`false\` and ignore SIMD feature checking.`),Ae.wasm.simd=!1),typeof Ae.wasm.proxy!="boolean"&&(Ae.wasm.proxy=!1),typeof Ae.wasm.trace!="boolean"&&(Ae.wasm.trace=!1),typeof Ae.wasm.numThreads!="number"||!Number.isInteger(Ae.wasm.numThreads)||Ae.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)Ae.wasm.numThreads=1;else{let e=typeof navigator>"u"?eu("node:os").cpus().length:navigator.hardwareConcurrency;Ae.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},ys=class{async init(e){jI(),await kI(),await NI(e)}async createInferenceSessionHandler(e,r){let t=new bs;return await t.loadModel(e,r),t}},DB=new ys});At();At();At();var bb="1.23.0";var dee=au;{let n=(Kw(),uo(qw)).onnxjsBackend;_n("webgl",n,-10)}{let n=(UI(),uo(GI)).wasmBackend;_n("webgpu",n,5),_n("webnn",n,5),_n("cpu",n,10),_n("wasm",n,10)}Object.defineProperty(Ae.versions,"web",{value:bb,enumerable:!0});export{c3 as InferenceSession,Ii as TRACE,Ft as TRACE_FUNC_BEGIN,Dt as TRACE_FUNC_END,Bt as Tensor,dee as default,Ae as env,_n as registerBackend}; +/** + * @license + * Copyright 2021 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ +/** + * @license + * Copyright 2019 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ +/*! Bundled license information: + +long/index.js: + (** + * @license + * Copyright 2009 The Closure Library Authors + * Copyright 2020 Daniel Wirtz / The long.js Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + *) +*/ +//# sourceMappingURL=ort.all.bundle.min.mjs.map