human/dist/human.js

8064 lines
1.6 MiB
JavaScript
Raw Normal View History

2021-09-11 03:21:29 +02:00
/*
Human
homepage: <https://github.com/vladmandic/human>
author: <https://github.com/vladmandic>'
*/
2021-03-10 00:32:35 +01:00
2022-01-16 15:49:55 +01:00
var Human=(()=>{var Rh=Object.defineProperty;var oR=Object.getOwnPropertyDescriptor;var iR=Object.getOwnPropertyNames;var lR=Object.prototype.hasOwnProperty;var uR=(e,t,n)=>t in e?Rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var cR=e=>Rh(e,"__esModule",{value:!0});var id=(e,t)=>{for(var n in t)Rh(e,n,{get:t[n],enumerable:!0})},dR=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of iR(t))!lR.call(e,s)&&(n||s!=="default")&&Rh(e,s,{get:()=>t[s],enumerable:!(r=oR(t,s))||r.enumerable});return e};var pR=(e=>(t,n)=>e&&e.get(t)||(n=dR(cR({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var fe=(e,t,n)=>(uR(e,typeof t!="symbol"?t+"":t,n),n),K5=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var ld=(e,t,n)=>(K5(e,t,"read from private field"),n?n.call(e):t.get(e)),ud=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},cd=(e,t,n,r)=>(K5(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var tAe={};id(tAe,{Human:()=>cE,default:()=>cE,defaults:()=>_a,env:()=>he});function J(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function Ve(e,t){let n=e.endsWith("/")?"":"/",s=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!s.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${s}`);return s}var ie=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function k2(e,t,n="config",r=[]){for(let s of Object.keys(t))if(typeof t[s]=="object")k2(e[s],t[s],s,r);else{let a=e&&typeof e[s]!="undefined";a||r.push({reason:"unknown property",where:`${n}.${s} = ${t[s]}`});let o=e&&typeof e[s]==typeof t[s];a&&!o&&r.push({reason:"property type mismatch",where:`${n}.${s} = ${t[s]}`,expected:typeof e[s]})}return t.debug&&n==="config"&&r.length>0&&J("invalid configuration",r),r}function yn(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,r)=>(Object.keys(r||{}).forEach(s=>{let a=n[s],o=r[s];Array.isArray(a)&&Array.isArray(o)?n[s]=a.concat(...o):t(a)&&t(o)?n[s]=yn(a,o):n[s]=o}),n),{})}var _a={backend:"",modelBasePath:"",wasmPath:"",debug:!0,async:!0,warmup:"full",cacheSensitivity:.7,skipAllowed:!1,deallocate:!1,filter:{enabled:!0,equalization:!1,width:0,height:0,flip:!1,return:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"blazeface.json",rotation:!0,maxDetected:1,skipFrames:99,skipTime:2500,minConfidence:.2,iouThreshold:.1,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json"},iris:{enabled:!0,modelPath:"iris.json"},emotion:{enabled:!0,minConfidence:.1,skipFrames:99,skipTime:1500,modelPath:"emotion.json"},description:{enabled:!0,modelPath:"faceres.json",skipFrames:99,skipTime:3e3,minConfidence:.1},antispoof:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"antispoof.json"},liveness:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"liveness.json"}},body:{enabled:!0,modelPath:"movenet-lightning.json",maxDetected:-1,minConfidence:.3,skipFrames:1,skipTime:200},hand:{enabled:!0,rotation:!0,skipFrames:99,skipTime:1e3,minConfidence:.5,iouThreshold:.2,maxDetected:-1,landmarks:!0,detector:{modelPath:"handtrack.json"},skeleton:{modelPath:"handlandmark-full.json"}},object:{enabled:!1,modelPath:"mb3-centernet.json",minConfidence:.2,iouThreshold:.4,maxDetected:10,skipFrames:99,skipTime:2e3},segmentation:{enabled:!1,modelPath:"selfie.json",blur:8}};var We={};id(We,{Abs:()=>yi,Acos:()=>uu,Acosh:()=>cu,AdadeltaOptimizer:()=>Hf,AdagradOptimizer:()=>jf,AdamOptimizer:()=>qf,AdamaxOptimizer:()=>Xf,Add:()=>Zs,AddN:()=>Fa,All:()=>du,Any:()=>pu,ArgMax:()=>Oa,ArgMin:()=>hu,Asin:()=>fu,
2021-11-08 13:36:26 +01:00
`)),l.join(`
2022-01-16 15:49:55 +01:00
`)}function w9(e,t,n,r){let s=Ct(t),a=r[r.length-1],o=new Array(a).fill(0),i=t.length,l=n==="complex64"?Ld(e):e;if(i>1)for(let c=0;c<s/a;c++){let u=c*a;for(let d=0;d<a;d++)o[d]=Math.max(o[d],zd(l[u+d],0,n).length)}return o}function zd(e,t,n){let r;return Array.isArray(e)?r=`${parseFloat(e[0].toFixed(P2))} + ${parseFloat(e[1].toFixed(P2))}j`:Pa(e)?r=`'${e}'`:n==="bool"?r=x3(e):r=parseFloat(e.toFixed(P2)).toString(),fd(r,t)}function x3(e){return e===0?"false":"true"}function gf(e,t,n,r,s,a=!0){let o=n==="complex64"?2:1,i=t[0],l=t.length;if(l===0){if(n==="complex64"){let m=Ld(e);return[zd(m[0],0,n)]}return n==="bool"?[x3(e[0])]:[e[0].toString()]}if(l===1){if(i>A3){let g=Md*o,y=Array.from(e.slice(0,g)),x=Array.from(e.slice((i-Md)*o,i*o));return n==="complex64"&&(y=Ld(y),x=Ld(x)),["["+y.map((A,b)=>zd(A,s[b],n)).join(", ")+", ..., "+x.map((A,b)=>zd(A,s[i-Md+b],n)).join(", ")+"]"]}let m=n==="complex64"?Ld(e):Array.from(e);return["["+m.map((g,y)=>zd(g,s[y],n)).join(", ")+"]"]}let c=t.slice(1),u=r.slice(1),d=r[0]*o,p=[];if(i>A3){for(let m=0;m<Md;m++){let g=m*d,y=g+d;p.push(...gf(e.slice(g,y),c,n,u,s,!1))}p.push("...");for(let m=i-Md;m<i;m++){let g=m*d,y=g+d;p.push(...gf(e.slice(g,y),c,n,u,s,m===i-1))}}else for(let m=0;m<i;m++){let g=m*d,y=g+d;p.push(...gf(e.slice(g,y),c,n,u,s,m===i-1))}let h=l===2?",":"";p[0]="["+p[0]+h;for(let m=1;m<p.length-1;m++)p[m]=" "+p[m]+h;let f=`,
2021-11-08 13:36:26 +01:00
`;for(let m=2;m<l;m++)f+=`
2022-01-16 15:49:55 +01:00
`;return p[p.length-1]=" "+p[p.length-1]+"]"+(a?"":f),p}function Ld(e){let t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var sn=class{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=Ct(e),n!=null){let r=n.length;M(r===this.size,()=>`Length of values '${r}' does not match the size inferred by the shape '${this.size}'.`)}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||t3(t,this.size),this.strides=iu(e)}set(e,...t){t.length===0&&(t=[0]),M(t.length===this.rank,()=>`The number of provided coordinates (${t.length}) must match the rank (${this.rank})`);let n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(let r of e){if(r<0||r>=this.shape[t]){let s=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(s)}t++}let n=e[e.length-1];for(let r=0;r<e.length-1;++r)n+=this.strides[r]*e[r];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];let t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return hs().makeTensor(this.values,this.shape,this.dtype)}},hs=null,Mu=null,k9=null;function I9(e){hs=e}function S9(e){Mu=e}function C9(e){k9=e}var nt=class{constructor(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=Ct(e),this.strides=iu(e),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){let e=await this.data();return Mu.buffer(this.shape,this.dtype,e)}bufferSync(){return Mu.buffer(this.shape,this.dtype,this.dataSync())}async array(){let e=await this.data();return lu(this.shape,e,this.dtype==="complex64")}arraySync(){return lu(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();let e=hs().read(this.dataId);if(this.dtype==="string"){let t=await e;try{return t.map(n=>mf(n))}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataToGPU(e){return this.throwIfDisposed(),hs().readToGPU(this.dataId,e)}dataSync(){this.throwIfDisposed();let e=hs().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>mf(t))}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();let e=await hs().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(hs().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Mu.print(this,e)}clone(){return this.throwIfDisposed(),Mu.clone(this)}toString(e=!1){let t=this.dataSync();return v9(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Mu.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),hs().makeVariable(this,e,t,n)}};Object.defineProperty(nt,Symbol.hasInstance,{value:e=>!!e&&e.data!=null&&e.dataSync!=null&&e.throwIfDisposed!=null});function T9(){return E2("Tensor",()=>nt)}T9();var Bd=class extends nt{constructor(e,t,n,r){super(e.shape,e.dtype,e.dataId,r);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);if(!Da(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);hs().disposeTensor(this),this.dataId=e.dataId,hs().incRef(this,null)}dispose(){hs().disposeVariable(this),this.isDisposedInternal=!0}};Ob
Manifest JSON has weights with names: ${i.join(", ")}.`)}let l=s.reduce((h,f,m)=>(f&&h.push(m),h),[]),c=[];l.forEach(h=>{t[h].paths.forEach(f=>{let m=n+(n.endsWith("/")?"":"/")+f;c.push(m)})});let u=await e(c),d={},p=0;return l.forEach(h=>{let f=t[h].paths.length,m=0;for(let b=0;b<f;b++)m+=u[p+b].byteLength;let g=new ArrayBuffer(m),y=new Uint8Array(g),x=0;for(let b=0;b<f;b++){let v=new Uint8Array(u[p+b]);y.set(v,x),x+=v.byteLength}a[h].forEach(b=>{let v=g.slice(b.groupOffset,b.groupOffset+b.sizeBytes),C=P3(v,[b.manifestEntry]);for(let I in C)d[I]=C[I]}),p+=f}),d}}var I_="application/octet-stream",S_="application/json",X2=class{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?(M(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=Y().platform.fetch,M(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&M(e.length===2,()=>`URL paths for http must have a length of 2, (actual length is ${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");let t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;let n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],r=O3(e,n);t.body.append("model.json",new Blob([JSON.stringify(r)],{type:S_}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:I_}),"model.weights.bin");let s=await this.fetch(this.path,t);if(s.ok)return{modelArtifactsInfo:Ud(e),responses:[s]};throw new Error(`BrowserHTTPRequest.save() failed due to HTTP response status ${s.status}.`)}async load(){let e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Request to ${this.path} failed with status code ${e.status}. Please verify this URL points to the model JSON of the model to load.`);let t;try{t=await e.json()}catch(s){let a=`Failed to parse model JSON of response from ${this.path}.`;throw this.path.endsWith(".pb")?a+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":a+=" Please make sure the server is serving valid JSON for this request.",new Error(a)}let n=t.modelTopology,r=t.weightsManifest;if(n==null&&r==null)throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);return V2(t,s=>this.loadWeights(s))}async loadWeights(e){let t=Array.isArray(this.path)?this.path[1]:this.path,[n,r]=C_(t),s=this.weightPathPrefix||n,a=[];for(let c of e)a.push(...c.weights);let o=[],i=[];for(let c of e)for(let u of c.paths)this.weightUrlConverter!=null?i.push(this.weightUrlConverter(u)):o.push(s+u+r);this.weightUrlConverter&&o.push(...await Promise.all(i));let l=await q3(o,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[a,W2(l)]}};X2.URL_SCHEME_REGEX=/^https?:\/\//;function C_(e){let t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),r=e.substring(0,t),s=n>t?e.substring(n):"";return[r+"/",s]}function K2(e){return e.match(X2.URL_SCHEME_REGEX)!=null}var K3=(e,t)=>{if(typeof fetch=="undefined"&&(t==null||t.fetchFunc==null))return null;{let n=!0;if(Array.isArray(e)?n=e.every(r=>K2(r)):n=K2(e),n)return Z2(e,t)}return null};Ut.registerSaveRouter(K3);Ut.registerLoadRouter(K3);function Z2(e,t){return new X2(e,t)}function T_(e,t){return Z2(e,t)}var Y2=class{
Actual: ${s}.
Expected: ${a}.`);for(let o=0;o<a.length;++o){let i=s[o],l=a[o];if(!n(i,l))throw new Error(`Arrays differ: actual[${o}] = ${i}, expected[${o}] = ${l}.
Actual: ${s}.
Expected: ${a}.`)}}function eD(e,t){e().then(()=>t.fail(),()=>t())}function tD(e,t){let n=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return Pa(e)||Pa(e[0])||Pa(t)||Pa(t[0])?sy(e,n,(r,s)=>r==s):sy(e,t,(r,s)=>ay(r,s,0))}function nD(e,t,n){if(n==null&&(n=ry()),!ay(e,t,n))throw new Error(`Numbers differ: actual === ${e}, expected === ${t}`)}function ay(e,t,n){return!isFinite(e)&&!isFinite(t)?!0:!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}function rD(e,t,n){for(let r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw new Error(`Value out of range:${e[r]} low: ${t}, high: ${n}`)}function sD(e,t){let n=new Float32Array(e),r=new Float32Array(t);if(n.length!==r.length)throw new Error(`Expected ArrayBuffer to be of length ${r.length}, but it was ${n.length}`);for(let s=0;s<r.length;s++)if(n[s]!==r[s])throw new Error(`Expected ArrayBuffer value at ${s} to be ${r[s]} but got ${n[s]} instead`)}function mv(e){for(let t=0;t<e.length;t++){let n=e[t];Array.isArray(n)?mv(n):e[t]=Od(n)}return e}var oy="0.0.0";function iy(){Y().set("PROD",!0)}function aD(){Y().set("DEBUG",!0)}function oD(){Y().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function ly(e){Y().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}C9(ly);function iD(){V.disposeVariables()}function Dn(){return V}function bf(){return V.memory()}function lD(e){return V.profile(e)}function X(e,t){return V.tidy(e,t)}function te(e){$2(e).forEach(n=>n.dispose())}function xn(e){return V.keep(e)}function uD(e){return V.time(e)}function uy(e){return V.setBackend(e)}function Wu(){return V.ready()}function xr(){return V.backendName}function cD(e){V.removeBackend(e)}function cy(e){return V.findBackend(e)}function dD(e){return V.findBackendFactory(e)}function dl(e,t,n=1){return V.registerBackend(e,t,n)}function gs(){return V.backend}function pD(e,t){Y().setPlatform(e,t)}function hD(e,t){let n=$(e,"a","add"),r=$(t,"b","add");[n,r]=Mt(n,r);let s={a:n,b:r};return V.runKernel(Zs,s)}var ue=U({add_:hD});function fD(e,t){let n=$(e,"a","floorDiv"),r=$(t,"b","floorDiv");[n,r]=Mt(n,r);let s={a:n,b:r};return V.runKernel(Za,s)}var Hd=U({floorDiv_:fD});function mD(e,t){let n=$(e,"a","div"),r=$(t,"b","div");if([n,r]=Mt(n,r),n.dtype==="int32"&&r.dtype==="int32")return Hd(n,r);let s={a:n,b:r},a={};return V.runKernel(ja,s,a)}var de=U({div_:mD});function gD(e,t){let n=$(e,"a","mul"),r=$(t,"b","mul");[n,r]=Mt(n,r);let s={a:n,b:r};return V.runKernel(uo,s)}var L=U({mul_:gD});function yD(e){let t=$(e,"x","abs");if(t.dtype==="complex64"){let n={x:t};return V.runKernel(yd,n)}else{let n={x:t};return V.runKernel(yi,n)}}var an=U({abs_:yD});function AD(e){let n={x:$(e,"x","acos")};return V.runKernel(uu,n)}var gv=U({acos_:AD});function xD(e){let n={x:$(e,"x","acosh")};return V.runKernel(cu,n)}var yv=U({acosh_:xD});function bD(e){M(Array.isArray(e),()=>"The argument passed to tf.addN() must be a list of tensors"),M(e.length>=1,()=>`Must pass at least one tensor to tf.addN(), but got ${e.length}`);let t=e.map((s,a)=>$(s,`tensors${a}`,"addN")),n=t[0];t.forEach(s=>{if(s.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(s=>{if(!Da(s.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});let r=t;return V.runKernel(Fa,r)}var vf=U({addN_:bD});function vD(e,t=null,n=!1){let s={x:$(e,"x","all","bool")},a={axis:t,keepDims:n};return V.runKernel(du,s,a)}var dy=U({all_:vD});function wD(e,t=null,n=!1){let s={x:$(e,"x","any","bool")},a={axis:t,keepDims:n};return V.runKernel(pu,s,a)}var wf=U({any_:wD});function kD(e,t=0){let r={x:$(e,"x","argMax")},s={axis:t};return V.runKernel(Oa,r,s)}var Mr=U({argMax_:kD});function ID(e,t=0){let r={x:$(e,"x","argMin")},s={axis:t};return V.runKernel(hu,r,s)}var Av=U({argMin_:ID});function SD(e){let n={x:$(e,"x","asin")};return V.runKernel(fu,n)}var xv=U({asin_:SD});function CD(e){let n={x:$(e,"x","asinh")};return V.runKernel(mu,n)}var bv=U({asinh_:CD});function
with dtype ${a.dtype}. `)}),n.length===1)return Vn(n[0]);let r=n,s={axis:t};return V.runKernel(xi,r,s)}var St=U({concat_:LD});function BD(e){let n={x:$(e,"x","sigmoid","float32")};return V.runKernel(xo,n)}var Pn=U({sigmoid_:BD});function WD(e,t,n){let r=$(e,"x","slice","string_or_numeric");if(r.rank===0)throw new Error("Slicing scalar is not possible");let s={x:r},a={begin:t,size:n};return V.runKernel(ji,s,a)}var Fe=U({slice_:WD});function VD(e){let n={x:$(e,"x","tanh","float32")};return V.runKernel(So,n)}var Uu=U({tanh_:VD});function UD(e,t,n,r,s,a){let o=$(e,"forgetBias","basicLSTMCell"),i=$(t,"lstmKernel","basicLSTMCell"),l=$(n,"lstmBias","basicLSTMCell"),c=$(r,"data","basicLSTMCell"),u=$(s,"c","basicLSTMCell"),d=$(a,"h","basicLSTMCell"),p=St([c,d],1),h=qe(p,i),f=ue(h,l),m=f.shape[0],g=f.shape[1]/4,y=[m,g],x=Fe(f,[0,0],y),A=Fe(f,[0,g],y),b=Fe(f,[0,g*2],y),v=Fe(f,[0,g*3],y),C=ue(L(Pn(x),Uu(A)),L(u,Pn(ue(o,b)))),I=L(Uu(C),Pn(v));return[C,I]}var GD=U({basicLSTMCell_:UD});function HD(e,t,n){let r=$(e,"x","batchToSpaceND"),s=t.reduce((i,l)=>i*l);M(r.rank>=1+t.length,()=>`input rank is ${r.rank} but should be > than blockShape.length ${t.length}`),M(n.length===t.length,()=>`crops.length is ${n.length} but should be equal to blockShape.length ${t.length}`),M(r.shape[0]%s===0,()=>`input tensor batch is ${r.shape[0]} but is not divisible by the product of the elements of blockShape ${t.join(" * ")} === ${s}`);let a={x:r},o={blockShape:t,crops:n};return V.runKernel(Ai,a,o)}var Sf=U({batchToSpaceND_:HD});function jD(e){let t;return e.rank===0||e.rank===1?t=H(e,[1,1,1,e.size]):e.rank===2?t=H(e,[1,1,e.shape[0],e.shape[1]]):e.rank===3?t=H(e,[1,e.shape[0],e.shape[1],e.shape[2]]):t=e,t}function qD(e,t,n,r,s,a){a==null&&(a=.001);let o=$(e,"x","batchNorm"),i=$(t,"mean","batchNorm"),l=$(n,"variance","batchNorm"),c;s!=null&&(c=$(s,"scale","batchNorm"));let u;r!=null&&(u=$(r,"offset","batchNorm")),M(i.rank===l.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),M(u==null||i.rank===u.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),M(c==null||i.rank===c.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let p={x:jD(o),scale:c,offset:u,mean:i,variance:l},h={varianceEpsilon:a},f=V.runKernel(Ya,p,h);return H(f,o.shape)}var Gu=U({batchNorm_:qD});function XD(e,t,n,r,s,a){let o=$(e,"x","batchNorm"),i=$(t,"mean","batchNorm"),l=$(n,"variance","batchNorm"),c;s!=null&&(c=$(s,"scale","batchNorm"));let u;return r!=null&&(u=$(r,"offset","batchNorm")),M(o.rank===2,()=>`Error in batchNorm2D: x must be rank 2 but got rank ${o.rank}.`),M(i.rank===2||i.rank===1,()=>`Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank ${i.rank}.`),M(l.rank===2||l.rank===1,()=>`Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank ${l.rank}.`),c!=null&&M(c.rank===2||c.rank===1,()=>`Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank ${c.rank}.`),u!=null&&M(u.rank===2||u.rank===1,()=>`Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank ${u.rank}.`),Gu(o,i,l,u,c,a)}var Tv=U({batchNorm2d_:XD});function KD(e,t,n,r,s,a){let o=$(e,"x","batchNorm"),i=$(t,"mean","batchNorm"),l=$(n,"variance","batchNorm"),c;s!=null&&(c=$(s,"scale","batchNorm"));let u;return r!=null&&(u=$(r,"offset","batchNorm")),M(o.rank===3,()=>`Error in batchNorm3D: x must be rank 3 but got rank ${o.rank}.`),M(i.rank===3||i.rank===1,()=>`Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank ${i.rank}.`),M(l.rank===3||l.rank===1,()=>`Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank ${l.rank}.`),c!=null&&M(c.rank===3||c.rank===1,()=>`Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank ${c.rank}.`),u!=null&&M(u.rank===3||u.rank===1,()=>`Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank ${u.rank}.`),Gu(o,i,l,u,c,a)}var Nv=U({batchNorm3d_:KD});function ZD(e,t,n,r,s,a){let o=$(e,"x","batchNorm"),i=$(t,"mean","batchNorm"),l=$(n,"variance","batchNorm"),c;s!=null&&(c=$(s,"scale","batchNor
${s} and ${t} for depthToSpace with input shape
${r.shape}`),M(a*t>=0,()=>`Negative dimension size caused by overflow when multiplying
2021-11-08 13:36:26 +01:00
${a} and ${t} for depthToSpace with input shape
2022-01-16 15:49:55 +01:00
${r.shape}`),M(o%(t*t)===0,()=>`Dimension size must be evenly divisible by ${t*t} but is ${o} for depthToSpace with input shape ${r.shape}`);let i={x:r},l={blockSize:t,dataFormat:n};return V.runKernel(wi,i,l)}var zv=U({depthToSpace_:yP});function AP(e,t,n,r,s="NHWC",a=[1,1],o){let i=$(e,"x","depthwiseConv2d","float32"),l=$(t,"filter","depthwiseConv2d","float32"),c=i,u=!1;i.rank===3&&(u=!0,c=H(i,[1,i.shape[0],i.shape[1],i.shape[2]])),M(c.rank===4,()=>`Error in depthwiseConv2d: input must be rank 4, but got rank ${c.rank}.`),M(l.rank===4,()=>`Error in depthwiseConv2d: filter must be rank 4, but got rank ${l.rank}.`),M(c.shape[3]===l.shape[2],()=>`Error in depthwiseConv2d: number of input channels (${c.shape[3]}) must match the inChannels dimension in filter ${l.shape[2]}.`),Un("depthwiseConv2d",r,o);let d={x:c,filter:l},p={strides:n,pad:r,dataFormat:s,dilations:a,dimRoundingMode:o},h=V.runKernel(Ha,d,p);return u?H(h,[h.shape[1],h.shape[2],h.shape[3]]):h}var Xd=U({depthwiseConv2d_:AP});function xP(e){let n={x:$(e,"x","diag")};return V.runKernel(Xh,n)}var bP=U({diag_:xP});function vP(e,t,n,r,s=[1,1],a="NHWC"){let o=$(e,"x","dilation2d"),i=$(t,"filter","dilation2d");M(o.rank===3||o.rank===4,()=>`Error in dilation2d: input must be rank 3 or 4, but got rank ${o.rank}.`),M(i.rank===3,()=>`Error in dilation2d: filter must be rank 3, but got rank ${i.rank}.`),M(a==="NHWC",()=>`Error in dilation2d: Only NHWC is currently supported, but got dataFormat of ${a}`);let l=o,c=!1;o.rank===3&&(l=H(o,[1,o.shape[0],o.shape[1],o.shape[2]]),c=!0);let u={x:l,filter:i},d={strides:n,pad:r,dilations:s},p=V.runKernel(xd,u,d);return c?H(p,[p.shape[1],p.shape[2],p.shape[3]]):p}var Lv=U({dilation2d_:vP});function wP(e,t){let n=$(e,"a","equal","string_or_numeric"),r=$(t,"b","equal","string_or_numeric");[n,r]=Mt(n,r),xt(n.shape,r.shape);let s={a:n,b:r};return V.runKernel(ki,s)}var zr=U({equal_:wP});function kP(e,t,n){let r=$(t,"a","where"),s=$(n,"b","where"),a=$(e,"condition","where","bool"),o=xt(xt(a.shape,r.shape),s.shape),i=qd(a,o),l=qd(r,o),c=qd(s,o),u={condition:i,t:l,e:c};return V.runKernel(Hi,u)}var Gn=U({where_:kP});function IP(e){let n={x:$(e,"x","zerosLike")};return V.runKernel(tl,n)}var at=U({zerosLike_:IP});function SP(e,t){let n=$(e,"a","div"),r=$(t,"b","div");[n,r]=Mt(n,r);let s=de(n,r),a=at(s),o=zr(r,a);return Gn(o,a,s)}var Bv=U({divNoNan_:SP});function CP(e,t){let n=$(e,"t1","dot"),r=$(t,"t2","dot");M((n.rank===1||n.rank===2)&&(r.rank===1||r.rank===2),()=>`Error in dot: inputs must all be rank 1 or 2, but got ranks ${n.rank} and ${r.rank}.`);let s=n.rank===1?n.size:n.shape[1],a=r.rank===1?r.size:r.shape[0];if(M(s===a,()=>`Error in dot: inner dimensions of inputs must match, but got ${s} and ${a}.`),n.rank===1&&r.rank===1){let o=H(n,[1,-1]),i=H(r,[-1,1]),l=qe(o,i);return H(l,[])}else if(n.rank===1&&r.rank===2){let o=H(n,[1,-1]),i=H(r,[r.shape[0],r.shape[1]]),l=qe(o,i);return H(l,[l.size])}else if(n.rank===2&&r.rank===1){let o=H(r,[-1,1]),i=qe(n,o);return H(i,[i.size])}else{let o=H(r,[r.shape[0],r.shape[1]]);return qe(n,o)}}var TP=U({dot_:CP});function NP(e,...t){let n=t.map((s,a)=>$(s,`tensors${a}`,"einsum")),r={equation:e};return V.runKernel(bd,n,r)}var Wv=U({einsum_:NP});function EP(e){let n={x:$(e,"x","elu","float32")};return V.runKernel(qa,n)}var Kd=U({elu_:EP});function RP(e){let t=$(e,"x","erf");M(t.dtype==="int32"||t.dtype==="float32",()=>"Input dtype must be `int32` or `float32`."),t.dtype==="int32"&&(t=ge(t,"float32"));let n={x:t};return V.runKernel(xu,n)}var Vv=U({erf_:RP});function _P(e){let n={x:$(e,"x","exp")};return V.runKernel(Xa,n)}var Lr=U({exp_:_P});function DP(e,t=0){let n=$(e,"x","expandDims","string_or_numeric");M(t<=n.rank,()=>"Axis must be <= rank of the tensor");let r={input:n},s={dim:t};return V.runKernel(Ii,r,s)}var Yt=U({expandDims_:DP});function PP(e){let n={x:$(e,"x","expm1")};return V.runKernel(Si,n)}var Uv=U({expm1_:PP});function $P(e,t){let n=$(e,"x","tile","string_or_numeric");M(n.rank===t.length,()=>`Error in transpose: rank of input ${n.rank} must match length of reps ${t}.`);let r={x:n},s={reps
rank ${a.rank}.`),M(ou(t),()=>`Error in localResponseNormalization: depthRadius must be an integer but got depthRadius ${t}.`);let o=a,i=!1;a.rank===3&&(i=!0,o=H(a,[1,a.shape[0],a.shape[1],a.shape[2]]));let l={x:o},c={depthRadius:t,bias:n,alpha:r,beta:s},u=V.runKernel(kd,l,c);return i?H(u,[u.shape[1],u.shape[2],u.shape[3]]):u}var jv=U({localResponseNormalization_:KP});function ZP(e){let n={x:$(e,"x","log","float32")};return V.runKernel(to,n)}var Br=U({log_:ZP});function YP(e){let n={x:$(e,"x","log1p")};return V.runKernel(Iu,n)}var Ef=U({log1p_:YP});function JP(e){return M($a(e),()=>"The f passed in grad(f) must be a function"),(t,n)=>{let r=$(t,"x","tf.grad","string_or_numeric"),s=n!=null?$(n,"dy","tf.grad"):null;return V.tidy(()=>{let{value:a,grads:o}=V.gradients(()=>e(r),[r],s);return s!=null&&Ln(a.shape,s.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Rf(o),o[0]})}}function QP(e){return M($a(e),()=>"The f passed in grads(f) must be a function"),(t,n)=>{M(Array.isArray(t),()=>"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");let r=Vd(t,"args","tf.grads","string_or_numeric"),s=n!=null?$(n,"dy","tf.grads"):null;return V.tidy(()=>{let{value:a,grads:o}=V.gradients(()=>e(...r),r,s);return s!=null&&Ln(a.shape,s.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Rf(o),o})}}function e$(e){return M($a(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,n)=>{M(t instanceof nt,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),M(n==null||n instanceof nt,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");let{grads:r,value:s}=V.gradients(()=>e(t),[t],n);return Rf(r),{grad:r[0],value:s}}}function t$(e){return M($a(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,n)=>{M(Array.isArray(t)&&t.every(s=>s instanceof nt),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),M(n==null||n instanceof nt,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");let r=V.gradients(()=>e(...t),t,n);return n!=null&&Ln(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Rf(r.grads),r}}function qv(e,t){M($a(e),()=>"The f passed in variableGrads(f) must be a function"),M(t==null||Array.isArray(t)&&t.every(c=>c instanceof Bd),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");let n=t!=null;if(!n){t=[];for(let c in V.registeredVariables)t.push(V.registeredVariables[c])}let r=n?t.filter(c=>!c.trainable):null,s=t.length;t=t.filter(c=>c.trainable),M(t.length>0,()=>`variableGrads() expects at least one of the input variables to be trainable, but none of the ${s} variables is trainable.`);let a=!0,{value:o,grads:i}=V.gradients(e,t,null,a);M(i.some(c=>c!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),M(o.rank===0,()=>`The f passed in variableGrads(f) must return a scalar, but it returned a rank-${o.rank} tensor`);let l={};return t.forEach((c,u)=>{i[u]!=null&&(l[c.name]=i[u])}),r!=null&&r.forEach(c=>l[c.name]=null),{value:o,grads:l}}function Fs(e){return V.customGrad(e)}function Rf(e){if(e.filter(n=>n==null).length>0)throw new Error(`Cannot compute gradient of y=f(x) with respect to x. Make sure that
the f you passed encloses all operations that lead from x to y.`)}function n$(e){let n={x:$(e,"x","neg")};return V.runKernel(Pi,n)}var Lt=U({neg_:n$});function r$(e){let n={x:$(e,"x","softplus")};return V.runKernel(Pu,n)}var Xu=U({softplus_:r$});function s$(e){let t=$(e,"x","logSigmoid");return Fs(r=>({value:Lt(Xu(Lt(r))),gradFunc:o=>L(o,Pn(Lt(r)))}))(t)}var a$=U({logSigmoid_:s$});function o$(e,t=null,n=!1){let s={x:$(e,"x","max")},a={reductionIndices:t,keepDims:n};return V.runKernel(no,s,a)}var bn=U({max_:o$});function i$(e,t){let n=$(e,"a","sub"),r=$(t,"b","sub");[n,r]=Mt(n,r);let s={a:n,b:r};return V.runKernel(Io,s)}var pe=U({sub_:i$});function l$(e,t=null,n=!1){let r=$(e,"x","sum");r.dtype==="bool"&&(r=ge(r,"int32"));let s={x:r},a={axis:t,keepDims:n};return V.runKernel(vo,s,a)}var we=U({sum_:l$});function u$(e,t=-1){let n=$(e,"logits","logSoftmax");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error(`Log Softmax along a non-last dimension is not yet supported. Logits was rank ${n.rank} and axis was ${t}`);return Fs((s,a)=>{let o=!0,i=bn(s,t,!0),l=pe(s,i),c=pe(ge(l,"float32"),Br(we(Lr(l),t,o)));return a([c]),{value:c,gradFunc:(d,p)=>{let[h]=p,f=!0,m=Lr(h);return pe(d,L(we(d,t,f),m))}}})(n)}var Iy=U({logSoftmax_:u$});function Sy(e,t){for(let n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function Xv(e,t,n){let r=e.length+t.length,s=[],a=0,o=0;for(let i=0;i<r;i++)n.indexOf(i)===-1?s.push(e[a++]):s.push(t[o++]);return s}function Kv(e,t){let n=[],r=e.length;for(let a=0;a<r;a++)t.indexOf(a)===-1&&n.push(e[a]);let s=t.map(a=>e[a]);return[n,s]}function ml(e,t){let n=t.map(r=>1);return Xv(e,n,t)}function c$(e,t,n){M(Sy(t,n),()=>`${e} supports only inner-most axes for now. Got axes ${t} and rank-${n} input.`)}function Zv(e,t){if(Sy(e,t))return null;let n=[];for(let r=0;r<t;++r)e.indexOf(r)===-1&&n.push(r);return e.forEach(r=>n.push(r)),n}function Cy(e){return e.map((t,n)=>[n,t]).sort((t,n)=>t[1]-n[1]).map(t=>t[0])}function d$(e,t){let n=[];for(let r=t-e;r<t;++r)n.push(r);return n}function p$(e,t=null,n=!1){let r=$(e,"x","logSumExp"),s=Yr(t,r.shape),a=bn(r,s,!0),o=pe(r,a),i=Lr(o),l=we(i,s),c=Br(l),u=ue(H(a,c.shape),c);if(n){let d=ml(u.shape,s);return H(u,d)}return u}var Yv=U({logSumExp_:p$});function h$(e,t){let n=$(e,"a","logicalAnd","bool"),r=$(t,"b","logicalAnd","bool");xt(n.shape,r.shape);let s={a:n,b:r};return V.runKernel(Di,s)}var ys=U({logicalAnd_:h$});function f$(e){let n={x:$(e,"x","logicalNot","bool")};return V.runKernel(Su,n)}var _f=U({logicalNot_:f$});function m$(e,t){let n=$(e,"a","logicalOr","bool"),r=$(t,"b","logicalOr","bool");xt(n.shape,r.shape);let s={a:n,b:r};return V.runKernel(wd,s)}var Ty=U({logicalOr_:m$});function g$(e,t){let n=$(e,"a","logicalXor","bool"),r=$(t,"b","logicalXor","bool");return xt(n.shape,r.shape),ys(Ty(e,t),_f(ys(e,t)))}var y$=U({logicalXor_:g$});function A$(e,t,n,r,s){let a=$(e,"x","maxPool"),o=1,i=a,l=!1;a.rank===3&&(l=!0,i=H(a,[1,a.shape[0],a.shape[1],a.shape[2]])),M(i.rank===4,()=>`Error in maxPool: input must be rank 4 but got rank ${i.rank}.`),M($s(n,o),()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${n} and dilations '${o}'`),Un("maxPool",r,s);let c={x:i},u={filterSize:t,strides:n,pad:r,dimRoundingMode:s},d=V.runKernel(so,c,u);return l?H(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var Df=U({maxPool_:A$});function x$(e,t=[1,1,1],n,r,s,a="NDHWC"){let o=$(e,"x","maxPool3d"),i=o,l=!1;o.rank===4&&(l=!0,i=H(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),M(i.rank===5,()=>`Error in maxPool3d: x must be rank 5 but got rank ${i.rank}.`),M(a==="NDHWC",()=>`Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of ${a}`),Un("maxPool3d",r,s);let c={x:i},u={filterSize:t,strides:n,pad:r,dimRoundingMode:s,dataFormat:a},d=V.runKernel(Id,c,u);return l?H(d,[d.shape[1],d.shape[2],d.shape[3],d.shape[4]]):d}var Ny=U({maxPool3d_:x$});function b$(e,t,n,r,s=!1){let o={x:$(e,"x","maxPoolWithArgmax")},i={filterSize:t,strides:n,pad:r,includeBatchInIndex:s},l=V.runKernel(sf,o,i);return{result:l[0],indexes:l[1]}}var Jv=U({maxPoolWithArgmax_:b$});
${s.shape}`);if(a.rank!==1)throw new Error(`Values should be Tensor1D but received shape ${a.shape}`);if(o.rank!==1)throw new Error(`Dense shape should be Tensor1D but received shape ${o.shape}`);if(i.rank!==0)throw new Error(`Default value should be a scalar but received shape ${i.shape}`);let l={indices:s,values:a,denseShape:o,defaultValue:i},c=V.runKernel(Cd,l);return{outputIndices:c[0],outputValues:c[1],emptyRowIndicator:c[2],reverseIndexMap:c[3]}}var OM=U({sparseFillEmptyRows_:FM});function MM(e,t,n){let r=$(e,"inputIndices","sparseReshape","int32"),s=$(t,"inputShape","sparseReshape","int32"),a=$(n,"newShape","sparseReshape","int32");if(r.rank!==2)throw new Error(`Input indices should be Tensor2D but received shape
${r.shape}`);if(s.rank!==1)throw new Error(`Input shape should be Tensor1D but received shape ${s.shape}`);if(a.rank!==1)throw new Error(`New shape should be Tensor1D but received shape ${a.shape}`);let o={inputIndices:r,inputShape:s,newShape:a},i=V.runKernel($u,o);return{outputIndices:i[0],outputShape:i[1]}}var zM=U({sparseReshape_:MM});function LM(e,t,n){let r=$(e,"data","sparseSegmentMean"),s=$(t,"indices","sparseSegmentMean","int32"),a=$(n,"segmentIds","sparseSegmentMean","int32");if(r.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.rank!==1)throw new Error(`Indices should be Tensor1D but received shape
${s.shape}`);if(a.rank!==1)throw new Error(`Segment ids should be Tensor1D but received shape
${a.shape}`);let o={data:r,indices:s,segmentIds:a};return V.runKernel(Td,o)}var BM=U({sparseSegmentMean_:LM});function WM(e,t,n){let r=$(e,"data","sparseSegmentSum"),s=$(t,"indices","sparseSegmentSum","int32"),a=$(n,"segmentIds","sparseSegmentSum","int32");if(r.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.rank!==1)throw new Error(`Indices should be Tensor1D but received shape
${s.shape}`);if(a.rank!==1)throw new Error(`Segment ids should be Tensor1D but received shape
${a.shape}`);let o={data:r,indices:s,segmentIds:a};return V.runKernel(Nd,o)}var VM=U({sparseSegmentSum_:WM});function UM(e,t,n,r,s,a,o,i){let l=$(e,"data","stringNGrams","string");if(l.dtype!=="string")throw new Error("Data must be of datatype string");if(l.shape.length!==1)throw new Error(`Data must be a vector, saw: ${l.shape}`);let c=$(t,"dataSplits","stringNGrams");if(c.dtype!=="int32")throw new Error("Data splits must be of datatype int32");let u={separator:n,nGramWidths:r,leftPad:s,rightPad:a,padWidth:o,preserveShortSequences:i},d={data:l,dataSplits:c},p=V.runKernel(Rd,d,u);return{nGrams:p[0],nGramsSplits:p[1]}}var GM=U({stringNGrams_:UM});function HM(e,t,n=!0){let r=$(e,"input","stringSplit","string"),s=$(t,"delimiter","stringSplit","string");if(r.rank!==1)throw new Error(`Input should be Tensor1D but received shape ${r.shape}`);if(s.rank!==0)throw new Error(`Delimiter should be a scalar but received shape ${s.shape}`);let a={skipEmpty:n},o={input:r,delimiter:s},i=V.runKernel(uf,o,a);return{indices:i[0],values:i[1],shape:i[2]}}var jM=U({stringSplit_:HM});function qM(e,t){let n=$(e,"input","stringToHashBucketFast","string"),r={numBuckets:t};if(t<=0)throw new Error("Number of buckets must be at least 1");let s={input:n};return V.runKernel(cf,s,r)}var XM=U({stringToHashBucketFast_:qM}),KM={fft:Mf,ifft:Qd,rfft:zf,irfft:Ly},ZM={hammingWindow:IO,hannWindow:xw,frame:bw,stft:NO},Ie={flipLeftRight:DO,grayscaleToRGB:$O,resizeNearestNeighbor:sM,resizeBilinear:nM,rotateWithOffset:OO,cropAndResize:RO,nonMaxSuppression:zO,nonMaxSuppressionAsync:jO,nonMaxSuppressionWithScore:XO,nonMaxSuppressionWithScoreAsync:ZO,nonMaxSuppressionPadded:JO,nonMaxSuppressionPaddedAsync:eM,threshold:iM,transform:uM},Cw={bandPart:dM,gramSchmidt:hM,qr:mM},YM={absoluteDifference:AM,computeWeightedLoss:ta,cosineDistance:bM,hingeLoss:wM,huberLoss:IM,logLoss:CM,meanSquaredError:NM,sigmoidCrossEntropy:_M,softmaxCrossEntropy:$M},tp={sparseFillEmptyRows:OM,sparseReshape:zM,sparseSegmentMean:BM,sparseSegmentSum:VM},Gf={stringNGrams:GM,stringSplit:jM,stringToHashBucketFast:XM},na=class extends pv{minimize(e,t=!1,n){let{value:r,grads:s}=this.computeGradients(e,n);if(n!=null){let a=n.map(o=>({name:o.name,tensor:s[o.name]}));this.applyGradients(a)}else this.applyGradients(s);return te(s),t?r:(r.dispose(),null)}get iterations(){return this.iterations_==null&&(this.iterations_=0),this.iterations_}incrementIterations(){this.iterations_=this.iterations+1}computeGradients(e,t){return qv(e,t)}dispose(){this.iterations_!=null&&te(this.iterations_)}async saveIterations(){return this.iterations_==null&&(this.iterations_=0),{name:"iter",tensor:Te(this.iterations_,"int32")}}async getWeights(){throw new Error("getWeights() is not implemented for this optimizer yet.")}async setWeights(e){throw new Error(`setWeights() is not implemented for this optimizer class ${this.getClassName()}`)}async extractIterations(e){return this.iterations_=(await e[0].tensor.data())[0],e.slice(1)}};Object.defineProperty(na,Symbol.hasInstance,{value:e=>e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null});var Hf=class extends na{constructor(e,t,n=null){super();this.learningRate=e,this.rho=t,this.epsilon=n,this.accumulatedGrads=[],this.accumulatedUpdates=[],n==null&&(this.epsilon=V.backend.epsilon())}applyGradients(e){(Array.isArray(e)?e.map(n=>n.name):Object.keys(e)).forEach((n,r)=>{let s=V.registeredVariables[n],a=!1;this.accumulatedGrads[r]==null&&(this.accumulatedGrads[r]={originalName:`${n}/accum_grad`,variable:X(()=>at(s).variable(a))}),this.accumulatedUpdates[r]==null&&(this.accumulatedUpdates[r]={originalName:`${n}/accum_var`,variable:X(()=>at(s).variable(a))});let o=Array.isArray(e)?e[r].tensor:e[n];if(o==null)return;let i=this.accumulatedGrads[r].variable,l=this.accumulatedUpdates[r].variable;X(()=>{let c=ue(L(i,this.rho),L(bt(o),1-this.rho)),u=L(de($n(ue(l,this.epsilon)),$n(ue(i,this.epsilon))),o),d=ue(L(l,this.rho),L(bt(u),1-this.rho));i.assign(c),l.assign(d);let p=ue(L(u,-this.learningRate),s);s.assign(p)})}),this.incrementIterations()}dispose(){this.accumulate
indices.shape[0] = ${e}`}function _z(e,t){return`indices(${e}, 0) is invalid: ${t} < 0`}function Dz(e,t,n){return`indices(${e}, 0) is invalid: ${t} >= ${n}`}function Pz(e,t){return`only one output dimension may be -1, not both ${e} and ${t}`}function $z(e,t){return`size ${e} must be non-negative, not ${t}`}function Fz(){return"reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero"}function Oz(e,t){let n=Ct(e),r=Ct(t);return`Input to reshape is a SparseTensor with ${n}
dense values, but the requested shape requires a multiple of ${r}. inputShape=${e} outputShape= ${t}`}function Mz(e,t){let n=Ct(e),r=Ct(t);return`Input to reshape is a tensor with ${n} dense values, but the requested shape has ${r}. inputShape=${e} outputShape=${t}`}function zz(){return"segment ids must be >= 0"}function Lz(){return"segment ids are not increasing"}function Bz(e,t){return`Segment id ${e} out of range [0, ${t}), possibly because segmentIds input is not sorted.`}function Wz(e,t,n){return`Bad: indices[${e}] == ${t} out of range [0, ${n})`}var Dw={};Me(Dw,{collectGatherOpShapeInfo:()=>Gz,computeOutShape:()=>Uz,segOpComputeOptimalWindowSize:()=>Vz});function Vz(e,t){let n=!1,r;for(e<=Xy?(r=e,n=!0):r=Oh(e,Math.floor(Math.sqrt(e)));!n;)r>t||r===e?n=!0:r=Oh(e,r+1);return r}function Uz(e,t,n){let r=[],s=e.length;for(let a=0;a<s;a++)a!==t?r.push(e[a]):r.push(n);return r}function Gz(e,t,n,r){let s=t.shape.length,a=e.shape.length;if(r!==0&&(r<-s||r>s))throw new Error(`Expect batchDims in the range of [-${s}, ${s}], but got ${r}`);if(r<0&&(r+=s),r>a)throw new Error(`batchDims (${r}) must be less than rank(x) (
${a}).`);if(n<r)throw new Error(`batchDims (${r}) must be less than or equal to axis (${n}).`);for(let d=0;d<r;++d)if(e.shape[d]!==t.shape[d])throw new Error(`x.shape[${d}]: ${e.shape[d]} should be equal to indices.shape[${d}]: ${t.shape[d]}.`);let o=e.shape[n],i=[],l=1,c=1,u=1;for(let d=0;d<r;++d)i.push(e.shape[d]),l*=e.shape[d];for(let d=r;d<n;d++)i.push(e.shape[d]),c*=e.shape[d];for(let d=r;d<s;d++)i.push(t.shape[d]);for(let d=n+1;d<a;d++)i.push(e.shape[d]),u*=e.shape[d];return{batchSize:l,sliceSize:u,outerSize:c,dimSize:o,outputShape:i}}function Hz(e){try{return e.map(t=>mf(t))}catch(t){throw new Error(`Failed to decode encoded string bytes into utf-8, error: ${t}`)}}function jz(e){return e.map(t=>Od(t))}var ts={};Me(ts,{nonMaxSuppressionV3Impl:()=>vw,nonMaxSuppressionV4Impl:()=>ww,nonMaxSuppressionV5Impl:()=>kw,whereImpl:()=>dw});var Pw={kernelName:yi,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>L(e,ep(ge(n,"float32"),-1))}}},qz={kernelName:uu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>{let r=bt(ge(n,"float32")),s=$n(pe(Te(1),r));return Lt(de(e,s))}}}},Xz={kernelName:cu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>{let r=$n(pe(bt(ge(n,"float32")),1));return de(e,r)}}}},Kz={kernelName:Zs,inputsToSave:["a","b"],gradFunc:(e,t)=>{let[n,r]=t,s=xt(n.shape,r.shape);return{a:()=>{let i=e,l=Zt(n.shape,s);return l.length>0&&(i=we(i,l)),H(i,n.shape)},b:()=>{let i=e,l=Zt(r.shape,s);return l.length>0&&(i=we(i,l)),H(i,r.shape)}}}},Zz={kernelName:Fa,saveAllInputs:!0,gradFunc:(e,t)=>{let n={};return t.forEach((r,s)=>{n[s]=()=>e.clone()}),n}},Yz={kernelName:Oa,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>at(n)}}},Jz={kernelName:hu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>at(n)}}},Qz={kernelName:fu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>de(e,$n(pe(Te(1),bt(ge(n,"float32")))))}}},eL={kernelName:mu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>{let r=$n(ue(Te(1),bt(ge(n,"float32"))));return de(e,r)}}}},tL={kernelName:Au,inputsToSave:["a","b"],gradFunc:(e,t)=>{let[n,r]=t,s=xt(n.shape,r.shape);return{a:()=>{let i=ue(bt(n),bt(r)),l=L(e,de(r,i)),c=Zt(n.shape,s);return c.length>0&&(l=we(l,c)),H(l,n.shape)},b:()=>{let i=ue(bt(n),bt(r)),l=Lt(L(e,de(n,i))),c=Zt(r.shape,s);return c.length>0&&(l=we(l,c)),H(l,r.shape)}}}},nL={kernelName:gu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>de(e,ue(bt(ge(n,"float32")),1))}}},rL={kernelName:yu,inputsToSave:["x"],gradFunc:(e,t)=>{let[n]=t;return{x:()=>de(e,pe(Te(1),bt(ge(n,"float32"))))}}};function sL(e,t,n,r,s,a){let o=$(e,"dy","avgPool3dGrad"),i=$(t,"input","avgPool3dGrad"),l=o,c=i,u=!1;i.rank===4&&(u=!0,l=H(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]]),c=H(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),M(l.rank===5,()=>`Error in avgPool3dGrad: dy must be rank 5 but got rank ${l.rank}.`),M(c.rank===5,()=>`Error in avgPool3dGrad: input must be rank 5 but got rank ${c.rank}.`),Un("avgPool3dGrad",s,a);let d={dy:l,input:c},p={filterSize:n,strides:r,pad:s,dimRoundingMode:a},h=V.runKernel(Lh,d,p);return u?H(h,[h.shape[1],h.shape[2],h.shape[3],h.shape[4]]):h}var aL=U({avgPool3dGrad_:sL}),oL={kernelName:md,inputsToSave:["x"],gradFunc:(e,t,n)=>{let[r]=t,{filterSize:s,strides:a,pad:o,dimRoundingMode:i}=n;return{x:()=>aL(e,r,s,a,o,i)}}};function iL(e,t,n,r,s){let a=$(e,"dy","avgPoolGrad"),o=$(t,"input","avgPoolGrad");M(o.rank===a.rank,()=>`Rank of input (${o.rank}) does not match rank of dy (${a.rank})`);let i=o,l=a,c=!1;o.rank===3&&(c=!0,i=H(o,[1,o.shape[0],o.shape[1],o.shape[2]]),l=H(a,[1,a.shape[0],a.shape[1],a.shape[2]])),M(l.rank===4,()=>`Error in avgPoolGrad: dy must be rank 4 but got rank ${l.rank}.`),M(i.rank===4,()=>`Error in avgPoolGrad: input must be rank 4 but got rank ${i.rank}.`);let u={dy:l,input:i},d={filterSize:n,strides:r,pad:s},p=V.runKernel(zh,u,d);return c?H(p,[p.shape[1],p.shape[2],p.shape[3]]):p}var lL=U({avgPoolGrad_:iL}),uL={kernelName:Ma,inputsToSave:["x"],gradFunc:(e,t,n)=>{let[r]=t,{filterSize:s,strides:a,pad:o}=n;return{x:()=>lL(e,r,s,a,o)}}},cL={kernelName:
1. The ${r} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom ${r} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);return o}else{let a=e;if(a.className==null||a.config==null)throw new q(`${r}: Improper config format: ${JSON.stringify(a)}.
'className' and 'config' must set.`);let o=a.className,i,l;if(o in n?[i,l]=n[o]:o in ns?[i,l]=ns.className:o in t&&([i,l]=t[o]),i==null)throw new q(`Unknown ${r}: ${o}. This may be due to one of the following reasons:
1. The ${r} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom ${r} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);if(l!=null){let c={};for(let h of Object.keys(ns))c[h]=ns[h];for(let h of Object.keys(n))c[h]=n[h];let u=a.config;u.customObjects=c;let d={...ns};for(let h of Object.keys(n))ns[h]=n[h];Jy(a.config);let p=l(i,a.config,n,s);return ns={...d},p}else{let c={...ns};for(let d of Object.keys(n))ns[d]=n[d];let u=new i(a.config);return ns={...c},u}}}function XB(e,t){return e<t?-1:e>t?1:0}function Yf(e,t){return-1*XB(e,t)}function Uo(e){if(e==null)return e;let t=[];for(let n of e)t.indexOf(n)===-1&&t.push(n);return t}function KB(e){if(e==null)throw new q(`Invalid value in obj: ${JSON.stringify(e)}`);for(let t in e)if(e.hasOwnProperty(t))return!1;return!0}function vl(e,t,n){if(n!=null&&e.indexOf(n)<0)throw new q(`${n} is not a valid ${t}. Valid values are ${e} or null/undefined.`)}function Qy(e,t,n=0,r=1/0){return Ms(n>=0),Ms(r>=n),Array.isArray(e)&&e.length>=n&&e.length<=r&&e.every(s=>typeof s===t)}function vn(e,t){Array.isArray(e)?(w.assert(e.length>0,()=>`${t} is unexpectedly an empty array.`),e.forEach((n,r)=>vn(n,`element ${r+1} of ${t}`))):w.assert(Number.isInteger(e)&&e>0,()=>`Expected ${t} to be a positive integer, but got ${Gw(e)}.`)}function Gw(e){return e===null?"null":Array.isArray(e)?"["+e.map(t=>Gw(t)).join(",")+"]":typeof e=="string"?`"${e}"`:`${e}`}function ZB(e,t,n){let r=n!=null?n():w.now(),s;return(...o)=>{let i=n!=null?n():w.now();return i-r<t||(r=i,s=e(...o)),s}}function Hw(e){return e==="relu"?"relu":e==="linear"?"linear":e==="elu"?"elu":null}function e1(e,t){return X(()=>$n(we(L(e,e),t,!0)))}var sp=class extends ce.Serializable{getConfig(){return{}}},t1=class extends sp{constructor(e){super();this.defaultMaxValue=2,this.defaultAxis=0,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return X(()=>{let t=e1(e,this.axis),n=br(t,0,this.maxValue);return L(e,de(n,ue(ln(),t)))})}getConfig(){return{maxValue:this.maxValue,axis:this.axis}}};t1.className="MaxNorm";ce.registerClass(t1);var n1=class extends sp{constructor(e){super();this.defaultAxis=0,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return X(()=>de(e,ue(ln(),e1(e,this.axis))))}getConfig(){return{axis:this.axis}}};n1.className="UnitNorm";ce.registerClass(n1);var r1=class extends sp{apply(e){return Os(e)}};r1.className="NonNeg";ce.registerClass(r1);var s1=class extends sp{constructor(e){super();this.defaultMinValue=0,this.defaultMaxValue=1,this.defaultRate=1,this.defaultAxis=0,this.minValue=e.minValue!=null?e.minValue:this.defaultMinValue,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.rate=e.rate!=null?e.rate:this.defaultRate,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return X(()=>{let t=e1(e,this.axis),n=ue(L(this.rate,br(t,this.minValue,this.maxValue)),L(1-this.rate,t));return L(e,de(n,ue(ln(),t)))})}getConfig(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}}};s1.className="MinMaxNorm";ce.registerClass(s1);var jw={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function un(e){return Yy(e)}function qw(e,t={}){return rp(e,ce.SerializationMap.getMap().classNameMap,t,"constraint")}function cn(e){if(e==null)return null;if(typeof e=="string"){let n={className:e in jw?jw[e]:e,config:{}};return qw(n)}else return e instanceof sp?e:qw(e)}function YB(e){return new t1(e)}function JB(e){return new n1(e)}function QB(){return new r1}function eW(e){return new s1(e)}var Xw={};Me(Xw,{constant:()=>kW,glorotNormal:()=>RW,glorotUniform:()=>EW,heNormal:()=>_W,heUniform:()=>DW,identity:()=>TW,leCunNormal:()=>PW,leCunUniform:()=>$W,ones:()=>wW,orthogonal:()=>FW,randomNormal:()=>SW,randomUniform:()=>IW,truncatedNormal:()=>CW,varianceScaling:()=>NW,zeros:()=>vW});var tW=["channelsFirst","channelsLast"],nW=["nearest","bilinear"],rW=["valid","same","causal"],sW=["max","avg"],aW=["sum","mul","concat","ave"],tc=new Map;function jt(e){vl(tW,"DataFormat",e)}function oW(e){vl(nW,"InterpolationForm
because the value dtype is ${t.dtype}, but TensorArray dtype is ${this.dtype}.`);if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=t.shape),ss(this.elementShape,t.shape,`TensorArray ${this.name}: Could not write to TensorArray index ${e}.`),n.read)throw new Error(`TensorArray ${this.name}: Could not write to TensorArray index ${e}, because it has already been read.`);if(n.written)throw new Error(`TensorArray ${this.name}: Could not write to TensorArray index ${e}, because it has already been written.`);n.tensor=t,xn(t),n.written=!0,this.tensors[e]=n}writeMany(e,t){if(e.length!==t.length)throw new Error(`TensorArray ${this.name}: could not write multiple tensors,because the index size: ${e.length} is not the same as tensors size: ${t.length}.`);e.forEach((n,r)=>this.write(n,t[r]))}gather(e,t){if(!!t&&t!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but gather requested dtype ${t}`);if(e)e=e.slice(0,this.size());else{e=[];for(let r=0;r<this.size();r++)e.push(r)}if(e.length===0)return ht([],[0].concat(this.elementShape));let n=this.readMany(e);return ss(this.elementShape,n[0].shape,"TensorArray shape mismatch: "),on(n,0)}concat(e){if(!!e&&e!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but concat requested dtype ${e}`);if(this.size()===0)return ht([],[0].concat(this.elementShape));let t=[];for(let r=0;r<this.size();r++)t.push(r);let n=this.readMany(t);return ss(this.elementShape,n[0].shape,`TensorArray shape mismatch: tensor array shape (${this.elementShape}) vs first tensor shape (${n[0].shape})`),St(n,0)}scatter(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${t.dtype}`);if(e.length!==t.shape[0])throw new Error(`Expected len(indices) == tensor.shape[0], but saw: ${e.length} vs. ${t.shape[0]}`);let n=Math.max(...e);if(!this.dynamicSize&&n>=this.maxSize)throw new Error(`Max index must be < array size (${n} vs. ${this.maxSize})`);this.writeMany(e,ir(t,0))}split(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${t.dtype}`);let n=0,r=e.map(i=>(n+=i,n));if(n!==t.shape[0])throw new Error(`Expected sum of lengths to be equal to
2021-11-08 13:36:26 +01:00
tensor.shape[0], but sum of lengths is
2022-01-16 15:49:55 +01:00
${n}, and tensor's shape is: ${t.shape}`);if(!this.dynamicSize&&e.length!==this.maxSize)throw new Error(`TensorArray's size is not equal to the size of lengths (${this.maxSize} vs. ${e.length}), and the TensorArray is not marked as dynamically resizeable`);let s=n===0?0:t.size/n,a=[];X(()=>{t=H(t,[1,n,s]);for(let i=0;i<e.length;++i){let l=i===0?0:r[i-1],c=[0,l,0],u=[1,e[i],s];a[i]=H(Fe(t,c,u),this.elementShape)}return a});let o=[];for(let i=0;i<e.length;i++)o[i]=i;this.writeMany(o,a)}},bp=class{constructor(e,t,n,r=-1){this.tensors=e,this.elementShape=t,this.elementDtype=n,e!=null&&e.forEach(s=>{if(n!==s.dtype)throw new Error(`Invalid data types; op elements ${n}, but list elements ${s.dtype}`);ss(t,s.shape,"TensorList shape mismatch: "),xn(s)}),this.idTensor=Te(0),this.maxNumElements=r,xn(this.idTensor)}get id(){return this.idTensor.id}copy(){return new bp([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(e){this.tensors.forEach(t=>{(e==null||!e.has(t.id))&&t.dispose()}),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(e,t,n=-1){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);if(n!==-1&&this.tensors.length!==n)throw new Error(`Operation expected a list with ${n} elements but got a list with ${this.tensors.length} elements.`);ss(e,this.elementShape,"TensorList shape mismatch: ");let r=xp(this.elementShape,this.tensors,e);return X(()=>{let s=this.tensors.map(a=>H(a,r));return on(s,0)})}popBack(e,t){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);if(this.size()===0)throw new Error("Trying to pop from an empty list.");let n=xp(this.elementShape,this.tensors,e),r=this.tensors.pop();return ss(r.shape,e,"TensorList shape mismatch: "),H(r,n)}pushBack(e){if(e.dtype!==this.elementDtype)throw new Error(`Invalid data types; op elements ${e.dtype}, but list elements ${this.elementDtype}`);if(ss(e.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");xn(e),this.tensors.push(e)}resize(e){if(e<0)throw new Error(`TensorListResize expects size to be non-negative. Got: ${e}`);if(this.maxNumElements!==-1&&e>this.maxNumElements)throw new Error(`TensorListResize input size ${e} is greater maxNumElement ${this.maxNumElements}.`);this.tensors.length=e}getItem(e,t,n){if(n!==this.elementDtype)throw new Error(`Invalid data types; op elements ${n}, but list elements ${this.elementDtype}`);if(e<0||e>this.tensors.length)throw new Error(`Trying to access element ${e} in a list with ${this.tensors.length} elements.`);if(this.tensors[e]==null)throw new Error(`element at index ${e} is null.`);ss(this.tensors[e].shape,t,"TensorList shape mismatch: ");let r=xp(this.elementShape,this.tensors,t);return H(this.tensors[e],r)}setItem(e,t){if(t.dtype!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t.dtype}, but list elements ${this.elementDtype}`);if(e<0||this.maxNumElements!==-1&&e>=this.maxNumElements)throw new Error(`Trying to set element ${e} in a list with max ${this.maxNumElements} elements.`);ss(this.elementShape,t.shape,"TensorList shape mismatch: "),xn(t),this.tensors[e]=t}gather(e,t,n){if(t!==this.elementDtype)throw new Error(`Invalid data types; op elements ${t}, but list elements ${this.elementDtype}`);ss(this.elementShape,n,"TensorList shape mismatch: "),e=e.slice(0,this.size());let r=xp(this.elementShape,this.tensors,n);return e.length===0?ht([],[0].concat(r)):X(()=>{let s=e.map(a=>H(this.tensors[a],r));return on(s,0)})}concat(e,t){if(!!e&&e!==this.elementDtype)throw new Error(`TensorList dtype is ${this.elementDtype} but concat requested dtype ${e}`);ss(this.elementShape,t,"TensorList shape mismatch: ");let n=xp(this.elementShape,this.tensors,t);return this.size()===0?ht([],[0].concat(n)):X(()=>{let r=this.tensors.map(s=>H(s,n));return St(r,0)})}};function sH(e,t,n){let r=e.dtype;if(e.shape.length<1)throw new Error(`Tensor m
2021-11-08 13:36:26 +01:00
tensor.shape[0], but sum of lengths is
2022-01-16 15:49:55 +01:00
${r}, and tensor's shape is: ${e.shape}`);let a=e.shape.slice(1),o=YA(a,n),i=r===0?0:e.size/r,l=X(()=>{let u=[];e=H(e,[1,r,i]);for(let d=0;d<t.length;++d){let p=d===0?0:s[d-1],h=[0,p,0],f=[1,t[d],i];u[d]=H(Fe(e,h,f),o)}return e.dispose(),u}),c=new bp([],n,e.dtype,t.length);for(let u=0;u<l.length;u++)c.setItem(u,l[u]);return c}var lH=async(e,t,n)=>{switch(e.op){case"If":case"StatelessIf":{let r=k("thenBranch",e,t,n),s=k("elseBranch",e,t,n),a=k("cond",e,t,n),o=k("args",e,t,n);return(await a.data())[0]?n.functionMap[r].executeFunctionAsync(o,n.tensorArrayMap,n.tensorListMap):n.functionMap[s].executeFunctionAsync(o,n.tensorArrayMap,n.tensorListMap)}case"While":case"StatelessWhile":{let r=k("body",e,t,n),s=k("cond",e,t,n),a=k("args",e,t,n),o=await n.functionMap[s].executeFunctionAsync(a,n.tensorArrayMap,n.tensorListMap),i=a.map(u=>u.id),l=await o[0].data();o.forEach(u=>{!u.kept&&i.indexOf(u.id)===-1&&u.dispose()});let c=a;for(;l[0];){let u=c;c=await n.functionMap[r].executeFunctionAsync(c,n.tensorArrayMap,n.tensorListMap);let d=c.map(h=>h.id);u.forEach(h=>{!h.kept&&i.indexOf(h.id)===-1&&d.indexOf(h.id)===-1&&h.dispose()});let p=await n.functionMap[s].executeFunctionAsync(c,n.tensorArrayMap,n.tensorListMap);l=await p[0].data(),p.forEach(h=>{!h.kept&&i.indexOf(h.id)===-1&&d.indexOf(h.id)===-1&&h.dispose()})}return c}case"LoopCond":{let r=k("pred",e,t,n);return[ia(r)]}case"Switch":{let r=k("pred",e,t,n),s=k("data",e,t,n);return s.kept||(s=ia(s)),(await r.data())[0]?[void 0,s]:[s,void 0]}case"Merge":{let r=e.inputNames.find(s=>Hn(s,t,n)!==void 0);if(r){let s=Hn(r,t,n);return[ia(s)]}return}case"Enter":{let r=k("frameName",e,t,n),s=k("tensor",e,t,n);return n.enterFrame(r),[ia(s)]}case"Exit":{let r=k("tensor",e,t,n);return n.exitFrame(),[ia(r)]}case"NextIteration":{let r=k("tensor",e,t,n);return n.nextIteration(),[ia(r)]}case"TensorArrayV3":{let r=k("size",e,t,n),s=k("dtype",e,t,n),a=k("elementShape",e,t,n),o=k("dynamicSize",e,t,n),i=k("clearAfterRead",e,t,n),l=k("identicalElementShapes",e,t,n),c=k("name",e,t,n),u=new rH(c,s,r,a,l,o,i);return n.addTensorArray(u),[u.idTensor,Te(1)]}case"TensorArrayWriteV3":{let r=k("tensorArrayId",e,t,n),s=k("index",e,t,n),a=k("tensor",e,t,n),o=n.getTensorArray(r.id);return o.write(s,a),[o.idTensor]}case"TensorArrayReadV3":{let r=k("tensorArrayId",e,t,n),s=k("index",e,t,n);return[n.getTensorArray(r.id).read(s)]}case"TensorArrayGatherV3":{let r=k("tensorArrayId",e,t,n),s=k("indices",e,t,n),a=k("dtype",e,t,n);return[n.getTensorArray(r.id).gather(s,a)]}case"TensorArrayScatterV3":{let r=k("tensorArrayId",e,t,n),s=k("indices",e,t,n),a=k("tensor",e,t,n),o=n.getTensorArray(r.id);return o.scatter(s,a),[o.idTensor]}case"TensorArrayConcatV3":{let r=k("tensorArrayId",e,t,n),s=n.getTensorArray(r.id),a=k("dtype",e,t,n);return[s.concat(a)]}case"TensorArraySplitV3":{let r=k("tensorArrayId",e,t,n),s=k("tensor",e,t,n),a=k("lengths",e,t,n),o=n.getTensorArray(r.id);return o.split(a,s),[o.idTensor]}case"TensorArraySizeV3":{let r=k("tensorArrayId",e,t,n),s=n.getTensorArray(r.id);return[Te(s.size(),"int32")]}case"TensorArrayCloseV3":{let r=k("tensorArrayId",e,t,n),s=n.getTensorArray(r.id);return s.clearAndClose(),[s.idTensor]}case"TensorListSetItem":{let r=k("tensorListId",e,t,n),s=k("index",e,t,n),a=k("tensor",e,t,n),o=n.getTensorList(r.id);return o.setItem(s,a),[o.idTensor]}case"TensorListGetItem":{let r=k("tensorListId",e,t,n),s=k("index",e,t,n),a=k("elementShape",e,t,n),o=k("elementDType",e,t,n);return[n.getTensorList(r.id).getItem(s,a,o)]}case"TensorListScatterV2":case"TensorListScatter":{let r=k("indices",e,t,n),s=k("tensor",e,t,n),a=k("elementShape",e,t,n),o=k("numElements",e,t,n),i=oH(s,r,a,o);return n.addTensorList(i),[i.idTensor]}case"TensorListReserve":case"EmptyTensorList":{let r=k("elementShape",e,t,n),s=k("elementDType",e,t,n),a;e.op==="TensorListReserve"?a="numElements":a="maxNumElements";let o=k(a,e,t,n),i=aH(r,s,o);return n.addTensorList(i),[i.idTensor]}case"TensorListGather":{let r=k("tensorListId",e,t,n),s=k("indices",e,t,n),a=k("elementShape",e,t,n),o=k("elementDType",e,t,n);return[n.getTensor
${e}`);let r;return this.size===1/0||this.size==null?r=this.size:t?r=Math.ceil(this.size/e):r=Math.floor(this.size/e),Ir(async()=>(await n.iterator()).columnMajorBatch(e,t,oj),r)}concatenate(e){let t=this,n;return this.size===1/0||e.size===1/0?n=1/0:this.size!=null&&e.size!=null?n=this.size+e.size:n=null,Ir(async()=>(await t.iterator()).concatenate(await e.iterator()),n)}filter(e){let t=this,n;return this.size===1/0?n=1/0:n=null,Ir(async()=>(await t.iterator()).filter(r=>X(()=>e(r))),n)}async forEachAsync(e){return(await this.iterator()).forEachAsync(e)}map(e){let t=this;return Ir(async()=>(await t.iterator()).map(n=>X(()=>e(n))),this.size)}mapAsync(e){let t=this;return Ir(async()=>(await t.iterator()).mapAsync(e),this.size)}prefetch(e){if(e==null)throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");let t=this;return Ir(async()=>(await t.iterator()).prefetch(e),this.size)}repeat(e){let t=this,n;return this.size!=null&&e>0?n=this.size*e:e===0?n=0:this.size!=null&&(e===void 0||e<0)?n=1/0:n=null,Ir(async()=>{let r=tx(async()=>({value:await t.iterator(),done:!1}));return GH(r.take(e))},n)}skip(e){let t=this,n;return this.size!=null&&e>=0&&this.size>=e?n=this.size-e:this.size!=null&&(this.size<e||e===void 0||e<0)?n=0:n=null,Ir(async()=>(await t.iterator()).skip(e),n)}shuffle(e,t,n=!0){if(e==null||e<0)throw this.size==null?new RangeError("`Dataset.shuffle()` requires bufferSize to be specified."):new RangeError(`\`Dataset.shuffle()\` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \`tf.Tensor\`s), consider setting bufferSize to the dataset size (${this.size} elements)`);let r=this,s=OH.alea(t||w.now().toString());return Ir(async()=>{let a=s.int32();return n&&(a+=s.int32()),(await r.iterator()).shuffle(e,a.toString())},this.size)}take(e){let t=this,n;return this.size!=null&&this.size>e?n=e:this.size!=null&&this.size<=e?n=this.size:n=null,Ir(async()=>(await t.iterator()).take(e),n)}async toArray(){if(this.size===1/0)throw new Error("Can not convert infinite data stream to array.");return(await this.iterator()).toArray()}async toArrayForTest(){if(this.size===1/0)throw new Error("Can not convert infinite data stream to array.");return(await this.iterator()).toArrayForTest()}};lc.MAX_BUFFER_SIZE=1e4;function Ir(e,t=null){return new class extends lc{constructor(){super(...arguments);this.size=t}async iterator(){return e()}}}function sj(e){return Ir(async()=>pS(e),e.length)}function aj(e){if(!ic(e))throw new Error("The argument to zip() must be an object or array.");let t;if(Array.isArray(e))for(let n=0;n<e.length;n++)t=t==null?e[n].size:Math.min(t,e[n].size);else if(e instanceof Object)for(let n in e)t=t==null?e[n].size:Math.min(t,e[n].size);return Ir(async()=>{let n=await lS(e,r=>{if(r instanceof lc)return{value:r.iterator(),recurse:!1};if(ic(r))return{value:null,recurse:!0};throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.")});return HH(n,rx.SHORTEST)},t)}function oj(e){if(e===null)return null;let t=e[0];return BH(t)?{value:ij(e),recurse:!1}:{value:null,recurse:!0}}function ij(e){if(e.length===0)throw new Error("Can't make a batch of zero elements.");return e[0]instanceof nt?on(e):ht(e)}var gS=class extends lc{constructor(e){super();this.input=e}async iterator(){return(await this.input.iterator()).decodeUTF8().split(`
`).map(r=>(r.endsWith("\r")&&(r=r.slice(0,-1)),r))}},$m='"',vp=Symbol("out"),yS=Symbol("field"),Fm=Symbol("quote"),sx=Symbol("quoteafterquote"),AS=Symbol("quoteinquote"),xS=class extends lc{constructor(e,t){super();this.input=e,this.hasHeader=!0,this.fullColumnNames=null,this.columnNamesValidated=!1,this.columnConfigs=null,this.configuredColumnsOnly=!1,this.delimiter=",",this.delimWhitespace=!1,this.base=new gS(e),t||(t={}),this.hasHeader=t.hasHeader!==!1,this.fullColumnNames=t.columnNames,this.columnConfigs=t.columnConfigs,this.configuredColumnsOnly=t.configuredColumnsOnly,t.delimWhitespace?(w.assert(t.delimiter==null,()=>"Delimiter should not be provided when delimWhitespace is true."),this.delimWhitespace=!0,this.delimiter=" "):this.delimiter=t.delimiter?t.delimiter:","}async columnNames(){return this.columnNamesValidated||await this.setColumnNames(),this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames}async setColumnNames(){let e=await this.maybeReadHeaderLine();if(!this.fullColumnNames&&!e)throw new Error("Column names must be provided if there is no header line.");this.fullColumnNames&&e&&w.assert(e.length===this.fullColumnNames.length,()=>"The length of provided columnNames ("+this.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+e.length.toString()+")."),this.fullColumnNames||(this.fullColumnNames=e);let t=this.fullColumnNames.reduce((r,s)=>(r[s]=r[s]+1||1,r),{}),n=Object.keys(t).filter(r=>t[r]>1);if(w.assert(n.length===0,()=>"Duplicate column names found: "+n.toString()),this.columnConfigs){for(let r of Object.keys(this.columnConfigs))if(this.fullColumnNames.indexOf(r)===-1)throw new Error('The key "'+r+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}this.columnNamesValidated=!0}async maybeReadHeaderLine(){if(this.hasHeader){let t=await(await this.base.iterator()).next();if(t.done)throw new Error("No data was found for CSV parsing.");let n=t.value;return this.parseRow(n,!1)}else return null}async iterator(){this.columnNamesValidated||await this.setColumnNames();let e=await this.base.iterator();return this.hasHeader&&(e=e.skip(1)),e.map(t=>this.makeDataElement(t))}makeDataElement(e){let t=this.parseRow(e),n={},r={};for(let s=0;s<this.fullColumnNames.length;s++){let a=this.fullColumnNames[s],o=this.columnConfigs?this.columnConfigs[a]:null;if(!(this.configuredColumnsOnly&&!o)){let i=t[s],l=null;if(i==="")if(o&&o.default!==void 0)l=o.default;else{if(o&&(o.required||o.isLabel))throw new Error(`Required column ${a} is empty in this line: ${e}`);l=void 0}else{let c=Number(i);if(isNaN(c))o&&o.dtype==="bool"?l=this.getBoolean(i):l=i;else if(!o||!o.dtype)l=c;else switch(o.dtype){case"float32":l=c;break;case"int32":l=Math.floor(c);break;case"bool":l=this.getBoolean(i);break;default:l=c}}o&&o.isLabel?r[a]=l:n[a]=l}}return Object.keys(r).length===0?n:{xs:n,ys:r}}getBoolean(e){return e==="1"||e.toLowerCase()==="true"?1:0}parseRow(e,t=!0){let n=[],r=0,s=e.length,a=vp;for(let o=0;o<s;o++)switch(a){case vp:switch(e.charAt(o)){case $m:r=o+1,a=Fm;break;case this.delimiter:if(r=o+1,this.delimiter===" "&&this.delimWhitespace)break;n.push(""),a=vp;break;default:a=yS,r=o;break}break;case yS:switch(e.charAt(o)){case this.delimiter:n.push(e.substring(r,o)),a=vp,r=o+1;break;default:}break;case Fm:switch(e.charAt(o)){case $m:a=sx;break;default:}break;case sx:switch(e.charAt(o)){case this.delimiter:n.push(e.substring(r,o-1)),a=vp,r=o+1;break;case $m:a=Fm;break;default:a=AS;break}break;case AS:switch(e.charAt(o)){case $m:a=Fm;break;default:}break;default:}if(a===sx?n.push(e.substring(r,s-1)):n.push(e.substring(r)),t&&n.length!==this.fullColumnNames.length)throw new Error(`Invalid row in csv file. Should have ${this.fullColumnNames.length} elements in a row, but got ${n}`);return n}},bS=class extends wn{constructor(e){super();this.microphoneConfig=e,this.isClosed=!1,this.fftSize=e.fftSize||1024;let t=Math.log2(this.fftSize);if(this.fftSize<0||t<4||t>14||!Number.isInteger(t))throw new Error(`Invalid fftSi
2021-11-08 13:36:26 +01:00
============================
Hi there \u{1F44B}. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
2022-01-16 15:49:55 +01:00
============================`));let r={id:this.nextDataId()};return this.data.set(r,{values:e,dtype:n,refCount:1}),r}makeTensorInfo(e,t,n){let r;if(t==="string"&&n!=null&&n.length>0&&w.isString(n[0])){let s=n.map(a=>w.encodeString(a));r=this.write(s,e,t)}else r=this.write(n,e,t);return{dataId:r,shape:e,dtype:t}}refCount(e){return this.data.has(e)?this.data.get(e).refCount:0}incRef(e){let t=this.data.get(e);t.refCount++}decRef(e){if(this.data.has(e)){let t=this.data.get(e);t.refCount--}}move(e,t,n,r,s){this.data.set(e,{values:t,dtype:r,refCount:s})}numDataIds(){return this.data.numDataIds()}async read(e){return this.readSync(e)}readSync(e){let{dtype:t,complexTensorInfos:n}=this.data.get(e);if(t==="complex64"){let r=this.readSync(n.real.dataId),s=this.readSync(n.imag.dataId);return N.mergeRealAndImagArrays(r,s)}return this.data.get(e).values}bufferSync(e){let t=this.readSync(e.dataId),n=t;if(e.dtype==="string")try{n=t.map(r=>w.decodeString(r))}catch(r){throw new Error("Failed to decode encoded string bytes into utf-8")}return Le(e.shape,e.dtype,n)}makeOutput(e,t,n){let r=this.write(e,t,n);return Dn().makeTensorFromDataId(r,t,n,this)}disposeData(e,t=!1){if(this.data.has(e)){if(this.data.get(e).refCount--,!t&&this.data.get(e).refCount>0)return!1;let{complexTensorInfos:n}=this.data.get(e);n!=null&&(this.disposeData(n.real.dataId,!0),this.disposeData(n.imag.dataId,!0)),this.data.delete(e)}return!0}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}async time(e){let t=w.now();return e(),{kernelMs:w.now()-t}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(e){Re([e],"where");let t=this.readSync(e.dataId);return vj(e.shape,t)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}},ax=NS;ax.nextDataId=0;var Om={};Me(Om,{addImpl:()=>RS,bincountImpl:()=>ix,bincountReduceImpl:()=>_S,ceilImpl:()=>DS,concatImpl:()=>lx,equalImpl:()=>PS,expImpl:()=>FS,expm1Impl:()=>MS,floorImpl:()=>zS,gatherNdImpl:()=>LS,gatherV2Impl:()=>BS,greaterEqualImpl:()=>VS,greaterImpl:()=>WS,lessEqualImpl:()=>GS,lessImpl:()=>US,linSpaceImpl:()=>HS,logImpl:()=>jS,maxImpl:()=>qS,maximumImpl:()=>XS,minimumImpl:()=>KS,multiplyImpl:()=>ux,negImpl:()=>ZS,notEqualImpl:()=>YS,prodImpl:()=>JS,rangeImpl:()=>dx,rsqrtImpl:()=>QS,sigmoidImpl:()=>uq,simpleAbsImpl:()=>ES,sliceImpl:()=>Lm,sparseFillEmptyRowsImpl:()=>t7,sparseReshapeImpl:()=>n7,sparseSegmentReductionImpl:()=>px,sqrtImpl:()=>pq,squaredDifferenceImpl:()=>r7,stridedSliceImpl:()=>s7,stringNGramsImpl:()=>a7,stringSplitImpl:()=>o7,stringToHashBucketFastImpl:()=>i7,subImpl:()=>l7,tileImpl:()=>u7,topKImpl:()=>d7,transposeImpl:()=>cx,uniqueImpl:()=>p7});function ES(e){let t=new Float32Array(e.length);for(let n=0;n<e.length;++n)t[n]=Math.abs(e[n]);return t}var wj=e=>{let{x:t}=e.inputs,n=e.backend;Re(t,"abs");let r=new Float32Array(w.sizeFromShape(t.shape)),s=n.data.get(t.dataId).values;return r=ES(s),n.makeOutput(r,t.shape,t.dtype)},kj={kernelName:yi,backendName:"cpu",kernelFunc:wj};function en(e){return(t,n,r,s,a)=>{let o=N.assertAndGetBroadcastShape(t,n),i=o.length,l=w.computeStrides(o),c=w.sizeFromShape(o),u=w.getTypedArrayFromDType(a,c),d=t.length,p=n.length,h=w.computeStrides(t),f=w.computeStrides(n),m=N.getBroadcastDims(t,o),g=N.getBroadcastDims(n,o);if(m.length+g.length===0)for(let y=0;y<u.length;++y)u[y]=e(r[y%r.length],s[y%s.length]);else for(let y=0;y<u.length;++y){let x=w.indexToLoc(y,i,l),A=x.slice(-d);m.forEach(I=>A[I]=0);let b=w.locToIndex(A,d,h),v=x.slice(-p);g.forEach(I=>v[I]=0);let C=w.locToIndex(v,p,f);u[y]=e(r[b],s[C])}return[u,o]}}function Sr(e){let{inputs:t,backend:n}=e,{real:r,imag:s}=t,a=n.data.get(r.dataId).values,o=n.data.get(s.dataId).values,i=n.makeTensorInfo(r.shape,"complex64"),l=n.data.get(i.dataId);return l.complexTensorInfos={real:n.makeTensorInfo(r.shape,"float32",a),imag:n.makeTensorInfo(s.shape,"float32",o)},i}var Ij={kernelName:gd,backendName:"cpu",kernelFunc:Sr};function Mm(e,t,n="float32"){if(n==="complex64"){let s=Mm(e,t,"float32"),a=Mm(e,t,"flo
${a.shape}`);if(r.shape.length!==2)throw new Error(`Indices must be a matrix, saw:
${r.shape}`);if(s.shape.length!==1)throw new Error(`Values must be a vector, saw:
${s.shape}`);if(o.shape.length!==0)throw new Error(`Default value must be a scalar, saw:
${o.shape}`);let i=n.data.get(r.dataId).values,l=n.data.get(s.dataId).values,c=n.data.get(a.dataId).values,u=n.data.get(o.dataId).values[0],[d,p,h,f,m]=t7(i,r.shape,r.dtype,l,s.dtype,c,u);return[n.makeTensorInfo(p,r.dtype,d),n.makeTensorInfo([p[0]],s.dtype,h),n.makeTensorInfo([f.length],"bool",new Uint8Array(f.map(g=>Number(g)))),n.makeTensorInfo([m.length],r.dtype,new Int32Array(m))]}var $Y={kernelName:Cd,backendName:"cpu",kernelFunc:PY};function FY(e){let{inputs:t,backend:n}=e,{inputIndices:r,inputShape:s,newShape:a}=t;if(r.shape.length!==2)throw new Error(`Input indices should be a matrix but received shape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Input shape should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Target shape should be a vector but received shape ${a.shape}`);let o=Array.from(n.data.get(s.dataId).values),i=n.data.get(r.dataId).values,l=Array.from(n.data.get(a.dataId).values),[c,u,d]=n7(i,r.shape,r.dtype,o,l);return[n.makeTensorInfo(u,r.dtype,c),n.makeTensorInfo([d.length],a.dtype,new Int32Array(d))]}var OY={kernelName:$u,backendName:"cpu",kernelFunc:FY};function MY(e){let{inputs:t,backend:n}=e,{data:r,indices:s,segmentIds:a}=t;if(r.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.shape.length!==1)throw new Error(`Indices should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Segment ids should be a vector but received shape
${a.shape}`);if(s.shape[0]!==a.shape[0])throw new Error("segmentIds and indices should have same size.");let o=n.data.get(r.dataId).values,i=n.data.get(s.dataId).values,l=n.data.get(a.dataId).values,[c,u]=px(o,r.shape,r.dtype,i,l,!0);return n.makeTensorInfo(u,r.dtype,c)}var zY={kernelName:Td,backendName:"cpu",kernelFunc:MY};function LY(e){let{inputs:t,backend:n}=e,{data:r,indices:s,segmentIds:a}=t;if(r.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.shape.length!==1)throw new Error(`Indices should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Segment ids should be a vector but received shape
${a.shape}`);if(s.shape[0]!==a.shape[0])throw new Error("segmentIds and indices should have same size.");let o=n.data.get(r.dataId).values,i=n.data.get(s.dataId).values,l=n.data.get(a.dataId).values,[c,u]=px(o,r.shape,r.dtype,i,l);return n.makeTensorInfo(u,r.dtype,c)}var BY={kernelName:Nd,backendName:"cpu",kernelFunc:LY};function WY(e){let{inputs:t,backend:n,attrs:r}=e,{sparseIndices:s,sparseValues:a,defaultValue:o}=t,{outputShape:i}=r,{sliceRank:l,numUpdates:c,sliceSize:u,strides:d,outputSize:p}=N.calculateShapes(a,s,i),h=!1,f=n.bufferSync(s),m=n.bufferSync(a),g=n.data.get(o.dataId).values[0],y=E7(f,m,i,p,u,c,l,d,g,h);return n.makeTensorInfo(i,y.dtype,y.values)}var VY={kernelName:Ed,backendName:"cpu",kernelFunc:WY};function UY(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{numOrSizeSplits:a,axis:o}=r,i=w.parseAxisParam(o,s.shape)[0],l=N.prepareSplitSize(s,a,i),c=new Array(s.shape.length).fill(0),u=s.shape.slice();return l.map(d=>{let p=[...u];p[i]=d;let h=Nl({inputs:{x:s},backend:n,attrs:{begin:c,size:p}});return c[i]+=d,h})}var GY={kernelName:Ki,backendName:"cpu",kernelFunc:UY},HY={kernelName:Fu,backendName:"cpu",kernelFunc:({inputs:e,backend:t})=>{let{x:n}=e,r=t;Re(n,"square");let s=r.data.get(n.dataId).values,a=new Float32Array(s.length);for(let i=0;i<s.length;++i){let l=s[i];a[i]=l*l}return{dataId:r.write(a,n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},jY=gt(To,(e,t)=>{let n=t;return isNaN(e)?NaN:e>0?1:n.alpha}),qY={kernelName:To,backendName:"cpu",kernelFunc:jY};function XY(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{begin:a,end:o,strides:i,beginMask:l,endMask:c,ellipsisMask:u,newAxisMask:d,shrinkAxisMask:p}=r;Re(s,"stridedSlice");let{finalShapeSparse:h,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:x,end:A,strides:b}=zt.sliceInfo(s.shape,a,o,i,l,c,u,d,p),v;if(m)v=Ot({inputs:{x:s},backend:n,attrs:{shape:f}});else if(g||y){w.assert(s.shape.length>=1,()=>`Input must have rank at least 1, got: ${s.shape.length}`);let C=zt.computeOutShape(x,A,b),I=Nl({inputs:{x:s},backend:n,attrs:{begin:x,size:C}});v=Ot({inputs:{x:I},backend:n,attrs:{shape:f}}),n.disposeIntermediateTensorInfo(I)}else{let C=n.bufferSync(s),I=s7(h,C,b,x);v=n.makeTensorInfo(f,I.dtype,I.values)}return v}var KY={kernelName:Zi,backendName:"cpu",kernelFunc:XY};function ZY(e){let{inputs:t,backend:n,attrs:r}=e,{separator:s,nGramWidths:a,leftPad:o,rightPad:i,padWidth:l,preserveShortSequences:c}=r,{data:u,dataSplits:d}=t,p=n.data.get(u.dataId).values,h=n.data.get(d.dataId).values,[f,m]=a7(p,h,s,a,o,i,l,c);return[n.makeTensorInfo([f.length],"string",f),n.makeTensorInfo(d.shape,"int32",m)]}var YY={kernelName:Rd,backendName:"cpu",kernelFunc:ZY};function JY(e){let{inputs:t,backend:n,attrs:r}=e,{skipEmpty:s}=r,{input:a,delimiter:o}=t;if(a.dtype!=="string")throw new Error("Input must be of datatype string");if(a.shape.length!==1)throw new Error(`Input must be a vector, got shape: ${a.shape}`);if(o.shape.length!==0)throw new Error(`Delimiter must be a scalar, got shape: ${o.shape}`);let i=n.data.get(a.dataId).values,l=n.data.get(o.dataId).values[0],[c,u,d]=o7(i,l,s),p=u.length;return[n.makeTensorInfo([p,2],"int32",c),n.makeTensorInfo([p],"string",u),n.makeTensorInfo([2],"int32",new Int32Array(d))]}var QY={kernelName:uf,backendName:"cpu",kernelFunc:JY};function eJ(e){let{inputs:t,backend:n,attrs:r}=e,{numBuckets:s}=r,{input:a}=t;if(a.dtype!=="string")throw new Error("Input must be of datatype string");if(s<=0)throw new Error("Number of buckets must be at least 1");let o=n.data.get(a.dataId).values,i=i7(o,s);return n.makeTensorInfo(a.shape,"int32",i)}var tJ={kernelName:cf,backendName:"cpu",kernelFunc:eJ},nJ=gt(Yi,e=>Math.tan(e)),rJ={kernelName:Yi,backendName:"cpu",kernelFunc:nJ},sJ=gt(So,e=>Math.tanh(e)),aJ={kernelName:So,backendName:"cpu",kernelFunc:sJ};function oJ(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{reps:a}=r;Re(s,"tile");let o=u7(n.bufferSync(s),a);return n.makeTensorInfo(o.shape,o.dtype,o.values)}var iJ={kernelName:Js,backendName:"cpu",kernelFunc:oJ};function lJ(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{k:a,sorted:o}=r;Re(s,"topk
`),a=s.length.toString().length+2,o=s.map((d,p)=>w.rightPad((p+1).toString(),a)+d),i=0;for(let d=0;d<o.length;d++)i=Math.max(o[d].length,i);let l=o.slice(0,r-1),c=o.slice(r-1,r),u=o.slice(r);console.log(l.join(`
2021-11-08 13:36:26 +01:00
`)),console.log(t.split(`
`)[0]),console.log(`%c ${w.rightPad(c[0],i)}`,"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(u.join(`
2022-01-16 15:49:55 +01:00
`))}function M7(e){return la(e,()=>e.createProgram(),"Unable to create WebGLProgram.")}function z7(e,t){if(ke(e,()=>e.linkProgram(t)),e.getProgramParameter(t,e.LINK_STATUS)===!1)throw console.log(e.getProgramInfoLog(t)),new Error("Failed to link vertex and fragment shaders.")}function Hm(e,t){if(ke(e,()=>e.validateProgram(t)),e.getProgramParameter(t,e.VALIDATE_STATUS)===!1)throw console.log(e.getProgramInfoLog(t)),new Error("Shader program validation failed.")}function L7(e,t){let n=la(e,()=>e.createBuffer(),"Unable to create WebGLBuffer");return ke(e,()=>e.bindBuffer(e.ARRAY_BUFFER,n)),ke(e,()=>e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW)),n}function B7(e,t){let n=la(e,()=>e.createBuffer(),"Unable to create WebGLBuffer");return ke(e,()=>e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n)),ke(e,()=>e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW)),n}function $J(){return Y().getNumber("WEBGL_VERSION")===2?1:4}function W7(e){return la(e,()=>e.createTexture(),"Unable to create WebGLTexture.")}function V7(e,t){let n=Y().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(e<=0||t<=0){let r=`[${e}x${t}]`;throw new Error("Requested texture size "+r+" is invalid.")}if(e>n||t>n){let r=`[${e}x${t}]`,s=`[${n}x${n}]`;throw new Error("Requested texture size "+r+" greater than WebGL maximum on this browser / GPU "+s+".")}}function U7(e){return la(e,()=>e.createFramebuffer(),"Unable to create WebGLFramebuffer.")}function wx(e,t,n,r,s,a,o){let i=e.getAttribLocation(t,n);return i===-1?!1:(ke(e,()=>e.bindBuffer(e.ARRAY_BUFFER,r)),ke(e,()=>e.vertexAttribPointer(i,s,e.FLOAT,!1,a,o)),ke(e,()=>e.enableVertexAttribArray(i)),!0)}function G7(e,t,n){K7(e,n),ke(e,()=>e.activeTexture(e.TEXTURE0+n)),ke(e,()=>e.bindTexture(e.TEXTURE_2D,t))}function FJ(e,t){K7(e,t),ke(e,()=>e.activeTexture(e.TEXTURE0+t)),ke(e,()=>e.bindTexture(e.TEXTURE_2D,null))}function H7(e,t,n){return la(e,()=>e.getUniformLocation(t,n),'uniform "'+n+'" not present in program.')}function j7(e,t,n){return e.getUniformLocation(t,n)}function q7(e,t,n,r){ke(e,()=>G7(e,t,r)),ke(e,()=>e.uniform1i(n,r))}function OJ(e){ke(e,()=>e.bindFramebuffer(e.FRAMEBUFFER,null)),ke(e,()=>e.viewport(0,0,e.canvas.width,e.canvas.height)),ke(e,()=>e.scissor(0,0,e.canvas.width,e.canvas.height))}function jm(e,t,n){ke(e,()=>e.bindFramebuffer(e.FRAMEBUFFER,n)),ke(e,()=>e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0))}function kx(e,t){ke(e,()=>e.bindFramebuffer(e.FRAMEBUFFER,t)),ke(e,()=>e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0))}function Np(e){let t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+X7(e,t))}function X7(e,t){switch(t){case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case e.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return`unknown error ${t}`}}function la(e,t,n){let r=ke(e,()=>t());if(r==null)throw new Error(n);return r}function K7(e,t){let n=e.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,r=t+e.TEXTURE0;if(r<e.TEXTURE0||r>n){let s=`[gl.TEXTURE0, gl.TEXTURE${n}]`;throw new Error(`textureUnit must be in ${s}.`)}}function Rl(e,t=2){return w.sizeFromShape(e.slice(0,e.length-t))}function _l(e){if(e.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[e.length>1?e[e.length-2]:1,e[e.length-1]]}function qm(e){let t=[1,1,1];return e.length===0||e.length===1&&e[0]===1||(t=[Rl(e),..._l(e)]),t}function Z7(e,t=!1){let n=Y().getNumber("WEBGL_MAX_TEXTURE_SIZE");t&&(n=n*2,e=e.map((s,a)=>a>=e.length-2?w.nearestLargerEven(e[a]):e[a]),e.length===1&&(e=[2,e[0]])),e.length!==2&&(e=w.squeezeShape(e).newShape);let r=w.sizeFromShape(e);if(e.length<=1&&r<=n)return[1,r];if(e.length===2&&e[0]<=n&&e[1]<=n)return e;if(e.length===3&&e[0]*e[1]<=n&&e[2]<=n)return[e[0]*e[1],e[2]];if(e.length===3&&e[0]<=n&&e[1]*e[2]<=n)return[e[0],e[1]*e[2]];if(e.length===4&&e[0]*e[1]
2021-11-08 13:36:26 +01:00
bool isnan_custom(float val) {
return (val > 0.0 || val < 0.0) ? false : val != 0.0;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
bvec4 isnan_custom(vec4 val) {
return bvec4(isnan_custom(val.x),
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
#define isnan(value) isnan_custom(value)
`,l="",c=`
#define round(value) newRound(value)
int newRound(float value) {
return int(floor(value + 0.5));
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
ivec4 newRound(vec4 value) {
return ivec4(floor(value + vec4(0.5)));
2021-09-11 16:29:31 +02:00
}
2022-01-16 15:49:55 +01:00
`):(e="",t="attribute",n="varying",r="varying",s="texture2D",a="gl_FragColor",o="",i=`
2021-11-08 13:36:26 +01:00
#define isnan(value) isnan_custom(value)
bool isnan_custom(float val) {
return (val > 0. || val < 1. || val == 0.) ? false : true;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
bvec4 isnan_custom(vec4 val) {
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
`,l=`
uniform float INFINITY;
bool isinf(float val) {
return abs(val) == INFINITY;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
bvec4 isinf(vec4 val) {
return equal(abs(val), vec4(INFINITY));
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
`,c=`
int round(float value) {
return int(floor(value + 0.5));
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
ivec4 round(vec4 value) {
return ivec4(floor(value + vec4(0.5)));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`),{version:e,attribute:t,varyingVs:n,varyingFs:r,texture2D:s,output:a,defineOutput:o,defineSpecialNaN:i,defineSpecialInf:l,defineRound:c}}function Dl(e,t,n="index"){let r=w.computeStrides(t);return r.map((s,a)=>{let o=`int ${e[a]} = ${n} / ${s}`,i=a===r.length-1?`int ${e[a+1]} = ${n} - ${e[a]} * ${s}`:`index -= ${e[a]} * ${s}`;return`${o}; ${i};`}).join("")}function Ym(e,t,n="index"){let r=w.computeStrides(t);return r.map((s,a)=>{let o=`int ${e[a]} = ${n} / outShapeStrides[${a}]`,i=a===r.length-1?`int ${e[a+1]} = ${n} - ${e[a]} * outShapeStrides[${a}]`:`index -= ${e[a]} * outShapeStrides[${a}]`;return`${o}; ${i};`}).join("")}function BJ(e,t){let n=e.length,r=e.map(a=>`${t}[${a}]`),s=new Array(n-1);s[n-2]=r[n-1];for(let a=n-3;a>=0;--a)s[a]=`(${s[a+1]} * ${r[a+1]})`;return s}function WJ(e,t,n="index"){let r=e.map((a,o)=>o),s=BJ(r,t);return s.map((a,o)=>{let i=`int ${e[o]} = ${n} / ${s[o]}`,l=o===s.length-1?`int ${e[o+1]} = ${n} - ${e[o]} * ${s[o]}`:`index -= ${e[o]} * ${s[o]}`;return`${i}; ${l};`}).join("")}function Cx(e){let t=w.computeStrides(e).map(n=>n.toString());return`
2021-11-08 13:36:26 +01:00
int getFlatIndex(ivec3 coords) {
return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
}
2022-01-16 15:49:55 +01:00
`}function Tx(){return`
2021-11-08 13:36:26 +01:00
int getFlatIndex(ivec3 coords) {
return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
}
2022-01-16 15:49:55 +01:00
`}var rC=`
2021-11-08 13:36:26 +01:00
const float FLOAT_MAX = 1.70141184e38;
const float FLOAT_MIN = 1.17549435e-38;
lowp vec4 encode_float(highp float v) {
if (isnan(v)) {
return vec4(255, 255, 255, 255);
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
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;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
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;
}
2022-01-16 15:49:55 +01:00
`,{getBroadcastDims:sC}=N;function VJ(e,t,n){let r=[];if(e.forEach(h=>{let f=w.sizeFromShape(h.shapeInfo.logicalShape);if(h.shapeInfo.isUniform?r.push(`uniform float ${h.name}${f>1?`[${f}]`:""};`):(r.push(`uniform sampler2D ${h.name};`),r.push(`uniform int offset${h.name};`)),n.enableShapeUniforms){let{uniformShape:m}=Nx(n.packedInputs,h.shapeInfo.logicalShape,h.shapeInfo.texShape);switch(m.length){case 1:r.push(`uniform int ${h.name}Shape;`);break;case 2:r.push(`uniform ivec2 ${h.name}Shape;`);break;case 3:r.push(`uniform ivec3 ${h.name}Shape;`);break;case 4:r.push(`uniform ivec4 ${h.name}Shape;`);break;default:break}r.push(`uniform ivec2 ${h.name}TexShape;`)}}),n.enableShapeUniforms){switch(t.logicalShape.length){case 1:r.push("uniform int outShape;");break;case 2:r.push("uniform ivec2 outShape;"),r.push("uniform int outShapeStrides;");break;case 3:r.push("uniform ivec3 outShape;"),r.push("uniform ivec2 outShapeStrides;");break;case 4:r.push("uniform ivec4 outShape;"),r.push("uniform ivec3 outShapeStrides;");break;default:break}r.push("uniform ivec2 outTexShape;")}n.customUniforms&&n.customUniforms.forEach(h=>{r.push(`uniform ${h.type} ${h.name}${h.arrayIndex?`[${h.arrayIndex}]`:""};`)});let s=r.join(`
`),a=e.map(h=>UJ(h,t,n.packedInputs,n.enableShapeUniforms)).join(`
`),o=t.texShape,i=jn(),l=jJ(i),c,u,d=KJ(i);return t.isPacked?(c=GJ(t.logicalShape,o,n.enableShapeUniforms),u=XJ(i)):(c=HJ(t.logicalShape,o,n.enableShapeUniforms),u=qJ(i)),n.packedInputs&&(d+=QJ),[d,l,u,s,c,a,n.userCode].join(`
`)}function fc(e,t=!1){let n=e.shapeInfo.logicalShape;switch(n.length){case 0:return dQ(e,t);case 1:return hQ(e,t);case 2:return mQ(e,t);case 3:return yQ(e,t);case 4:return xQ(e,t);case 5:return bQ(e);case 6:return vQ(e);default:throw new Error(`${n.length}-D input sampling is not yet supported`)}}function aC(e,t){switch(e.shapeInfo.logicalShape.length){case 0:return cQ(e);case 1:return pQ(e,t);case 2:return fQ(e,t);case 3:return gQ(e,t);default:return AQ(e,t)}}function UJ(e,t,n=!1,r){let s="";n?s+=aC(e,r):s+=fc(e,r);let a=e.shapeInfo.logicalShape,o=t.logicalShape;return a.length<=o.length&&(n?s+=wQ(e,t):s+=kQ(e,t)),s}function GJ(e,t,n){switch(e.length){case 0:return oC();case 1:return eQ(e,t,n);case 2:return lQ(e,t,n);case 3:return nQ(e,t,n);default:return sQ(e,t,n)}}function HJ(e,t,n){switch(e.length){case 0:return oC();case 1:return tQ(e,t,n);case 2:return uQ(e,t,n);case 3:return rQ(e,t,n);case 4:return aQ(e,t,n);case 5:return oQ(e,t);case 6:return iQ(e,t);default:throw new Error(`${e.length}-D output sampling is not yet supported`)}}function jJ(e){return`
2021-11-08 13:36:26 +01:00
float sampleTexture(sampler2D textureSampler, vec2 uv) {
return ${e.texture2D}(textureSampler, uv).r;
2021-09-11 16:29:31 +02:00
}
2022-01-16 15:49:55 +01:00
`}function qJ(e){return`
2021-11-08 13:36:26 +01:00
void setOutput(float val) {
${e.output} = vec4(val, 0, 0, 0);
2021-09-11 16:29:31 +02:00
}
2022-01-16 15:49:55 +01:00
`}function XJ(e){return`
2021-11-08 13:36:26 +01:00
void setOutput(vec4 val) {
${e.output} = val;
2021-09-11 16:29:31 +02:00
}
2022-01-16 15:49:55 +01:00
`}function KJ(e){return`${e.version}
2021-11-08 13:36:26 +01:00
precision highp float;
precision highp int;
precision highp sampler2D;
${e.varyingFs} vec2 resultUV;
${e.defineOutput}
const vec2 halfCR = vec2(0.5, 0.5);
struct ivec5
{
int x;
int y;
int z;
int w;
int u;
};
struct ivec6
{
int x;
int y;
int z;
int w;
int u;
int v;
};
uniform float NAN;
${e.defineSpecialNaN}
${e.defineSpecialInf}
${e.defineRound}
int imod(int x, int y) {
return x - y * (x / y);
2021-09-01 00:24:30 +02:00
}
2021-11-08 13:36:26 +01:00
int idiv(int a, int b, float sign) {
int res = a / b;
int mod = imod(a, b);
if (sign < 0. && mod != 0) {
res -= 1;
}
return res;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
//Based on the work of Dave Hoskins
//https://www.shadertoy.com/view/4djSRW
#define HASHSCALE1 443.8975
float random(float seed){
vec2 p = resultUV * seed;
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
2021-06-05 21:10:28 +02:00
}
2021-09-01 00:24:30 +02:00
${ZJ}
2022-01-16 15:49:55 +01:00
${YJ}
${JJ}
`}var ZJ=`
2021-11-08 13:36:26 +01:00
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
int texR = index / texNumC;
int texC = index - texR * texNumC;
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
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);
}
2022-01-16 15:49:55 +01:00
`,YJ=`
2021-11-08 13:36:26 +01:00
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
int texNumC, 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);
}
2022-01-16 15:49:55 +01:00
`,JJ=`
2021-11-08 13:36:26 +01:00
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);
}
2022-01-16 15:49:55 +01:00
`,QJ=`
2021-11-08 13:36:26 +01:00
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);
}
float getChannel(vec4 frag, int dim) {
float modCoord = mod(float(dim), 2.);
return modCoord == 0. ? frag.r : frag.g;
}
2022-01-16 15:49:55 +01:00
`;function oC(){return`
2021-11-08 13:36:26 +01:00
int getOutputCoords() {
return 0;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function eQ(e,t,n){let r=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];return r[0]===1?n?`
2021-11-08 13:36:26 +01:00
int getOutputCoords() {
return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
int getOutputCoords() {
2022-01-16 15:49:55 +01:00
return 2 * int(resultUV.x * ${r[1]}.0);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`:r[1]===1?n?`
2021-11-08 13:36:26 +01:00
int getOutputCoords() {
return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
int getOutputCoords() {
2022-01-16 15:49:55 +01:00
return 2 * int(resultUV.y * ${r[0]}.0);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:n?`
int getOutputCoords() {
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(packedTexShape[0], packedTexShape[1]));
return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
int getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
2022-01-16 15:49:55 +01:00
vec2(${r[0]}, ${r[1]}));
return 2 * (resTexRC.x * ${r[1]} + resTexRC.y);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function tQ(e,t,n){return t[0]===1?n?`
2021-11-08 13:36:26 +01:00
int getOutputCoords() {
return int(resultUV.x * float(outTexShape[1]));
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
int getOutputCoords() {
return int(resultUV.x * ${t[1]}.0);
}
`:t[1]===1?n?`
int getOutputCoords() {
return int(resultUV.y * float(outTexShape[0]));
}
`:`
int getOutputCoords() {
return int(resultUV.y * ${t[0]}.0);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:n?`
int getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
return resTexRC.x * outTexShape[1] + resTexRC.y;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
int getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
return resTexRC.x * ${t[1]} + resTexRC.y;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function nQ(e,t,n){if(n)return`
2021-11-08 13:36:26 +01:00
ivec3 getOutputCoords() {
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(packedTexShape[0], packedTexShape[1]));
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
int b = index / texelsInBatch;
index -= b * texelsInBatch;
int r = 2 * (index / texelsInLogicalRow);
int c = imod(index, texelsInLogicalRow) * 2;
return ivec3(b, r, c);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;let r=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],s=Math.ceil(e[2]/2),a=s*Math.ceil(e[1]/2);return`
2021-11-08 13:36:26 +01:00
ivec3 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
2022-01-16 15:49:55 +01:00
vec2(${r[0]}, ${r[1]}));
int index = resTexRC.x * ${r[1]} + resTexRC.y;
2021-11-08 13:36:26 +01:00
int b = index / ${a};
index -= b * ${a};
2022-01-16 15:49:55 +01:00
int r = 2 * (index / ${s});
int c = imod(index, ${s}) * 2;
2021-11-08 13:36:26 +01:00
return ivec3(b, r, c);
}
2022-01-16 15:49:55 +01:00
`}function rQ(e,t,n){if(n)return`
2021-11-08 13:36:26 +01:00
ivec3 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
2022-01-16 15:49:55 +01:00
${Ym(["r","c","d"],e)}
2021-11-08 13:36:26 +01:00
return ivec3(r, c, d);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;let r=Dl(["r","c","d"],e);return`
2021-11-08 13:36:26 +01:00
ivec3 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
2022-01-16 15:49:55 +01:00
${r}
2021-11-08 13:36:26 +01:00
return ivec3(r, c, d);
}
2022-01-16 15:49:55 +01:00
`}function sQ(e,t,n){if(n)return`
2021-11-08 13:36:26 +01:00
ivec4 getOutputCoords() {
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(packedTexShape[0], packedTexShape[1]));
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));
int texelsInBatchN = texelsInBatch * outShape[1];
int b2 = index / texelsInBatchN;
index -= b2 * texelsInBatchN;
int b = index / texelsInBatch;
index -= b * texelsInBatch;
int r = 2 * (index / texelsInLogicalRow);
int c = imod(index, texelsInLogicalRow) * 2;
return ivec4(b2, b, r, c);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;let r=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],s=Math.ceil(e[e.length-1]/2),a=s*Math.ceil(e[e.length-2]/2),o=a,i="",l="b, r, c";for(let c=2;c<e.length-1;c++)o*=e[e.length-c-1],i=`
2021-11-08 13:36:26 +01:00
int b${c} = index / ${o};
index -= b${c} * ${o};
`+i,l=`b${c}, `+l;return`
ivec${e.length} getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
2022-01-16 15:49:55 +01:00
vec2(${r[0]}, ${r[1]}));
int index = resTexRC.x * ${r[1]} + resTexRC.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${i}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int b = index / ${a};
index -= b * ${a};
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
int r = 2 * (index / ${s});
int c = imod(index, ${s}) * 2;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
return ivec${e.length}(${l});
}
2022-01-16 15:49:55 +01:00
`}function aQ(e,t,n){if(n)return`
2021-11-08 13:36:26 +01:00
ivec4 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
2022-01-16 15:49:55 +01:00
${Ym(["r","c","d","d2"],e)}
2021-11-08 13:36:26 +01:00
return ivec4(r, c, d, d2);
}
2022-01-16 15:49:55 +01:00
`;let r=Dl(["r","c","d","d2"],e);return`
2021-11-08 13:36:26 +01:00
ivec4 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
2022-01-16 15:49:55 +01:00
${r}
2021-11-08 13:36:26 +01:00
return ivec4(r, c, d, d2);
}
2022-01-16 15:49:55 +01:00
`}function oQ(e,t){let n=Dl(["r","c","d","d2","d3"],e);return`
2021-11-08 13:36:26 +01:00
ivec5 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
${t[1]}));
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int index = resTexRC.x * ${t[1]} + resTexRC.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${n}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec5 outShape = ivec5(r, c, d, d2, d3);
return outShape;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function iQ(e,t){let n=Dl(["r","c","d","d2","d3","d4"],e);return`
2021-11-08 13:36:26 +01:00
ivec6 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
${n}
ivec6 result = ivec6(r, c, d, d2, d3, d4);
return result;
}
2022-01-16 15:49:55 +01:00
`}function lQ(e,t,n){let r=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];if(w.arraysEqual(e,t))return n?`
2021-11-08 13:36:26 +01:00
ivec2 getOutputCoords() {
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));
}
`:`
ivec2 getOutputCoords() {
2022-01-16 15:49:55 +01:00
return 2 * ivec2(resultUV.yx * vec2(${r[0]}, ${r[1]}));
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let s=Math.ceil(e[1]/2);return n?`
2021-11-08 13:36:26 +01:00
ivec2 getOutputCoords() {
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(packedTexShape[0], packedTexShape[1]));
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
int r = 2 * (index / texelsInLogicalRow);
int c = imod(index, texelsInLogicalRow) * 2;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
return ivec2(r, c);
}
`:`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
2022-01-16 15:49:55 +01:00
vec2(${r[0]}, ${r[1]}));
2021-09-01 00:24:30 +02:00
2022-01-16 15:49:55 +01:00
int index = resTexRC.x * ${r[1]} + resTexRC.y;
int r = 2 * (index / ${s});
int c = imod(index, ${s}) * 2;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
return ivec2(r, c);
}
2022-01-16 15:49:55 +01:00
`}function uQ(e,t,n){return w.arraysEqual(e,t)?n?`
2021-11-08 13:36:26 +01:00
ivec2 getOutputCoords() {
return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
ivec2 getOutputCoords() {
return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
}
`:e[1]===1?n?`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
return ivec2(index, 0);
}
`:`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
return ivec2(index, 0);
}
`:e[0]===1?n?`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
return ivec2(0, index);
}
`:`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
return ivec2(0, index);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:n?`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(outTexShape[0], outTexShape[1]));
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
int r = index / outShape[1];
int c = index - r * outShape[1];
return ivec2(r, c);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(${t[0]}, ${t[1]}));
int index = resTexRC.x * ${t[1]} + resTexRC.y;
int r = index / ${e[1]};
int c = index - r * ${e[1]};
return ivec2(r, c);
}
2022-01-16 15:49:55 +01:00
`}function Pl(e){return`offset${e}`}function cQ(e){let t=e.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1),r=jn();return`
2021-11-08 13:36:26 +01:00
vec4 ${n}() {
2022-01-16 15:49:55 +01:00
return ${r.texture2D}(${t}, halfCR);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function dQ(e,t){let n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1);if(e.shapeInfo.isUniform)return`float ${r}() {return ${n};}`;let[s,a]=e.shapeInfo.texShape;if(s===1&&a===1)return`
float ${r}() {
2021-11-08 13:36:26 +01:00
return sampleTexture(${n}, halfCR);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`;let o=Pl(n);if(t)return`
float ${r}() {
2021-11-08 13:36:26 +01:00
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${o});
return sampleTexture(${n}, uv);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`;let[i,l]=e.shapeInfo.texShape;return`
2022-01-16 15:49:55 +01:00
float ${r}() {
2021-11-08 13:36:26 +01:00
vec2 uv = uvFromFlat(${i}, ${l}, ${o});
return sampleTexture(${n}, uv);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function pQ(e,t){let n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),s=e.shapeInfo.texShape,a=jn();if(t)return`
vec4 ${r}(int index) {
2021-11-08 13:36:26 +01:00
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
vec2 uv = packedUVfrom1D(
packedTexShape[0], packedTexShape[1], index);
return ${a.texture2D}(${n}, uv);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;let o=[Math.ceil(s[0]/2),Math.ceil(s[1]/2)];return`
vec4 ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = packedUVfrom1D(
${o[0]}, ${o[1]}, index);
return ${a.texture2D}(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`}function hQ(e,t){let n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1);if(e.shapeInfo.isUniform)return`
float ${r}(int index) {
${mc(e)}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let s=e.shapeInfo.texShape,a=s[0],o=s[1];if(o===1&&a===1)return`
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
return sampleTexture(${n}, halfCR);
}
2022-01-16 15:49:55 +01:00
`;let i=Pl(n);return o===1?t?`
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = vec2(0.5, (float(index + ${i}) + 0.5) / float(${n}TexShape[0]));
return sampleTexture(${n}, uv);
}
`:`
2022-01-16 15:49:55 +01:00
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = vec2(0.5, (float(index + ${i}) + 0.5) / ${a}.0);
return sampleTexture(${n}, uv);
}
`:a===1?t?`
2022-01-16 15:49:55 +01:00
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = vec2((float(index + ${i}) + 0.5) / float(${n}TexShape[1]), 0.5);
return sampleTexture(${n}, uv);
}
`:`
2022-01-16 15:49:55 +01:00
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = vec2((float(index + ${i}) + 0.5) / ${o}.0, 0.5);
return sampleTexture(${n}, uv);
}
`:t?`
2022-01-16 15:49:55 +01:00
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${i});
return sampleTexture(${n}, uv);
}
`:`
2022-01-16 15:49:55 +01:00
float ${r}(int index) {
2021-11-08 13:36:26 +01:00
vec2 uv = uvFromFlat(${a}, ${o}, index + ${i});
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`}function fQ(e,t){let n=e.shapeInfo.logicalShape,r=e.name,s="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape,o=a[0],i=a[1],l=jn();if(a!=null&&w.arraysEqual(n,a))return t?`
vec4 ${s}(int row, int col) {
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
return ${l.texture2D}(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
vec4 ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
vec2 uv = (vec2(col, row) + halfCR) / vec2(${i}.0, ${o}.0);
2022-01-16 15:49:55 +01:00
return ${l.texture2D}(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`;if(t)return`
2022-01-16 15:49:55 +01:00
vec4 ${s}(int row, int col) {
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
2021-11-08 13:36:26 +01:00
vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
2022-01-16 15:49:55 +01:00
return ${l.texture2D}(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`;let c=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)],u=Math.ceil(n[1]/2);return`
2022-01-16 15:49:55 +01:00
vec4 ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
vec2 uv = packedUVfrom2D(${u}, ${c[0]}, ${c[1]}, row, col);
2022-01-16 15:49:55 +01:00
return ${l.texture2D}(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function mQ(e,t){let n=e.shapeInfo.logicalShape,r=e.name,s="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape;if(a!=null&&w.arraysEqual(n,a)){if(t)return`
float ${s}(int row, int col) {
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`;let p=a[0],h=a[1];return`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
vec2 uv = (vec2(col, row) + halfCR) / vec2(${h}.0, ${p}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}let{newShape:o,keptDims:i}=w.squeezeShape(n),l=o;if(l.length<n.length){let p=gc(e,l),h=["row","col"];return`
${fc(p,t)}
float ${s}(int row, int col) {
return ${s}(${yc(h,i)});
2021-11-08 13:36:26 +01:00
}
`}if(e.shapeInfo.isUniform)return`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
int index = round(dot(vec2(row, col), vec2(${n[1]}, 1)));
2022-01-16 15:49:55 +01:00
${mc(e)}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let c=a[0],u=a[1],d=Pl(r);return u===1?t?`
float ${s}(int row, int col) {
float index = dot(vec3(row, col, ${d}), vec3(${r}Shape[1], 1, 1));
vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
float index = dot(vec3(row, col, ${d}), vec3(${n[1]}, 1, 1));
vec2 uv = vec2(0.5, (index + 0.5) / ${c}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:c===1?t?`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
float index = dot(vec3(row, col, ${d}), vec3(${r}Shape[1], 1, 1));
vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
float index = dot(vec3(row, col, ${d}), vec3(${n[1]}, 1, 1));
vec2 uv = vec2((index + 0.5) / ${u}.0, 0.5);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:t?`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
2022-01-16 15:49:55 +01:00
int index = row * ${r}Shape[1] + col + ${d};
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
int index = row * ${n[1]} + col + ${d};
vec2 uv = uvFromFlat(${c}, ${u}, index);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function gQ(e,t){let n=e.shapeInfo.logicalShape,r=e.name,s="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape,o=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)];if(n[0]===1){let p=n.slice(1),h=[1,2],f=gc(e,p),m=["b","row","col"];return`
${aC(f,t)}
vec4 ${s}(int b, int row, int col) {
return ${s}(${yc(m,h)});
2021-11-08 13:36:26 +01:00
}
`}let i=jn();if(t)return`
2022-01-16 15:49:55 +01:00
vec4 ${s}(int b, int row, int col) {
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
int valuesPerRow = int(ceil(float(${r}Shape[2]) / 2.0));
int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
2021-11-08 13:36:26 +01:00
vec2 uv = packedUVfrom3D(
packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
2022-01-16 15:49:55 +01:00
return ${i.texture2D}(${r}, uv);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`;let l=o[0],c=o[1],u=Math.ceil(n[2]/2),d=u*Math.ceil(n[1]/2);return`
2022-01-16 15:49:55 +01:00
vec4 ${s}(int b, int row, int col) {
2021-11-08 13:36:26 +01:00
vec2 uv = packedUVfrom3D(
${l}, ${c}, ${d}, ${u}, b, row, col);
2022-01-16 15:49:55 +01:00
return ${i.texture2D}(${r}, uv);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function yQ(e,t){let n=e.shapeInfo.logicalShape,r=e.name,s="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[1]*n[2],o=n[2],{newShape:i,keptDims:l}=w.squeezeShape(n),c=i;if(c.length<n.length){let m=gc(e,c),g=["row","col","depth"];return`
${fc(m,t)}
float ${s}(int row, int col, int depth) {
return ${s}(${yc(g,l)});
2021-11-08 13:36:26 +01:00
}
`}if(e.shapeInfo.isUniform)return`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
2021-11-08 13:36:26 +01:00
int index = round(dot(vec3(row, col, depth),
vec3(${a}, ${o}, 1)));
2022-01-16 15:49:55 +01:00
${mc(e)}
2021-11-08 13:36:26 +01:00
}
`;let u=e.shapeInfo.texShape,d=u[0],p=u[1],h=e.shapeInfo.flatOffset;if(p===a&&h==null)return t?`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
int stride1 = ${r}Shape[2];
2021-11-08 13:36:26 +01:00
float texR = float(row);
float texC = dot(vec2(col, depth), vec2(stride1, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
2022-01-16 15:49:55 +01:00
vec2(${r}TexShape[1], ${r}TexShape[0]);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
2021-11-08 13:36:26 +01:00
float texR = float(row);
float texC = dot(vec2(col, depth), vec2(${o}, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${p}.0, ${d}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`;if(p===o&&h==null)return t?`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
2021-11-08 13:36:26 +01:00
float texC = float(depth);
2022-01-16 15:49:55 +01:00
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
2021-11-08 13:36:26 +01:00
float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
float texC = float(depth);
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${p}.0, ${d}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let f=Pl(r);return t?`
float ${s}(int row, int col, int depth) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
2022-01-16 15:49:55 +01:00
int stride0 = ${r}Shape[1] * ${r}Shape[2];
int stride1 = ${r}Shape[2];
2021-11-08 13:36:26 +01:00
int index = row * ${a} + col * ${o} + depth + ${f};
2022-01-16 15:49:55 +01:00
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
int index = row * ${a} + col * ${o} + depth + ${f};
vec2 uv = uvFromFlat(${d}, ${p}, index);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function AQ(e,t){let n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),s=jn();if(t)return`
vec4 ${r}(int b2, int b, int row, int col) {
2021-11-08 13:36:26 +01:00
int valuesPerRow = int(ceil(float(${n}Shape[3]) / 2.0));
int texelsInBatch = valuesPerRow * int(ceil(float(${n}Shape[2]) / 2.0));
int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
texelsInBatch *= ${n}Shape[1];
index = b2 * texelsInBatch + index;
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
int texR = index / packedTexShape[1];
int texC = index - texR * packedTexShape[1];
2022-01-16 15:49:55 +01:00
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${s.texture2D}(${n}, uv);
2021-11-08 13:36:26 +01:00
}
`;let a=e.shapeInfo.logicalShape,o=a.length,i=e.shapeInfo.texShape,l=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],c=l[0],u=l[1],d=Math.ceil(a[o-1]/2),p=d*Math.ceil(a[o-2]/2),h="int b, int row, int col",f=`b * ${p} + (row / 2) * ${d} + (col / 2)`;for(let m=2;m<o-1;m++)h=`int b${m}, `+h,p*=a[o-m-1],f=`b${m} * ${p} + `+f;return`
2022-01-16 15:49:55 +01:00
vec4 ${r}(${h}) {
2021-11-08 13:36:26 +01:00
int index = ${f};
int texR = index / ${u};
int texC = index - texR * ${u};
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${u}, ${c});
2022-01-16 15:49:55 +01:00
return ${s.texture2D}(${n}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function xQ(e,t){let n=e.shapeInfo.logicalShape,r=e.name,s="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[3],o=n[2]*a,i=n[1]*o,{newShape:l,keptDims:c}=w.squeezeShape(n);if(l.length<n.length){let x=gc(e,l),A=["row","col","depth","depth2"];return`
${fc(x,t)}
float ${s}(int row, int col, int depth, int depth2) {
return ${s}(${yc(A,c)});
2021-11-08 13:36:26 +01:00
}
`}if(e.shapeInfo.isUniform)return`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
int index = round(dot(vec4(row, col, depth, depth2),
vec4(${i}, ${o}, ${a}, 1)));
2022-01-16 15:49:55 +01:00
${mc(e)}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let u=e.shapeInfo.flatOffset,d=e.shapeInfo.texShape,p=d[0],h=d[1],f=`int stride2 = ${r}Shape[3];`,m=`int stride1 = ${r}Shape[2] * stride2;`,g=`int stride0 = ${r}Shape[1] * stride1;`;if(h===i&&u==null)return t?`
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
${f}
${m}
float texR = float(row);
float texC =
dot(vec3(col, depth, depth2),
vec3(stride1, stride2, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
2022-01-16 15:49:55 +01:00
vec2(${r}TexShape[1], ${r}TexShape[0]);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
float texR = float(row);
float texC =
dot(vec3(col, depth, depth2),
vec3(${o}, ${a}, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${h}.0, ${p}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`;if(h===a&&u==null)return t?`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
float texR = dot(vec3(row, col, depth),
2022-01-16 15:49:55 +01:00
vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
2021-11-08 13:36:26 +01:00
float texC = float(depth2);
vec2 uv = (vec2(texC, texR) + halfCR) /
2022-01-16 15:49:55 +01:00
vec2(${r}TexShape[1], ${r}TexShape[0]);
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
float texR = dot(vec3(row, col, depth),
vec3(${n[1]*n[2]}, ${n[2]}, 1));
float texC = float(depth2);
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${h}.0, ${p}.0);
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;let y=Pl(r);return t?`
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
${f}
${m}
${g}
int index = row * stride0 + col * stride1 +
depth * stride2 + depth2;
2022-01-16 15:49:55 +01:00
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${y});
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-16 15:49:55 +01:00
float ${s}(int row, int col, int depth, int depth2) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
int index = row * ${i} + col * ${o} +
depth * ${a} + depth2;
2021-12-01 14:27:05 +01:00
vec2 uv = uvFromFlat(${p}, ${h}, index + ${y});
2022-01-16 15:49:55 +01:00
return sampleTexture(${r}, uv);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function bQ(e){let t=e.shapeInfo.logicalShape,n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),s=t[4],a=t[3]*s,o=t[2]*a,i=t[1]*o,{newShape:l,keptDims:c}=w.squeezeShape(t);if(l.length<t.length){let m=gc(e,l),g=["row","col","depth","depth2","depth3"];return`
${fc(m)}
float ${r}(int row, int col, int depth, int depth2, int depth3) {
return ${r}(${yc(g,c)});
2021-11-08 13:36:26 +01:00
}
`}if(e.shapeInfo.isUniform)return`
2022-01-16 15:49:55 +01:00
float ${r}(int row, int col, int depth, int depth2, int depth3) {
2021-11-08 13:36:26 +01:00
float index = dot(
vec4(row, col, depth, depth2),
2022-01-16 15:49:55 +01:00
vec4(${i}, ${o}, ${a}, ${s})) +
2021-11-08 13:36:26 +01:00
depth3;
2022-01-16 15:49:55 +01:00
${mc(e)}
2021-11-08 13:36:26 +01:00
}
`;let u=e.shapeInfo.flatOffset,d=e.shapeInfo.texShape,p=d[0],h=d[1];if(h===i&&u==null)return`
2022-01-16 15:49:55 +01:00
float ${r}(int row, int col, int depth, int depth2, int depth3) {
2021-11-08 13:36:26 +01:00
int texR = row;
float texC = dot(vec4(col, depth, depth2, depth3),
2022-01-16 15:49:55 +01:00
vec4(${o}, ${a}, ${s}, 1));
2021-11-08 13:36:26 +01:00
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${h}.0, ${p}.0);
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`;if(h===s&&u==null)return`
float ${r}(int row, int col, int depth, int depth2, int depth3) {
2021-11-08 13:36:26 +01:00
float texR = dot(
vec4(row, col, depth, depth2),
vec4(${t[1]*t[2]*t[3]},
${t[2]*t[3]}, ${t[3]}, 1));
int texC = depth3;
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${h}.0, ${p}.0);
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`;let f=Pl(n);return`
float ${r}(int row, int col, int depth, int depth2, int depth3) {
2021-11-08 13:36:26 +01:00
// Explicitly use integer operations as dot() only works on floats.
int index = row * ${i} + col * ${o} + depth * ${a} +
2022-01-16 15:49:55 +01:00
depth2 * ${s} + depth3 + ${f};
2021-11-08 13:36:26 +01:00
vec2 uv = uvFromFlat(${p}, ${h}, index);
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`}function vQ(e){let t=e.shapeInfo.logicalShape,n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),{newShape:s,keptDims:a}=w.squeezeShape(t);if(s.length<t.length){let g=gc(e,s),y=["row","col","depth","depth2","depth3","depth4"];return`
${fc(g)}
float ${r}(int row, int col, int depth,
2021-11-08 13:36:26 +01:00
int depth2, int depth3, int depth4) {
2022-01-16 15:49:55 +01:00
return ${r}(${yc(y,a)});
2021-11-08 13:36:26 +01:00
}
`}let o=t[5],i=t[4]*o,l=t[3]*i,c=t[2]*l,u=t[1]*c;if(e.shapeInfo.isUniform)return`
2022-01-16 15:49:55 +01:00
float ${r}(int row, int col, int depth,
2021-11-08 13:36:26 +01:00
int depth2, int depth3, int depth4) {
int index = round(dot(
vec4(row, col, depth, depth2),
vec4(${u}, ${c}, ${l}, ${i})) +
dot(
vec2(depth3, depth4),
vec2(${o}, 1)));
2022-01-16 15:49:55 +01:00
${mc(e)}
2021-11-08 13:36:26 +01:00
}
`;let d=e.shapeInfo.flatOffset,p=e.shapeInfo.texShape,h=p[0],f=p[1];if(f===u&&d==null)return`
2022-01-16 15:49:55 +01:00
float ${r}(int row, int col, int depth,
2021-11-08 13:36:26 +01:00
int depth2, int depth3, int depth4) {
int texR = row;
float texC = dot(vec4(col, depth, depth2, depth3),
vec4(${c}, ${l}, ${i}, ${o})) +
float(depth4);
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${f}.0, ${h}.0);
return sampleTexture(${n}, uv);
}
`;if(f===o&&d==null)return`
2022-01-16 15:49:55 +01:00
float ${r}(int row, int col, int depth,
2021-11-08 13:36:26 +01:00
int depth2, int depth3, int depth4) {
float texR = dot(vec4(row, col, depth, depth2),
vec4(${t[1]*t[2]*t[3]*t[4]},
${t[2]*t[3]*t[4]},
${t[3]*t[4]},
${t[4]})) + float(depth3);
int texC = depth4;
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(${f}.0, ${h}.0);
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`;let m=Pl(n);return`
float ${r}(int row, int col, int depth,
2021-11-08 13:36:26 +01:00
int depth2, int depth3, int depth4) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ${u} + col * ${c} + depth * ${l} +
depth2 * ${i} + depth3 * ${o} + depth4 + ${m};
vec2 uv = uvFromFlat(${h}, ${f}, index);
return sampleTexture(${n}, uv);
}
2022-01-16 15:49:55 +01:00
`}function mc(e){let t=e.name,n=w.sizeFromShape(e.shapeInfo.logicalShape);return n<2?`return ${t};`:`
2021-11-08 13:36:26 +01:00
for (int i = 0; i < ${n}; i++) {
if (i == index) {
return ${t}[i];
}
}
2022-01-16 15:49:55 +01:00
`}function wQ(e,t){let n=e.name,r=n.charAt(0).toUpperCase()+n.slice(1),s="get"+r+"AtOutCoords",a=e.shapeInfo.logicalShape.length,o=t.logicalShape.length,i=sC(e.shapeInfo.logicalShape,t.logicalShape),l=wt(o),c=o-a,u,d=["x","y","z","w","u","v"];a===0?u="":o<2&&i.length>=1?u="coords = 0;":u=i.map(x=>`coords.${d[x+c]} = 0;`).join(`
`);let p="";o<2&&a>0?p="coords":p=e.shapeInfo.logicalShape.map((x,A)=>`coords.${d[A+c]}`).join(", ");let h="return outputValue;",m=w.sizeFromShape(e.shapeInfo.logicalShape)===1,y=w.sizeFromShape(t.logicalShape)===1;if(a===1&&!m&&!y)h=`
2021-11-08 13:36:26 +01:00
return vec4(outputValue.xy, outputValue.xy);
2021-12-01 14:27:05 +01:00
`;else if(m&&!y)o===1?h=`
2021-11-08 13:36:26 +01:00
return vec4(outputValue.x, outputValue.x, 0., 0.);
`:h=`
return vec4(outputValue.x);
2021-12-01 14:27:05 +01:00
`;else if(i.length){let x=a-2,A=a-1;i.indexOf(x)>-1&&i.indexOf(A)>-1?h="return vec4(outputValue.x);":i.indexOf(x)>-1?h="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":i.indexOf(A)>-1&&(h="return vec4(outputValue.xx, outputValue.zz);")}return`
2022-01-16 15:49:55 +01:00
vec4 ${s}() {
2021-11-08 13:36:26 +01:00
${l} coords = getOutputCoords();
${u}
2022-01-16 15:49:55 +01:00
vec4 outputValue = get${r}(${p});
2021-11-08 13:36:26 +01:00
${h}
}
2022-01-16 15:49:55 +01:00
`}function kQ(e,t){let n=e.name,r=n.charAt(0).toUpperCase()+n.slice(1),s="get"+r+"AtOutCoords",a=t.texShape,o=e.shapeInfo.texShape,i=e.shapeInfo.logicalShape.length,l=t.logicalShape.length;if(!e.shapeInfo.isUniform&&i===l&&e.shapeInfo.flatOffset==null&&w.arraysEqual(o,a))return`
float ${s}() {
2021-11-08 13:36:26 +01:00
return sampleTexture(${n}, resultUV);
}
2022-01-16 15:49:55 +01:00
`;let c=wt(l),u=sC(e.shapeInfo.logicalShape,t.logicalShape),d=l-i,p,h=["x","y","z","w","u","v"];i===0?p="":l<2&&u.length>=1?p="coords = 0;":p=u.map(m=>`coords.${h[m+d]} = 0;`).join(`
2021-11-08 13:36:26 +01:00
`);let f="";return l<2&&i>0?f="coords":f=e.shapeInfo.logicalShape.map((m,g)=>`coords.${h[g+d]}`).join(", "),`
2022-01-16 15:49:55 +01:00
float ${s}() {
2021-11-08 13:36:26 +01:00
${c} coords = getOutputCoords();
${p}
2022-01-16 15:49:55 +01:00
return get${r}(${f});
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function wt(e){if(e<=1)return"int";if(e===2)return"ivec2";if(e===3)return"ivec3";if(e===4)return"ivec4";if(e===5)return"ivec5";if(e===6)return"ivec6";throw Error(`GPU for rank ${e} is not yet supported`)}function Nx(e,t,n){let{newShape:r,keptDims:s}=w.squeezeShape(t),a=t.length,o=e&&a===3&&t[0]===1,i=o?t.slice(1):r,l=!e&&a>1&&!w.arraysEqual(t,n)&&r.length<a||o;return{useSqueezeShape:l,uniformShape:l?i:t,keptDims:s}}function gc(e,t){let n=JSON.parse(JSON.stringify(e));return n.shapeInfo.logicalShape=t,n}function yc(e,t){return t.map(n=>e[n]).join(", ")}function IQ(e,t,n,r){let s=n.map((b,v)=>{let C={logicalShape:b.shape,texShape:b.isUniform?null:b.texData.texShape,isUniform:b.isUniform,isPacked:b.isUniform?!1:b.texData.isPacked,flatOffset:null};return b.texData!=null&&b.texData.slice!=null&&b.texData.slice.flatOffset>0&&(C.flatOffset=b.texData.slice.flatOffset),{name:t.variableNames[v],shapeInfo:C}}),a=s.map(b=>b.shapeInfo),o={logicalShape:r.shape,texShape:r.texData.texShape,isUniform:!1,isPacked:r.texData.isPacked,flatOffset:null},i=VJ(s,o,t),l=O7(e.gl,i),c=e.createProgram(l),u=null,d=e.getUniformLocation(c,"NAN",!1);Y().getNumber("WEBGL_VERSION")===1&&(u=e.getUniformLocation(c,"INFINITY",!1));let p=!1,h={},f={},m={};for(let b=0;b<t.variableNames.length;b++){let v=t.variableNames[b];h[v]=e.getUniformLocation(c,v,p),h[`offset${v}`]=e.getUniformLocation(c,`offset${v}`,p),t.enableShapeUniforms&&(f[`${v}Shape`]=e.getUniformLocation(c,`${v}Shape`,p),m[`${v}TexShape`]=e.getUniformLocation(c,`${v}TexShape`,p))}let g,y,x;t.enableShapeUniforms&&(g=e.getUniformLocation(c,"outShape",p),x=e.getUniformLocation(c,"outShapeStrides",p),y=e.getUniformLocation(c,"outTexShape",p));let A=[];return t.customUniforms&&t.customUniforms.forEach((b,v)=>{A[v]=e.getUniformLocation(c,b.name,p)}),{program:t,fragmentShader:l,source:i,webGLProgram:c,uniformLocations:h,customUniformLocations:A,inShapeInfos:a,outShapeInfo:o,infLoc:u,nanLoc:d,inShapesLocations:f,inTexShapesLocations:m,outShapeLocation:g,outShapeStridesLocation:x,outTexShapeLocation:y}}function iC(e,t){if(e.length!==t.length)throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);e.forEach((n,r)=>{let s=n.logicalShape,a=t[r],o=a.shape;if(!w.arraysEqual(s,o))throw Error(`Binary was compiled with different shapes than the current args. Shapes ${s} and ${o} must match`);if(n.isUniform&&a.isUniform)return;let i=n.texShape,l=a.isUniform?null:a.texData.texShape;if(!w.arraysEqual(i,l))throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${i} and ${l} must match`)})}function SQ(e,t,n,r,s){t.program.enableShapeUniforms||(iC(t.inShapeInfos,n),iC([t.outShapeInfo],[r]));let a=r.texData.texture,o=r.texData.texShape;r.texData.isPacked?e.setOutputPackedMatrixTexture(a.texture,o[0],o[1]):e.setOutputMatrixTexture(a.texture,o[0],o[1]),e.setProgram(t.webGLProgram),Y().getNumber("WEBGL_VERSION")===1&&t.infLoc!==null&&e.gl.uniform1f(t.infLoc,1/0),t.nanLoc!==null&&e.gl.uniform1f(t.nanLoc,NaN),n.forEach((l,c)=>{let u=t.program.variableNames[c],d=t.uniformLocations[u],p=t.uniformLocations[`offset${u}`],h=t.inShapesLocations[`${u}Shape`],f=t.inTexShapesLocations[`${u}TexShape`];if(h){let{uniformShape:m}=Nx(t.program.packedInputs,l.shape,l.texData.texShape);switch(m.length){case 1:e.gl.uniform1iv(h,new Int32Array(m));break;case 2:e.gl.uniform2iv(h,new Int32Array(m));break;case 3:e.gl.uniform3iv(h,new Int32Array(m));break;case 4:e.gl.uniform4iv(h,new Int32Array(m));break;default:break}}if(f&&e.gl.uniform2i(f,l.texData.texShape[0],l.texData.texShape[1]),d!=null){if(l.isUniform){if(w.sizeFromShape(l.shape)<2)e.gl.uniform1f(d,l.uniformValues[0]);else{let m=l.uniformValues;m instanceof Float32Array||(m=new Float32Array(m)),e.gl.uniform1fv(d,m)}return}l.texData.slice!=null&&p!=null&&e.gl.uniform1i(p,l.texData.slice.flatOffset),e.setInputMatrixTexture(l.texData.texture.texture,d,c)}});let i=t.outShapeLocation;if(i)switch(r.shape.length){case 1:e.gl.uniform1iv(i,new Int32Array(r.shape));break;case 2:e.gl.uniform2iv(i,new Int32Array(r.s
2021-11-08 13:36:26 +01:00
ivec3 outCoordsFromFlatIndex(int index) {
2022-01-16 15:49:55 +01:00
${this.enableShapeUniforms?Ym(["r","c","d"],e):Dl(["r","c","d"],e)}
2021-11-08 13:36:26 +01:00
return ivec3(r, c, d);
}
2021-09-11 16:29:31 +02:00
2021-08-14 17:17:51 +02:00
void main() {
2021-11-08 13:36:26 +01:00
ivec2 resTexRC = ivec2(resultUV.yx * vec2(texShape[0], texShape[1]));
int index = 4 * (resTexRC.x * texShape[1] + resTexRC.y);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
for (int i=0; i<4; i++) {
int flatIndex = index + i;
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
result[i] = getA(rc.x, rc.y, rc.z);
}
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
${t.output} = result;
}
2022-01-16 15:49:55 +01:00
`}},NQ=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=Um.DENSE,this.customUniforms=[{name:"texShape",type:"ivec2"}];let t=jn();this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length),this.userCode=`
2021-11-08 13:36:26 +01:00
ivec3 outCoordsFromFlatIndex(int index) {
2022-01-16 15:49:55 +01:00
${this.enableShapeUniforms?Ym(["r","c","d"],e):Dl(["r","c","d"],e)}
2021-11-08 13:36:26 +01:00
return ivec3(r, c, d);
}
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec2 resTexRC = ivec2(resultUV.yx * vec2(texShape[0], texShape[1]));
int index = 4 * (resTexRC.x * texShape[1] + resTexRC.y);
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
for (int i=0; i<4; i++) {
int flatIndex = index + i;
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));
}
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
${t.output} = result;
}
2022-01-16 15:49:55 +01:00
`}},EQ=class{constructor(e){this.variableNames=["A"],this.outTexUsage=as.DOWNLOAD;let t=jn();this.outputShape=e,this.userCode=`
${rC}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
void main() {
float x = getAAtOutCoords();
${t.output} = encode_float(x);
}
2022-01-16 15:49:55 +01:00
`}},RQ=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=as.DOWNLOAD;let t=jn();this.outputShape=e,this.userCode=`
${rC}
2021-11-08 13:36:26 +01:00
void main() {
ivec3 coords = getOutputCoords();
float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));
${t.output} = encode_float(x);
2021-09-11 16:29:31 +02:00
}
2022-01-16 15:49:55 +01:00
`}},_Q=class{constructor(e,t=!1){this.variableNames=["A"],this.customUniforms=[{name:"texShape",type:"ivec2"}];let n=jn();this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length);let r="result";t&&(r="floor(result * 255. + 0.5)"),this.userCode=`
${this.enableShapeUniforms?Tx():Cx(e)}
2021-09-05 22:42:11 +02:00
2021-09-11 16:29:31 +02:00
void main() {
2021-11-08 13:36:26 +01:00
ivec3 coords = getOutputCoords();
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int flatIndex = getFlatIndex(coords);
int offset = imod(flatIndex, 4);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
flatIndex = idiv(flatIndex, 4, 1.);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int r = flatIndex / texShape[1];
int c = imod(flatIndex, texShape[1]);
vec2 uv = (vec2(c, r) + halfCR) / vec2(texShape[1], texShape[0]);
vec4 values = ${n.texture2D}(A, uv);
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
float result;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
if(offset == 0) {
result = values[0];
} else if(offset == 1) {
result = values[1];
} else if(offset == 2) {
result = values[2];
} else {
result = values[3];
}
2021-08-14 17:17:51 +02:00
2022-01-16 15:49:55 +01:00
${n.output} = vec4(${r}, 0., 0., 0.);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}},DQ=class{constructor(e,t=!1){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.customUniforms=[{name:"texShape",type:"ivec2"}];let n=jn();this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length);let r="",s="result";t&&(s="floor(result * 255. + 0.5)");for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let i=a*2+o;r+=`
2021-11-08 13:36:26 +01:00
localCoords = coords;
if(localCoords[2] + ${o} < ${this.enableShapeUniforms?"outShape[2]":`${e[2]}`}) {
localCoords[2] += ${o};
if (localCoords[1] + ${a} < ${this.enableShapeUniforms?"outShape[1]":`${e[1]}`}) {
localCoords[1] += ${a};
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
flatIndex = getFlatIndex(localCoords);
offset = imod(flatIndex, 4);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
flatIndex = idiv(flatIndex, 4, 1.);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
int r = flatIndex / texShape[1];
int c = imod(flatIndex, texShape[1]);
vec2 uv = (vec2(c, r) + halfCR) / vec2(texShape[1], texShape[0]);
values = ${n.texture2D}(A, uv);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
if (offset == 0) {
result[${i}] = values[0];
} else if (offset == 1) {
result[${i}] = values[1];
} else if (offset == 2) {
result[${i}] = values[2];
} else {
result[${i}] = values[3];
2021-09-05 22:42:11 +02:00
}
}
}
2021-11-08 13:36:26 +01:00
`}this.userCode=`
2022-01-16 15:49:55 +01:00
${this.enableShapeUniforms?Tx():Cx(e)}
2021-09-11 16:29:31 +02:00
2021-11-06 15:21:51 +01:00
void main() {
2021-11-08 13:36:26 +01:00
ivec3 coords = getOutputCoords();
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
int flatIndex, r, c, offset;
ivec3 localCoords;
vec2 uv;
vec4 values;
2022-01-16 15:49:55 +01:00
${r}
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
${n.output} = ${s};
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},lC={};Me(lC,{bindVertexProgramAttributeStreams:()=>yC,createBufferFromOutputTexture:()=>bC,createFloat16MatrixTexture:()=>hC,createFloat16PackedMatrixTexture:()=>gC,createFloat32MatrixTexture:()=>pC,createIndexBuffer:()=>dC,createPackedMatrixTexture:()=>mC,createUnsignedBytesMatrixTexture:()=>fC,createVertexBuffer:()=>cC,createVertexShader:()=>uC,downloadByteEncodedFloatMatrixFromOutputTexture:()=>wC,downloadFloat32MatrixFromBuffer:()=>vC,downloadMatrixFromPackedOutputTexture:()=>IC,downloadPackedMatrixFromBuffer:()=>kC,getInternalFormatForFloat16MatrixTexture:()=>Rx,getInternalFormatForFloat16PackedMatrixTexture:()=>Px,getInternalFormatForFloat32MatrixTexture:()=>Ex,getInternalFormatForPackedMatrixTexture:()=>Dx,getInternalFormatForUnsignedBytesMatrixTexture:()=>_x,uploadDenseMatrixToTexture:()=>AC,uploadPixelDataToTexture:()=>xC});function uC(e){let t=jn(),n=`${t.version}
2021-11-08 13:36:26 +01:00
precision highp float;
${t.attribute} vec3 clipSpacePos;
${t.attribute} vec2 uv;
${t.varyingVs} vec2 resultUV;
void main() {
gl_Position = vec4(clipSpacePos, 1);
resultUV = uv;
2022-01-16 15:49:55 +01:00
}`;return F7(e,n)}function cC(e){let t=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return L7(e,t)}function dC(e){let t=new Uint16Array([0,1,2,2,1,3]);return B7(e,t)}function Rp(e,t,n,r,s,a){V7(t,n);let o=W7(e),i=e.TEXTURE_2D;return ke(e,()=>e.bindTexture(i,o)),ke(e,()=>e.texParameteri(i,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE)),ke(e,()=>e.texParameteri(i,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)),ke(e,()=>e.texParameteri(i,e.TEXTURE_MIN_FILTER,e.NEAREST)),ke(e,()=>e.texParameteri(i,e.TEXTURE_MAG_FILTER,e.NEAREST)),Y().getNumber("WEBGL_VERSION")===1?ke(e,()=>e.texImage2D(i,0,r,t,n,0,s,a,null)):ke(e,()=>e.texStorage2D(i,1,r,t,n)),ke(e,()=>e.bindTexture(e.TEXTURE_2D,null)),{texture:o,texShape:[n,t]}}function Ex(e){return e.internalFormatFloat}function pC(e,t,n,r){let[s,a]=Cp(t,n);return Rp(e,s,a,Ex(r),r.textureFormatFloat,e.FLOAT)}function Rx(e){return e.internalFormatHalfFloat}function hC(e,t,n,r){let[s,a]=Cp(t,n);return Rp(e,s,a,Rx(r),r.textureFormatFloat,r.textureTypeHalfFloat)}function _x(e){return e.downloadTextureFormat}function fC(e,t,n,r){let[s,a]=Cp(t,n);return Rp(e,s,a,_x(r),e.RGBA,e.UNSIGNED_BYTE)}function Dx(e){return e.internalFormatPackedFloat}function mC(e,t,n,r){let[s,a]=pc(t,n);return Rp(e,s,a,Dx(r),e.RGBA,e.FLOAT)}function Px(e){return e.internalFormatPackedHalfFloat}function gC(e,t,n,r){let[s,a]=pc(t,n);return Rp(e,s,a,Px(r),e.RGBA,r.textureTypeHalfFloat)}function yC(e,t,n){let r=0,s=3*4,a=3*4+2*4;return ke(e,()=>e.bindBuffer(e.ARRAY_BUFFER,n)),wx(e,t,"clipSpacePos",n,3,a,r)&&wx(e,t,"uv",n,2,a,s)}function AC(e,t,n,r,s,a){ke(e,()=>e.bindTexture(e.TEXTURE_2D,t));let o,i,l;s instanceof Uint8Array?(o=new Uint8Array(n*r*4),i=e.UNSIGNED_BYTE,l=e.RGBA):(o=new Float32Array(n*r*4),i=e.FLOAT,l=a.internalFormatPackedFloat),o.set(s),Y().getNumber("WEBGL_VERSION")===2?ke(e,()=>e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGBA,i,o)):ke(e,()=>e.texImage2D(e.TEXTURE_2D,0,l,n,r,0,e.RGBA,i,o)),ke(e,()=>e.bindTexture(e.TEXTURE_2D,null))}function xC(e,t,n){ke(e,()=>e.bindTexture(e.TEXTURE_2D,t)),n.data instanceof Uint8Array?Y().getNumber("WEBGL_VERSION")===2?ke(e,()=>e.texSubImage2D(e.TEXTURE_2D,0,0,0,n.width,n.height,e.RGBA,e.UNSIGNED_BYTE,n.data)):ke(e,()=>e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n.width,n.height,0,e.RGBA,e.UNSIGNED_BYTE,n.data)):Y().getNumber("WEBGL_VERSION")===2?ke(e,()=>e.texSubImage2D(e.TEXTURE_2D,0,0,0,e.RGBA,e.UNSIGNED_BYTE,n)):ke(e,()=>e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n)),ke(e,()=>e.bindTexture(e.TEXTURE_2D,null))}function bC(e,t,n,r){let s=e.createBuffer();ke(e,()=>e.bindBuffer(e.PIXEL_PACK_BUFFER,s));let i=4*4*t*n;return ke(e,()=>e.bufferData(e.PIXEL_PACK_BUFFER,i,e.STREAM_READ)),ke(e,()=>e.readPixels(0,0,n,t,e.RGBA,e.FLOAT,0)),ke(e,()=>e.bindBuffer(e.PIXEL_PACK_BUFFER,null)),s}function vC(e,t,n){let r=e,s=new Float32Array(n);return r.bindBuffer(r.PIXEL_PACK_BUFFER,t),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,s),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),s}function wC(e,t,n,r){let[s,a]=Cp(t,n),o=4,i=new Uint8Array(TJ(t*n,o));return ke(e,()=>e.readPixels(0,0,s,a,r.downloadTextureFormat,e.UNSIGNED_BYTE,i)),new Float32Array(i.buffer)}function kC(e,t,n,r,s,a,o,i){let l=e,c=new Float32Array(NJ(a,o));return l.bindBuffer(l.PIXEL_PACK_BUFFER,t),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,c),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),c}function IC(e,t,n){let r=new Float32Array(t*n*4);return ke(e,()=>e.readPixels(0,0,n,t,e.RGBA,e.FLOAT,r)),r}var Ac=class{constructor(e){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];let t=Y().getNumber("WEBGL_VERSION");e!=null?(this.gl=e,Vm(t,e)):this.gl=Ns(t);let n="WEBGL_color_buffer_float",r="EXT_color_buffer_half_float";if(Y().getNumber("WEBGL_VERSION")===1){let s="OES_texture_float",a="OES_texture_half_float";if(this.textureFloatExtension=Tp(this.gl,s),Hr(this.gl,a))this.textureHalfFloatExtension=Tp(this.gl,a);else if(Y().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.color
2021-11-08 13:36:26 +01:00
void main() {
setOutput(vec4(getA(), 0., 0., 0.));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;else{let t=qn("rc",this.rank),n=wt(this.rank),r=this.getOutOfBoundsCondition(t),s=this.getSetup(t),a=this.getOutput(t);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${n} rc = getOutputCoords();
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
if(${r}) {
2021-11-08 13:36:26 +01:00
setOutput(vec4(0));
} else {
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
setOutput(vec4(${a}));
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}}getSourceCoordsArr(e){let t=[];for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){let s=`${n===0?"r":"rp1"}, ${r===0?"c":"cp1"}`;for(let a=2;a<this.rank;a++)s=`${e[e.length-1-a]},`+s;t.push(s)}return t}getOutOfBoundsCondition(e){if(this.rank===1)return`rc > ${this.enableShapeUniforms?"outShape":this.outputShape[0]}`;let t="";for(let n=this.rank-2;n<this.rank;n++)t+=`${e[n]} >= ${this.enableShapeUniforms?`outShape[${n}]`:this.outputShape[n]}`,n<this.rank-1&&(t+="||");return t}getSetup(e){if(this.rank===1)return"";let t=e.slice(-2),n=this.enableShapeUniforms?`outShape[${this.rank} - 1]`:this.outputShape[this.rank-1],r=this.enableShapeUniforms?`outShape[${this.rank} - 2]`:this.outputShape[this.rank-2];return`
int r = ${t[0]};
int c = ${t[1]};
int rp1 = r + 1;
int cp1 = c + 1;
bool cEdge = cp1 >= ${n};
2022-01-16 15:49:55 +01:00
bool rEdge = rp1 >= ${r};
`}getOutput(e){let t=this.getSourceCoordsArr(e);return this.rank===1?`getA(rc), (rc + 1 >= ${this.enableShapeUniforms?"outShape":this.outputShape[0]} ? 0. : getA(rc + 1)), 0, 0`:`getA(${t[0]}),
cEdge ? 0. : getA(${t[1]}),
rEdge ? 0. : getA(${t[2]}),
2022-01-16 15:49:55 +01:00
rEdge || cEdge ? 0. : getA(${t[3]})`}},EC=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"inputShape",type:"ivec3"}],this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length);let n="";for(let r=0;r<4;r++){let s="thisRC = rc;";r%2===1&&(s+="thisRC.z += 1;"),r>1&&(s+="thisRC.y += 1;"),n+=`
${s}
${r>0?"if(thisRC.y < rows && thisRC.z < cols){":""}
2021-11-08 13:36:26 +01:00
int flatIndex = getFlatIndex(thisRC);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
2021-11-06 15:21:51 +01:00
2022-01-16 15:49:55 +01:00
result[${r}] =
2021-11-08 13:36:26 +01:00
getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
2022-01-16 15:49:55 +01:00
${r>0?"}":""}
2021-11-08 13:36:26 +01:00
`}this.userCode=`
2022-01-16 15:49:55 +01:00
${bee(t,this.enableShapeUniforms)}
${this.enableShapeUniforms?Tx():Cx(e)}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
void main() {
ivec3 rc = getOutputCoords();
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
ivec3 thisRC;
int rows = ${this.enableShapeUniforms?"outShape[1]":e[1]};
int cols = ${this.enableShapeUniforms?"outShape[2]":e[2]};
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
${n}
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function bee(e,t){return`
2021-11-08 13:36:26 +01:00
ivec3 inputCoordsFromReshapedOutCoords(int index) {
2022-01-16 15:49:55 +01:00
${t?WJ(["r","c","d"],"inputShape"):Dl(["r","c","d"],e)}
2021-11-08 13:36:26 +01:00
return ivec3(r, c, d);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}var vee=class{constructor(e){this.gpgpu=e,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}acquireTexture(e,t,n){let r=_C(t,n),s=DC(e,r,n);s in this.freeTextures||(this.freeTextures[s]=[]),s in this.usedTextures||(this.usedTextures[s]=[]);let a=RC(e,r,this.gpgpu.gl,this.gpgpu.textureConfig,n);if(this.freeTextures[s].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=a,this.log();let i=this.freeTextures[s].shift();return this.usedTextures[s].push(i),i}let o;return r===Fn.PACKED_2X2_FLOAT32?o=this.gpgpu.createPackedMatrixTexture(e[0],e[1]):r===Fn.PACKED_2X2_FLOAT16?o=this.gpgpu.createFloat16PackedMatrixTexture(e[0],e[1]):r===Fn.UNPACKED_FLOAT32?o=this.gpgpu.createFloat32MatrixTexture(e[0],e[1]):r===Fn.UNPACKED_FLOAT16?o=this.gpgpu.createFloat16MatrixTexture(e[0],e[1]):r===Fn.PACKED_4X1_UNSIGNED_BYTE&&(o=this.gpgpu.createUnsignedBytesMatrixTexture(e[0],e[1])),this.usedTextures[s].push(o),this.numUsedTextures++,this._numBytesAllocated+=a,this.log(),o}releaseTexture(e,t,n,r){if(this.freeTextures==null)return;let s=_C(n,r),a=DC(t,s,r);a in this.freeTextures||(this.freeTextures[a]=[]);let o=RC(t,s,this.gpgpu.gl,this.gpgpu.textureConfig,r),i=Y().get("WEBGL_DELETE_TEXTURE_THRESHOLD");i!==-1&&this._numBytesAllocated>i?(this.gpgpu.deleteMatrixTexture(e.texture),this._numBytesAllocated-=o):(this.freeTextures[a].push(e),this.numFreeTextures++,this._numBytesFree+=o),this.numUsedTextures--;let l=this.usedTextures[a],c=l.indexOf(e);if(c<0)throw new Error("Cannot release a texture that was never provided by this texture manager");l.splice(c,1),this.log()}log(){if(!this.logEnabled)return;let e=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",`${this.numFreeTextures} / ${this.numUsedTextures}`,`(${e})`);let t=this._numBytesFree/this._numBytesAllocated;console.log(`Bytes allocated: ${this._numBytesAllocated}`),console.log(`Bytes unused: ${this._numBytesFree} (${Math.round(100*t)}%)`)}get numBytesAllocated(){return this._numBytesAllocated}get numBytesFree(){return this._numBytesFree}getNumUsedTextures(){return this.numUsedTextures}getNumFreeTextures(){return this.numFreeTextures}dispose(){if(this.freeTextures!=null){for(let e in this.freeTextures)this.freeTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t.texture)});for(let e in this.usedTextures)this.usedTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t.texture)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0}}};function wee(e,t){let n=e;if(t===n.R32F)return 4;if(t===n.R16F)return 2;if(t===n.RGBA32F)return 16;if(t===e.RGBA)return 16;if(t===n.RGBA16F)return 8;if(t===n.RGBA8)return 4;throw new Error(`Unknown internal format ${t}`)}function RC(e,t,n,r,s){let a=kee(t,r),o;if(s){let[l,c]=pc(e[0],e[1]);o=l*c}else{let[l,c]=Cp(e[0],e[1]);o=l*c}let i=wee(n,a);return o*i}function kee(e,t){switch(e){case Fn.PACKED_2X2_FLOAT32:return Dx(t);case Fn.PACKED_2X2_FLOAT16:return Px(t);case Fn.UNPACKED_FLOAT32:return Ex(t);case Fn.UNPACKED_FLOAT16:return Rx(t);case Fn.PACKED_4X1_UNSIGNED_BYTE:return _x(t);default:throw new Error(`Unknown physical texture type ${e}`)}}function Iee(e){return Y().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?e?Fn.PACKED_2X2_FLOAT32:Fn.UNPACKED_FLOAT32:e?Fn.PACKED_2X2_FLOAT16:Fn.UNPACKED_FLOAT16}function _C(e,t){if(e===as.UPLOAD)return Fn.PACKED_2X2_FLOAT32;if(e===as.RENDER||e==null)return Iee(t);if(e===as.DOWNLOAD||e===as.PIXELS)return Fn.PACKED_4X1_UNSIGNED_BYTE;throw new Error(`Unknown logical texture type ${e}`)}function DC(e,t,n){return`${e[0]}_${e[1]}_${t}_${n}`}var ua=class{constructor(e,t){this.variableNames=["A"],this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length),this.userCode=`
2021-11-08 13:36:26 +01:00
float unaryOperation(float x) {
${t}
2021-09-05 22:42:11 +02:00
}
2021-11-06 15:21:51 +01:00
2021-09-11 16:29:31 +02:00
void main() {
2021-11-08 13:36:26 +01:00
float x = getAAtOutCoords();
float y = unaryOperation(x);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
setOutput(y);
}
2022-01-16 15:49:55 +01:00
`}},os="if (isnan(x)) return x;",See="return x;",PC="return abs(x);",Cee="return (x >= 0.0) ? x : (exp(x) - 1.0);",Tee=os+`
2021-11-08 13:36:26 +01:00
return (x < 0.0) ? 0.0 : x;
2022-01-16 15:49:55 +01:00
`,Nee=os+`
2021-11-08 13:36:26 +01:00
return (x < 0.0) ? 0.0 : min(6.0, x);
2022-01-16 15:49:55 +01:00
`,xc="return x;",Eee="return 1.0 / (1.0 + exp(-1.0 * x));",Ree="return x;",_ee=`
2021-11-08 13:36:26 +01:00
vec4 result;
result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);
2021-11-06 15:21:51 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,Dee=`
2021-11-06 15:21:51 +01:00
vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
2022-01-16 15:49:55 +01:00
`,Pee=`
2021-11-06 15:21:51 +01:00
vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
2022-01-16 15:49:55 +01:00
`,$ee="return 1.0 / (1.0 + exp(-1.0 * x));",$l=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length),this.userCode=`
2021-11-08 13:36:26 +01:00
vec4 unaryOperation(vec4 x) {
${t}
2021-09-05 22:42:11 +02:00
}
2021-11-06 15:21:51 +01:00
2021-09-11 16:29:31 +02:00
void main() {
2021-11-08 13:36:26 +01:00
vec4 x = getAAtOutCoords();
vec4 y = unaryOperation(x);
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
setOutput(y);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Fee=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length);let t=e.length,n=qn("rc",t),r=wt(t),s=Aee(t,n),a=n.slice(-2),o=t<=1?"rc":`vec2(${a.join(",")})`;this.userCode=`
2021-09-01 00:24:30 +02:00
void main() {
2022-01-16 15:49:55 +01:00
${r} rc = getOutputCoords();
vec4 packedInput = getA(${s});
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
setOutput(getChannel(packedInput, ${o}));
}
2022-01-16 15:49:55 +01:00
`}},Oee=ts.whereImpl,Mee=1e-7,zee=1e-4,Jm={};function Lee(e){return e in Jm||(Jm[e]={}),Jm[e]}var Bee=Y().getNumber("CPU_HANDOFF_SIZE_THRESHOLD"),Wee=600;function Vee(){return Y().global.screen==null?1024:Y().global.screen.height*Y().global.screen.width*window.devicePixelRatio*Wee/1024/1024}var $C=class extends au{constructor(e){super();if(this.pendingRead=new WeakMap,this.pendingDisposal=new WeakSet,this.dataRefCount=new WeakMap,this.numBytesInGPU=0,this.uploadWaitMs=0,this.downloadWaitMs=0,this.lastGlFlushTime=0,this.warnedAboutMemory=!1,this.pendingDeletes=0,this.disposed=!1,!Y().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");let t;if(e!=null){if(e instanceof Ac)t=e;else{let n=Ns(Y().getNumber("WEBGL_VERSION"),e);t=new Ac(n)}this.binaryCache={},this.gpgpuCreatedLocally=!1}else{let n=Ns(Y().getNumber("WEBGL_VERSION"));t=new Ac(n),this.binaryCache=Lee(Y().getNumber("WEBGL_VERSION")),this.gpgpuCreatedLocally=!0}this.gpgpu=t,this.canvas=this.gpgpu.gl.canvas,this.textureManager=new vee(this.gpgpu),this.numMBBeforeWarning=Vee(),this.texData=new pd(this,Dn())}nextDataId(){return $C.nextDataId++}numDataIds(){return this.texData.numDataIds()-this.pendingDeletes}write(e,t,n){if((Y().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||Y().getBool("DEBUG"))&&this.checkNumericalProblems(e),n==="complex64"&&e!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");let r={id:this.nextDataId()};return this.texData.set(r,{shape:t,dtype:n,values:e,usage:as.UPLOAD,refCount:1}),r}refCount(e){return this.texData.has(e)?this.texData.get(e).refCount:0}incRef(e){let t=this.texData.get(e);t.refCount++}decRef(e){if(this.texData.has(e)){let t=this.texData.get(e);t.refCount--}}move(e,t,n,r,s){if(Y().getBool("DEBUG")&&this.checkNumericalProblems(t),r==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(e,{shape:n,dtype:r,values:t,usage:as.UPLOAD,refCount:s})}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}readSync(e){let t=this.texData.get(e),{values:n,dtype:r,complexTensorInfos:s,slice:a,shape:o,isPacked:i}=t;if(a!=null){let d;i?d=new $l(o,xc):d=new ua(o,xc);let p=this.runWebGLProgram(d,[{dataId:e,shape:o,dtype:r}],r),h=this.readSync(p.dataId);return this.disposeIntermediateTensorInfo(p),h}if(n!=null)return this.convertAndCacheOnCPU(e);if(r==="string")return n;let l=this.activeTimers!=null,c;l&&(c=w.now());let u;if(r==="complex64"){let d=this.readSync(s.real.dataId),p=this.readSync(s.imag.dataId);u=N.mergeRealAndImagArrays(d,p)}else u=this.getValuesFromTexture(e);return l&&(this.downloadWaitMs+=w.now()-c),this.convertAndCacheOnCPU(e,u)}async read(e){if(this.pendingRead.has(e)){let h=this.pendingRead.get(e);return new Promise(f=>h.push(f))}let t=this.texData.get(e),{values:n,shape:r,slice:s,dtype:a,complexTensorInfos:o,isPacked:i}=t;if(s!=null){let h;i?h=new $l(r,xc):h=new ua(r,xc);let f=this.runWebGLProgram(h,[{dataId:e,shape:r,dtype:a}],a),m=this.read(f.dataId);return this.disposeIntermediateTensorInfo(f),m}if(n!=null)return this.convertAndCacheOnCPU(e);if(Y().getBool("DEBUG")&&!Y().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&Y().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");let l=null,c;if(a!=="complex64"&&Y().get("WEBGL_BUFFER_SUPPORTED")){c=this.decode(e);let h=this.texData.get(c.dataId);l=this.gpgpu.createBufferFromTexture(h.texture.texture,...Gm(r))}this.pendingRead.set(e,[]),a!=="complex64"&&await this.gpgpu.createAndWaitForFence();let u;if(a==="complex64"){let h=await Promise.all([this.read(o.real.dataId),this.read(o.imag.dataId)]),f=h[0],m=h[1];u=N.mergeRealAndImagArrays(f,m)}else if(l==null)u=this.getValuesFromTexture(e);else{let h=w.sizeFromShape(r);u=this.gpgpu.downloadFloat32MatrixFromBuffer(l,h)}if(c!=null&&this.disposeIntermediateTensorInfo(c),l!=null){let h=this.gpgpu.gl;ke(h,()=>h.deleteBuffer(l))}let d=this.convertAndCacheOnCPU(e,u),p=this.pendingRead.get(e);return this.pendingRead.delete(e),p
2021-11-08 13:36:26 +01:00
if (isnan(a)) return a;
if (isnan(b)) return b;
2022-01-16 15:49:55 +01:00
`,bc=class{constructor(e,t,n){this.variableNames=["A","B"],this.outputShape=N.assertAndGetBroadcastShape(t,n),this.enableShapeUniforms=pr(this.outputShape.length),this.userCode=`
2021-11-08 13:36:26 +01:00
float binaryOperation(float a, float b) {
${e}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
void main() {
float a = getAAtOutCoords();
float b = getBAtOutCoords();
setOutput(binaryOperation(a, b));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Qm=`
2021-11-08 13:36:26 +01:00
result.r = isNaN.r > 0. ? NAN : result.r;
result.g = isNaN.g > 0. ? NAN : result.g;
result.b = isNaN.b > 0. ? NAN : result.b;
result.a = isNaN.a > 0. ? NAN : result.a;
2022-01-16 15:49:55 +01:00
`,Dp=class{constructor(e,t,n,r=!1){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=N.assertAndGetBroadcastShape(t,n);let s=this.outputShape.length;this.enableShapeUniforms=pr(s);let a="";if(r)if(s===0||w.sizeFromShape(this.outputShape)===1)a=`
2021-11-08 13:36:26 +01:00
result.y = 0.;
result.z = 0.;
result.w = 0.;
`;else if(a=`
2022-01-16 15:49:55 +01:00
${wt(s)} coords = getOutputCoords();
`,s===1)this.enableShapeUniforms?a+=`
2021-11-08 13:36:26 +01:00
result.y = (coords + 1) >= outShape ? 0. : result.y;
result.z = 0.;
result.w = 0.;
`:a+=`
result.y = (coords + 1) >= ${this.outputShape[0]} ? 0. : result.y;
result.z = 0.;
result.w = 0.;
2022-01-16 15:49:55 +01:00
`;else{let i=qn("coords",s);this.enableShapeUniforms?a+=`
2021-11-08 13:36:26 +01:00
bool nextRowOutOfBounds =
2022-01-16 15:49:55 +01:00
(${i[s-2]} + 1) >= outShape[${s} - 2];
2021-11-08 13:36:26 +01:00
bool nextColOutOfBounds =
2022-01-16 15:49:55 +01:00
(${i[s-1]} + 1) >= outShape[${s} - 1];
2021-11-08 13:36:26 +01:00
result.y = nextColOutOfBounds ? 0. : result.y;
result.z = nextRowOutOfBounds ? 0. : result.z;
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
`:a+=`
bool nextRowOutOfBounds =
2022-01-16 15:49:55 +01:00
(${i[s-2]} + 1) >= ${this.outputShape[s-2]};
2021-11-08 13:36:26 +01:00
bool nextColOutOfBounds =
2022-01-16 15:49:55 +01:00
(${i[s-1]} + 1) >= ${this.outputShape[s-1]};
2021-11-08 13:36:26 +01:00
result.y = nextColOutOfBounds ? 0. : result.y;
result.z = nextRowOutOfBounds ? 0. : result.z;
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
`}this.userCode=`
vec4 binaryOperation(vec4 a, vec4 b) {
${e}
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
void main() {
2021-11-08 13:36:26 +01:00
vec4 a = getAAtOutCoords();
vec4 b = getBAtOutCoords();
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
vec4 result = binaryOperation(a, b);
${a}
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Cr(e){let{inputs:t,backend:n}=e,{x:r}=t;return n.incRef(r.dataId),{dataId:r.dataId,shape:r.shape,dtype:r.dtype}}var jee={kernelName:Qa,backendName:"webgl",kernelFunc:Cr};function Jo(e){let{inputs:t,backend:n}=e,{real:r,imag:s}=t,a=n.makeTensorInfo(r.shape,"complex64"),o=n.texData.get(a.dataId),i=Cr({inputs:{x:r},backend:n}),l=Cr({inputs:{x:s},backend:n});return o.complexTensorInfos={real:i,imag:l},a}var qee={kernelName:gd,backendName:"webgl",kernelFunc:Jo},MC="return (a < 0.) ? b * a : a;",zC=`
2021-11-08 13:36:26 +01:00
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
2022-01-16 15:49:55 +01:00
`;function Xee(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{alpha:a}=r,o=n.makeTensorInfo([],"float32",w.createScalarValue(a,"float32")),i=Y().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Dp(zC,s.shape,o.shape):new bc(MC,s.shape,o.shape),l=n.runWebGLProgram(i,[s,o],"float32");return n.disposeIntermediateTensorInfo(o),l}var Kee={kernelName:eo,backendName:"webgl",kernelFunc:Xee},LC="return (a < 0.) ? b * a : a;",BC=`
2021-11-08 13:36:26 +01:00
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
2022-01-16 15:49:55 +01:00
`;function Zee(e){let{inputs:t,backend:n}=e,{x:r,alpha:s}=t,a=Y().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Dp(BC,r.shape,s.shape):new bc(LC,r.shape,s.shape);return n.runWebGLProgram(a,[r,s],"float32")}var Yee={kernelName:ho,backendName:"webgl",kernelFunc:Zee},vc="if (isnan(x)) return x;",Jee=`
2021-11-08 13:36:26 +01:00
if (isnan(a)) return a;
if (isnan(b)) return b;
2022-01-16 15:49:55 +01:00
`,Qee=`
2021-11-08 13:36:26 +01:00
result.r = isNaN.r > 0. ? NAN : result.r;
result.g = isNaN.g > 0. ? NAN : result.g;
result.b = isNaN.b > 0. ? NAN : result.b;
result.a = isNaN.a > 0. ? NAN : result.a;
2022-01-16 15:49:55 +01:00
`;function it({opSnippet:e,packedOpSnippet:t,cpuKernelImpl:n,dtype:r}){return({inputs:s,backend:a})=>{let{x:o}=s,i=a,l=r||o.dtype;if(i.shouldExecuteOnCPU([o])&&n!=null){let d=i.texData.get(o.dataId),p=n(d.values,l);return i.makeTensorInfo(o.shape,l,p)}let c=Y().getBool("WEBGL_PACK_UNARY_OPERATIONS")&&t!=null,u;return c?u=new $l(o.shape,t):u=new ua(o.shape,e),i.runWebGLProgram(u,[o],l)}}function Tn({opSnippet:e,packedOpSnippet:t,checkOutOfBounds:n=!1,supportsComplex:r=!1,cpuKernelImpl:s,dtype:a}){return({inputs:o,backend:i})=>{let{a:l,b:c}=o,u=i;if(r&&l.dtype==="complex64"){let f=u.texData.get(l.dataId),m=u.texData.get(c.dataId),[g,y]=[[f.complexTensorInfos.real,m.complexTensorInfos.real],[f.complexTensorInfos.imag,m.complexTensorInfos.imag]].map(A=>{let[b,v]=A,C={dataId:b.dataId,dtype:b.dtype,shape:l.shape},I={dataId:v.dataId,dtype:v.dtype,shape:c.shape},E=new bc(e,l.shape,c.shape);return u.runWebGLProgram(E,[C,I],Wn(b.dtype,v.dtype))}),x=Jo({inputs:{real:g,imag:y},backend:u});return u.disposeIntermediateTensorInfo(g),u.disposeIntermediateTensorInfo(y),x}let d=a||Wn(l.dtype,c.dtype);if((l.dtype==="string"||c.dtype==="string"||u.shouldExecuteOnCPU([l,c]))&&s!=null){let f=u.texData.get(l.dataId).values,m=u.texData.get(c.dataId).values,g=l.dtype==="string"?N.fromUint8ToStringArray(f):f,y=l.dtype==="string"?N.fromUint8ToStringArray(m):m,[x,A]=s(l.shape,c.shape,g,y,d),b=u.makeTensorInfo(A,d),v=u.texData.get(b.dataId);return v.values=x,b}let p=Y().getBool("WEBGL_PACK_BINARY_OPERATIONS")&&t!=null,h;return p?h=new Dp(t,l.shape,c.shape,n):h=new bc(e,l.shape,c.shape),u.runWebGLProgram(h,[l,c],d)}}function e0(e,t=!1){if(e==="linear")return t?Ree:See;if(e==="relu")return t?Dee:Tee;if(e==="elu")return t?_ee:Cee;if(e==="relu6")return t?Pee:Nee;if(e==="prelu")return t?BC:LC;if(e==="leakyrelu")return t?zC:MC;if(e==="sigmoid")return t?$ee:Eee;throw new Error(`Activation ${e} has not been implemented for the WebGL backend.`)}var WC=class{constructor(e,t,n,r=!1,s=!1,a=!1,o=null,i=!1,l=!1){this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=n,this.enableShapeUniforms=pr(this.outputShape.length);let c=r?e[1]:e[2],u=Math.ceil(c/2),d=r?"i * 2, rc.y":"rc.y, i * 2",p=s?"rc.z, i * 2":"i * 2, rc.z",h=r?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],f=s?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],m="",g="";o&&(i?m=`vec4 activation(vec4 a) {
2021-11-08 13:36:26 +01:00
vec4 b = getPreluActivationWeightsAtOutCoords();
${o}
}`:l?m=`vec4 activation(vec4 a) {
vec4 b = getLeakyreluAlphaAtOutCoords();
${o}
}`:m=`vec4 activation(vec4 x) {
${o}
2021-12-01 14:27:05 +01:00
}`,g="result = activation(result);");let y=a?"result += getBiasAtOutCoords();":"";a&&this.variableNames.push("bias"),i&&this.variableNames.push("preluActivationWeights"),l&&this.variableNames.push("leakyreluAlpha");let x="rc.x",A="rc.x";e[0]<t[0]?x=`int(min(float(rc.x), ${e[0]-1}.))`:t[0]<e[0]&&(A=`int(min(float(rc.x), ${t[0]-1}.))`),this.userCode=`
2021-11-08 13:36:26 +01:00
${m}
// Don't use uniform for sharedDimensionPacked for performance.
const float sharedDimension = ${u}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
vec4 dot2x2ARowBCol(ivec3 rc) {
vec4 result = vec4(0);
for (int i = 0; i < ${u}; i++) {
int batchA = ${x};
2021-12-01 14:27:05 +01:00
int batchB = ${A};
2021-11-08 13:36:26 +01:00
vec4 a = getMatrixA(batchA, ${d});
vec4 b = getMatrixB(batchB, ${p});
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
result += (${h[0]} * ${f[0]});
result += (${h[1]} * ${f[1]});
}
return result;
2021-09-05 22:42:11 +02:00
}
2021-11-06 15:21:51 +01:00
2021-09-11 16:29:31 +02:00
void main() {
2021-11-08 13:36:26 +01:00
ivec3 rc = getOutputCoords();
vec4 result = dot2x2ARowBCol(rc);
2021-09-11 16:29:31 +02:00
2021-12-01 14:27:05 +01:00
${y}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${g}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
setOutput(result);
}
2022-01-16 15:49:55 +01:00
`}},VC={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"},UC=class{constructor(e,t,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=N.assertAndGetBroadcastShape(t,n),this.userCode=`
2021-11-08 13:36:26 +01:00
float binaryOpComplex(
float areal, float aimag, float breal, float bimag) {
${e}
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
float areal = getARealAtOutCoords();
float aimag = getAImagAtOutCoords();
float breal = getBRealAtOutCoords();
float bimag = getBImagAtOutCoords();
setOutput(binaryOpComplex(areal, aimag, breal, bimag));
}
2022-01-16 15:49:55 +01:00
`}},GC="return a * b;";function Fx(e){let{inputs:t,backend:n}=e,{a:r,b:s}=t,a=N.upcastType(r.dtype,s.dtype);if(r.dtype==="complex64"){let i=n.texData.get(r.dataId),l=n.texData.get(s.dataId),c=new UC(VC.REAL,r.shape,s.shape),u=new UC(VC.IMAG,r.shape,s.shape),d=[{dataId:i.complexTensorInfos.real.dataId,dtype:i.complexTensorInfos.real.dtype,shape:r.shape},{dataId:i.complexTensorInfos.imag.dataId,dtype:i.complexTensorInfos.imag.dtype,shape:r.shape},{dataId:l.complexTensorInfos.real.dataId,dtype:l.complexTensorInfos.real.dtype,shape:s.shape},{dataId:l.complexTensorInfos.imag.dataId,dtype:l.complexTensorInfos.imag.dtype,shape:s.shape}],p=n.runWebGLProgram(c,d,"float32"),h=n.runWebGLProgram(u,d,"float32"),f=Jo({inputs:{real:p,imag:h},backend:n});return n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(h),f}if(n.shouldExecuteOnCPU([r,s])){let i=n.texData.get(r.dataId),l=n.texData.get(s.dataId),[c,u]=QQ(r.shape,s.shape,i.values,l.values,a),d=n.makeTensorInfo(u,a),p=n.texData.get(d.dataId);return p.values=c,d}let o;return Y().getBool("WEBGL_PACK_BINARY_OPERATIONS")?o=new Dp(GC,r.shape,s.shape):o=new bc(GC,r.shape,s.shape),n.runWebGLProgram(o,[r,s],a)}var ete={kernelName:uo,backendName:"webgl",kernelFunc:Fx};function tte(e,t,n){let r=[Rl(e.shape),..._l(e.shape)],s={dtype:e.dtype,shape:r,dataId:e.dataId},a=[Rl(t),..._l(t)],o=new EC(a,r),i=!0,l=[r],c=n.runWebGLProgram(o,[s],e.dtype,l,i);return{dataId:c.dataId,shape:t,dtype:c.dtype}}function ve(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{shape:a}=r,o=n,i=w.sizeFromShape(s.shape),l=w.inferFromImplicitShape(a,i),c=w.sizeFromShape(l);w.assert(i===c,()=>`The new shape (${l}) has ${c} elements and the old shape (${s.shape}) has ${i} elements. The new shape and old shape must have the same number of elements.`);let u=o.texData.get(s.dataId);return u.isPacked&&!Ep(s.shape,l)&&!(u.texture!==null&&Ep(u.shape,l))?tte(s,l,o):(o.incRef(s.dataId),{dataId:s.dataId,shape:l,dtype:s.dtype})}var nte={kernelName:Wi,backendName:"webgl",kernelFunc:ve},HC=class{constructor(e,t){this.variableNames=["x"];let{windowSize:n,batchSize:r,inSize:s,outSize:a}=e;this.outputShape=[r,a];let o=Math.floor(n/4)*4,i=n%4,l="sumValue += dot(values, ones);";if(t!=null){let u=1/t;l=`sumValue += dot(values * ${w.isInt(u)?u.toPrecision(2):u}, ones);`}let c="";s%n>0&&(c=`
if (inIdx < 0 || inIdx >= ${s}) {
2021-11-08 13:36:26 +01:00
return 0.0;
}
`),this.userCode=`
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float getValue(int batch, int inIdx) {
${c}
return getX(batch, inIdx);
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = outIdx * ${n};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float sumValue = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int i = 0; i < ${o}; i += 4) {
int inIdx = inOffset + i;
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${l}
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int inIdx = inOffset + ${o};
if (${i===1}) {
vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${l}
} else if (${i===2}) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1), 0.0, 0.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${l}
} else if (${i===3}) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2), 0.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${l}
}
setOutput(sumValue);
}
2022-01-16 15:49:55 +01:00
`}},rte=class{constructor(e,t){this.variableNames=["x"];let{windowSize:n,batchSize:r,inSize:s,outSize:a}=e;this.outputShape=[r,a];let o="0.0",i="";t==="prod"?o="1.0":t==="min"?(o="1.0 / 1e-20",i="min"):t==="max"&&(o="-1.0 / 1e-20",i="max");let l=`${t}(${t}(${t}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;t==="sum"?l="sumValue":t==="prod"?l="prodValue":t==="all"?l="allValue":t==="any"&&(l="anyValue");let c=Math.floor(n/4)*4,u=n%4,d=`
2021-11-08 13:36:26 +01:00
if (${t==="sum"}) {
sumValue += dot(values, ones);
} else if (${t==="prod"}) {
vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
prodValue *= tmp[0] * tmp[1];
} else {
minMaxValue = ${i}(values, minMaxValue);
if (${t==="min"} || ${t==="max"}) {
minMaxValue = ${i}(values, minMaxValue);
bvec4 isNaN = isnan(values);
if (isNaN.r || isNaN.g || isNaN.b || isNaN.a) {
minMaxValue = vec4(NAN);
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
}
}
`,p="vec4";t==="all"?(o="1.0",d=`
bool reducedAllValue = all(values);
float floatedReducedAllValue = float(reducedAllValue);
allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
`,p="bvec4"):t==="any"&&(o="0.0",d=`
bool reducedAnyValue = any(values);
float floatedReducedAnyValue = float(reducedAnyValue);
anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
2022-01-16 15:49:55 +01:00
`,p="bvec4");let h="";s%n>0&&(h=`
if (inIdx < 0 || inIdx >= ${s}) {
2021-11-08 13:36:26 +01:00
return initializationValue;
}
`),this.userCode=`
const float initializationValue = ${o};
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float getValue(int batch, int inIdx) {
${h}
return getX(batch, inIdx);
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = outIdx * ${n};
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
vec4 minMaxValue = vec4(${o});
float prodValue = 1.0;
float sumValue = 0.0;
float allValue = 1.0;
float anyValue = 0.0;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
for (int i = 0; i < ${c}; i += 4) {
int inIdx = inOffset + i;
${p} values = ${p}(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${d}
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int inIdx = inOffset + ${c};
if (${u===1}) {
${p} values = ${p}(
getValue(batch, inIdx),
initializationValue,
initializationValue,
initializationValue
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${d}
} else if (${u===2}) {
${p} values = ${p}(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
initializationValue,
initializationValue
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${d}
} else if (${u===3}) {
${p} values = ${p}(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
initializationValue
);
${d}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(${l});
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function ste(e){let t=[];for(;t.length===0||t[t.length-1].outSize!==1;){let n=t.length?t[t.length-1].outSize:e[1],r=N.computeOptimalWindowSize(n);t.push({inSize:n,windowSize:r,outSize:Math.ceil(n/r)})}return t}function Fl(e,t,n,r){let s=ste(e.shape),a=e;for(let o=0;o<s.length;o++){let{inSize:i,windowSize:l,outSize:c}=s[o],u,d;n==="mean"?u=o===0?new HC({windowSize:l,inSize:i,batchSize:e.shape[0],outSize:c},i):new HC({windowSize:l,inSize:i,batchSize:e.shape[0],outSize:c}):u=new rte({windowSize:l,inSize:i,batchSize:e.shape[0],outSize:c},n),d=a,a=r.runWebGLProgram(u,[a],t),d.dataId!==e.dataId&&r.disposeIntermediateTensorInfo(d)}return a}var ate=class{constructor(e,t){this.variableNames=["A"];let n=new Array(e.length);for(let a=0;a<n.length;a++)n[a]=e[t[a]];this.outputShape=n,this.rank=n.length;let r=wt(this.rank),s=ote(t);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${r} resRC = getOutputCoords();
setOutput(getA(${s}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function ote(e){let t=e.length;if(t>6)throw Error(`Transpose for rank ${t} is not yet supported`);let n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],r=new Array(t);for(let s=0;s<e.length;s++)r[e[s]]=n[s];return r.join()}var ite=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;let n=new Array(e.length);for(let c=0;c<n.length;c++)n[c]=e[t[c]];if(this.outputShape=n,this.rank=n.length,this.rank>6)throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`);let r=wt(this.rank),s=NC("rc",this.rank),a=new Array(this.rank);for(let c=0;c<t.length;c++)a[t[c]]=s[c];let o=`vec2(${a.slice(-2).join()})`,i=`++${s[this.rank-1]} < ${n[this.rank-1]}`,l=`getChannel(getA(${a.join()}), ${o})`;this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${r} rc = getOutputCoords();
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
result[0] = ${l};
if(${i}) {
result[1] = ${l};
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
--${s[this.rank-1]};
if(++${s[this.rank-2]} < ${n[this.rank-2]}) {
2021-11-08 13:36:26 +01:00
result[2] = ${l};
if(${i}) {
result[3] = ${l};
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function t0(e,t,n){let r=Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new ite(e.shape,t):new ate(e.shape,t);return n.runWebGLProgram(r,[e],e.dtype)}function lte(e,t,n,r){let s=t,a=e.shape.length,o=w.parseAxisParam(s,e.shape),i=o,l=N.getAxesPermutation(i,a),c=l!=null,u=e;c&&(u=t0(e,l,r),i=N.getInnerMostAxes(i.length,a)),N.assertAxesAreInnerMostDims("sum",i,a);let[d,p]=N.computeOutAndReduceShapes(u.shape,i),h=d;n&&(h=N.expandShapeToKeepDim(d,o));let f=w.sizeFromShape(p),g=w.sizeFromShape(e.shape)/f,y=ve({inputs:{x:u},attrs:{shape:[g,f]},backend:r}),x=Wd(e.dtype),A=Fl(y,x,"sum",r),b=ve({inputs:{x:A},attrs:{shape:h},backend:r});return r.disposeIntermediateTensorInfo(y),r.disposeIntermediateTensorInfo(A),c&&r.disposeIntermediateTensorInfo(u),b}function n0(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r;return lte(s,a,o,n)}var ute={kernelName:vo,backendName:"webgl",kernelFunc:n0};function Xn(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{perm:a}=r,o=n,i=s.shape.length,l=new Array(i);for(let u=0;u<l.length;u++)l[u]=s.shape[a[u]];let c;if(o.shouldExecuteOnCPU([s])){let d=o.texData.get(s.dataId).values,p=$x(d,s.shape,s.dtype,a,l);c=o.makeTensorInfo(l,s.dtype);let h=o.texData.get(c.dataId);h.values=p}else c=t0(s,a,o);return c}var cte={kernelName:Co,backendName:"webgl",kernelFunc:Xn},jC=1e3;function r0({a:e,b:t,transposeA:n,transposeB:r,backend:s,bias:a=null,preluActivationWeights:o=null,leakyreluAlpha:i=0,activation:l=null}){let c=e.shape.length,u=t.shape.length,d=n?e.shape[c-2]:e.shape[c-1],p=r?t.shape[u-1]:t.shape[u-2],h=n?e.shape[c-1]:e.shape[c-2],f=r?t.shape[u-2]:t.shape[u-1],m=e.shape.slice(0,-2),g=t.shape.slice(0,-2),y=w.sizeFromShape(m),x=w.sizeFromShape(g),b=ll.assertAndGetBroadcastShape(e.shape.slice(0,-2),t.shape.slice(0,-2)).concat([h,f]);w.assert(d===p,()=>`Error in matMul: inner shapes (${d}) and (${p}) of Tensors with shapes ${e.shape} and ${t.shape} and transposeA=${n} and transposeB=${r} must match.`);let v=n?[y,d,h]:[y,h,d],C=r?[x,f,p]:[x,p,f],I=ve({inputs:{x:e},backend:s,attrs:{shape:v}}),E=ve({inputs:{x:t},backend:s,attrs:{shape:C}}),R=[I,E],F=Math.max(y,x),_=n?I.shape[1]:I.shape[2],P=a!=null,T=o!=null,O=l==="leakyrelu",G=l!=null?e0(l,!0):null,K=P||T||O||G!=null,z;if((h===1||f===1)&&_>jC&&K===!1){let W=I,Q=E;n&&(W=Xn({inputs:{x:I},backend:s,attrs:{perm:[0,2,1]}}),R.push(W)),r&&(Q=Xn({inputs:{x:E},backend:s,attrs:{perm:[0,2,1]}}),R.push(Q));let ne=f!==1,oe=f===1,Z=W;ne&&(Z=ve({inputs:{x:W},backend:s,attrs:{shape:[F,_,1]}}),R.push(Z));let ae=f===1?2:1,se=Q;oe&&(se=ve({inputs:{x:Q},backend:s,attrs:{shape:[F,1,_]}}),R.push(se));let me=Fx({inputs:{a:Z,b:se},backend:s});z=n0({inputs:{x:me},backend:s,attrs:{axis:ae,keepDims:!0}}),R.push(me)}else{let W=Wn(e.dtype,t.dtype),Q=new WC(v,C,[F,h,f],n,r,P,G,T,O),ne=[I,E];if(a!=null&&ne.push(a),T&&ne.push(o),O){let oe=s.makeTensorInfo([],"float32",w.createScalarValue(i,"float32"));ne.push(oe),R.push(oe)}z=s.runWebGLProgram(Q,ne,W)}let j=ve({inputs:{x:z},backend:s,attrs:{shape:b}});R.push(z);for(let W of R)s.disposeIntermediateTensorInfo(W);return j}function dte(e){let{inputs:t,backend:n,attrs:r}=e,{a:s,b:a,bias:o,preluActivationWeights:i}=t,{transposeA:l,transposeB:c,activation:u,leakyreluAlpha:d}=r;return r0({a:s,b:a,transposeA:l,transposeB:c,backend:n,bias:o,preluActivationWeights:i,leakyreluAlpha:d,activation:u})}var pte={kernelName:No,backendName:"webgl",kernelFunc:dte},qC="return abs(x);";function hte(e){let{inputs:t,backend:n}=e,{x:r}=t;if(n.shouldExecuteOnCPU([r])&&r.dtype!=="complex64"){let a=n.texData.get(r.dataId),o=CC(a.values);return n.makeTensorInfo(r.shape,r.dtype,o)}let s;return Y().getBool("WEBGL_PACK_UNARY_OPERATIONS")?s=new $l(r.shape,qC):s=new ua(r.shape,qC),n.runWebGLProgram(s,[r],r.dtype)}var fte={kernelName:yi,backendName:"webgl",kernelFunc:hte},mte=os+`
2021-11-08 13:36:26 +01:00
if (abs(x) > 1.) {
return NAN;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return acos(x);
2022-01-16 15:49:55 +01:00
`,gte=it({opSnippet:mte}),yte={kernelName:uu,backendName:"webgl",kernelFunc:gte},Ate=os+`
2021-11-08 13:36:26 +01:00
if (x < 1.0) return NAN;
2022-01-16 15:49:55 +01:00
return log(x + sqrt(x * x - 1.0));`,xte=it({opSnippet:Ate}),bte={kernelName:cu,backendName:"webgl",kernelFunc:xte},XC="return a + b;",vte=Tn({opSnippet:XC,packedOpSnippet:XC,supportsComplex:!0,cpuKernelImpl:$Q}),wte={kernelName:Zs,backendName:"webgl",kernelFunc:vte},kte=class{constructor(e,t){this.outputShape=[],this.outputShape=e,this.variableNames=t.map((s,a)=>`T${a}`);let n=[];this.variableNames.forEach(s=>{n.push(`float v${s} = get${s}AtOutCoords();`)});let r=this.variableNames.map(s=>`v${s}`).join(" + ");this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${n.join(`
`)}
2022-01-16 15:49:55 +01:00
float result = ${r};
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Ite=class{constructor(e,t){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.variableNames=t.map((s,a)=>`T${a}`);let n=[];this.variableNames.forEach(s=>{n.push(`vec4 v${s} = get${s}AtOutCoords();`)});let r=this.variableNames.map(s=>`v${s}`).join(" + ");this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${n.join(`
`)}
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
vec4 result = ${r};
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function s0(e){let{inputs:t,backend:n}=e,r=t;if(r.length===1)return Cr({inputs:{x:r[0]},backend:n});if(r.length>Y().get("WEBGL_MAX_TEXTURES_IN_SHADER")){let l=Math.floor(r.length/2),c=s0({inputs:r.slice(0,l),backend:n}),u=s0({inputs:r.slice(l),backend:n});return s0({inputs:[c,u],backend:n})}let s=r.map(l=>l.dtype).reduce((l,c)=>Wn(l,c)),a=r.map(l=>l.shape),i=Y().getBool("WEBGL_PACK")?new Ite(r[0].shape,a):new kte(r[0].shape,a);return n.runWebGLProgram(i,r,s)}var Ste={kernelName:Fa,backendName:"webgl",kernelFunc:s0};function Cte(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r,i=s.shape.length,l=w.parseAxisParam(a,s.shape),c=l,u=N.getAxesPermutation(c,i),d=s;u!=null&&(d=Xn({inputs:{x:s},backend:n,attrs:{perm:u}}),c=N.getInnerMostAxes(c.length,i)),N.assertAxesAreInnerMostDims("all",c,i);let[p,h]=N.computeOutAndReduceShapes(d.shape,c),f=w.sizeFromShape(h),m=ve({inputs:{x:d},backend:n,attrs:{shape:[-1,f]}}),g=Fl(m,m.dtype,"all",n),y;if(o){let x=N.expandShapeToKeepDim(p,l);y=ve({inputs:{x:g},backend:n,attrs:{shape:x}})}else y=ve({inputs:{x:g},backend:n,attrs:{shape:p}});return n.disposeIntermediateTensorInfo(m),n.disposeIntermediateTensorInfo(g),u!=null&&n.disposeIntermediateTensorInfo(d),y}var Tte={kernelName:du,backendName:"webgl",kernelFunc:Cte};function Nte(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r,i=s.shape.length,l=w.parseAxisParam(a,s.shape),c=l,u=N.getAxesPermutation(c,i),d=s;u!=null&&(d=Xn({inputs:{x:s},backend:n,attrs:{perm:u}}),c=N.getInnerMostAxes(c.length,i)),N.assertAxesAreInnerMostDims("any",c,i);let[p,h]=N.computeOutAndReduceShapes(d.shape,c),f=w.sizeFromShape(h),m=ve({inputs:{x:d},backend:n,attrs:{shape:[-1,f]}}),g=Fl(m,m.dtype,"any",n),y;if(o){let x=N.expandShapeToKeepDim(p,l);y=ve({inputs:{x:g},backend:n,attrs:{shape:x}})}else y=ve({inputs:{x:g},backend:n,attrs:{shape:p}});return n.disposeIntermediateTensorInfo(m),n.disposeIntermediateTensorInfo(g),u!=null&&n.disposeIntermediateTensorInfo(d),y}var Ete={kernelName:pu,backendName:"webgl",kernelFunc:Nte},Rte=class{constructor(e,t,n){this.variableNames=["A"];let{windowSize:r,batchSize:s,outSize:a}=e;n||this.variableNames.push("bestIndicesA"),this.outputShape=[s,a];let o=t==="max"?">":"<",i=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
2022-01-16 15:49:55 +01:00
int inOffset = outIdx * ${r};
2021-11-08 13:36:26 +01:00
int bestIndex = inOffset;
float bestValue = getA(batch, bestIndex);
2022-01-16 15:49:55 +01:00
for (int i = 0; i < ${r}; i++) {
2021-11-08 13:36:26 +01:00
int inIdx = ${i};
float candidate = getA(batch, inIdx);
if (candidate ${o} bestValue) {
bestValue = candidate;
bestIndex = inIdx;
2021-09-11 16:29:31 +02:00
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(float(bestIndex));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},_te=class{constructor(e,t,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,w.assert(e.length>2,()=>`Packed arg${n.charAt(0).toUpperCase()+n.slice(1)} supports only inputs with rank above 2.`);let s=e[e.length-1],a=Math.ceil(s/t);this.outputShape=e.slice(0,-1),a>1&&this.outputShape.push(a),r||this.variableNames.push("bestIndicesA");let o=this.outputShape,i=o.length,l=wt(i),c=qn("coords",i),u,d;if(a===1){d=i+1;let I=wt(d);u=`
2022-01-08 18:43:44 +01:00
${I} sourceLocR = ${I}(${c.join()}, 0);
2021-11-08 13:36:26 +01:00
++${c[i-1]};
2022-01-08 18:43:44 +01:00
${I} sourceLocG = ${I}(${c.join()}, 0);
2021-11-08 13:36:26 +01:00
++${c[i-2]};
2022-01-08 18:43:44 +01:00
${I} sourceLocA = ${I}(${c.join()}, 0);
2021-11-08 13:36:26 +01:00
--${c[i-1]};
2022-01-08 18:43:44 +01:00
${I} sourceLocB = ${I}(${c.join()}, 0);
2021-11-08 13:36:26 +01:00
--${c[i-2]};`}else d=i,u=`
${l} sourceLocR = coords;
++${c[i-1]};
${l} sourceLocG = coords;
++${c[i-2]};
${l} sourceLocA = coords;
--${c[i-1]};
${l} sourceLocB = coords;
2022-01-16 15:49:55 +01:00
--${c[i-2]};`;let p=["x","y","z","w","u","v"].slice(0,d),h="."+p[d-1],f=p.map(I=>"int "+I),m=qn("sourceLocR",d-1).concat("inIdx.r"),g=qn("sourceLocG",d-1).concat("inIdx.g"),y=qn("sourceLocB",d-1).concat("inIdx.b"),x=qn("sourceLocA",d-1).concat("inIdx.a"),A=n==="max"?"greaterThan":"lessThan",b=r?"":`
2021-11-08 13:36:26 +01:00
inIdx = round(vec4(getBestIndicesAChannel(${m.join()}),
getBestIndicesAChannel(${g.join()}),
2021-12-01 14:27:05 +01:00
getBestIndicesAChannel(${y.join()}),
getBestIndicesAChannel(${x.join()})));`,v=`vec4(
2021-11-08 13:36:26 +01:00
getAChannel(${m.join()}),
hasNextCol ? getAChannel(${g.join()}) : 0.,
2021-12-01 14:27:05 +01:00
hasNextRow ? getAChannel(${y.join()}) : 0.,
2022-01-16 15:49:55 +01:00
hasNextRow && hasNextCol ? getAChannel(${x.join()}) : 0.)`,C=r?"":`
2021-11-08 13:36:26 +01:00
float getBestIndicesAChannel(${f.join()}) {
return getChannel(getBestIndicesA(${p.join()}),
vec2(${p.slice(-2).join()}));
}`;this.userCode=`
float getAChannel(${f.join()}) {
return getChannel(getA(${p.join()}),
vec2(${p.slice(-2).join()}));
}
2021-12-27 16:59:56 +01:00
${C}
2021-11-06 15:21:51 +01:00
void main() {
2021-11-08 13:36:26 +01:00
${l} coords = getOutputCoords();
bool hasNextCol = ${c[i-1]} < ${o[i-1]-1};
bool hasNextRow = ${c[i-2]} < ${o[i-2]-1};
${u}
ivec4 srcIdx = ivec4(sourceLocR${h}, sourceLocG${h},
sourceLocB${h}, sourceLocA${h}) * ${t};
ivec4 inIdx = srcIdx;
vec4 bestIndex = vec4(inIdx);
vec4 bestValue = ${v};
2021-11-08 13:36:26 +01:00
for (int i = 0; i < ${t}; i++) {
inIdx = srcIdx;
${b}
vec4 candidate = ${v};
2021-11-08 13:36:26 +01:00
bvec4 nan = isnan(candidate);
bvec4 replace = bvec4(
2021-12-01 14:27:05 +01:00
vec4(${A}(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));
2021-11-08 13:36:26 +01:00
bestValue = vec4(replace.x ? candidate.x : bestValue.x,
replace.y ? candidate.y : bestValue.y,
replace.z ? candidate.z : bestValue.z,
replace.w ? candidate.w : bestValue.w);
bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));
srcIdx++;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(bestIndex);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function KC(e,t,n,r=null){let s=t.shape[0],a=t.shape[1];r!=null&&(s=r.shape[0],a=r.shape[1]);let o=N.computeOptimalWindowSize(a),i={windowSize:o,inSize:a,batchSize:s,outSize:Math.ceil(a/o)},l=new Rte(i,n,r==null),c=[t];r!=null&&c.push(r);let u=e.runWebGLProgram(l,c,"int32");if(u.shape[1]===1)return u;let d=KC(e,t,n,u);return e.disposeIntermediateTensorInfo(u),d}function ZC(e,t,n,r=null){let s=r!=null?r.shape:t.shape,a=s[s.length-1],o=N.computeOptimalWindowSize(a),i=new _te(s,o,n,r==null),l=r==null?[t]:[t,r],c=e.runWebGLProgram(i,l,"int32");if(c.shape.length===t.shape.length){let u=ZC(e,t,n,c);return e.disposeIntermediateTensorInfo(c),u}return c}function YC(e,t,n,r){let s=[n];if(N.assertAxesAreInnerMostDims("arg"+r.charAt(0).toUpperCase()+r.slice(1),s,t.shape.length),!Y().getBool("WEBGL_PACK_REDUCE")||t.shape.length<=2){let a=[],o=e.texData.get(t.dataId),i=o!==null&&o.isPacked,l=t;i&&(l=e.unpackTensor(t),a.push(l));let[c,u]=N.computeOutAndReduceShapes(l.shape,s),d=w.sizeFromShape(u),p=ve({inputs:{x:l},backend:e,attrs:{shape:[-1,d]}});a.push(p);let h=KC(e,p,r);a.push(h);let f=ve({inputs:{x:h},backend:e,attrs:{shape:c}});return a.forEach(m=>e.disposeIntermediateTensorInfo(m)),f}return ZC(e,t,r)}function Dte(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a}=r,o=w.parseAxisParam(a,s.shape),i=N.getAxesPermutation(o,s.shape.length),l=s,c=[];i!=null&&(l=Xn({inputs:{x:s},backend:n,attrs:{perm:i}}),c.push(l),o=N.getInnerMostAxes(o.length,l.shape.length)),N.assertAxesAreInnerMostDims("argMax",[o[0]],l.shape.length);let u=YC(n,l,o[0],"max");return c.forEach(d=>n.disposeIntermediateTensorInfo(d)),u}var Pte={kernelName:Oa,backendName:"webgl",kernelFunc:Dte};function $te(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a}=r,o=w.parseAxisParam(a,s.shape),i=N.getAxesPermutation(o,s.shape.length),l=s,c=[];i!=null&&(l=Xn({inputs:{x:s},backend:n,attrs:{perm:i}}),c.push(l),o=N.getInnerMostAxes(o.length,l.shape.length)),N.assertAxesAreInnerMostDims("argMin",[o[0]],l.shape.length);let u=YC(n,l,o[0],"min");return c.forEach(d=>n.disposeIntermediateTensorInfo(d)),u}var Fte={kernelName:hu,backendName:"webgl",kernelFunc:$te},Ote=os+`
2021-11-08 13:36:26 +01:00
if (abs(x) > 1.) {
return NAN;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return asin(x);
2022-01-16 15:49:55 +01:00
`,Mte=it({opSnippet:Ote}),zte={kernelName:fu,backendName:"webgl",kernelFunc:Mte},Lte=os+"return log(x + sqrt(x * x + 1.0));",Bte=it({opSnippet:Lte}),Wte={kernelName:mu,backendName:"webgl",kernelFunc:Bte},Vte=os+`
2021-11-08 13:36:26 +01:00
return atan(x);
2022-01-16 15:49:55 +01:00
`,Ute=it({opSnippet:Vte}),Gte={kernelName:gu,backendName:"webgl",kernelFunc:Ute},Hte=Jee+`
2021-11-08 13:36:26 +01:00
return atan(a, b);
2022-01-16 15:49:55 +01:00
`,jte=`
2021-11-08 13:36:26 +01:00
vec4 result = atan(a, b);
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
2022-01-16 15:49:55 +01:00
`+Qee+`
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,qte=Tn({opSnippet:Hte,packedOpSnippet:jte}),Xte={kernelName:Au,backendName:"webgl",kernelFunc:qte},Kte=os+`
2021-11-08 13:36:26 +01:00
if ((x < -1.0) || (x > 1.0)) return NAN;
2022-01-16 15:49:55 +01:00
return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,Zte=it({opSnippet:Kte}),Yte={kernelName:yu,backendName:"webgl",kernelFunc:Zte},Pp=class{constructor(e,t,n,r=!1,s=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let a=e.filterWidth,o=e.strideHeight,i=e.strideWidth,l=e.dilationHeight,c=e.dilationWidth,u=e.effectiveFilterHeight,d=e.effectiveFilterWidth,p=e.padInfo.top,h=e.padInfo.left;this.outputShape=e.outShape;let f=t==="avg",m=`((batch * ${e.inHeight} + xR) * ${e.inWidth} + xC) * ${e.inChannels} + d`,g=`(xR * ${e.inWidth} + xC) * ${e.inChannels} + d`,y="0.0";if(f||(y="-1.0 / 1e-20"),n){let I=">=";this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec2 strides = ivec2(${o}, ${i});
const ivec2 pads = ivec2(${p}, ${h});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d = coords[3];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec2 xRCCorner = coords.yz * strides - pads;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
float minMaxValue = 0.0;
float minMaxValueFound = 0.0;
int minMaxPosition = 0;
float avgValue = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${u};
wR += ${l}) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
for (int wC = 0; wC < ${d};
wC += ${c}) {
int xC = xCCorner + wC;
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
float value = getX(batch, xR, xC, d);
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix(
value, minMaxValue, minMaxValueFound);
2022-01-08 18:43:44 +01:00
if (value ${I} currMinMaxValue) {
2021-11-08 13:36:26 +01:00
minMaxValue = value;
minMaxValueFound = 1.0;
2022-01-16 15:49:55 +01:00
minMaxPosition = ${r?s?m:g:`wR * ${d} + wC`};
2021-11-08 13:36:26 +01:00
}
}
}
setOutput(float(minMaxPosition));
}
`;return}let x="max",A=`${t}(${t}(${t}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;t==="avg"&&(A="avgValue / count");let b=Math.floor(a/4)*4,v=a%4,C=`
2021-11-08 13:36:26 +01:00
if (${f}) {
avgValue += dot(values, ones);
2021-11-06 15:21:51 +01:00
} else {
2021-11-08 13:36:26 +01:00
minMaxValue = ${x}(values, minMaxValue);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`;this.userCode=`
const ivec2 strides = ivec2(${o}, ${i});
const ivec2 pads = ivec2(${p}, ${h});
2021-12-01 14:27:05 +01:00
const float initializationValue = ${y};
2021-11-08 13:36:26 +01:00
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
float count = 0.0;
float getValue(int batch, int xR, int xC, int d) {
if (xC < 0 || xC >= ${e.inWidth}) {
return initializationValue;
}
count += 1.0;
return getX(batch, xR, xC, d);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2021-11-06 15:21:51 +01:00
void main() {
2021-11-08 13:36:26 +01:00
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d = coords[3];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec2 xRCCorner = coords.yz * strides - pads;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
2021-12-01 14:27:05 +01:00
vec4 minMaxValue = vec4(${y});
2021-11-08 13:36:26 +01:00
float avgValue = 0.0;
count = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${u};
wR += ${l}) {
int xR = xRCorner + wR;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${b}; wC += 4) {
int xC = xCCorner + wC * ${c};
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ${c}, d),
getValue(batch, xR, xC + 2 * ${c}, d),
getValue(batch, xR, xC + 3 * ${c}, d)
);
2021-12-27 16:59:56 +01:00
${C}
2021-11-08 13:36:26 +01:00
}
int xC = xCCorner + ${b};
if (${v===1}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xR, xC, d),
initializationValue,
initializationValue,
initializationValue
);
2021-12-27 16:59:56 +01:00
${C}
} else if (${v===2}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ${c}, d),
initializationValue,
initializationValue
);
2021-12-27 16:59:56 +01:00
${C}
} else if (${v===3}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ${c}, d),
getValue(batch, xR, xC + 2 * ${c}, d),
initializationValue
);
2021-12-27 16:59:56 +01:00
${C}
2021-11-08 13:36:26 +01:00
}
}
2021-12-01 14:27:05 +01:00
setOutput(${A});
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Ox=class{constructor(e,t,n,r=!1,s=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let a=e.filterWidth,o=e.strideDepth,i=e.strideHeight,l=e.strideWidth,c=e.dilationDepth,u=e.dilationHeight,d=e.dilationWidth,p=e.effectiveFilterDepth,h=e.effectiveFilterHeight,f=e.effectiveFilterWidth,m=e.padInfo.front,g=e.padInfo.top,y=e.padInfo.left;this.outputShape=e.outShape;let x=t==="avg",A="0.0";if(x||(A="-1.0 / 1e-20"),n){let R=">=";this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec3 strides =
ivec3(${o}, ${i}, ${l});
2021-12-01 14:27:05 +01:00
const ivec3 pads = ivec3(${m}, ${g}, ${y});
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xDCorner = xCorner.x;
int xRCorner = xCorner.y;
int xCCorner = xCorner.z;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
// ? = to be determined
float minMaxValue = 0.0;
float minMaxValueFound = 0.0;
int minMaxPosition = 0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wD = 0; wD < ${p};
wD += ${c}) {
int xD = xDCorner + wD;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xD < 0 || xD >= ${e.inDepth}) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${h};
wR += ${u}) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${f};
wC += ${d}) {
int xC = xCCorner + wC;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
float value = getX(batch, xD, xR, xC, ch);
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix(
value, minMaxValue, minMaxValueFound);
2021-11-13 18:23:32 +01:00
if (value ${R} currMinMaxValue) {
2021-11-08 13:36:26 +01:00
minMaxValue = value;
minMaxValueFound = 1.0;
2022-01-16 15:49:55 +01:00
minMaxPosition = ${r?s?`(((batch * ${e.inDepth} + xD) * ${e.inHeight} + xR) * ${e.inWidth} + xC) * ${e.inChannels} + ch`:`((xD * ${e.inHeight} + xR) * ${e.inWidth} + xC) * ${e.inChannels} + ch`:`wD * ${h} * ${f} +
2021-11-08 13:36:26 +01:00
wR * ${f} + wC`};
2021-11-06 15:21:51 +01:00
}
}
}
2021-11-08 13:36:26 +01:00
}
setOutput(float(minMaxPosition));
2021-09-11 16:29:31 +02:00
}
`;return}let b="max",v=`${t}(${t}(${t}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;t==="avg"&&(v="avgValue / count");let C=Math.floor(a/4)*4,I=a%4,E=`
2021-11-08 13:36:26 +01:00
if (${x}) {
avgValue += dot(values, ones);
} else {
minMaxValue = ${b}(values, minMaxValue);
2021-09-01 00:22:16 +02:00
}
2021-11-08 13:36:26 +01:00
`;this.userCode=`
const ivec3 strides =
ivec3(${o}, ${i}, ${l});
2021-12-01 14:27:05 +01:00
const ivec3 pads = ivec3(${m}, ${g}, ${y});
const float initializationValue = ${A};
2021-11-08 13:36:26 +01:00
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float count = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float getValue(int batch, int xD, int xR, int xC, int ch) {
if (xC < 0 || xC >= ${e.inWidth}) {
return initializationValue;
}
count += 1.0;
return getX(batch, xD, xR, xC, ch);
2021-11-06 15:21:51 +01:00
}
2021-09-01 00:24:30 +02:00
void main() {
2021-11-08 13:36:26 +01:00
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xDCorner = xCorner.x;
int xRCorner = xCorner.y;
int xCCorner = xCorner.z;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
2021-12-01 14:27:05 +01:00
vec4 minMaxValue = vec4(${A});
2021-11-08 13:36:26 +01:00
float avgValue = 0.0;
count = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wD = 0; wD < ${p};
wD += ${c}) {
int xD = xDCorner + wD;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
if (xD < 0 || xD >= ${e.inDepth}) {
continue;
}
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${h};
wR += ${u}) {
int xR = xRCorner + wR;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
2021-09-11 16:29:31 +02:00
2021-12-27 16:59:56 +01:00
for (int wC = 0; wC < ${C}; wC += 4) {
2021-11-08 13:36:26 +01:00
int xC = xCCorner + wC * ${d};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ${d}, ch),
getValue(batch, xD, xR, xC + 2 * ${d}, ch),
getValue(batch, xD, xR, xC + 3 * ${d}, ch)
);
2021-09-11 16:29:31 +02:00
2021-12-01 14:27:05 +01:00
${E}
2021-11-08 13:36:26 +01:00
}
2021-09-11 16:29:31 +02:00
2021-12-27 16:59:56 +01:00
int xC = xCCorner + ${C};
2022-01-08 18:43:44 +01:00
if (${I===1}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
initializationValue,
initializationValue,
initializationValue
);
2021-09-11 16:29:31 +02:00
2021-12-01 14:27:05 +01:00
${E}
2022-01-08 18:43:44 +01:00
} else if (${I===2}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ${d}, ch),
initializationValue,
initializationValue
);
2021-12-01 14:27:05 +01:00
${E}
2022-01-08 18:43:44 +01:00
} else if (${I===3}) {
2021-11-08 13:36:26 +01:00
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ${d}, ch),
getValue(batch, xD, xR, xC + 2 * ${d}, ch),
initializationValue
);
2021-09-11 16:29:31 +02:00
2021-12-01 14:27:05 +01:00
${E}
2021-11-08 13:36:26 +01:00
}
}
setOutput(${v});
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Jte(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t;hc(s,"avgPool");let{filterSize:a,strides:o,pad:i,dimRoundingMode:l}=r,c=1;w.assert(N.eitherStridesOrDilationsAreOne(o,c),()=>`Error in avgPool: Either strides or dilations must be 1. Got strides ${o} and dilations '${c}'`);let u=N.computePool2DInfo(s.shape,a,o,c,i,l);if(u.filterWidth===1&&u.filterHeight===1&&w.arraysEqual(u.inShape,u.outShape))return Cr({inputs:{x:s},backend:n});let d=new Pp(u,"avg",!1);return n.runWebGLProgram(d,[s],"float32")}var Qte={kernelName:Ma,backendName:"webgl",kernelFunc:Jte};function ene(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{filterSize:a,strides:o,pad:i,dimRoundingMode:l,dataFormat:c}=r,u=[1,1,1],d=N.computePool3DInfo(s.shape,a,o,u,i,l,c),p=new Ox(d,"avg",!1);return n.runWebGLProgram(p,[s],"float32")}var tne={kernelName:md,backendName:"webgl",kernelFunc:ene},nne=class{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,s=e.strideWidth,a=e.dilationHeight,o=e.dilationWidth,i=e.effectiveFilterHeight,l=e.effectiveFilterWidth,c=i-1-e.padInfo.top,u=l-1-e.padInfo.left,d=1/(t*n);this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec2 pads = ivec2(${c}, ${u});
const float avgMultiplier = float(${d});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec2 dyRCCorner = coords.yz - pads;
int dyRCorner = dyRCCorner.x;
int dyCCorner = dyRCCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ${i};
wR += ${a}) {
2022-01-16 15:49:55 +01:00
float dyR = float(dyRCorner + wR) / ${r}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${l};
wC+= ${o}) {
2022-01-16 15:49:55 +01:00
float dyC = float(dyCCorner + wC) / ${s}.0;
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(b, idyR, idyC, d);
dotProd += dyValue * avgMultiplier;
}
}
setOutput(dotProd);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`}},rne=class{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;let t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,s=e.strideDepth,a=e.strideHeight,o=e.strideWidth,i=e.dilationDepth,l=e.dilationHeight,c=e.dilationWidth,u=e.effectiveFilterDepth,d=e.effectiveFilterHeight,p=e.effectiveFilterWidth,h=u-1-e.padInfo.front,f=d-1-e.padInfo.top,m=p-1-e.padInfo.left,g=1/(t*n*r);this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec3 pads = ivec3(${h}, ${f}, ${m});
const float avgMultiplier = float(${g});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyDCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wD = 0; wD < ${u};
wD += ${i}) {
2022-01-16 15:49:55 +01:00
float dyD = float(dyDCorner + wD) / ${s}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyD < 0.0 || dyD >= ${e.outDepth}.0 || fract(dyD) > 0.0) {
continue;
}
int idyD = int(dyD);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${d};
wR += ${l}) {
float dyR = float(dyRCorner + wR) / ${a}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 ||
fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${p};
wC += ${c}) {
float dyC = float(dyCCorner + wC) / ${o}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
dotProd += dyValue * avgMultiplier;
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function sne(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,input:a}=t,o=a,{filterSize:i,strides:l,pad:c,dimRoundingMode:u}=r,d=[1,1,1],p=N.computePool3DInfo(o.shape,i,l,d,c,u),h=new rne(p);return n.runWebGLProgram(h,[s],o.dtype)}var ane={kernelName:Lh,backendName:"webgl",kernelFunc:sne};function one(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,input:a}=t,o=a;hc([s,a],"avgPoolGrad");let{filterSize:i,strides:l,pad:c}=r,u=N.computePool2DInfo(o.shape,i,l,1,c),d=new nne(u);return n.runWebGLProgram(d,[s],o.dtype)}var ine={kernelName:zh,backendName:"webgl",kernelFunc:one};function lne(e){let{inputs:t,backend:n,attrs:r}=e,{a:s,b:a}=t,{transposeA:o,transposeB:i}=r;return r0({a:s,b:a,transposeA:o,transposeB:i,backend:n})}var une={kernelName:za,backendName:"webgl",kernelFunc:lne},cne=class{constructor(e,t,n,r,s,a){this.outputShape=[],this.variableNames=["x","mean","variance"],N.assertAndGetBroadcastShape(e,t),N.assertAndGetBroadcastShape(e,n);let o="0.0";r!=null&&(N.assertAndGetBroadcastShape(e,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");let i="1.0";s!=null&&(N.assertAndGetBroadcastShape(e,s),this.variableNames.push("scale"),i="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
float x = getXAtOutCoords();
float mean = getMeanAtOutCoords();
float variance = getVarianceAtOutCoords();
float offset = ${o};
float scale = ${i};
float inv = scale * inversesqrt(variance + float(${a}));
setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},dne=class{constructor(e,t,n,r,s,a){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],N.assertAndGetBroadcastShape(e,t),N.assertAndGetBroadcastShape(e,n);let o="vec4(0.0)";r!=null&&(N.assertAndGetBroadcastShape(e,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");let i="vec4(1.0)";s!=null&&(N.assertAndGetBroadcastShape(e,s),this.variableNames.push("scale"),i="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
vec4 offset = ${o};
vec4 scale = ${i};
vec4 x = getXAtOutCoords();
vec4 mean = getMeanAtOutCoords();
vec4 variance = getVarianceAtOutCoords();
vec4 inv = scale * inversesqrt(variance + vec4(${a}));
setOutput((x - mean) * inv + offset);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},pne=({inputs:e,backend:t,attrs:n})=>{let{x:r,mean:s,variance:a,offset:o,scale:i}=e;w.assert(s.shape.length===a.shape.length,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),w.assert(o==null||s.shape.length===o.shape.length,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),w.assert(i==null||s.shape.length===i.shape.length,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let{varianceEpsilon:l}=n;l==null&&(l=.001);let c=[r,s,a],u=null;o!=null&&(u=o.shape,c.push(o));let d=null;i!=null&&(d=i.shape,c.push(i));let p=Y().getBool("WEBGL_PACK_NORMALIZATION")?new dne(r.shape,s.shape,a.shape,u,d,l):new cne(r.shape,s.shape,a.shape,u,d,l);return t.runWebGLProgram(p,c,c[0].dtype)},hne={kernelName:Ya,backendName:"webgl",kernelFunc:pne},fne=class{constructor(e){this.variableNames=["source"],this.outputShape=e,this.rank=e.length;let t=wt(this.rank);this.customUniforms=[{name:"start",arrayIndex:this.rank,type:"int"}];let n=mne(this.rank),r,s=e.map((a,o)=>`sourceLoc.${Mx[o]} = start[${o}] + coords.${Mx[o]};`);r=`
2021-11-08 13:36:26 +01:00
${t} sourceLoc;
${t} coords = getOutputCoords();
2022-01-16 15:49:55 +01:00
${s.join(`
2021-11-08 13:36:26 +01:00
`)}
`,this.userCode=`
void main() {
2022-01-16 15:49:55 +01:00
${r}
2021-11-08 13:36:26 +01:00
setOutput(getSource(${n}));
}
2022-01-16 15:49:55 +01:00
`}},Mx=["x","y","z","w","u","v"];function mne(e){if(e===1)return"sourceLoc";if(e<=6)return Mx.slice(0,e).map(t=>"sourceLoc."+t).join(",");throw Error(`Slicing for rank ${e} is not yet supported`)}var gne=class{constructor(e){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.rank=e.length,this.customUniforms=[{name:"start",arrayIndex:this.rank,type:"int"}];let t=wt(this.rank),n=qn("coords",this.rank),r=qn("sourceLoc",this.rank),s=this.rank===1?"sourceLoc":`vec2(${r.slice(-2).join()})`,a=`getChannel(getSource(${r.join()}), ${s})`,o=`
2021-11-08 13:36:26 +01:00
result.x = ${a};
if (++${n[this.rank-1]} < ${e[this.rank-1]}) {
2022-01-16 15:49:55 +01:00
++${r[this.rank-1]};
2021-11-08 13:36:26 +01:00
result.y = ${a};
2022-01-16 15:49:55 +01:00
--${r[this.rank-1]};
2021-11-08 13:36:26 +01:00
}
`,i=this.rank===1?"":`
--${n[this.rank-1]};
if (++${n[this.rank-2]} < ${e[this.rank-2]}) {
2022-01-16 15:49:55 +01:00
++${r[this.rank-2]};
2021-11-08 13:36:26 +01:00
result.z = ${a};
if (++${n[this.rank-1]} < ${e[this.rank-1]}) {
2022-01-16 15:49:55 +01:00
++${r[this.rank-1]};
2021-11-08 13:36:26 +01:00
result.w = ${a};
}
}
`,l=this.rank<=4?`sourceLoc = coords +
2022-01-16 15:49:55 +01:00
${t}(${e.map((c,u)=>`start[${u}]`).join()});`:e.map((c,u)=>`${r[u]} = ${n[u]} + start[${u}];`).join(`
2021-11-08 13:36:26 +01:00
`);this.userCode=`
void main() {
${t} coords = getOutputCoords();
${t} sourceLoc;
${l}
vec4 result = vec4(0.);
${o}
${i}
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function yne(e,t,n,r){let s=r.texData.get(e.dataId),a=r.makeTensorInfo(n,e.dtype),o=r.texData.get(a.dataId);Object.assign(o,s),o.refCount=1,o.shape=n,o.dtype=e.dtype;let i=zt.computeFlatOffset(t,w.computeStrides(e.shape));s.slice&&(i+=s.slice.flatOffset),o.slice={flatOffset:i,origDataId:s.slice&&s.slice.origDataId||e.dataId};let l=r.dataRefCount.get(o.slice.origDataId)||1;return r.dataRefCount.set(o.slice.origDataId,l+1),a}function wc(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{begin:a,size:o}=r,[i,l]=zt.parseSliceParams(s,a,o);if(zt.assertParamsValid(s,i,l),w.sizeFromShape(l)===0)return n.makeTensorInfo(l,s.dtype,[]);if(n.shouldExecuteOnCPU([s])||s.dtype==="string"){let d=n.texData.get(s.dataId),p=oee(d.values,i,l,s.shape,s.dtype);return n.makeTensorInfo(l,s.dtype,p)}let{isPacked:c}=n.texData.get(s.dataId),u=zt.isSliceContinous(s.shape,i,l);if(c||!u){let d=Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new gne(l):new fne(l),p=[i];return n.runWebGLProgram(d,[s],s.dtype,p)}return n.uploadToGPU(s.dataId),yne(s,i,l,n)}var Ane={kernelName:ji,backendName:"webgl",kernelFunc:wc},xne=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockShape:a,crops:o}=r;w.assert(s.shape.length<=4,()=>"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet");let i=a.reduce((x,A)=>x*A),l=N.getReshaped(s.shape,a,i),c=N.getPermuted(l.length,a.length),u=N.getReshapedPermuted(s.shape,a,i),d=N.getSliceBeginCoords(o,a.length),p=N.getSliceSize(u,o,a.length),h=[],f=ve({inputs:{x:s},backend:n,attrs:{shape:l}}),m=Xn({inputs:{x:f},backend:n,attrs:{perm:c}}),g=ve({inputs:{x:m},backend:n,attrs:{shape:u}}),y=wc({inputs:{x:g},backend:n,attrs:{begin:d,size:p}});return h.push(f),h.push(m),h.push(g),h.forEach(x=>n.disposeIntermediateTensorInfo(x)),y},bne={kernelName:Ai,backendName:"webgl",kernelFunc:xne};function vne(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,weights:a}=t,{size:o}=r,i=n.readSync(s.dataId),l=n.readSync(a.dataId),c=SC(i,l,a.dtype,a.shape,o);return n.makeTensorInfo([o],a.dtype,c)}var wne={kernelName:Bh,backendName:"webgl",kernelFunc:vne};function kne(e){let{inputs:t,backend:n}=e,{s0:r,s1:s}=t,a=n.readSync(r.dataId),o=n.readSync(s.dataId),i=N.assertAndGetBroadcastShape(Array.from(a),Array.from(o));return n.makeTensorInfo([i.length],"int32",Int32Array.from(i))}var Ine={kernelName:Wh,backendName:"webgl",kernelFunc:kne},Sne="return float(a != b);",JC=Tn({opSnippet:Sne,cpuKernelImpl:tee,dtype:"bool"}),Cne={kernelName:$i,backendName:"webgl",kernelFunc:JC};function $p(e){let{inputs:t,backend:n}=e,{input:r}=t,s=n.texData.get(r.dataId);return Cr({inputs:{x:s.complexTensorInfos.real},backend:n})}var Tne={kernelName:Sd,backendName:"webgl",kernelFunc:$p},Nne="return float(int(x));";function Ene(e,t){let n=new ua(e.shape,Nne),r=t.runWebGLProgram(n,[e],"int32");return{dataId:r.dataId,shape:r.shape,dtype:r.dtype}}function zx(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{dtype:a}=r;if(a==="complex64"){if(s.dtype==="complex64")return Cr({inputs:{x:s},backend:n});let o=Ht(s.shape),i=zx({inputs:{x:s},backend:n,attrs:{dtype:"float32"}}),l=Jo({inputs:{real:i,imag:o},backend:n});return o.dispose(),n.disposeIntermediateTensorInfo(i),l}if(s.dtype==="complex64"){let o=$p({inputs:{input:s},backend:n}),i=zx({inputs:{x:o},backend:n,attrs:{dtype:a}});return n.disposeIntermediateTensorInfo(o),i}if(!w.hasEncodingLoss(s.dtype,a)){let o=Cr({inputs:{x:s},backend:n});return{dataId:o.dataId,shape:o.shape,dtype:a}}if(a==="int32")return Ene(s,n);if(a==="bool"){let o=n.makeTensorInfo([],"bool",w.getTypedArrayFromDType("bool",1)),l=JC({inputs:{a:s,b:o},backend:n});return n.disposeIntermediateTensorInfo(o),l}throw new Error(`Error in Cast: failed to cast ${s.dtype} to ${a}`)}var Rne={kernelName:La,backendName:"webgl",kernelFunc:zx},QC="return ceil(x);",_ne=it({opSnippet:QC,packedOpSnippet:QC,cpuKernelImpl:OQ}),Dne={kernelName:Ba,backendName:"webgl",kernelFunc:_ne},Pne=class{constructor(e){this.variableNames=["A"],this.customUniforms=[{name:"minVal",type:"float"},{name:"maxVal",type:"float"}],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
float value = getAAtOutCoords();
if (isnan(value)) {
setOutput(value);
return;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(clamp(value, minVal, maxVal));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},$ne=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"minVal",type:"float"},{name:"maxVal",type:"float"}],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
vec4 value = getAAtOutCoords();
if (any(isnan(value))) {
setOutput(value);
return;
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
setOutput(clamp(value, vec4(minVal), vec4(maxVal)));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Fne(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{clipValueMin:a,clipValueMax:o}=r,i;Y().getBool("WEBGL_PACK_CLIP")?i=new $ne(s.shape):i=new Pne(s.shape);let l=[[a],[o]];return n.runWebGLProgram(i,[s],s.dtype,l)}var One={kernelName:Ys,backendName:"webgl",kernelFunc:Fne},Mne=class{constructor(e){this.variableNames=["real","imag"],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
float re = abs(getRealAtOutCoords());
float im = abs(getImagAtOutCoords());
float mx = max(re, im);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// sadly the length function in glsl is not underflow-safe
// (at least not on Intel GPUs). So the safe solution is
// to ensure underflow-safety in all cases.
setOutput(
mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))
);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function e4(e,t){return{dataId:t.dataId,dtype:t.dtype,shape:e.shape}}function zne(e){let{inputs:t,backend:n}=e,{x:r}=t,s=n.texData.get(r.dataId),a=new Mne(r.shape),o=[e4(r,s.complexTensorInfos.real),e4(r,s.complexTensorInfos.imag)];return n.runWebGLProgram(a,o,o[0].dtype)}var Lne={kernelName:yd,backendName:"webgl",kernelFunc:zne},Bne=class{constructor(e){this.outputShape=[],this.outputShape=N.computeOutShape(e,1),this.variableNames=e.map((a,o)=>`T${o}`);let t=new Array(e.length-1);t[0]=e[0][1];for(let a=1;a<t.length;a++)t[a]=t[a-1]+e[a][1];let n=[`if (yC < ${t[0]}) setOutput(getT0(yR, yC));`];for(let a=1;a<t.length;a++){let o=t[a-1];n.push(`else if (yC < ${t[a]}) setOutput(getT${a}(yR, yC-${o}));`)}let r=t.length,s=t[t.length-1];n.push(`else setOutput(getT${r}(yR, yC-${s}));`),this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int yR = coords.x;
int yC = coords.y;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
${n.join(`
`)}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Wne=class{constructor(e,t){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=N.computeOutShape(e,t);let n=this.outputShape,r=n.length,s=wt(r),a=qn("coords",r),o=["x","y","z","w","u","v"].slice(0,r);this.variableNames=e.map((f,m)=>`T${m}`);let i=new Array(e.length-1);i[0]=e[0][t];for(let f=1;f<i.length;f++)i[f]=i[f-1]+e[f][t];let l=o[t],c=o.slice(-2),u=o.join(),d=`if (${l} < ${i[0]}) {
2021-11-08 13:36:26 +01:00
return getChannel(
getT0(${u}), vec2(${c.join()}));
}`;for(let f=1;f<i.length;f++){let m=i[f-1];d+=`
if (${l} < ${i[f]} && ${l} >= ${i[f-1]}) {
return getChannel(
2022-01-16 15:49:55 +01:00
getT${f}(${a0(o,l,m)}),
vec2(${a0(c,l,m)}));
2021-11-08 13:36:26 +01:00
}`}let p=i.length,h=i[i.length-1];d+=`
return getChannel(
2022-01-16 15:49:55 +01:00
getT${p}(${a0(o,l,h)}),
vec2(${a0(c,l,h)}));`,this.userCode=`
2021-11-08 13:36:26 +01:00
float getValue(${o.map(f=>"int "+f)}) {
${d}
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} coords = getOutputCoords();
2021-11-08 13:36:26 +01:00
vec4 result = vec4(getValue(${a}), 0., 0., 0.);
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
${a[r-1]} = ${a[r-1]} + 1;
if (${a[r-1]} < ${n[r-1]}) {
2021-11-08 13:36:26 +01:00
result.g = getValue(${a});
}
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
${a[r-2]} = ${a[r-2]} + 1;
if (${a[r-2]} < ${n[r-2]}) {
2021-11-08 13:36:26 +01:00
result.a = getValue(${a});
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
${a[r-1]} = ${a[r-1]} - 1;
if (${a[r-2]} < ${n[r-2]} &&
${a[r-1]} < ${n[r-1]}) {
2021-11-08 13:36:26 +01:00
result.b = getValue(${a});
}
setOutput(result);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function a0(e,t,n){let r=e.indexOf(t);return e.map((a,o)=>o===r?`${a} - ${n}`:a).join()}function o0(e){let{inputs:t,backend:n}=e,{input:r}=t,s=n.texData.get(r.dataId);return Cr({inputs:{x:s.complexTensorInfos.imag},backend:n})}var Vne={kernelName:vd,backendName:"webgl",kernelFunc:o0};function kc(e,t,n){let r=e[0].dtype;if(r==="complex64"){let u=e.map(m=>$p({inputs:{input:m},backend:n})),d=e.map(m=>o0({inputs:{input:m},backend:n})),p=kc(u,t,n),h=kc(d,t,n),f=Jo({inputs:{real:p,imag:h},backend:n});return u.forEach(m=>n.disposeIntermediateTensorInfo(m)),d.forEach(m=>n.disposeIntermediateTensorInfo(m)),n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(h),f}let s=n.shouldExecuteOnCPU(e);if(r==="string"&&(s=!0),s){let u=e.map(y=>{let x=w.sizeFromShape(y.shape.slice(t));return ve({inputs:{x:y},backend:n,attrs:{shape:[-1,x]}})}),d=u.map(y=>({vals:n.readSync(y.dataId),shape:y.shape})),p=N.computeOutShape(u.map(y=>y.shape),1),h=u[0].shape[0]===1,f=MQ(d,p,r,h),m=N.computeOutShape(e.map(y=>y.shape),t),g=n.makeTensorInfo(m,r,f);return u.forEach(y=>n.disposeIntermediateTensorInfo(y)),g}if(e.length>Y().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){let u=Math.floor(e.length/2),d=kc(e.slice(0,u),t,n),p=kc(e.slice(u),t,n),h=kc([d,p],t,n);return n.disposeIntermediateTensorInfo(d),n.disposeIntermediateTensorInfo(p),h}if(Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&e[0].shape.length>1){let u=new Wne(e.map(d=>d.shape),t);return n.runWebGLProgram(u,e,r)}let{tensors2D:a,outShape:o}=Une(e,t,n),i=new Bne(a.map(u=>u.shape)),l=n.runWebGLProgram(i,a,r);a.forEach(u=>n.disposeIntermediateTensorInfo(u));let c=ve({inputs:{x:l},attrs:{shape:o},backend:n});return n.disposeIntermediateTensorInfo(l),c}function Une(e,t,n){let r=N.computeOutShape(e.map(a=>a.shape),t);return{tensors2D:e.map(a=>ve({inputs:{x:a},attrs:{shape:[-1,w.sizeFromShape(a.shape.slice(t))]},backend:n})),outShape:r}}function t4(e){let{inputs:t,backend:n,attrs:r}=e,{axis:s}=r,a=w.parseAxisParam(s,t[0].shape)[0],o=N.computeOutShape(t.map(c=>c.shape),a);if(w.sizeFromShape(o)===0)return n.makeTensorInfo(o,t[0].dtype,[]);let i=t.filter(c=>w.sizeFromShape(c.shape)>0);if(i.length===1)return Cr({inputs:{x:i[0]},backend:n});let l=i.map(c=>c.shape);return N.assertParamsConsistent(l,a),kc(i,a,n)}var Gne={kernelName:xi,backendName:"webgl",kernelFunc:t4},n4=class{constructor(e,t=!1,n=null,r=!1,s=!1){this.variableNames=["x","W"],this.outputShape=e.outShape;let a=e.padInfo.top,o=e.padInfo.left,i=e.strideHeight,l=e.strideWidth,c=e.dilationHeight,u=e.dilationWidth,d=e.filterHeight,p=e.filterWidth,h=Math.floor(e.inChannels/4)*4,f=e.inChannels%4,m=e.dataFormat==="channelsLast",g=m?1:2,y=m?2:3,x=m?3:1,A="",b="";n&&(r?A=`float activation(float a) {
2021-11-08 13:36:26 +01:00
float b = getPreluActivationWeightsAtOutCoords();
${n}
2022-01-16 15:49:55 +01:00
}`:s?A=`float activation(float a) {
2021-11-08 13:36:26 +01:00
float b = getLeakyreluAlphaAtOutCoords();
${n}
2021-12-01 14:27:05 +01:00
}`:A=`
2021-11-08 13:36:26 +01:00
float activation(float x) {
${n}
}
2022-01-16 15:49:55 +01:00
`,b="result = activation(result);");let v=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode=`
2021-12-01 14:27:05 +01:00
${A}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
const ivec2 strides = ivec2(${i}, ${l});
const ivec2 pads = ivec2(${a}, ${o});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d2 = coords[${x}];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec2 xRCCorner =
2021-12-01 14:27:05 +01:00
ivec2(coords[${g}], coords[${y}]) * strides - pads;
2021-11-08 13:36:26 +01:00
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
// Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ${d}; wR++) {
int xR = xRCorner + wR * ${c};
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
for (int wC = 0; wC < ${p}; wC++) {
int xC = xCCorner + wC * ${u};
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
for (int d1 = 0; d1 < ${h}; d1 += 4) {
vec4 wValues = vec4(
getW(wR, wC, d1, d2),
getW(wR, wC, d1 + 1, d2),
getW(wR, wC, d1 + 2, d2),
getW(wR, wC, d1 + 3, d2)
);
if (${m}) {
vec4 xValues = vec4(
getX(batch, xR, xC, d1),
getX(batch, xR, xC, d1 + 1),
getX(batch, xR, xC, d1 + 2),
getX(batch, xR, xC, d1 + 3)
);
dotProd += dot(xValues, wValues);
} else {
vec4 xValues = vec4(
getX(batch, d1, xR, xC),
getX(batch, d1 + 1, xR, xC),
getX(batch, d1 + 2, xR, xC),
getX(batch, d1 + 3, xR, xC)
);
dotProd += dot(xValues, wValues);
}
}
if (${f===1}) {
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (${m}) {
dotProd +=
getX(batch, xR, xC, ${h}) *
getW(wR, wC, ${h}, d2);
} else {
dotProd +=
getX(batch, ${h}, xR, xC) *
getW(wR, wC, ${h}, d2);
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
} else if (${f===2}) {
vec2 wValues = vec2(
getW(wR, wC, ${h}, d2),
getW(wR, wC, ${h} + 1, d2)
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (${m}) {
vec2 xValues = vec2(
getX(batch, xR, xC, ${h}),
getX(batch, xR, xC, ${h} + 1)
);
dotProd += dot(xValues, wValues);
} else {
vec2 xValues = vec2(
getX(batch, ${h}, xR, xC),
getX(batch, ${h} + 1, xR, xC)
);
dotProd += dot(xValues, wValues);
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
} else if (${f===3}) {
vec3 wValues = vec3(
getW(wR, wC, ${h}, d2),
getW(wR, wC, ${h} + 1, d2),
getW(wR, wC, ${h} + 2, d2)
);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (${m}) {
vec3 xValues = vec3(
getX(batch, xR, xC, ${h}),
getX(batch, xR, xC, ${h} + 1),
getX(batch, xR, xC, ${h} + 2)
);
dotProd += dot(xValues, wValues);
} else {
vec3 xValues = vec3(
getX(batch, ${h}, xR, xC),
getX(batch, ${h} + 1, xR, xC),
getX(batch, ${h} + 2, xR, xC)
);
dotProd += dot(xValues, wValues);
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
}
}
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
float result = dotProd;
${v}
2021-11-08 13:36:26 +01:00
${b}
setOutput(result);
}
2022-01-16 15:49:55 +01:00
`}},Hne=class{constructor(e){this.variableNames=["x","W"],this.outputShape=e.outShape;let t=e.padInfo.front,n=e.padInfo.top,r=e.padInfo.left,s=e.strideDepth,a=e.strideHeight,o=e.strideWidth,i=e.dilationDepth,l=e.dilationHeight,c=e.dilationWidth,u=e.filterDepth,d=e.filterHeight,p=e.filterWidth,h=Math.floor(e.inChannels/4)*4,f=e.inChannels%4;this.userCode=`
const ivec3 strides = ivec3(${s}, ${a}, ${o});
const ivec3 pads = ivec3(${t}, ${n}, ${r});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int d2 = coords.u;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xFCorner = xFRCCorner.x;
int xRCorner = xFRCCorner.y;
int xCCorner = xFRCCorner.z;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get
// y(yF, yR, yC, d2). ? = to be determined. : = across all
// values in that axis.
float dotProd = 0.0;
for (int wF = 0; wF < ${u}; wF++) {
int xF = xFCorner + wF * ${i};
if (xF < 0 || xF >= ${e.inDepth}) {
continue;
}
for (int wR = 0; wR < ${d}; wR++) {
int xR = xRCorner + wR * ${l};
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
for (int wC = 0; wC < ${p}; wC++) {
int xC = xCCorner + wC * ${c};
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
for (int d1 = 0; d1 < ${h}; d1 += 4) {
vec4 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)
);
vec4 wValues = vec4(
getW(wF, wR, wC, d1, d2),
getW(wF, wR, wC, d1 + 1, d2),
getW(wF, wR, wC, d1 + 2, d2),
getW(wF, wR, wC, d1 + 3, d2)
);
dotProd += dot(xValues, wValues);
}
if (${f===1}) {
dotProd +=
getX(batch, xF, xR, xC, ${h}) *
getW(wF, wR, wC, ${h}, d2);
} else if (${f===2}) {
vec2 xValues = vec2(
getX(batch, xF, xR, xC, ${h}),
getX(batch, xF, xR, xC, ${h} + 1)
);
vec2 wValues = vec2(
getW(wF, wR, wC, ${h}, d2),
getW(wF, wR, wC, ${h} + 1, d2)
);
dotProd += dot(xValues, wValues);
} else if (${f===3}) {
vec3 xValues = vec3(
getX(batch, xF, xR, xC, ${h}),
getX(batch, xF, xR, xC, ${h} + 1),
getX(batch, xF, xR, xC, ${h} + 2)
);
vec3 wValues = vec3(
getW(wF, wR, wC, ${h}, d2),
getW(wF, wR, wC, ${h} + 1, d2),
getW(wF, wR, wC, ${h} + 2, d2)
);
dotProd += dot(xValues, wValues);
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
}
2022-01-16 15:49:55 +01:00
`}},jne=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"inputShape",type:"ivec3"},{name:"pad",type:"ivec2"},{name:"stride",type:"ivec2"},{name:"dilation",type:"ivec2"},{name:"inChannels",type:"int"},{name:"itemsPerBlockRow",type:"int"},{name:"outWidth",type:"int"}],this.outputShape=e,this.enableShapeUniforms=pr(this.outputShape.length);let{dataFormat:n}=t,r=jn(),s=n==="channelsLast",a=s?0:1,o=s?1:2,i=this.enableShapeUniforms?"if(blockIndex < outShape[1] && pos < outShape[0]) {":`if(blockIndex < ${e[1]} && pos < ${e[0]}) {`,l="";for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)l+=`
2021-11-08 13:36:26 +01:00
blockIndex = rc.y + ${u};
pos = rc.x + ${c};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${i}
offsetY = int(blockIndex / outWidth) * stride[0] - pad[0];
d0 = offsetY + dilation[0] * (pos / itemsPerBlockRow);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
if(d0 < inputShape[${a}] && d0 >= 0) {
// Use custom imod instead mod. On Intel GPU, mod may generate
// unexpected value.
// https://github.com/tensorflow/tfjs/issues/5447
offsetX = imod(blockIndex, outWidth) * stride[1] - pad[1];
d1 = offsetX + dilation[1] * (imod(pos, itemsPerBlockRow) /
inChannels);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if(d1 < inputShape[${o}] && d1 >= 0) {
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ch = imod(pos, inChannels);
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
if (${s}) {
2021-11-08 13:36:26 +01:00
innerDims = vec2(d1, ch);
result[${c*2+u}] = getChannel(
getA(d0, int(innerDims.x),
int(innerDims.y)), innerDims);
} else {
innerDims = vec2(d0, d1);
result[${c*2+u}] = getChannel(
getA(ch, int(innerDims.x),
int(innerDims.y)), innerDims);
}
}
}
}
`;this.userCode=`
void main() {
ivec2 rc = getOutputCoords();
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int blockIndex, pos, offsetY, d0, offsetX, d1, ch;
vec2 innerDims;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
${l}
2022-01-16 15:49:55 +01:00
${r.output} = result;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function r4({x:e,filter:t,convInfo:n,backend:r,bias:s=null,preluActivationWeights:a=null,leakyreluAlpha:o=0,activation:i=null}){let l=e.shape,c=r.texData.get(e.dataId),u=n.inChannels,d=l[0]*l[1]*l[2],p=n.outChannels,h=n.dataFormat==="channelsLast",f=!1,m=!1,g,y=[];if(!((d===1||p===1)&&u>jC)&&c.isPacked&&h&&c.texture!=null&&l[2]%2!==0&&w.arraysEqual(c.shape.slice(-3),l.slice(-3))){let b=l[0]*l[1]*(l[2]+1),v={dataId:e.dataId,shape:[1,b,n.inChannels],dtype:e.dtype},C=c.shape;c.shape=c.shape.slice(),c.shape[c.shape.length-2]++,w.assert(Ep(c.shape,v.shape),()=>`packed reshape ${c.shape} to ${v.shape} isn't free`);let I=ve({inputs:{x:t},backend:r,attrs:{shape:[1,n.inChannels,n.outChannels]}});y.push(I);let E=r0({a:v,b:I,backend:r,transposeA:f,transposeB:m,bias:s,activation:i,preluActivationWeights:a,leakyreluAlpha:o}),R=r.texData.get(E.dataId);w.assert(R.isPacked,()=>"batchMatMul result is expected to be packed"),c.shape=C,R.shape=n.outShape,g=Cr({inputs:{x:E},backend:r}),g.shape=n.outShape,y.push(E)}else{let b=h?l[0]*l[1]*l[2]:l[0]*l[2]*l[3],v=ve({inputs:{x:e},backend:r,attrs:{shape:[1,b,n.inChannels]}}),C=ve({inputs:{x:t},backend:r,attrs:{shape:[1,n.inChannels,n.outChannels]}}),I=r0({a:v,b:C,transposeA:f,transposeB:m,backend:r,bias:s,activation:i,preluActivationWeights:a,leakyreluAlpha:o});g=ve({inputs:{x:I},backend:r,attrs:{shape:n.outShape}}),y.push(v),y.push(C),y.push(I)}for(let b of y)r.disposeIntermediateTensorInfo(b);return g}function s4({x:e,filter:t,convInfo:n,backend:r,bias:s=null,preluActivationWeights:a=null,leakyreluAlpha:o=0,activation:i=null}){let{filterWidth:l,filterHeight:c,inChannels:u,outWidth:d,outHeight:p,dataFormat:h}=n,f=h==="channelsLast",m=l*c*u,g=p*d,y=[m,g],x=!0,A=!1,b=[],v=ve({inputs:{x:e},backend:r,attrs:{shape:e.shape.slice(1)}}),C=ve({inputs:{x:t},backend:r,attrs:{shape:[1,m,w.sizeFromShape(t.shape)/m]}});b.push(v),b.push(C);let I=new jne(y,n),E=[v.shape,[n.padInfo.top,n.padInfo.left],[n.strideHeight,n.strideWidth],[n.dilationHeight,n.dilationWidth],[n.inChannels],[n.filterWidth*n.inChannels],[n.outWidth]],R=r.runWebGLProgram(I,[v],"float32",E),F=ve({inputs:{x:R},backend:r,attrs:{shape:[1,y[0],y[1]]}});b.push(R),b.push(F);let _=s!=null,P=a!=null,T=i==="leakyrelu",O=i?e0(i,!0):null,G=new WC(F.shape,C.shape,[1,g,n.outChannels],x,A,_,O,P,T),K=[F,C];if(s&&K.push(s),P&&K.push(a),T){let Q=r.makeTensorInfo([],"float32",w.createScalarValue(o,"float32"));K.push(Q),b.push(Q)}let z=r.runWebGLProgram(G,K,"float32"),j=f?[1,p,d,n.outChannels]:[1,n.outChannels,p,d],W=ve({inputs:{x:z},backend:r,attrs:{shape:j}});b.push(z);for(let Q of b)r.disposeIntermediateTensorInfo(Q);return W}function qne(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dataFormat:l,dilations:c,dimRoundingMode:u}=r,d=N.convertConv2DDataFormat(l),p=N.computeConv2DInfo(s.shape,a.shape,o,c,i,u,!1,d),h;if(p.filterHeight===1&&p.filterWidth===1&&p.dilationHeight===1&&p.dilationWidth===1&&p.strideHeight===1&&p.strideWidth===1&&(p.padInfo.type==="SAME"||p.padInfo.type==="VALID"))h=r4({x:s,filter:a,convInfo:p,backend:n});else if(Y().getBool("WEBGL_CONV_IM2COL")&&s.shape[0]===1)h=s4({x:s,filter:a,convInfo:p,backend:n});else{let m=new n4(p);h=n.runWebGLProgram(m,[s,a],"float32")}let f=ve({inputs:{x:h},backend:n,attrs:{shape:p.outShape}});return n.disposeIntermediateTensorInfo(h),f}var Xne={kernelName:Wa,backendName:"webgl",kernelFunc:qne},Kne=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,s=e.padInfo.left,a=e.dataFormat==="channelsLast";this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int wR = coords.x;
int wC = coords.y;
int d1 = coords.z;
int d2 = coords.w;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
for (int b = 0; b < ${e.batchSize}; b++) {
for (int yR = 0; yR < ${e.outHeight}; yR++) {
2022-01-16 15:49:55 +01:00
int xR = wR + yR * ${t} - ${r};
2021-11-08 13:36:26 +01:00
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
for (int yC = 0; yC < ${e.outWidth}; yC++) {
2022-01-16 15:49:55 +01:00
int xC = wC + yC * ${n} - ${s};
2021-11-08 13:36:26 +01:00
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
if (${a}) {
float dyValue = getDy(b, yR, yC, d2);
float xValue = getX(b, xR, xC, d1);
dotProd += (xValue * dyValue);
} else {
float dyValue = getDy(b, d2, yR, yC);
float xValue = getX(b, d1, xR, xC);
dotProd += (xValue * dyValue);
}
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`}},Zne=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,s=e.strideWidth,a=e.dataFormat==="channelsLast",o=t-1-e.padInfo.top,i=n-1-e.padInfo.left,l=a?1:2,c=a?2:3,u=a?3:1;this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec2 pads = ivec2(${o}, ${i});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d1 = coords[${u}];
ivec2 dyCorner = ivec2(coords[${l}], coords[${c}]) - pads;
int dyRCorner = dyCorner.x;
int dyCCorner = dyCorner.y;
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ${t}; wR++) {
2022-01-16 15:49:55 +01:00
float dyR = float(dyRCorner + wR) / ${r}.0;
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
int wRPerm = ${t} - 1 - wR;
for (int wC = 0; wC < ${n}; wC++) {
2022-01-16 15:49:55 +01:00
float dyC = float(dyCCorner + wC) / ${s}.0;
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
int wCPerm = ${n} - 1 - wC;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int d2 = 0; d2 < ${e.outChannels}; d2++) {
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (${a}) {
float xValue = getDy(batch, idyR, idyC, d2);
float wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
} else {
float xValue = getDy(batch, d2, idyR, idyC);
float wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
}
}
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Yne=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,s=e.padInfo.front,a=e.padInfo.top,o=e.padInfo.left;this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int wF = coords.x;
int wR = coords.y;
int wC = coords.z;
int d1 = coords.w;
int d2 = coords.u;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float dotProd = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int b = 0; b < ${e.batchSize}; b++) {
for (int yF = 0; yF < ${e.outDepth}; yF++) {
2022-01-16 15:49:55 +01:00
int xF = wF + yF * ${t} - ${s};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xF < 0 || xF >= ${e.inDepth}) {
continue;
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
for (int yR = 0; yR < ${e.outHeight}; yR++) {
int xR = wR + yR * ${n} - ${a};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int yC = 0; yC < ${e.outWidth}; yC++) {
2022-01-16 15:49:55 +01:00
int xC = wC + yC * ${r} - ${o};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
float dyValue = getDy(b, yF, yR, yC, d2);
float xValue = getX(b, xF, xR, xC, d1);
dotProd += (xValue * dyValue);
}
2021-09-11 16:29:31 +02:00
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Jne=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,s=e.strideDepth,a=e.strideHeight,o=e.strideWidth,i=t-1-e.padInfo.front,l=n-1-e.padInfo.top,c=r-1-e.padInfo.left;this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec3 pads = ivec3(${i}, ${l}, ${c});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int d1 = coords.u;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyFCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
float dotProd = 0.0;
for (int wF = 0; wF < ${t}; wF++) {
2022-01-16 15:49:55 +01:00
float dyF = float(dyFCorner + wF) / ${s}.0;
2021-11-08 13:36:26 +01:00
if (dyF < 0.0 || dyF >= ${e.outDepth}.0 || fract(dyF) > 0.0) {
continue;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
int idyF = int(dyF);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int wFPerm = ${t} - 1 - wF;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${n}; wR++) {
float dyR = float(dyRCorner + wR) / ${a}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 ||
fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int wRPerm = ${n} - 1 - wR;
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
for (int wC = 0; wC < ${r}; wC++) {
2021-11-08 13:36:26 +01:00
float dyC = float(dyCCorner + wC) / ${o}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
int wCPerm = ${r} - 1 - wC;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int d2 = 0; d2 < ${e.outChannels}; d2++) {
float xValue = getDy(batch, idyF, idyR, idyC, d2);
float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Qne(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,dy:a}=t,{strides:o,pad:i,dataFormat:l,dimRoundingMode:c,filterShape:u}=r,d=N.convertConv2DDataFormat(l),p=N.computeConv2DInfo(s.shape,u,o,1,i,c,!1,d),h=new Kne(p);return n.runWebGLProgram(h,[s,a],"float32")}var ere={kernelName:Vh,backendName:"webgl",kernelFunc:Qne};function tre(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,filter:a}=t,{inputShape:o,strides:i,pad:l,dataFormat:c,dimRoundingMode:u}=r,d=N.convertConv2DDataFormat(c),p=N.computeConv2DInfo(o,a.shape,i,1,l,u,!1,d),h=new Zne(p);return n.runWebGLProgram(h,[s,a],"float32")}var nre={kernelName:Va,backendName:"webgl",kernelFunc:tre};function rre(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dilations:l}=r,c=N.computeConv3DInfo(s.shape,a.shape,o,l,i),u=new Hne(c);return n.runWebGLProgram(u,[s,a],"float32")}var sre={kernelName:Ad,backendName:"webgl",kernelFunc:rre};function are(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,dy:a}=t,{strides:o,pad:i,filterShape:l}=r,c=N.computeConv3DInfo(s.shape,l,o,1,i),u=new Yne(c);return n.runWebGLProgram(u,[s,a],"float32")}var ore={kernelName:Uh,backendName:"webgl",kernelFunc:are};function ire(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,filter:a}=t,{pad:o,strides:i,inputShape:l}=r,c=N.computeConv3DInfo(l,a.shape,i,1,o),u=new Jne(c);return n.runWebGLProgram(u,[s,a],"float32")}var lre={kernelName:Gh,backendName:"webgl",kernelFunc:ire},ure=vc+`
2021-11-08 13:36:26 +01:00
return cos(x);
2022-01-16 15:49:55 +01:00
`,cre=it({opSnippet:ure}),dre={kernelName:Ua,backendName:"webgl",kernelFunc:cre},pre=`
2021-11-08 13:36:26 +01:00
float e2x = exp(-x);
return (e2x + 1.0 / e2x) / 2.0;
2022-01-16 15:49:55 +01:00
`,hre=it({opSnippet:pre}),fre={kernelName:Ga,backendName:"webgl",kernelFunc:hre},mre=class{constructor(e,t,n,r,s){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];let[a,o,i,l]=e,[c]=t,[u,d]=n;this.outputShape=[c,u,d,l];let p=r==="bilinear"?1:0,[h,f]=[`${o-1}.0`,`${i-1}.0`],[m,g,y]=u>1?[`${(o-1)/(u-1)}`,"(y2-y1) * height_ratio",`y1*${h} + float(y)*(height_scale)`]:["0.0","0.0",`0.5 * (y1+y2) * ${h}`],[x,A,b]=d>1?[`${(i-1)/(d-1)}`,"(x2-x1) * width_ratio",`x1*${f} + float(x)*(width_scale)`]:["0.0","0.0",`0.5 * (x1+x2) * ${f}`];this.userCode=`
2021-11-08 13:36:26 +01:00
const float height_ratio = float(${m});
const float width_ratio = float(${x});
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int y = coords[1];
int x = coords[2];
int d = coords[3];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// get box vals
float y1 = getBoxes(b,0);
float x1 = getBoxes(b,1);
float y2 = getBoxes(b,2);
float x2 = getBoxes(b,3);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// get image in batch index
int bInd = round(getBoxInd(b));
if(bInd < 0 || bInd >= ${a}) {
return;
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float height_scale = ${g};
2021-12-01 14:27:05 +01:00
float width_scale = ${A};
2021-11-06 15:21:51 +01:00
2021-12-01 14:27:05 +01:00
float in_y = ${y};
2021-11-08 13:36:26 +01:00
if( in_y < 0.0 || in_y > ${h} ) {
2022-01-16 15:49:55 +01:00
setOutput(float(${s}));
2021-11-08 13:36:26 +01:00
return;
}
float in_x = ${b};
if( in_x < 0.0 || in_x > ${f} ) {
2022-01-16 15:49:55 +01:00
setOutput(float(${s}));
2021-11-08 13:36:26 +01:00
return;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
vec2 sourceFracIndexCR = vec2(in_x,in_y);
if(${p} == 1) {
// Compute the four integer indices.
ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);
ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));
float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);
float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);
float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);
float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);
vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);
float top = topLeft + (topRight - topLeft) * fracCR.x;
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;
float newValue = top + (bottom - top) * fracCR.y;
setOutput(newValue);
2021-11-06 15:21:51 +01:00
} else {
2021-11-08 13:36:26 +01:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestCR = ivec2(floor(
sourceFracIndexCR + vec2(0.5,0.5)));
float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);
setOutput(newValue);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},gre=e=>{let{inputs:t,backend:n,attrs:r}=e,{image:s,boxes:a,boxInd:o}=t,{cropSize:i,method:l,extrapolationValue:c}=r,u=new mre(s.shape,a.shape,i,l,c);return n.runWebGLProgram(u,[s,a,o],"float32")},yre={kernelName:vi,backendName:"webgl",kernelFunc:gre},a4=class{constructor(e,t,n){this.variableNames=["x"],this.customUniforms=[{name:"index",type:"float"}],this.outputShape=e;let r=e.length,s=t?"0.0":`getX(${o4(r,"coords")})`,a=e[e.length-1],o="",i="";t?(o=n?`end != ${a-1}`:"end != 0",i=n?"end + 1":"end - 1"):(o=n?`end + pow2 < ${a}`:"end >= pow2",i=n?"end + pow2":"end - pow2"),this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${wt(r)} coords = getOutputCoords();
int end = ${i4(r,"coords")};
float val = ${s};
2021-11-08 13:36:26 +01:00
int pow2 = int(pow(2.0, index));
if (${o}) {
int idx = ${i};
2022-01-16 15:49:55 +01:00
${i4(r,"coords")} = idx;
val += getX(${o4(r,"coords")});
2021-11-08 13:36:26 +01:00
}
setOutput(val);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function o4(e,t){if(e===1)return`${t}`;if(e===2)return`${t}.x, ${t}.y`;if(e===3)return`${t}.x, ${t}.y, ${t}.z`;if(e===4)return`${t}.x, ${t}.y, ${t}.z, ${t}.w`;throw Error(`Cumulative sum for rank ${e} is not yet supported`)}function i4(e,t){if(e===1)return`${t}`;if(e===2)return`${t}.y`;if(e===3)return`${t}.z`;if(e===4)return`${t}.w`;throw Error(`Cumulative sum for rank ${e} is not yet supported`)}function Are(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,exclusive:o,reverse:i}=r,l=s.shape.length,c=N.getAxesPermutation([a],l),u=s;c!=null&&(u=Xn({inputs:{x:s},backend:n,attrs:{perm:c}}));let d=N.getInnerMostAxes(1,l)[0];if(d!==l-1)throw new Error(`WebGL cumsum shader expects an inner-most axis=${s.shape.length-1} but got axis=${a}`);let p=u.shape[d],h=Cr({inputs:{x:u},backend:n});for(let f=0;f<=Math.ceil(Math.log2(p))-1;f++){let m=new a4(u.shape,!1,i),g=[[f]],y=h;h=n.runWebGLProgram(m,[h],h.dtype,g),n.disposeIntermediateTensorInfo(y)}if(o){let f=new a4(u.shape,o,i),m=h;h=n.runWebGLProgram(f,[h],h.dtype),n.disposeIntermediateTensorInfo(m)}if(c!=null){let f=N.getUndoAxesPermutation(c),m=Xn({inputs:{x:h},backend:n,attrs:{perm:f}});return n.disposeIntermediateTensorInfo(h),n.disposeIntermediateTensorInfo(u),m}return h}var xre={kernelName:bi,backendName:"webgl",kernelFunc:Are};function bre(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,weights:a}=t,{size:o,binaryOutput:i}=r;if(s.shape.length===1){let l=n.readSync(s.dataId),c=n.readSync(a.dataId),u=SC(l,c,a.dtype,a.shape,o);return n.makeTensorInfo([o],a.dtype,u)}else if(s.shape.length===2){let l=n.bufferSync(s),c=n.bufferSync(a),u=FQ(l,c,o,i);return n.makeTensorInfo(u.shape,a.dtype,u.values)}throw new Error(`Error in denseBincount: input must be at most rank 2, but got rank${s.shape.length}.`)}var vre={kernelName:Hh,backendName:"webgl",kernelFunc:bre},wre=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=[],this.outputShape=e,this.blockSize=t,this.dataFormat=n,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int h = ${this.getHeightCoordString()};
int w = ${this.getWidthCoordString()};
int d = ${this.getDepthCoordString()};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int in_h = h / ${t};
int offset_h = imod(h, ${t});
int in_w = w / ${t};
int offset_w = imod(w, ${t});
int offset_d = (offset_h * ${t} + offset_w) *
${this.getOutputDepthSize()};
int in_d = d + offset_d;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float result = ${this.getInputSamplingString()};
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}getHeightCoordString(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"}getWidthCoordString(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"}getDepthCoordString(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"}getOutputDepthSize(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]}getInputSamplingString(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"}};function kre(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockSize:a,dataFormat:o}=r,i=s.shape[0],l=o==="NHWC"?s.shape[1]:s.shape[2],c=o==="NHWC"?s.shape[2]:s.shape[3],u=o==="NHWC"?s.shape[3]:s.shape[1],d=l*a,p=c*a,h=u/(a*a),f=o==="NHWC"?[i,d,p,h]:[i,h,d,p],m=new wre(f,a,o);return n.runWebGLProgram(m,[s],s.dtype)}var Ire={kernelName:wi,backendName:"webgl",kernelFunc:kre},l4=class{constructor(e,t=!1,n=null,r=!1,s=!1){this.variableNames=["x","W"],this.customUniforms=[{name:"pads",type:"ivec2"},{name:"strides",type:"ivec2"},{name:"dilations",type:"ivec2"},{name:"inDims",type:"ivec2"}],this.outputShape=e.outShape,this.enableShapeUniforms=pr(this.outputShape.length);let a=e.filterHeight,o=e.filterWidth,i=e.outChannels/e.inChannels,l="",c="";n&&(r?l=`float activation(float a) {
2021-11-08 13:36:26 +01:00
float b = getPreluActivationWeightsAtOutCoords();
${n}
2022-01-16 15:49:55 +01:00
}`:s?l=`float activation(float a) {
2021-11-08 13:36:26 +01:00
float b = getLeakyreluAlphaAtOutCoords();
${n}
}`:l=`
float activation(float x) {
${n}
}
2022-01-16 15:49:55 +01:00
`,c="result = activation(result);");let u=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode=`
2021-11-08 13:36:26 +01:00
${l}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords.x;
ivec2 xRCCorner = coords.yz * strides - pads;
int d2 = coords.w;
int d1 = d2 / ${i};
int q = d2 - d1 * ${i};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
// TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.
for (int wR = 0; wR < ${a}; wR++) {
int xR = xRCorner + wR * dilations[0];
if (xR < 0 || xR >= inDims[0]) {
continue;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${o}; wC++) {
int xC = xCCorner + wC * dilations[1];
if (xC < 0 || xC >= inDims[1]) {
2021-11-06 15:21:51 +01:00
continue;
}
2021-11-08 13:36:26 +01:00
float xVal = getX(batch, xR, xC, d1);
float wVal = getW(wR, wC, d1, q);
dotProd += xVal * wVal;
2021-09-11 16:29:31 +02:00
}
2021-09-05 22:42:11 +02:00
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float result = dotProd;
${u}
${c}
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},u4=class{constructor(e,t=!1,n=null,r=!1,s=!1){this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"pads",type:"ivec2"},{name:"strides",type:"ivec2"},{name:"dilations",type:"ivec2"},{name:"inDims",type:"ivec2"}],this.outputShape=e.outShape,this.enableShapeUniforms=pr(this.outputShape.length);let a=e.outChannels/e.inChannels,o=e.padInfo.left,i=e.strideWidth,l=e.dilationWidth,c=e.filterHeight,u=e.filterWidth,d=u,p=`
2021-11-08 13:36:26 +01:00
int xR; int xC; int xCOffset;
vec4 wTexel; vec4 previous; vec4 final;`;for(let g=0;g<u;g++)p+=`
vec4 xTexelC${g*2};
int xTexelC${g*2}Ready;
vec4 xTexelC${g*2+1};
int xTexelC${g*2+1}Ready;
vec4 xC${g};`;p+=`
for (int r = 0; r < ${c}; r++) {
`;for(let g=0;g<u;g++)p+=`
xTexelC${g*2} = vec4(0.0);
xTexelC${g*2}Ready = 0;
xTexelC${g*2+1} = vec4(0.0);
xTexelC${g*2+1}Ready = 0;
xC${g} = vec4(0.0);`;p+=`
xR = xRCorner + r * dilations[0];
if (xR >=0 && xR < inDims[0]) {
2021-12-01 14:27:05 +01:00
`;for(let g=0;g<(d+1)/2;g++){let y=g*2;if(p+=`
xC = xCCorner + ${y*l};
`,i===1){if(y<u&&(o%2===1?(p+=`
2021-11-08 13:36:26 +01:00
xCOffset = xC + 1;
2021-12-01 14:27:05 +01:00
if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y}Ready == 0) {
xTexelC${y} = getX(batch, xR, xCOffset, d1);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if (xCOffset + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
`,l===1&&y>0?p+=`
xC${y} = vec4(xTexelC${y-2}.zw, xTexelC${y}.xy);
2021-11-08 13:36:26 +01:00
`:p+=`
xCOffset = xC + 1 - 2;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (xCOffset >= 0 && xCOffset < inDims[1]) {
previous = getX(batch, xR, xCOffset, d1);
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if (xCOffset + 1 >= inDims[1]) {
previous.zw = vec2(0.0);
}
2021-12-01 14:27:05 +01:00
xC${y} = vec4(previous.zw, xTexelC${y}.xy);
2021-11-08 13:36:26 +01:00
} else {
2021-12-01 14:27:05 +01:00
xC${y} = vec4(0.0, 0.0, xTexelC${y}.xy);
2021-11-08 13:36:26 +01:00
}
`):p+=`
2021-12-01 14:27:05 +01:00
if (xC >= 0 && xC < inDims[1] && xTexelC${y}Ready == 0) {
xTexelC${y} = getX(batch, xR, xC, d1);
2021-11-08 13:36:26 +01:00
if (xC + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xC${y} = xTexelC${y};
`,y+1<u)){let x=o%2===0?w.nearestLargerEven(l):l;l%2===0&&o%2===1||l%2!==0&&o%2!==1?(p+=`
2021-11-08 13:36:26 +01:00
xCOffset = xC + imod(pads[1], 2) + ${x};
2021-12-01 14:27:05 +01:00
if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y+1}Ready == 0) {
xTexelC${y+1} = getX(batch, xR, xCOffset, d1);
2021-11-08 13:36:26 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if (xCOffset + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y+1}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y+1}Ready = 1;
2021-11-08 13:36:26 +01:00
}
`,l>1&&(p+=`
xCOffset -= 2;
2021-12-01 14:27:05 +01:00
if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y}Ready == 0) {
xTexelC${y} = getX(batch, xR, xCOffset, d1);
xTexelC${y}Ready = 1;
2021-11-08 13:36:26 +01:00
}
`),p+=`
2021-12-01 14:27:05 +01:00
xC${y+1} = vec4(xTexelC${y}.zw, xTexelC${y+1}.xy);
2021-11-08 13:36:26 +01:00
`):x===1?p+=`
2021-12-01 14:27:05 +01:00
xC${y+1} = xTexelC${y};
2021-11-08 13:36:26 +01:00
`:p+=`
xCOffset = xC + ${x};
2021-12-01 14:27:05 +01:00
if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y+1}Ready == 0) {
xTexelC${y+1} = getX(batch, xR, xCOffset, d1);
2021-11-08 13:36:26 +01:00
if (xCOffset + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y+1}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y+1}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xC${y+1} = xTexelC${y+1};
`}}else y<u&&(o%2===1?(p+=`
2021-11-08 13:36:26 +01:00
xCOffset = xC + 1 - strides[1];
2021-12-01 14:27:05 +01:00
if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y}Ready == 0) {
xTexelC${y} = getX(batch, xR, xCOffset, d1);
2021-11-08 13:36:26 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if (xCOffset + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
if(xC + 1 >= 0 && xC + 1 < inDims[1] && xTexelC${y+1}Ready == 0) {
xTexelC${y+1} = getX(batch, xR, xC + 1, d1);
2021-11-08 13:36:26 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if (xC + 2 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y+1}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y+1}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xC${y} = vec4(xTexelC${y}.zw, xTexelC${y+1}.zw);
`,y+1<u&&(p+=`
2021-11-08 13:36:26 +01:00
final = vec4(0.0);
xCOffset = xC + 1 + strides[1];
if(xCOffset >= 0 && xCOffset < inDims[1]) {
final = getX(batch, xR, xCOffset, d1);
}
2021-12-01 14:27:05 +01:00
xC${y+1} = vec4(xTexelC${y+1}.xy, final.xy);
2021-11-08 13:36:26 +01:00
`)):(p+=`
2021-12-01 14:27:05 +01:00
if(xC >= 0 && xC < inDims[1] && xTexelC${y}Ready == 0) {
xTexelC${y} = getX(batch, xR, xC, d1);
2021-11-08 13:36:26 +01:00
if (xC + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y}.zw = vec2(0.0);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y}Ready = 1;
2021-11-08 13:36:26 +01:00
}
xCOffset = xC + strides[1];
2021-12-01 14:27:05 +01:00
if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${y+1}Ready == 0) {
xTexelC${y+1} = getX(batch, xR, xCOffset, d1);
2021-11-08 13:36:26 +01:00
if (xCOffset + 1 >= inDims[1]) {
2021-12-01 14:27:05 +01:00
xTexelC${y+1}.zw = vec2(0.);
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xTexelC${y+1}Ready = 1;
2021-11-08 13:36:26 +01:00
}
2021-12-01 14:27:05 +01:00
xC${y} = vec4(
xTexelC${y}.xy, xTexelC${y+1}.xy);
`,y+1<u&&(p+=`
xC${y+1} = vec4(xTexelC${y}.zw, xTexelC${y+1}.zw);
`)));y<u&&(p+=`
wTexel = getW(r, ${y}, d1, q);
dotProd += xC${y} * vec4(wTexel.xz, wTexel.xz);
`,y+1<u&&(p+=`
wTexel = getW(r, ${y+1}, d1, q);
dotProd += xC${y+1} * vec4(wTexel.xz, wTexel.xz);
2021-11-08 13:36:26 +01:00
`))}p+=`
}
`,p+=`
}
2022-01-16 15:49:55 +01:00
`;let h="",f="";n&&(r?h=`vec4 activation(vec4 a) {
2021-11-08 13:36:26 +01:00
vec4 b = getPreluActivationWeightsAtOutCoords();
${n}
2022-01-16 15:49:55 +01:00
}`:s?h=`vec4 activation(vec4 a) {
2021-11-08 13:36:26 +01:00
vec4 b = getLeakyreluAlphaAtOutCoords();
${n}
}`:h=`vec4 activation(vec4 x) {
${n}
2022-01-16 15:49:55 +01:00
}`,f="result = activation(result);");let m=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode=`
2021-11-08 13:36:26 +01:00
${h}
void main() {
ivec4 coords = getOutputCoords();
int batch = coords.x;
ivec2 xRCCorner = coords.yz * strides - pads;
int d2 = coords.w;
int d1 = d2 / ${a};
int q = d2 - d1 * ${a};
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
//intialize dotProd with a small epsilon seems to reduce GPU accuracy loss.
vec4 dotProd = vec4(0.000000000000001);
${p}
vec4 result = dotProd - vec4(0.000000000000001);
${m}
${f}
setOutput(result);
}
2022-01-16 15:49:55 +01:00
`}};function Sre(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dilations:l,dimRoundingMode:c}=r,u=l;u==null&&(u=[1,1]),w.assert(N.eitherStridesOrDilationsAreOne(o,u),()=>`Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${o} and dilations '${u}'`);let d=N.computeConv2DInfo(s.shape,a.shape,o,u,i,c,!0),p;Y().getBool("WEBGL_PACK_DEPTHWISECONV")&&d.strideWidth<=2&&d.outChannels/d.inChannels===1?p=new u4(d):p=new l4(d);let h=[[d.padInfo.top,d.padInfo.left],[d.strideHeight,d.strideWidth],[d.dilationHeight,d.dilationWidth],[d.inHeight,d.inWidth]];return n.runWebGLProgram(p,[s,a],"float32",h)}var Cre={kernelName:Ha,backendName:"webgl",kernelFunc:Sre},Tre=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,s=e.padInfo.left,a=e.outChannels/e.inChannels;this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int wR = coords.x;
int wC = coords.y;
int d1 = coords.z;
int dm = coords.w;
int d2 = d1 * ${a} + dm;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float dotProd = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// TO DO: Vec4 over the batch size
for (int b = 0; b < ${e.batchSize}; b++) {
for (int yR = 0; yR < ${e.outHeight}; yR++) {
2022-01-16 15:49:55 +01:00
int xR = wR + yR * ${t} - ${r};
2021-11-08 13:36:26 +01:00
if (xR < 0 || xR >= ${e.inHeight}) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
for (int yC = 0; yC < ${e.outWidth}; yC++) {
2022-01-16 15:49:55 +01:00
int xC = wC + yC * ${n} - ${s};
2021-11-08 13:36:26 +01:00
if (xC < 0 || xC >= ${e.inWidth}) {
continue;
}
float dyValue = getDy(b, yR, yC, d2);
float xValue = getX(b, xR, xC, d1);
dotProd += (xValue * dyValue);
2021-11-06 15:21:51 +01:00
}
}
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-09-01 00:22:16 +02:00
}
2022-01-16 15:49:55 +01:00
`}},Nre=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,s=e.strideWidth,a=t-1-e.padInfo.top,o=n-1-e.padInfo.left,i=e.outChannels/e.inChannels;this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec2 pads = ivec2(${a}, ${o});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d1 = coords[3];
ivec2 dyCorner = coords.yz - pads;
int dyRCorner = dyCorner.x;
int dyCCorner = dyCorner.y;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float dotProd = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${t}; wR++) {
2022-01-16 15:49:55 +01:00
float dyR = float(dyRCorner + wR) / ${r}.0;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int wRPerm = ${t} - 1 - wR;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${n}; wC++) {
2022-01-16 15:49:55 +01:00
float dyC = float(dyCCorner + wC) / ${s}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
int wCPerm = ${n} - 1 - wC;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// TO DO: Vec4 over the channelMul
for (int dm = 0; dm < ${i}; dm++) {
int d2 = d1 * ${i} + dm;
float xValue = getDy(batch, idyR, idyC, d2);
float wValue = getW(wRPerm, wCPerm, d1, dm);
dotProd += xValue * wValue;
}
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Ere(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,dy:a}=t,{strides:o,dilations:i,pad:l,dimRoundingMode:c,filterShape:u}=r,d=N.computeConv2DInfo(s.shape,u,o,i,l,c,!0),p=new Tre(d);return n.runWebGLProgram(p,[s,a],"float32")}var Rre={kernelName:jh,backendName:"webgl",kernelFunc:Ere};function _re(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,filter:a}=t,{strides:o,dilations:i,pad:l,dimRoundingMode:c,inputShape:u}=r,d=N.computeConv2DInfo(u,a.shape,o,i,l,c,!0),p=new Nre(d);return n.runWebGLProgram(p,[s,a],"float32")}var Dre={kernelName:qh,backendName:"webgl",kernelFunc:_re},Pre=class{constructor(e){this.variableNames=["X"],this.outputShape=[e,e],this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;
setOutput(val);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function $re(e){let{inputs:t,backend:n}=e,{x:r}=t,s=[...r.shape,...r.shape],a=w.sizeFromShape(r.shape),o=ve({inputs:{x:r},backend:n,attrs:{shape:[a]}}),i=new Pre(a),l=n.runWebGLProgram(i,[o],o.dtype),c=ve({inputs:{x:l},backend:n,attrs:{shape:s}});return n.disposeIntermediateTensorInfo(o),n.disposeIntermediateTensorInfo(l),c}var Fre={kernelName:Xh,backendName:"webgl",kernelFunc:$re},Ore=class{constructor(e){this.variableNames=["x","W"],this.outputShape=e.outShape;let{inHeight:t,inWidth:n,padInfo:r,strideHeight:s,strideWidth:a,filterHeight:o,filterWidth:i,dilationHeight:l,dilationWidth:c}=e,{top:u,left:d}=r;this.userCode=`
const ivec2 strides = ivec2(${s}, ${a});
2021-11-08 13:36:26 +01:00
const ivec2 pads = ivec2(${u}, ${d});
const float neg_infinity = -3.4e38;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int batch = coords.x;
int d1 = coords.w;
ivec2 outTopLeftCorner =
coords.yz * strides - pads;
int hBeg = outTopLeftCorner.x;
int wBeg = outTopLeftCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float curVal = neg_infinity;
for (int h = 0; h < ${o}; h++) {
int hIn = hBeg + h * ${l};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (hIn >= 0 && hIn < ${t}) {
for (int w = 0; w < ${i}; w++) {
int wIn = wBeg + w * ${c};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (wIn >= 0 && wIn < ${n}) {
float xVal = getX(batch, hIn, wIn, d1);
float wVal = getW(h, w, d1);
float val = xVal + wVal;
if (val > curVal) {
curVal = val;
}
}
2021-11-06 15:21:51 +01:00
}
}
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float result = curVal;
setOutput(result);
2021-09-05 22:42:11 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function Mre(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dilations:l}=r,c=N.computeDilation2DInfo(s.shape,a.shape,o,i,"NHWC",l),u,d=new Ore(c);u=n.runWebGLProgram(d,[s,a],"float32");let p=ve({inputs:{x:u},backend:n,attrs:{shape:c.outShape}});return n.disposeIntermediateTensorInfo(u),p}var zre={kernelName:xd,backendName:"webgl",kernelFunc:Mre};function Lre(e){let{inputs:t,backend:n,attrs:r}=e,{equation:s}=r,a=t,{allDims:o,summedDims:i,idDims:l}=N.decodeEinsumEquation(s,a.length);N.checkEinsumDimSizes(o.length,l,a);let{path:c,steps:u}=N.getEinsumComputePath(i,l),d=u.length,p=null,h=o.length,f=[];for(let m=0;m<d;++m){for(let g of u[m]){let{permutationIndices:y,expandDims:x}=N.getEinsumPermutation(h,l[g]),A;N.isIdentityPermutation(y)?A=a[g]:(A=Xn({inputs:{x:a[g]},backend:n,attrs:{perm:y}}),f.push(A));let b=A.shape.slice();for(let v=0;v<x.length;++v)b.splice(x[v],0,1);w.arraysEqual(A.shape,b)||(A=ve({inputs:{x:A},backend:n,attrs:{shape:b}}),f.push(A)),p===null?p=A:(p=Fx({inputs:{a:A,b:p},backend:n}),f.push(p))}m<d-1&&(c[m]>=0&&(p=n0({inputs:{x:p},backend:n,attrs:{axis:c[m]-(o.length-h),keepDims:!1}}),f.push(p)),h--)}for(let m of f)m!==p&&n.disposeIntermediateTensorInfo(m);return p}var Bre={kernelName:bd,backendName:"webgl",kernelFunc:Lre},Wre="return (x >= 0.0) ? x : (exp(x) - 1.0);",Vre=`
2021-11-08 13:36:26 +01:00
vec4 result;
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,Ure=it({opSnippet:Wre,packedOpSnippet:Vre}),Gre={kernelName:qa,backendName:"webgl",kernelFunc:Ure},Hre="return (b >= 1.0) ? a : a * (b + 1.0);",jre=`
2021-11-08 13:36:26 +01:00
vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
2022-01-16 15:49:55 +01:00
`,qre=e=>{let{inputs:t,backend:n}=e,{dy:r,y:s}=t,a=Y().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Dp(jre,r.shape,s.shape):new bc(Hre,r.shape,s.shape);return n.runWebGLProgram(a,[r,s],r.dtype)},Xre={kernelName:Yh,backendName:"webgl",kernelFunc:qre},Kre=`
2021-11-08 13:36:26 +01:00
return vec4(equal(a, b));
2022-01-16 15:49:55 +01:00
`,Zre="return float(a == b);",Yre=Tn({opSnippet:Zre,packedOpSnippet:Kre,dtype:"bool",cpuKernelImpl:zQ}),Jre={kernelName:ki,backendName:"webgl",kernelFunc:Yre},Qre=`
2021-11-08 13:36:26 +01:00
// Error function is calculated approximately with elementary function.
// See "Handbook of Mathematical Functions with Formulas,
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
2021-12-01 14:27:05 +01:00
float p = ${N.ERF_P};
float a1 = ${N.ERF_A1};
float a2 = ${N.ERF_A2};
float a3 = ${N.ERF_A3};
float a4 = ${N.ERF_A4};
float a5 = ${N.ERF_A5};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float sign = sign(x);
x = abs(x);
float t = 1.0 / (1.0 + p * x);
return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
2022-01-16 15:49:55 +01:00
`,ese=it({opSnippet:Qre}),tse={kernelName:xu,backendName:"webgl",kernelFunc:ese},nse=vc+`
return exp(x);
2022-01-16 15:49:55 +01:00
`,rse=`
vec4 result = exp(x);
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
2022-01-16 15:49:55 +01:00
`,c4=it({opSnippet:nse,packedOpSnippet:rse,cpuKernelImpl:LQ,dtype:"float32"}),sse={kernelName:Xa,backendName:"webgl",kernelFunc:c4};function Lx(e){let{inputs:t,attrs:n,backend:r}=e,{dim:s}=n,{input:a}=t,o=a.shape.length,i=a.shape.slice(),l=s;return s<0&&(w.assert(-(o+1)<=s,()=>`Axis must be in the interval [${-(o+1)}, ${o}]`),l=o+s+1),i.splice(l,0,1),ve({inputs:{x:a},backend:r,attrs:{shape:i}})}var ase={kernelName:Ii,backendName:"webgl",kernelFunc:Lx},d4="return exp(x) - 1.0;",ose=it({opSnippet:d4,packedOpSnippet:d4,cpuKernelImpl:BQ}),ise={kernelName:Si,backendName:"webgl",kernelFunc:ose},p4=class{constructor(e,t,n){this.variableNames=["real","imag"];let r=t[1];this.outputShape=t;let s=n?`2.0 * ${Math.PI}`:`-2.0 * ${Math.PI}`,a=n?`${r}.0`:"1.0",o;if(e==="real")o="return real * expR - imag * expI;";else if(e==="imag")o="return real * expI + imag * expR;";else throw new Error(`FFT component must be either "real" or "imag", got ${e}.`);this.userCode=`
const float exponentMultiplier = ${s};
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float unaryOpComplex(float real, float expR, float imag, float expI) {
${o}
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float mulMatDFT(int batch, int index) {
2022-01-16 15:49:55 +01:00
float indexRatio = float(index) / float(${r});
2021-11-08 13:36:26 +01:00
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float result = 0.0;
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
for (int i = 0; i < ${r}; i++) {
2021-11-08 13:36:26 +01:00
// x = (-2|2 * PI / N) * index * i;
float x = exponentMultiplierTimesIndexRatio * float(i);
float expR = cos(x);
float expI = sin(x);
float real = getReal(batch, i);
float imag = getImag(batch, i);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
result +=
unaryOpComplex(real, expR, imag, expI) / ${a};
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
return result;
}
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
setOutput(mulMatDFT(coords[0], coords[1]));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function h4(e,t,n){let r=n.texData.get(e.dataId),s=w.sizeFromShape(e.shape),a=e.shape[e.shape.length-1],o=s/a,i=ve({inputs:{x:e},backend:n,attrs:{shape:[o,a]}}),l=i.shape,c=new p4("real",l,t),u=new p4("imag",l,t),d=[{dataId:r.complexTensorInfos.real.dataId,dtype:r.complexTensorInfos.real.dtype,shape:l},{dataId:r.complexTensorInfos.imag.dataId,dtype:r.complexTensorInfos.imag.dtype,shape:l}],p=n.runWebGLProgram(c,d,"float32"),h=n.runWebGLProgram(u,d,"float32"),f=Jo({inputs:{real:p,imag:h},backend:n});n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(h);let m=ve({inputs:{x:f},backend:n,attrs:{shape:e.shape}});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(f),m}function lse(e){let{inputs:t,backend:n}=e,{input:r}=t;return h4(r,!1,n)}var use={kernelName:Jh,backendName:"webgl",kernelFunc:lse},cse=class{constructor(e,t){this.outputShape=[],this.customUniforms=[{name:"value",type:"float"}],this.variableNames=["x"],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
// Input can be obtained from uniform value.
setOutput(value);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Fp(e){let{backend:t,attrs:n}=e,{shape:r,value:s}=n,{dtype:a}=n;if(a=a||w.inferDtype(s),a==="string"){let o=w.getArrayFromDType(a,w.sizeFromShape(r));return o.fill(s),t.makeTensorInfo(r,a,o)}else{let o=new cse(r,s),i=[[s]];return t.runWebGLProgram(o,[],a,i)}}var dse={kernelName:bu,backendName:"webgl",kernelFunc:Fp},pse=class{constructor(e){this.variableNames=["Image"],this.outputShape=[];let t=e[2];this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int x = coords[2];
int coordX = ${t} - x - 1;
float outputValue;
if(coordX >= 0 && coordX < ${t}) {
outputValue = getImage(coords[0], coords[1], coordX, coords[3]);
} else {
outputValue = getImage(coords[0], coords[1], coords[2], coords[3]);
}
setOutput(outputValue);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},hse={kernelName:Ci,backendName:"webgl",kernelFunc:({inputs:e,backend:t})=>{let{image:n}=e,r=t,s=new pse(n.shape);return r.runWebGLProgram(s,[n],n.dtype)}},f4="return floor(x);",fse=it({opSnippet:f4,packedOpSnippet:f4,cpuKernelImpl:WQ}),mse={kernelName:Ka,backendName:"webgl",kernelFunc:fse},gse=`
2021-11-08 13:36:26 +01:00
float s = sign(a) * sign(b);
int ia = round(a);
int ib = round(b);
if (ib != 0) {
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
return float(idiv(ia, ib, s));
} else {
return NAN;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`,yse=`
2021-11-08 13:36:26 +01:00
ivec4 ia = round(a);
ivec4 ib = round(b);
bvec4 cond = notEqual(ib, ivec4(0));
ivec4 result = ivec4(0);
vec4 s = sign(a) * sign(b);
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
if (cond[0]) {
result[0] = idiv(ia[0], ib[0], s[0]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (cond[1]) {
result[1] = idiv(ia[1], ib[1], s[1]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (cond[2]) {
result[2] = idiv(ia[2], ib[2], s[2]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (cond[3]) {
result[3] = idiv(ia[3], ib[3], s[3]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return vec4(result);
2022-01-16 15:49:55 +01:00
`,Ase=Tn({opSnippet:gse,packedOpSnippet:yse,dtype:"int32"}),xse={kernelName:Za,backendName:"webgl",kernelFunc:Ase},bse=class{constructor(e){this.variableNames=["A"];let t=jn(),[n,r]=e;this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec3 coords = getOutputCoords();
int texR = coords[0];
int texC = coords[1];
int depth = coords[2];
2022-01-16 15:49:55 +01:00
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}.0, ${n}.0);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
vec4 values = ${t.texture2D}(A, uv);
float value;
if (depth == 0) {
value = values.r;
} else if (depth == 1) {
value = values.g;
} else if (depth == 2) {
value = values.b;
} else if (depth == 3) {
value = values.a;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(floor(value * 255.0 + 0.5));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},vse=class{constructor(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;let t=jn(),[n,r]=e;this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec3 coords = getOutputCoords();
int texR = coords[0];
int texC = coords[1];
int depth = coords[2];
vec4 result = vec4(0.);
for(int row=0; row<=1; row++) {
for(int col=0; col<=1; col++) {
texC = coords[1] + row;
depth = coords[2] + col;
vec2 uv = (vec2(texC, texR) + halfCR) /
2022-01-16 15:49:55 +01:00
vec2(${r}.0, ${n}.0);
2021-11-08 13:36:26 +01:00
vec4 values = ${t.texture2D}(A, uv);
float value;
if (depth == 0) {
value = values.r;
} else if (depth == 1) {
value = values.g;
} else if (depth == 2) {
value = values.b;
} else if (depth == 3) {
value = values.a;
}
result[row * 2 + col] = floor(value * 255.0 + 0.5);
2021-09-01 00:22:16 +02:00
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
${t.output} = result;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},wse={kernelName:Dd,backendName:"webgl",kernelFunc:kse},Ic;function kse(e){let{inputs:t,backend:n,attrs:r}=e,{pixels:s}=t,{numChannels:a}=r,o=typeof HTMLVideoElement!="undefined"&&s instanceof HTMLVideoElement,i=typeof HTMLImageElement!="undefined"&&s instanceof HTMLImageElement,[l,c]=o?[s.videoWidth,s.videoHeight]:[s.width,s.height],u=[c,l],d=[c,l,a];(i||o)&&(Ic==null&&(Ic=document.createElement("canvas").getContext("2d")),Ic.canvas.width=l,Ic.canvas.height=c,Ic.drawImage(s,0,0,l,c),s=Ic.canvas);let p=n.makeTensorInfo(u,"int32");n.texData.get(p.dataId).usage=as.PIXELS,n.gpgpu.uploadPixelDataToTexture(n.getTexture(p.dataId),s);let h=Y().getBool("WEBGL_PACK")?new vse(d):new bse(d),f=n.runWebGLProgram(h,[p],"int32");return n.disposeData(p.dataId),f}function Ise(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a,bias:o,preluActivationWeights:i}=t,{strides:l,pad:c,dataFormat:u,dilations:d,dimRoundingMode:p,activation:h,leakyreluAlpha:f}=r,m=N.convertConv2DDataFormat(u),g=N.computeConv2DInfo(s.shape,a.shape,l,d,c,p,!1,m),y,x=[];if(g.filterHeight===1&&g.filterWidth===1&&g.dilationHeight===1&&g.dilationWidth===1&&g.strideHeight===1&&g.strideWidth===1&&(g.padInfo.type==="SAME"||g.padInfo.type==="VALID"))y=r4({x:s,filter:a,convInfo:g,backend:n,bias:o,activation:h,preluActivationWeights:i,leakyreluAlpha:f});else if(Y().getBool("WEBGL_CONV_IM2COL")&&s.shape[0]===1)y=s4({x:s,filter:a,convInfo:g,backend:n,bias:o,activation:h,preluActivationWeights:i,leakyreluAlpha:f});else{let b=o!=null,v=i!=null,C=h==="leakyrelu",I=h?e0(h,!1):null,E=new n4(g,b,I,v,C),R=[s,a];if(o&&R.push(o),i&&R.push(i),C){let F=n.makeTensorInfo([],"float32",w.createScalarValue(f,"float32"));R.push(F),x.push(F)}y=n.runWebGLProgram(E,R,"float32")}let A=ve({inputs:{x:y},backend:n,attrs:{shape:g.outShape}});return x.push(y),x.forEach(b=>n.disposeIntermediateTensorInfo(b)),A}var Sse={kernelName:Eo,backendName:"webgl",kernelFunc:Ise};function Cse(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a,bias:o,preluActivationWeights:i}=t,{strides:l,pad:c,dilations:u,dimRoundingMode:d,activation:p,leakyreluAlpha:h}=r,f=[],m=u;m==null&&(m=[1,1]),w.assert(N.eitherStridesOrDilationsAreOne(l,m),()=>`Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${l} and dilations '${m}'`);let g=N.computeConv2DInfo(s.shape,a.shape,l,m,c,d,!0),y=Y().getBool("WEBGL_PACK_DEPTHWISECONV")&&g.strideWidth<=2&&g.outChannels/g.inChannels===1,x=p?e0(p,y):null,A=[s,a],b=o!=null,v=i!=null,C=p==="leakyrelu";if(b&&A.push(o),v&&A.push(i),C){let F=n.makeTensorInfo([],"float32",w.createScalarValue(h,"float32"));A.push(F),f.push(F)}let I;y?I=new u4(g,b,x,v,C):I=new l4(g,b,x,v,C);let E=[[g.padInfo.top,g.padInfo.left],[g.strideHeight,g.strideWidth],[g.dilationHeight,g.dilationWidth],[g.inHeight,g.inWidth]],R=n.runWebGLProgram(I,A,"float32",E);return f.forEach(F=>n.disposeIntermediateTensorInfo(F)),R}var Tse={kernelName:Ro,backendName:"webgl",kernelFunc:Cse},Nse=class{constructor(e,t,n){this.sliceDim=e,this.strides=t,this.variableNames=["x","indices"],this.outputShape=n;let r=wt(t.length),s=wt(n.length),a=this.sliceDim>1?"strides[j]":"strides";this.userCode=`
${r} strides = ${r}(${this.strides});
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} coords = getOutputCoords();
2021-11-08 13:36:26 +01:00
int flattenIndex = 0;
for (int j = 0; j < ${this.sliceDim}; j++) {
int index = round(getIndices(coords[0], j));
flattenIndex += index * ${a};
}
setOutput(getX(flattenIndex, coords[1]));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Ese(e){let{inputs:t,backend:n}=e,{params:r,indices:s}=t,a=s.shape,o=a[a.length-1],i=w.sizeFromShape(r.shape),[l,c,u,d]=N.prepareAndValidate(r,s),p=ve({inputs:{x:s},backend:n,attrs:{shape:[c,o]}}),h=ve({inputs:{x:r},backend:n,attrs:{shape:[w.sizeFromShape(r.shape)/u,u]}});if(n.shouldExecuteOnCPU([r,s])||r.dtype==="string"){let y=n.readSync(s.dataId),x=n.bufferSync(r),A=VQ(y,x,r.dtype,c,o,u,d,r.shape,i);return n.makeTensorInfo(l,r.dtype,A.values)}let f=new Nse(o,d,[c,u]),m=n.runWebGLProgram(f,[h,p],h.dtype),g=ve({inputs:{x:m},backend:n,attrs:{shape:l}});return n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(h),n.disposeIntermediateTensorInfo(m),g}var Rse={kernelName:Ni,backendName:"webgl",kernelFunc:Ese},_se=class{constructor(e,t){this.variableNames=["A","indices"],this.outputShape=t,this.rank=t.length;let n=wt(this.rank),r=Dse(e,2);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${n} resRC = getOutputCoords();
2022-01-08 18:43:44 +01:00
int index = int(getIndices(resRC.x, resRC.z));
float inBounds = (index >= 0) && (index < ${e[2]}) ? 1.0 : 0.0;
2022-01-16 15:49:55 +01:00
setOutput(inBounds * getA(${r}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Dse(e,t){let n=["resRC.x","resRC.y","resRC.z","resRC.w"],r=[];for(let s=0;s<e.length;s++)s===2?r.push("index"):r.push(`${n[s]}`);return r.join()}function m4(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,indices:a}=t,{axis:o,batchDims:i}=r,l=w.parseAxisParam(o,s.shape)[0];if(Y().get("DEBUG")){let x=n.readSync(a.dataId),A=s.shape[l];for(let b=0;b<x.length;++b){let v=x[b];w.assert(v<=A-1&&v>=0,()=>`GatherV2: the index value ${v} is not in [0, ${A-1}]`)}}let c=N.segment_util.collectGatherOpShapeInfo(s,a,l,i),u=w.sizeFromShape(a.shape),d=[],p=ve({inputs:{x:s},backend:n,attrs:{shape:[c.batchSize,c.outerSize,c.dimSize,c.sliceSize]}}),h=ve({inputs:{x:a},backend:n,attrs:{shape:[c.batchSize,u/c.batchSize]}});d.push(p),d.push(h);let f=[c.batchSize,c.outerSize,u/c.batchSize,c.sliceSize];if(n.shouldExecuteOnCPU([s,a])||s.dtype==="string"){let x=n.bufferSync(h),A=n.bufferSync(p),b=UQ(A,x,f);return d.forEach(v=>n.disposeIntermediateTensorInfo(v)),n.makeTensorInfo(c.outputShape,b.dtype,b.values)}let m=new _se(p.shape,f),g=n.runWebGLProgram(m,[p,h],p.dtype);d.push(g);let y=ve({inputs:{x:g},backend:n,attrs:{shape:c.outputShape}});return d.forEach(x=>n.disposeIntermediateTensorInfo(x)),y}var Pse={kernelName:Ti,backendName:"webgl",kernelFunc:m4},$se="return float(a > b);",Fse=`
2021-11-08 13:36:26 +01:00
return vec4(greaterThan(a, b));
2022-01-16 15:49:55 +01:00
`,Ose=Tn({opSnippet:$se,packedOpSnippet:Fse,cpuKernelImpl:GQ,dtype:"bool"}),Mse={kernelName:Ei,backendName:"webgl",kernelFunc:Ose},zse="return float(a >= b);",Lse=`
2021-11-08 13:36:26 +01:00
return vec4(greaterThanEqual(a, b));
2022-01-16 15:49:55 +01:00
`,Bse=Tn({opSnippet:zse,packedOpSnippet:Lse,dtype:"bool",cpuKernelImpl:HQ}),Wse={kernelName:Ja,backendName:"webgl",kernelFunc:Bse};function Vse(e){let{inputs:t,backend:n}=e,{input:r}=t;return h4(r,!0,n)}var Use={kernelName:Qh,backendName:"webgl",kernelFunc:Vse},Gse="return float(!isnan(x) && !isinf(x));",Hse=it({opSnippet:Gse,dtype:"bool"}),jse={kernelName:vu,backendName:"webgl",kernelFunc:Hse},qse="return float(isinf(x));",Xse=it({opSnippet:qse,dtype:"bool"}),Kse={kernelName:wu,backendName:"webgl",kernelFunc:Xse},Zse="return float(isnan(x));",Yse=it({opSnippet:Zse,dtype:"bool"}),Jse={kernelName:ku,backendName:"webgl",kernelFunc:Yse},Qse="return float(a < b);",eae=`
2021-11-08 13:36:26 +01:00
return vec4(lessThan(a, b));
2022-01-16 15:49:55 +01:00
`,tae=Tn({opSnippet:Qse,packedOpSnippet:eae,cpuKernelImpl:jQ,dtype:"bool"}),nae={kernelName:Ri,backendName:"webgl",kernelFunc:tae},rae="return float(a <= b);",sae=`
2021-11-08 13:36:26 +01:00
return vec4(lessThanEqual(a, b));
2022-01-16 15:49:55 +01:00
`,aae=Tn({opSnippet:rae,packedOpSnippet:sae,cpuKernelImpl:qQ,dtype:"bool"}),oae={kernelName:_i,backendName:"webgl",kernelFunc:aae};function iae(e){let{backend:t,attrs:n}=e,{start:r,stop:s,num:a}=n,o=XQ(r,s,a);return t.makeTensorInfo([o.length],"float32",o)}var lae={kernelName:ef,backendName:"webgl",kernelFunc:iae},uae=vc+`
return x < 0.0 ? 0./0. : log(x);
2022-01-16 15:49:55 +01:00
`,cae=`
2021-11-08 13:36:26 +01:00
vec4 result = log(x);
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : (x.r < 0.0 ? 0./0. : result.r);
result.g = isNaN.g ? x.g : (x.g < 0.0 ? 0./0. : result.g);
result.b = isNaN.b ? x.b : (x.b < 0.0 ? 0./0. : result.b);
result.a = isNaN.a ? x.a : (x.a < 0.0 ? 0./0. : result.a);
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,dae=it({opSnippet:uae,packedOpSnippet:cae,cpuKernelImpl:KQ}),pae={kernelName:to,backendName:"webgl",kernelFunc:dae},hae=vc+`
return log(1.0 + x);
2022-01-16 15:49:55 +01:00
`,fae=it({opSnippet:hae}),mae={kernelName:Iu,backendName:"webgl",kernelFunc:fae},gae="return float(a >= 1.0 && b >= 1.0);",yae=`
2021-11-08 13:36:26 +01:00
return vec4(
vec4(greaterThanEqual(a, vec4(1.0))) *
vec4(greaterThanEqual(b, vec4(1.0))));
2022-01-16 15:49:55 +01:00
`,Aae=Tn({opSnippet:gae,packedOpSnippet:yae,dtype:"bool"}),xae={kernelName:Di,backendName:"webgl",kernelFunc:Aae},bae="return float(!(x >= 1.0));",vae=it({opSnippet:bae}),wae={kernelName:Su,backendName:"webgl",kernelFunc:vae},kae="return float(a >= 1.0 || b >= 1.0);",Iae=`
2021-11-08 13:36:26 +01:00
return min(
vec4(greaterThanEqual(a, vec4(1.0))) +
vec4(greaterThanEqual(b, vec4(1.0))),
vec4(1.0));
2022-01-16 15:49:55 +01:00
`,Sae=Tn({opSnippet:kae,packedOpSnippet:Iae,dtype:"bool"}),Cae={kernelName:wd,backendName:"webgl",kernelFunc:Sae},Tae=class{constructor(e,t,n,r,s){this.variableNames=["x"],this.outputShape=[];let a=t,o=e[3]-1;this.outputShape=e;let i,l=`float(${n}) + float(${r}) * sum`;s===.5?i=`inversesqrt(${l})`:s===1?i=`1.0/(${l})`:i=`exp(log(${l}) * float(-${s}));`,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int r = coords[1];
int c = coords[2];
int d = coords[3];
float x = getX(b, r, c, d);
float sum = 0.0;
for (int j = -${a}; j <= ${a}; j++) {
int idx = d + j;
if (idx >= 0 && idx <= ${o}) {
float z = getX(b, r, c, idx);
sum += z * z;
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
float val = x * ${i};
setOutput(val);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Nae=class{constructor(e,t,n,r,s){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;let a=t,o=e[3]-1;this.outputShape=e;let i,l=`float(${n}) + float(${r}) * sum`;s===.5?i=`inversesqrt(${l})`:s===1?i=`1.0/(${l})`:i=`exp(log(${l}) * float(-${s}));`,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords.x;
int r = coords.y;
int c = coords.z;
int d = coords.w;
bool hasNextCol = d < ${this.outputShape[3]};
bool hasNextRow = c < ${this.outputShape[2]};
vec4 sum = vec4(0.);
vec4 xFragAtOutputCoords = getX(b, r, c, d);
vec4 xAtOutputCoords = vec4(
getChannel(xFragAtOutputCoords, vec2(c, d)),
hasNextCol ?
getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,
hasNextRow ?
getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,
(hasNextRow && hasNextCol) ?
getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0
);
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
int firstChannel = d - ${a};
vec2 cache = vec2(0.);
if(firstChannel >= 0){
vec4 firstChannelFrag = getX(b, r, c, firstChannel);
cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));
if(hasNextRow){
cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));
}
}
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
ivec2 depth = ivec2(d, d + 1);
for (int j = - ${a}; j <= ${a}; j++) {
ivec2 idx = depth + j;
bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));
bvec2 belowUpperBound = lessThanEqual(idx, ivec2(${o}));
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
bool depthInRange = aboveLowerBound.x && belowUpperBound.x;
bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if(depthInRange || depthPlusOneInRange){
vec4 z = vec4(0.);
vec4 xFragAtCurrentDepth;
z.xz = cache.xy;
if(depthPlusOneInRange && hasNextCol){
xFragAtCurrentDepth = idx.y != d ?
getX(b, r, c, idx.y) : xFragAtOutputCoords;
z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));
if(hasNextRow){
z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));
}
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
cache.xy = z.yw;
sum += z * z;
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
vec4 result = xAtOutputCoords * ${i};
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Eae=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{depthRadius:a,bias:o,alpha:i,beta:l}=r,c=Y().getBool("WEBGL_PACK_NORMALIZATION")?new Nae(s.shape,a,o,i,l):new Tae(s.shape,a,o,i,l);return n.runWebGLProgram(c,[s],s.dtype)},Rae={kernelName:kd,backendName:"webgl",kernelFunc:Eae},_ae=class{constructor(e,t,n,r,s){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=e,this.depth=e[3],this.depthRadius=t,this.bias=n,this.alpha=r,this.beta=s,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int r = coords[1];
int c = coords[2];
float result = 0.0;
for (int d = 0; d < ${this.depth}; ++d) {
int depthBegin = int(max(0.0, float(d - ${t})));
int depthEnd = int(min(float(${this.depth}),
float(d + ${t} + 1)));
const int MIN_DEPTH_BEGIN = 0;
const int MAX_DEPTH_END = ${this.depth};
float norm = 0.0;
for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {
if (k < depthBegin){
continue;
}
else if (k >= depthBegin && k < depthEnd) {
norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);
}
else {
break;
2021-09-11 16:29:31 +02:00
}
2021-11-06 15:21:51 +01:00
}
2021-09-11 16:29:31 +02:00
2022-01-16 15:49:55 +01:00
norm = float(${r}) * norm + float(${n});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){
if (k < depthBegin){
continue;
}
else if (k >= depthBegin && k < depthEnd){
2022-01-16 15:49:55 +01:00
float dyi = -2.0 * float(${r})
* float(${s})
2021-11-08 13:36:26 +01:00
* getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)
/ norm;
if (k == d) {
2022-01-16 15:49:55 +01:00
dyi += pow(norm, -1.0 * ${s});
2021-11-08 13:36:26 +01:00
}
if (k == coords[3]) {
dyi *= getDy(b, r, c, d);
result += dyi;
}
}
else {
break;
}
2021-09-05 22:42:11 +02:00
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Dae=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s,y:a,dy:o}=t,{depthRadius:i,bias:l,alpha:c,beta:u}=r,d=new _ae(s.shape,i,l,c,u);return n.runWebGLProgram(d,[s,a,o],s.dtype)},Pae={kernelName:tf,backendName:"webgl",kernelFunc:Dae};function $ae(e,t,n,r){let s=w.sizeFromShape(t),o=w.sizeFromShape(e.shape)/s,i=ve({inputs:{x:e},attrs:{shape:[o,s]},backend:r}),l=Fl(i,e.dtype,"max",r),c=ve({inputs:{x:l},attrs:{shape:n},backend:r});return r.disposeIntermediateTensorInfo(i),r.disposeIntermediateTensorInfo(l),c}function g4(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{reductionIndices:a,keepDims:o}=r,i=s.shape.length,l=w.parseAxisParam(a,s.shape),c=l,u=N.getAxesPermutation(c,i),d=u!=null,p=n.shouldExecuteOnCPU([s]),h=s;if(d){if(p){let A=n.texData.get(h.dataId).values,b=new Array(i);for(let I=0;I<b.length;I++)b[I]=s.shape[u[I]];let v=$x(A,s.shape,s.dtype,u,b);h=n.makeTensorInfo(b,s.dtype);let C=n.texData.get(h.dataId);C.values=v}else h=t0(s,u,n);c=N.getInnerMostAxes(c.length,i)}N.assertAxesAreInnerMostDims("max",c,i);let[f,m]=N.computeOutAndReduceShapes(h.shape,c),g=f;o&&(g=N.expandShapeToKeepDim(f,l));let y;if(p){let A=n.texData.get(h.dataId).values,b=ZQ(A,w.sizeFromShape(m),g,s.dtype);y=n.makeTensorInfo(g,s.dtype);let v=n.texData.get(y.dataId);v.values=b}else y=$ae(h,m,g,n);return d&&n.disposeIntermediateTensorInfo(h),y}var Fae={kernelName:no,backendName:"webgl",kernelFunc:g4},Oae=OC+`
2021-11-08 13:36:26 +01:00
return max(a, b);
2022-01-16 15:49:55 +01:00
`,Mae=`
2021-11-08 13:36:26 +01:00
vec4 result = vec4(max(a, b));
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
2022-01-16 15:49:55 +01:00
`+Qm+`
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,zae=Tn({opSnippet:Oae,packedOpSnippet:Mae,cpuKernelImpl:YQ}),Lae={kernelName:ro,backendName:"webgl",kernelFunc:zae};function Bae(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t;hc(s,"maxPool");let{filterSize:a,strides:o,pad:i,dimRoundingMode:l}=r,c=1;w.assert(N.eitherStridesOrDilationsAreOne(o,c),()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${o} and dilations '${c}'`);let u=N.computePool2DInfo(s.shape,a,o,c,i,l);if(u.filterWidth===1&&u.filterHeight===1&&w.arraysEqual(u.inShape,u.outShape))return Cr({inputs:{x:s},backend:n});let d=new Pp(u,"max",!1);return n.runWebGLProgram(d,[s],s.dtype)}var Wae={kernelName:so,backendName:"webgl",kernelFunc:Bae};function Vae(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{filterSize:a,strides:o,pad:i,dataFormat:l,dimRoundingMode:c}=r,u=[1,1,1],d=N.computePool3DInfo(s.shape,a,o,u,i,c,l),p=new Ox(d,"max",!1);return n.runWebGLProgram(p,[s],s.dtype)}var Uae={kernelName:Id,backendName:"webgl",kernelFunc:Vae},Gae=class{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;let t=e.strideHeight,n=e.strideWidth,r=e.dilationHeight,s=e.effectiveFilterHeight,a=e.effectiveFilterWidth,o=s-1-e.padInfo.top,i=a-1-e.padInfo.left,l=s*a-1;this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec2 pads = ivec2(${o}, ${i});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec2 dyRCCorner = coords.yz - pads;
int dyRCorner = dyRCCorner.x;
int dyCCorner = dyRCCorner.y;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
2022-01-16 15:49:55 +01:00
for (int wR = 0; wR < ${s};
wR += ${r}) {
2021-11-08 13:36:26 +01:00
float dyR = float(dyRCorner + wR) / ${t}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${a}; wC++) {
float dyC = float(dyCCorner + wC) / ${n}.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
int idyC = int(dyC);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
float dyValue = getDy(b, idyR, idyC, d);
int maxPosValue = ${l} - int(getMaxPos(b, idyR, idyC, d));
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
// Get the current value, check it against the value from the
// position matrix.
int curPosValue = wR * ${a} + wC;
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
dotProd += dyValue * mask;
}
}
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Hae=class{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;let t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,s=e.dilationDepth,a=e.dilationHeight,o=e.dilationWidth,i=e.effectiveFilterDepth,l=e.effectiveFilterHeight,c=e.effectiveFilterWidth,u=i-1-e.padInfo.front,d=l-1-e.padInfo.top,p=c-1-e.padInfo.left,h=i*l*c-1;this.userCode=`
2021-11-08 13:36:26 +01:00
const ivec3 pads = ivec3(${u}, ${d}, ${p});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyDCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
// Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
// dx(xD, xR, xC, ch).
2021-11-06 15:21:51 +01:00
// ? = to be determined. : = across all values in that axis.
2021-11-08 13:36:26 +01:00
float dotProd = 0.0;
for (int wD = 0; wD < ${i};
2022-01-16 15:49:55 +01:00
wD += ${s}) {
2021-11-08 13:36:26 +01:00
float dyD = float(dyDCorner + wD) / ${t}.0;
if (dyD < 0.0 || dyD >= ${e.outDepth}.0 || fract(dyD) > 0.0) {
2021-07-29 22:06:03 +02:00
continue;
2021-09-11 16:29:31 +02:00
}
2021-11-08 13:36:26 +01:00
int idyD = int(dyD);
2021-11-08 13:36:26 +01:00
for (int wR = 0; wR < ${l};
wR += ${a}) {
float dyR = float(dyRCorner + wR) / ${n}.0;
if (dyR < 0.0 || dyR >= ${e.outHeight}.0 ||
fract(dyR) > 0.0) {
2021-09-11 16:29:31 +02:00
continue;
}
2021-11-08 13:36:26 +01:00
int idyR = int(dyR);
2021-07-29 15:53:13 +02:00
2021-11-08 13:36:26 +01:00
for (int wC = 0; wC < ${c};
wC += ${o}) {
2022-01-16 15:49:55 +01:00
float dyC = float(dyCCorner + wC) / ${r}.0;
2021-11-08 13:36:26 +01:00
if (dyC < 0.0 || dyC >= ${e.outWidth}.0 ||
fract(dyC) > 0.0) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
int idyC = int(dyC);
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
int maxPosValue = ${h} -
int(getMaxPos(batch, idyD, idyR, idyC, ch));
// Get the current value, check it against the value from the
// position matrix.
int curPosValue =
wD * ${l} * ${c} +
wR * ${c} + wC;
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
2021-08-14 17:17:51 +02:00
2021-11-08 13:36:26 +01:00
dotProd += dyValue * mask;
2021-11-06 15:21:51 +01:00
}
}
}
2021-11-08 13:36:26 +01:00
setOutput(dotProd);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function jae(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,input:a}=t,o=a,{filterSize:i,strides:l,pad:c,dimRoundingMode:u}=r,d=[1,1,1],p=N.computePool3DInfo(o.shape,i,l,d,c,u),h=new Ox(p,"max",!0),f=n.runWebGLProgram(h,[o],o.dtype),m=new Hae(p),g=n.runWebGLProgram(m,[s,f],o.dtype);return n.disposeIntermediateTensorInfo(f),g}var qae={kernelName:rf,backendName:"webgl",kernelFunc:jae};function Xae(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,input:a,output:o}=t,i=a;hc([a,o],"maxPoolGrad");let{filterSize:l,strides:c,pad:u,dimRoundingMode:d}=r,p=N.computePool2DInfo(i.shape,l,c,1,u,d),h=!0,f=new Pp(p,"max",h),m=n.runWebGLProgram(f,[i],i.dtype),g=new Gae(p),y=n.runWebGLProgram(g,[s,m],i.dtype);return n.disposeIntermediateTensorInfo(m),y}var Kae={kernelName:nf,backendName:"webgl",kernelFunc:Xae};function Zae(e,t,n,r){let s=new Pp(n,"max",!1),a=r.runWebGLProgram(s,[e],"float32");s=new Pp(n,"max",!0,!0,t);let o=r.runWebGLProgram(s,[e],"float32");return[a,o]}var Yae={kernelName:sf,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{x:r}=e,{filterSize:s,strides:a,pad:o,includeBatchInIndex:i}=t,l=n;w.assert(r.shape.length===4,()=>`Error in maxPool: input must be rank 4 but got rank ${r.shape.length}.`);let c=[1,1];w.assert(N.eitherStridesOrDilationsAreOne(a,c),()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${a} and dilations '${c}'`);let u=N.computePool2DInfo(r.shape,s,a,c,o),[d,p]=Zae(r,i,u,l);return[d,p]}};function Jae(e,t,n,r){let s=w.sizeFromShape(t),o=w.sizeFromShape(e.shape)/s,i=ve({inputs:{x:e},attrs:{shape:[o,s]},backend:r}),l=Fl(i,"float32","mean",r),c=ve({inputs:{x:l},attrs:{shape:n},backend:r});return r.disposeIntermediateTensorInfo(i),r.disposeIntermediateTensorInfo(l),c}var Qae={kernelName:ao,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{x:r}=e,{keepDims:s,axis:a}=t,o=n,i=r.shape.length,l=w.parseAxisParam(a,r.shape),c=l,u=N.getAxesPermutation(c,i),d=u!=null,p=o.shouldExecuteOnCPU([r]),h=[],f=r;if(d){if(p){let b=o.texData.get(f.dataId).values,v=new Array(i);for(let E=0;E<v.length;E++)v[E]=r.shape[u[E]];let C=$x(b,r.shape,r.dtype,u,v);f=o.makeTensorInfo(v,r.dtype);let I=o.texData.get(f.dataId);I.values=C}else f=t0(r,u,o);h.push(f),c=N.getInnerMostAxes(c.length,i)}N.assertAxesAreInnerMostDims("sum",c,i);let[m,g]=N.computeOutAndReduceShapes(f.shape,c),y=m;s&&(y=N.expandShapeToKeepDim(m,l));let x=Jae(f,g,y,o);for(let A of h)o.disposeIntermediateTensorInfo(A);return x}};function eoe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r,i=s.shape.length,l=w.parseAxisParam(a,s.shape),c=l,u=N.getAxesPermutation(c,i),d=s;u!=null&&(d=Xn({inputs:{x:s},backend:n,attrs:{perm:u}}),c=N.getInnerMostAxes(c.length,s.shape.length)),N.assertAxesAreInnerMostDims("min",c,i);let[p,h]=N.computeOutAndReduceShapes(d.shape,c),f=w.sizeFromShape(h),m=ve({inputs:{x:d},backend:n,attrs:{shape:[-1,f]}}),g=Fl(m,m.dtype,"min",n),y;if(o){let x=N.expandShapeToKeepDim(p,l);y=ve({inputs:{x:g},backend:n,attrs:{shape:x}})}else y=ve({inputs:{x:g},backend:n,attrs:{shape:p}});return n.disposeIntermediateTensorInfo(m),n.disposeIntermediateTensorInfo(g),u!=null&&n.disposeIntermediateTensorInfo(d),y}var toe={kernelName:oo,backendName:"webgl",kernelFunc:eoe},noe=OC+`
2021-11-08 13:36:26 +01:00
return min(a, b);
2022-01-16 15:49:55 +01:00
`,roe=`
2021-11-08 13:36:26 +01:00
vec4 result = vec4(min(a, b));
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
2022-01-16 15:49:55 +01:00
`+Qm+`
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,soe=Tn({opSnippet:noe,packedOpSnippet:roe,cpuKernelImpl:JQ}),aoe={kernelName:io,backendName:"webgl",kernelFunc:soe},ooe=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=t.map((c,u)=>c[0]+e[u]+c[1]);let r=e.length,s=wt(r),a=t.map(c=>c[0]).join(","),o=t.map((c,u)=>c[0]+e[u]).join(","),i=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r),l=n==="reflect"?0:1;if(r===1){this.userCode=`
2021-11-08 13:36:26 +01:00
int start = ${a};
int end = ${o};
void main() {
int outC = getOutputCoords();
if (outC < start) {
outC = start * 2 - outC - ${l};
} else if(outC >= end) {
outC = (end - 1) * 2 - outC + ${l};
}
setOutput(getX(outC - start));
}
`;return}this.userCode=`
2022-01-16 15:49:55 +01:00
${s} start = ${s}(${a});
${s} end = ${s}(${o});
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} outC = getOutputCoords();
for (int i = 0; i < ${r}; i++) {
2021-11-08 13:36:26 +01:00
if (outC[i] < start[i]) {
outC[i] = start[i] * 2 - outC[i] - ${l};
} else if(outC[i] >= end[i]) {
outC[i] = (end[i] - 1) * 2 - outC[i] + ${l};
}
}
2022-01-16 15:49:55 +01:00
${s} coords = outC - start;
2021-11-08 13:36:26 +01:00
setOutput(getX(${i}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},ioe=class{constructor(e,t,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.map((h,f)=>h[0]+e[f]+h[1]);let r=e.length,s=wt(r),a=t.map(h=>h[0]).join(","),o=t.map((h,f)=>h[0]+e[f]).join(","),i=qn("rc",r),l=qn("source",r),c=`${i[r-1]} < ${this.outputShape[r-1]}`,u=r===1?"source":`vec2(${l.slice(-2).join()})`,d=n==="reflect"?0:1,p="";if(r===1){let h=`
${s} source = rc;
2021-11-08 13:36:26 +01:00
if (source < start) {
source = start * 2 - source - ${d};
} else if (source >= end) {
source = (end - 1) * 2 - source + ${d};
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
source -= start;
`;p=`
2022-01-16 15:49:55 +01:00
${s} rc = outputLoc;
2021-11-08 13:36:26 +01:00
${h}
result[0] = getChannel(getX(${l.join()}), ${u});
2022-01-16 15:49:55 +01:00
${i[r-1]} += 1;
2021-11-08 13:36:26 +01:00
if(${c}) {
${h}
result[1] = getChannel(getX(${l.join()}), ${u});
}
`}else{let h=`
2022-01-16 15:49:55 +01:00
${s} source = rc;
${s} lt = ${s}(lessThan(source, start));
${s} gte = ${s}(greaterThanEqual(source, end));
${s} orig = 1 - (lt + gte);
2021-11-08 13:36:26 +01:00
source = orig * source +
lt * (start * 2 - source - ${d}) +
gte * ((end - 1) * 2 - source + ${d});
source -= start;
`;p=`
2022-01-16 15:49:55 +01:00
${s} rc = outputLoc;
2021-11-08 13:36:26 +01:00
${h}
result[0] = getChannel(getX(${l.join()}), ${u});
2022-01-16 15:49:55 +01:00
${i[r-1]} += 1;
2021-11-08 13:36:26 +01:00
if(${c}) {
${h}
result[1] = getChannel(getX(${l.join()}), ${u});
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
rc = outputLoc;
2022-01-16 15:49:55 +01:00
${i[r-2]} += 1;
if(${i[r-2]} < ${this.outputShape[r-2]}) {
2021-11-08 13:36:26 +01:00
${h}
result[2] = getChannel(getX(${l.join()}), ${u});
2022-01-16 15:49:55 +01:00
${i[r-1]} += 1;
2021-11-08 13:36:26 +01:00
if(${c}) {
${h}
result[3] = getChannel(getX(${l.join()}), ${u});
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`}this.userCode=`
2022-01-16 15:49:55 +01:00
const ${s} start = ${s}(${a});
const ${s} end = ${s}(${o});
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} outputLoc = getOutputCoords();
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
${p}
setOutput(result);
}
2022-01-16 15:49:55 +01:00
`}},loe=({inputs:e,backend:t,attrs:n})=>{let{x:r}=e,{paddings:s,mode:a}=n,o=Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new ioe(r.shape,s,a):new ooe(r.shape,s,a);return t.runWebGLProgram(o,[r],r.dtype)},uoe={kernelName:lo,backendName:"webgl",kernelFunc:loe},coe=`if (b == 0.0) return NAN;
return mod(a, b);`,doe=`
2021-11-08 13:36:26 +01:00
vec4 result = mod(a, b);
vec4 isNaN = vec4(equal(b, vec4(0.0)));
2022-01-16 15:49:55 +01:00
`+Qm+`
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,poe=Tn({opSnippet:coe,packedOpSnippet:doe}),hoe={kernelName:Cu,backendName:"webgl",kernelFunc:poe},foe=class{constructor(e,t,n){this.variableNames=["probs"],this.customUniforms=[{name:"seed",type:"float"}],this.outputShape=[e,n],this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
float r = random(seed);
float cdf = 0.0;
for (int i = 0; i < ${t-1}; i++) {
cdf += getProbs(batch, i);
if (r < cdf) {
setOutput(float(i));
return;
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
// If no other event happened, last event happened.
setOutput(float(${t-1}));
}
2022-01-16 15:49:55 +01:00
`}},moe=`
2021-11-08 13:36:26 +01:00
if (a == b) {
return 1.0;
};
2022-01-16 15:49:55 +01:00
return a / b;`,goe=`
2021-11-08 13:36:26 +01:00
// vec4 one = vec4(equal(a, b));
// return one + (vec4(1.0) - one) * a / b;
vec4 result = a / b;
if(a.x == b.x) {
result.x = 1.;
}
if(a.y == b.y) {
result.y = 1.;
}
if(a.z == b.z) {
result.z = 1.;
}
if(a.w == b.w) {
result.w = 1.;
}
return result;
2022-01-16 15:49:55 +01:00
`,y4=Tn({opSnippet:moe,packedOpSnippet:goe,checkOutOfBounds:!0}),yoe={kernelName:ja,backendName:"webgl",kernelFunc:y4},A4="return a - b;",x4=Tn({opSnippet:A4,packedOpSnippet:A4,supportsComplex:!0,cpuKernelImpl:fee}),Aoe={kernelName:Io,backendName:"webgl",kernelFunc:x4};function b4(e){let{inputs:t,backend:n,attrs:r}=e,{logits:s}=t,{dim:a}=r,o=w.parseAxisParam([a],s.shape),i=g4({inputs:{x:s},backend:n,attrs:{reductionIndices:o,keepDims:!1}}),l=N.expandShapeToKeepDim(i.shape,o),c=ve({inputs:{x:i},backend:n,attrs:{shape:l}}),u=x4({inputs:{a:s,b:c},backend:n}),d=c4({inputs:{x:u},backend:n}),p=n0({inputs:{x:d},backend:n,attrs:{axis:o,keepDims:!1}}),h=ve({inputs:{x:p},backend:n,attrs:{shape:l}}),f=y4({inputs:{a:d,b:h},backend:n});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(c),n.disposeIntermediateTensorInfo(u),n.disposeIntermediateTensorInfo(d),n.disposeIntermediateTensorInfo(p),n.disposeIntermediateTensorInfo(h),f}var xoe={kernelName:wo,backendName:"webgl",kernelFunc:b4};function boe(e){let{inputs:t,backend:n,attrs:r}=e,{logits:s}=t,{numSamples:a,seed:o,normalized:i}=r,l=i?s:b4({inputs:{logits:s},backend:n,attrs:{dim:s.shape.length-1}}),c=l.shape[0],u=l.shape[1],d=new foe(c,u,a),p=[[o]],h=n.runWebGLProgram(d,[l],"int32",p);return i||n.disposeIntermediateTensorInfo(l),h}var voe={kernelName:af,backendName:"webgl",kernelFunc:boe},woe=os+`
return -x;
2022-01-16 15:49:55 +01:00
`,koe=`
vec4 result = -x;
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
2022-01-16 15:49:55 +01:00
`;function Ioe(e){let{inputs:t,backend:n}=e,{x:r}=t;if(n.shouldExecuteOnCPU([r])){let a=n.texData.get(r.dataId),[o,i]=eee(a.values,r.shape,r.dtype);return n.makeTensorInfo(i,r.dtype,o)}let s;return Y().getBool("WEBGL_PACK_UNARY_OPERATIONS")?s=new $l(r.shape,koe):s=new ua(r.shape,woe),n.runWebGLProgram(s,[r],r.dtype)}var Soe={kernelName:Pi,backendName:"webgl",kernelFunc:Ioe},Coe=ts.nonMaxSuppressionV3Impl;function Toe(e){N.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:t,backend:n,attrs:r}=e,{boxes:s,scores:a}=t,{maxOutputSize:o,iouThreshold:i,scoreThreshold:l}=r,c=n.readSync(s.dataId),u=n.readSync(a.dataId),{selectedIndices:d}=Coe(c,u,o,i,l);return n.makeTensorInfo([d.length],"int32",new Int32Array(d))}var Noe={kernelName:Fi,backendName:"webgl",kernelFunc:Toe},Eoe=ts.nonMaxSuppressionV4Impl;function Roe(e){N.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:t,backend:n,attrs:r}=e,{boxes:s,scores:a}=t,{maxOutputSize:o,iouThreshold:i,scoreThreshold:l,padToMaxOutputSize:c}=r,u=n.readSync(s.dataId),d=n.readSync(a.dataId),{selectedIndices:p,validOutputs:h}=Eoe(u,d,o,i,l,c);return[n.makeTensorInfo([p.length],"int32",new Int32Array(p)),n.makeTensorInfo([],"int32",new Int32Array([h]))]}var _oe={kernelName:Tu,backendName:"webgl",kernelFunc:Roe},Doe=ts.nonMaxSuppressionV5Impl;function Poe(e){N.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:t,backend:n,attrs:r}=e,{boxes:s,scores:a}=t,{maxOutputSize:o,iouThreshold:i,scoreThreshold:l,softNmsSigma:c}=r,u=n.readSync(s.dataId),d=n.readSync(a.dataId),p=o,h=i,f=l,m=c,{selectedIndices:g,selectedScores:y}=Doe(u,d,p,h,f,m);return[n.makeTensorInfo([g.length],"int32",new Int32Array(g)),n.makeTensorInfo([y.length],"float32",new Float32Array(y))]}var $oe={kernelName:Oi,backendName:"webgl",kernelFunc:Poe},Foe=class{constructor(e,t,n,r){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int index = round(getIndices(coords.x));
2022-01-16 15:49:55 +01:00
setOutput(mix(float(${r}), float(${n}),
2021-11-08 13:36:26 +01:00
float(index == coords.y)));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Ooe=e=>{let{inputs:t,backend:n,attrs:r}=e,{indices:s}=t,{depth:a,onValue:o,offValue:i}=r,l=w.sizeFromShape(s.shape),c=new Foe(l,a,o,i),u=ve({inputs:{x:s},backend:n,attrs:{shape:[l]}}),d=n.runWebGLProgram(c,[u],s.dtype);n.disposeIntermediateTensorInfo(u);let p=[...s.shape,a],h=ve({inputs:{x:d},backend:n,attrs:{shape:p}});return n.disposeIntermediateTensorInfo(d),h},Moe={kernelName:zi,backendName:"webgl",kernelFunc:Ooe};function i0(e){let{inputs:t,backend:n}=e,{x:r}=t;if(r.dtype==="complex64"){let s=$p({inputs:{input:r},backend:n}),a=i0({inputs:{x:s},backend:n}),o=o0({inputs:{input:r},backend:n}),i=i0({inputs:{x:o},backend:n}),l=Jo({inputs:{real:a,imag:i},backend:n});return n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(a),n.disposeIntermediateTensorInfo(o),n.disposeIntermediateTensorInfo(i),l}else return Fp({attrs:{shape:r.shape,dtype:r.dtype,value:r.dtype==="string"?"":0},backend:n})}var zoe={kernelName:tl,backendName:"webgl",kernelFunc:i0};function v4(e){let{inputs:t,backend:n}=e,{x:r}=t;if(r.dtype==="string")throw new Error("onesLike is not supported under string dtype");if(r.dtype==="complex64"){let s=$p({inputs:{input:r},backend:n}),a=v4({inputs:{x:s},backend:n}),o=o0({inputs:{input:r},backend:n}),i=i0({inputs:{x:o},backend:n}),l=Jo({inputs:{real:a,imag:i},backend:n});return n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(a),n.disposeIntermediateTensorInfo(o),n.disposeIntermediateTensorInfo(i),l}else return Fp({attrs:{shape:r.shape,dtype:r.dtype,value:1},backend:n})}var Loe={kernelName:Mi,backendName:"webgl",kernelFunc:v4};function Boe(e){let{inputs:t,backend:n,attrs:r}=e,{axis:s}=r;if(t.length===1)return Lx({inputs:{input:t[0]},backend:n,attrs:{dim:s}});let a=t[0].shape,o=t[0].dtype;t.forEach(u=>{w.assertShapesMatch(a,u.shape,"All tensors passed to stack must have matching shapes"),w.assert(o===u.dtype,()=>"All tensors passed to stack must have matching dtypes")});let i=[],l=t.map(u=>{let d=Lx({inputs:{input:u},backend:n,attrs:{dim:s}});return i.push(d),d}),c=t4({inputs:l,backend:n,attrs:{axis:s}});return i.forEach(u=>n.disposeIntermediateTensorInfo(u)),c}var Woe={kernelName:Li,backendName:"webgl",kernelFunc:Boe},Voe=class{constructor(e,t,n){this.variableNames=["x"],this.customUniforms=[{name:"value",type:"float"}],this.outputShape=t.map((l,c)=>l[0]+e[c]+l[1]);let r=e.length,s=wt(r),a=t.map(l=>l[0]).join(","),o=t.map((l,c)=>l[0]+e[c]).join(","),i=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r);if(r===1){this.userCode=`
2021-11-08 13:36:26 +01:00
int start = ${a};
int end = ${o};
2021-09-01 00:24:30 +02:00
2021-11-08 13:36:26 +01:00
void main() {
int outC = getOutputCoords();
if (outC < start || outC >= end) {
setOutput(value);
} else {
setOutput(getX(outC - start));
}
}
`;return}this.userCode=`
2022-01-16 15:49:55 +01:00
${s} start = ${s}(${a});
${s} end = ${s}(${o});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} outC = getOutputCoords();
2021-11-08 13:36:26 +01:00
if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {
setOutput(value);
} else {
2022-01-16 15:49:55 +01:00
${s} coords = outC - start;
2021-11-08 13:36:26 +01:00
setOutput(getX(${i}));
2021-07-29 22:06:03 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Uoe=class{constructor(e,t,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"value",type:"float"}],this.outputShape=t.map((f,m)=>f[0]+e[m]+f[1]);let r=e.length,s=wt(r),a=t.map(f=>f[0]).join(","),o=t.map((f,m)=>f[0]+e[m]).join(","),i=qn("rc",r),l=qn("source",r),c=`${i[r-1]} < ${this.outputShape[r-1]}`,u=r===1?"source":`vec2(${l.slice(-2).join()})`,d=[`${s} rc = outputLoc;`,`${i[r-1]} += 1;
2021-11-08 13:36:26 +01:00
if(${c}) {
2022-01-16 15:49:55 +01:00
`,r===1?"":`}
2021-11-08 13:36:26 +01:00
rc = outputLoc;
2022-01-16 15:49:55 +01:00
${i[r-2]} += 1;
if(${i[r-2]} < ${this.outputShape[r-2]}) {`,r===1?"":` ${i[r-1]} += 1;
if(${c}) {`],p=r===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",h="";for(let f=0,m=r===1?2:4;f<m;f++)h+=`
2021-11-08 13:36:26 +01:00
${d[f]}
if (${p}) {
result[${f}] = float(value);
2021-11-06 15:21:51 +01:00
} else {
2022-01-16 15:49:55 +01:00
${s} source = rc - start;
2021-11-08 13:36:26 +01:00
result[${f}] = getChannel(getX(${l.join()}), ${u});
2021-08-14 17:16:26 +02:00
}
2022-01-16 15:49:55 +01:00
`;h+=r===1?"} ":"}}",this.userCode=`
const ${s} start = ${s}(${a});
const ${s} end = ${s}(${o});
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${s} outputLoc = getOutputCoords();
2021-11-08 13:36:26 +01:00
vec4 result = vec4(0.);
${h}
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},w4=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{paddings:a,constantValue:o}=r;if(w.sizeFromShape(s.shape)===0){let c=a.map((u,d)=>u[0]+s.shape[d]+u[1]);return Fp({backend:n,attrs:{shape:c,value:o,dtype:s.dtype}})}let i=Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new Uoe(s.shape,a,o):new Voe(s.shape,a,o),l=[[o]];return n.runWebGLProgram(i,[s],s.dtype,l)},Goe={kernelName:co,backendName:"webgl",kernelFunc:w4},Hoe=`
2021-11-08 13:36:26 +01:00
if(a < 0.0 && floor(b) < b){
return NAN;
}
if (b == 0.0) {
return 1.0;
}
return (round(mod(b, 2.0)) != 1) ?
pow(abs(a), b) : sign(a) * pow(abs(a), b);
2022-01-16 15:49:55 +01:00
`,joe=`
2021-11-08 13:36:26 +01:00
// isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));
vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);
vec4 result = multiplier * pow(abs(a), b);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
bvec4 isExpZero = equal(b, vec4(0.0));
result.r = isExpZero.r ? 1.0 : result.r;
result.g = isExpZero.g ? 1.0 : result.g;
result.b = isExpZero.b ? 1.0 : result.b;
result.a = isExpZero.a ? 1.0 : result.a;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));
2022-01-16 15:49:55 +01:00
`+Qm+`
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,qoe=Tn({opSnippet:Hoe,packedOpSnippet:joe}),Xoe={kernelName:po,backendName:"webgl",kernelFunc:qoe};function Koe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r,i=s.shape.length,l=[],c=w.parseAxisParam(a,s.shape),u=c,d=N.getAxesPermutation(u,i),p=s;d!=null&&(p=Xn({inputs:{x:s},backend:n,attrs:{perm:d}}),u=N.getInnerMostAxes(u.length,i),l.push(p)),N.assertAxesAreInnerMostDims("prod",u,i);let h;if(n.shouldExecuteOnCPU([p])){let f=n.texData.get(p.dataId).values,{outVals:m,outShape:g,outDtype:y}=nee(p.shape,p.dtype,f,u);h=n.makeTensorInfo(g,y,m)}else{let[f,m]=N.computeOutAndReduceShapes(p.shape,u),g=w.sizeFromShape(m),y=ve({inputs:{x:p},backend:n,attrs:{shape:[-1,g]}}),x=Wd(s.dtype),A=Fl(y,x,"prod",n);h=ve({inputs:{x:A},backend:n,attrs:{shape:f}}),l.push(y),l.push(A)}if(o){l.push(h);let f=N.expandShapeToKeepDim(h.shape,c);h=ve({inputs:{x:h},backend:n,attrs:{shape:f}})}return l.forEach(f=>n.disposeIntermediateTensorInfo(f)),h}var Zoe={kernelName:Bi,backendName:"webgl",kernelFunc:Koe},k4=e=>{let{backend:t,attrs:n}=e,{start:r,stop:s,step:a,dtype:o}=n,i=ree(r,s,a,o);return t.makeTensorInfo([i.length],o,i)},Yoe={kernelName:Nu,backendName:"webgl",kernelFunc:k4},Joe="return 1.0 / x;",Qoe=it({opSnippet:Joe}),eie={kernelName:Eu,backendName:"webgl",kernelFunc:Qoe},tie=os+`
2021-11-08 13:36:26 +01:00
return (x < 0.0) ? 0.0 : x;
2022-01-16 15:49:55 +01:00
`,nie=`
2021-11-08 13:36:26 +01:00
vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,rie=it({opSnippet:tie,packedOpSnippet:nie}),sie={kernelName:fo,backendName:"webgl",kernelFunc:rie},aie=os+`
2021-11-08 13:36:26 +01:00
return (x < 0.0) ? 0.0 : min(6.0, x);
2022-01-16 15:49:55 +01:00
`,oie=`
2021-11-08 13:36:26 +01:00
vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,iie=it({opSnippet:aie,packedOpSnippet:oie}),lie={kernelName:go,backendName:"webgl",kernelFunc:iie},uie=class{constructor(e,t,n,r,s){this.variableNames=["A"],this.outputShape=[];let[a,o,i,l]=e;this.outputShape=[a,t,n,l];let c=[r&&t>1?o-1:o,r&&n>1?i-1:i],u=[r&&t>1?t-1:t,r&&n>1?n-1:n],d;s?d="(vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC - vec2(0.5)":d="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode=`
2021-11-08 13:36:26 +01:00
const vec2 effectiveInputOverOutputRatioRC = vec2(
${c[0]/u[0]},
${c[1]/u[1]});
const vec2 inputShapeRC = vec2(${o}.0, ${i}.0);
2021-09-05 22:42:11 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 yRC = coords.yz;
// Fractional source index.
vec2 sourceFracIndexRC = ${d};
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2(max(sourceFracIndexRC, vec2(0.0)));
ivec2 sourceCeilRC = ivec2(
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);
float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);
float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);
float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);
vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);
float top = topLeft + (topRight - topLeft) * fracRC.y;
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;
float newValue = top + (bottom - top) * fracRC.x;
setOutput(newValue);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},cie=class{constructor(e,t,n,r,s){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];let[a,o,i,l]=e;this.outputShape=[a,t,n,l];let c=[r&&t>1?o-1:o,r&&n>1?i-1:i],u=[r&&t>1?t-1:t,r&&n>1?n-1:n],d;s?d="(vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC - vec3(0.5)":d="vec3(yRC) * effectiveInputOverOutputRatioRC",this.userCode=`
2021-11-08 13:36:26 +01:00
const vec3 effectiveInputOverOutputRatioRC = vec3(
${c[0]/u[0]},
${c[1]/u[1]},
${c[1]/u[1]});
const vec3 inputShapeRC = vec3(${o}.0, ${i}.0,
${i}.0);
float getAValue(int b, int r, int c, int d) {
return getChannel(getA(b, r, c, d), vec2(c, d));
2021-09-05 22:42:11 +02:00
}
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
// Calculate values for next column in yRC.z.
ivec3 yRC = coords.yzz + ivec3(0, 0, 1);
// Fractional source index.
vec3 sourceFracIndexRC = ${d};
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3(max(sourceFracIndexRC, vec3(0.0)));
ivec3 sourceCeilRC = ivec3(
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < ${l-1};
bool hasNextRow = coords.z < ${n-1};
// In parallel, construct four corners for all four components in
// packed 2x2 cell.
vec4 topLeft = vec4(
getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);
vec4 bottomLeft = vec4(
getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);
vec4 topRight = vec4(
getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);
vec4 bottomRight = vec4(
getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);
vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);
vec4 top = mix(topLeft, topRight, fracRC.yyzz);
vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);
vec4 newValue = mix(top, bottom, fracRC.x);
setOutput(newValue);
2021-08-14 17:17:51 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function die(e){let{inputs:t,backend:n,attrs:r}=e,{images:s}=t,{alignCorners:a,halfPixelCenters:o,size:i}=r,[l,c]=i,u=Y().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new cie(s.shape,l,c,a,o):new uie(s.shape,l,c,a,o);return n.runWebGLProgram(u,[s],"float32")}var pie={kernelName:mo,backendName:"webgl",kernelFunc:die},hie=class{constructor(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t;let[,r,s]=t,[,a,o]=e,i=[n&&a>1?r-1:r,n&&o>1?s-1:s],l=[n&&a>1?a-1:a,n&&o>1?o-1:o],c=i[0]/l[0],u=i[1]/l[1],d=1/c,p=1/u,h=Math.ceil(d)*2+2,f=Math.ceil(p)*2+2;this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
int r = coords[1];
int c = coords[2];
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
float accumulator = 0.0;
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
const float heightScale = float(${c});
const float widthScale = float(${u});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
const float invHeightScale = float(${d});
const float invWidthScale = float(${p});
2021-09-11 16:29:31 +02:00
2021-11-08 13:36:26 +01:00
const int winHeight = int(${h});
const int winWidth = int(${f});
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Compute bounds for where in dy we will look
float startRLerp = floor(float(r) * invHeightScale);
int startDyR = int(startRLerp - float(winHeight / 2));
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float startCLerp = floor(float(c) * invWidthScale);
int startDyC = int(startCLerp - float(winWidth / 2));
2021-11-08 13:36:26 +01:00
// Loop over dy
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
int dyR = dyROffset + startDyR;
2021-11-08 13:36:26 +01:00
// Guard against the window exceeding the bounds of dy
if (dyR < 0 || dyR >= ${a}) {
continue;
}
2021-08-14 17:16:26 +02:00
2021-11-08 13:36:26 +01:00
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
int dyC = dyCOffset + startDyC;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Guard against the window exceeding the bounds of dy
if (dyC < 0 || dyC >= ${o}) {
continue;
2021-09-11 16:29:31 +02:00
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float dxR = float(dyR) * heightScale;
int topDxRIndex = int(floor(dxR));
2022-01-16 15:49:55 +01:00
int bottomDxRIndex = int(min(ceil(dxR), ${r-1}.0));
2021-11-08 13:36:26 +01:00
float dxRLerp = dxR - float(topDxRIndex);
float inverseDxRLerp = 1.0 - dxRLerp;
float dxC = float(dyC) * widthScale;
int leftDxCIndex = int(floor(dxC));
2022-01-16 15:49:55 +01:00
int rightDxCIndex = int(min(ceil(dxC), ${s-1}.0));
2021-11-08 13:36:26 +01:00
float dxCLerp = dxC - float(leftDxCIndex);
float inverseDxCLerp = 1.0 - dxCLerp;
if (r == topDxRIndex && c == leftDxCIndex) {
// topLeft
accumulator +=
getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
if (r == topDxRIndex && c == rightDxCIndex) {
// topRight
accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
if (r == bottomDxRIndex && c == leftDxCIndex) {
// bottomLeft
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;
}
if (r == bottomDxRIndex && c == rightDxCIndex) {
// bottomRight
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;
}
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
// End loop over dy
setOutput(accumulator);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function fie(e){let{inputs:t,backend:n,attrs:r}=e,{images:s,dy:a}=t,{alignCorners:o}=r,i=new hie(a.shape,s.shape,o);return n.runWebGLProgram(i,[a],a.dtype)}var mie={kernelName:lf,backendName:"webgl",kernelFunc:fie},gie=class{constructor(e,t,n,r,s){this.variableNames=["A"],this.outputShape=[];let[a,o,i,l]=e;this.outputShape=[a,t,n,l];let c=[r&&t>1?o-1:o,r&&n>1?i-1:i],u=[r&&t>1?t-1:t,r&&n>1?n-1:n],d=r?"0.5":"0.0",p;s?p="max((vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC, vec2(0.0))":p="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode=`
2021-11-08 13:36:26 +01:00
const vec2 effectiveInputOverOutputRatioRC = vec2(
${c[0]/u[0]},
${c[1]/u[1]});
const vec2 inputShapeRC = vec2(${o}.0, ${i}.0);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 yRC = coords.yz;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Fractional source index.
vec2 sourceFracIndexRC = ${p};
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2(
min(inputShapeRC - 1.0, floor(sourceFracIndexRC + ${d})));
float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
setOutput(newValue);
}
2022-01-16 15:49:55 +01:00
`}},yie=class{constructor(e,t,n,r,s){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];let[a,o,i,l]=e;this.outputShape=[a,t,n,l];let c=[r&&t>1?o-1:o,r&&n>1?i-1:i],u=[r&&t>1?t-1:t,r&&n>1?n-1:n],d=r?"0.5":"0.0",p;s?p="max((vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC, vec3(0.0))":p="vec3(yRC) * effectiveInputOverOutputRatioRC",this.userCode=`
2021-11-08 13:36:26 +01:00
const vec3 effectiveInputOverOutputRatioRC = vec3(
${c[0]/u[0]},
${c[1]/u[1]},
${c[1]/u[1]});
const vec3 inputShapeRC = vec3(${o}.0, ${i}.0,
${i}.0);
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float getAValue(int b, int r, int c, int d) {
return getChannel(getA(b, r, c, d), vec2(c, d));
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
// Calculate values for next column in yRC.z.
ivec3 yRC = coords.yzz + ivec3(0, 0, 1);
2021-11-05 18:36:53 +01:00
2021-11-08 13:36:26 +01:00
// Fractional source index.
vec3 sourceFracIndexRC = ${p};
2021-11-05 18:36:53 +01:00
2021-11-08 13:36:26 +01:00
// Compute the coordinators of nearest neighbor point.
ivec3 sourceNearestRC = ivec3(
min(inputShapeRC - 1.0, floor(sourceFracIndexRC + ${d})));
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < ${l-1};
bool hasNextRow = coords.z < ${n-1};
vec4 newValue = vec4(
getAValue(b, sourceNearestRC.x, sourceNearestRC.y, d),
hasNextCol ? getAValue(b, sourceNearestRC.x, sourceNearestRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceNearestRC.x, sourceNearestRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceNearestRC.x, sourceNearestRC.z, d + 1) : 0.0);
setOutput(newValue);
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function Aie(e){let{inputs:t,backend:n,attrs:r}=e,{images:s}=t,{alignCorners:a,halfPixelCenters:o,size:i}=r,[l,c]=i,u=Y().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new yie(s.shape,l,c,a,o):new gie(s.shape,l,c,a,o);return n.runWebGLProgram(u,[s],s.dtype)}var xie={kernelName:Ru,backendName:"webgl",kernelFunc:Aie},bie=class{constructor(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t;let[,r,s]=t,[,a,o]=e,i=[n&&a>1?r-1:r,n&&o>1?s-1:s],l=[n&&a>1?a-1:a,n&&o>1?o-1:o],c=i[0]/l[0],u=i[1]/l[1],d=1/c,p=1/u,h=Math.ceil(d)*2+2,f=Math.ceil(p)*2+2;this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
int r = coords[1];
int c = coords[2];
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float accumulator = 0.0;
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
const float heightScale = float(${c});
const float widthScale = float(${u});
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
const float invHeightScale = float(${d});
const float invWidthScale = float(${p});
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
const int winHeight = int(${h});
const int winWidth = int(${f});
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Compute bounds for where in dy we will look
float startRLerp = floor(float(r) * invHeightScale);
int startDyR = int(floor(startRLerp - float(winHeight / 2)));
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
float startCLerp = floor(float(c) * invWidthScale);
int startDyC = int(floor(startCLerp - float(winWidth / 2)));
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
// Loop over dy
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
int dyR = dyROffset + startDyR;
// Guard against the window exceeding the bounds of dy
if (dyR < 0 || dyR >= ${a}) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
int dyC = dyCOffset + startDyC;
// Guard against the window exceeding the bounds of dy
if (dyC < 0 || dyC >= ${o}) {
continue;
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
float sourceFracRow =
float(${i[0]}) *
(float(dyR) / float(${l[0]}));
float sourceFracCol =
float(${i[1]}) *
(float(dyC) / float(${l[1]}));
int sourceNearestRow = int(min(
2022-01-16 15:49:55 +01:00
float(int(${r}) - 1),
2021-11-08 13:36:26 +01:00
${n} ? float(round(sourceFracRow)) :
float(floor(sourceFracRow))));
int sourceNearestCol = int(min(
2022-01-16 15:49:55 +01:00
float(int(${s}) - 1),
2021-11-08 13:36:26 +01:00
${n} ? float(round(sourceFracCol)) :
float(floor(sourceFracCol))));
if (r == sourceNearestRow && c == sourceNearestCol) {
accumulator += getDy(b, dyR, dyC, d);
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
// End loop over dy
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
setOutput(accumulator);
}
2022-01-16 15:49:55 +01:00
`}};function vie(e){let{inputs:t,backend:n,attrs:r}=e,{images:s,dy:a}=t,{alignCorners:o}=r,i=new bie(a.shape,s.shape,o);return n.runWebGLProgram(i,[a],a.dtype)}var wie={kernelName:of,backendName:"webgl",kernelFunc:vie},kie=class{constructor(e,t){this.variableNames=["x"];let n=e.length;if(n>4)throw new Error(`WebGL backend: Reverse of rank-${n} tensor is not yet supported`);if(this.outputShape=e,n===1){this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
int coord = getOutputCoords();
setOutput(getX(${e[0]} - coord - 1));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;return}let r=o=>t.indexOf(o)!==-1&&e[o]!==1?`${e[o]} - coords[${o}] - 1`:`coords[${o}]`,s=e.map((o,i)=>r(i)).join(","),a=wt(n);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${a} coords = getOutputCoords();
2022-01-16 15:49:55 +01:00
setOutput(getX(${s}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Iie=class{constructor(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;let n=e.length;if(n>4)throw new Error(`WebGL backend: Reverse of rank-${n} tensor is not yet supported`);this.outputShape=e;let r=qn("rc",n),s=`${r[n-1]} + 1 < ${this.outputShape[n-1]}`,a=`${r[n-2]} + 1 < ${this.outputShape[n-2]}`,o=wt(n);n===1?this.userCode=`
2021-11-08 13:36:26 +01:00
void main(){
int rc = getOutputCoords();
vec4 result = vec4(0.);
result.r = getChannel(getX(${e[0]} - rc - 1),
${e[0]} - rc - 1);
2022-01-16 15:49:55 +01:00
if(${s}){
2021-11-08 13:36:26 +01:00
result.g = getChannel(getX(${e[0]} - (rc + 1) - 1),
${e[0]} - (rc + 1) - 1);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(result);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:this.userCode=`
void main() {
${o} rc = getOutputCoords();
vec4 result = vec4(0.);
2022-01-16 15:49:55 +01:00
result.r = ${i(r.slice())};
if(${s}){
result.g = ${l(r.slice())};
2021-11-08 13:36:26 +01:00
}
if(${a}) {
2022-01-16 15:49:55 +01:00
result.b = ${c(r.slice())};
if(${s}) {
result.a = ${u(r.slice())};
2021-11-08 13:36:26 +01:00
}
}
setOutput(result);
}
2022-01-16 15:49:55 +01:00
`;function i(h){return d(h)}function l(h){return h[n-1]="("+h[n-1]+" + 1)",d(h)}function c(h){return h[n-2]="("+h[n-2]+" + 1)",d(h)}function u(h){return h[n-1]="("+h[n-1]+" + 1)",h[n-2]="("+h[n-2]+" + 1)",d(h)}function d(h){let f=e.map((y,x)=>p(x,h)),m=f.join(","),g=f.slice(-2).join(",");return`getChannel(getX(${m}), vec2(${g}))`}function p(h,f){return t.indexOf(h)!==-1&&e[h]!==1?`${e[h]} - ${f[h]} - 1`:`${f[h]}`}}};function Sie(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{dims:a}=r,o=s.shape.length,i=w.parseAxisParam(a,s.shape);if(o===0)return Cr({inputs:{x:s},backend:n});let l=Y().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new Iie(s.shape,i):new kie(s.shape,i);return n.runWebGLProgram(l,[s],s.dtype)}var Cie={kernelName:Vi,backendName:"webgl",kernelFunc:Sie},Tie=class{constructor(e,t){this.variableNames=["Image"],this.outputShape=[],this.customUniforms=[{name:"params",type:"vec4"}];let n=e[1],r=e[2];this.outputShape=e;let s="";typeof t=="number"?s=`float outputValue = ${t.toFixed(2)};`:s=`
2021-11-08 13:36:26 +01:00
vec3 fill = vec3(${t.join(",")});
float outputValue = fill[coords[3]];`,this.userCode=`
void main() {
ivec4 coords = getOutputCoords();
int x = coords[2];
int y = coords[1];
float coordXFloat = (float(x) - params[0]) * params[3] -
(float(y) - params[1]) * params[2];
float coordYFloat = (float(x) - params[0]) * params[2] +
(float(y) - params[1]) * params[3];
int coordX = int(round(coordXFloat + params[0]));
int coordY = int(round(coordYFloat + params[1]));
2022-01-16 15:49:55 +01:00
${s}
if(coordX >= 0 && coordX < ${r} && coordY >= 0 && coordY < ${n}) {
2021-11-08 13:36:26 +01:00
outputValue = getImage(coords[0], coordY, coordX, coords[3]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(outputValue);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Nie={kernelName:nl,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{image:r}=e,{radians:s,fillValue:a,center:o}=t,i=n,l=new Tie(r.shape,a),[c,u]=N.getImageCenter(o,r.shape[1],r.shape[2]),d=[[c,u,Math.sin(s),Math.cos(s)]];return i.runWebGLProgram(l,[r],r.dtype,d)}},Eie=`
2021-11-08 13:36:26 +01:00
// OpenGL ES does not support round function.
// The algorithm is based on banker's rounding.
float base = floor(x);
if ((x - base) < 0.5) {
return floor(x);
} else if ((x - base) > 0.5) {
return ceil(x);
} else {
if (mod(base, 2.0) == 0.0) {
return base;
} else {
return base + 1.0;
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`,Rie=it({opSnippet:Eie}),_ie={kernelName:Ui,backendName:"webgl",kernelFunc:Rie},Die="return inversesqrt(x);",Pie=it({opSnippet:Die,cpuKernelImpl:see}),$ie={kernelName:yo,backendName:"webgl",kernelFunc:Pie},I4=class{constructor(e,t,n,r,s,a,o=!0){this.variableNames=["updates","indices","defaultValue"],this.outputShape=a;let i=wt(s.length),l=wt(a.length),c="";n===1?c="i":n===2&&(c="i, j");let u=`getIndices(${c})`,d="";r===1?d="i":r===2&&(d="i, coords[1]");let p=`getUpdates(${d})`,h=t>1?"strides[j]":"strides";this.userCode=`
${i} strides = ${i}(${s});
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
void main() {
${l} coords = getOutputCoords();
float sum = 0.0;
bool found = false;
for (int i = 0; i < ${e}; i++) {
int flattenedIndex = 0;
for (int j = 0; j < ${t}; j++) {
int index = round(${u});
flattenedIndex += index * ${h};
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (flattenedIndex == coords[0]) {
sum += ${p};
found = true;
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
setOutput(mix(getDefaultValue(), sum, float(found)));
}
2022-01-16 15:49:55 +01:00
`}};function Fie(e){let{inputs:t,backend:n,attrs:r}=e,{indices:s,updates:a}=t,{shape:o}=r,{sliceRank:i,numUpdates:l,sliceSize:c,strides:u,outputSize:d}=N.calculateShapes(a,s,o),p=[d/c,c];if(d===0)return n.makeTensorInfo(o,s.dtype);let h=ve({inputs:{x:s},backend:n,attrs:{shape:[l,i]}}),f=ve({inputs:{x:a},backend:n,attrs:{shape:[l,c]}}),m=n.makeTensorInfo([],"float32",new Float32Array([0])),g=new I4(l,i,h.shape.length,f.shape.length,u,p),y=n.runWebGLProgram(g,[f,h,m],f.dtype),x=ve({inputs:{x:y},backend:n,attrs:{shape:o}});return n.disposeIntermediateTensorInfo(h),n.disposeIntermediateTensorInfo(f),n.disposeIntermediateTensorInfo(y),n.disposeIntermediateTensorInfo(m),x}var Oie={kernelName:Gi,backendName:"webgl",kernelFunc:Fie},Mie=class{constructor(e,t,n){this.variableNames=["c","a","b"],this.outputShape=t;let r,s;if(n>4)throw Error(`Where for rank ${n} is not yet supported`);if(n===1)s="resRC",r="resRC";else{let o=["resRC.x","resRC.y","resRC.z","resRC.w"],i=[],l=[];for(let c=0;c<t.length;c++)l.push(`${o[c]}`),c<e&&i.push(`${o[c]}`);r=i.join(),s=l.join()}let a=wt(n);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
${a} resRC = getOutputCoords();
2022-01-16 15:49:55 +01:00
float cVal = getC(${r});
2021-11-08 13:36:26 +01:00
if (cVal >= 1.0) {
2022-01-16 15:49:55 +01:00
setOutput(getA(${s}));
2021-11-08 13:36:26 +01:00
} else {
2022-01-16 15:49:55 +01:00
setOutput(getB(${s}));
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function zie(e){let{inputs:t,backend:n}=e,{condition:r,t:s,e:a}=t,o=new Mie(r.shape.length,s.shape,s.shape.length);return n.runWebGLProgram(o,[r,s,a],Wn(s.dtype,a.dtype))}var Lie={kernelName:Hi,backendName:"webgl",kernelFunc:zie},Bie=`
2021-11-08 13:36:26 +01:00
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
2021-12-01 14:27:05 +01:00
float scaleAlpha = ${N.SELU_SCALEALPHA};
float scale = ${N.SELU_SCALE};
2021-11-08 13:36:26 +01:00
return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);
2022-01-16 15:49:55 +01:00
`,Wie=it({opSnippet:Bie}),Vie={kernelName:_u,backendName:"webgl",kernelFunc:Wie},Uie=vc+`
return 1.0 / (1.0 + exp(-1.0 * x));
2022-01-16 15:49:55 +01:00
`,Gie=`
vec4 result = 1.0 / (1.0 + exp(-1.0 * x));
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
2022-01-16 15:49:55 +01:00
`,Hie=it({opSnippet:Uie,packedOpSnippet:Gie,cpuKernelImpl:aee}),jie={kernelName:xo,backendName:"webgl",kernelFunc:Hie},qie=`
2021-11-08 13:36:26 +01:00
if (isnan(x)) { return 0.0; }
return sign(x);
2022-01-16 15:49:55 +01:00
`,Xie=it({opSnippet:qie}),Kie={kernelName:Du,backendName:"webgl",kernelFunc:Xie},Zie=vc+`
2021-11-08 13:36:26 +01:00
return sin(x);
2022-01-16 15:49:55 +01:00
`,Yie=it({opSnippet:Zie}),Jie={kernelName:Ao,backendName:"webgl",kernelFunc:Yie},Qie=`
2021-11-08 13:36:26 +01:00
float e2x = exp(x);
return (e2x - 1.0 / e2x) / 2.0;
2022-01-16 15:49:55 +01:00
`,ele=it({opSnippet:Qie}),tle={kernelName:qi,backendName:"webgl",kernelFunc:ele},nle=`
2021-11-08 13:36:26 +01:00
float epsilon = 1.1920928955078125e-7;
float threshold = log(epsilon) + 2.0;
bool too_large = x > -threshold;
bool too_small = x < threshold;
float result;
float exp_x = exp(x);
if (too_large){
result = x;
}
else if (too_small){
result = exp_x;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
else{
result = log(exp_x + 1.0);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
return result;
2022-01-16 15:49:55 +01:00
`,rle=it({opSnippet:nle}),sle={kernelName:Pu,backendName:"webgl",kernelFunc:rle},ale=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockShape:a,paddings:o}=r;w.assert(s.shape.length<=4,()=>"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet");let i=a.reduce((y,x)=>y*x),l=[[0,0]];l.push(...o);for(let y=1+a.length;y<s.shape.length;++y)l.push([0,0]);let c=[],u=w4({inputs:{x:s},backend:n,attrs:{paddings:l,constantValue:0}}),d=N.getReshaped(u.shape,a,i,!1),p=N.getPermuted(d.length,a.length,!1),h=N.getReshapedPermuted(u.shape,a,i,!1),f=ve({inputs:{x:u},backend:n,attrs:{shape:d}}),m=Xn({inputs:{x:f},backend:n,attrs:{perm:p}}),g=ve({inputs:{x:m},backend:n,attrs:{shape:h}});return c.push(u),c.push(f),c.push(m),c.forEach(y=>n.disposeIntermediateTensorInfo(y)),g},ole={kernelName:Xi,backendName:"webgl",kernelFunc:ale};function ile(e){let{inputs:t,backend:n}=e,{indices:r,values:s,denseShape:a,defaultValue:o}=t;if(a.shape.length!==1)throw new Error(`Dense shape must be a vector, saw:
${a.shape}`);if(r.shape.length!==2)throw new Error(`Indices must be a matrix, saw:
${r.shape}`);if(s.shape.length!==1)throw new Error(`Values must be a vector, saw:
${s.shape}`);if(o.shape.length!==0)throw new Error(`Default value must be a scalar, saw:
${o.shape}`);let i=n.readSync(r.dataId),l=n.readSync(s.dataId),c=n.readSync(a.dataId),u=n.readSync(o.dataId)[0],[d,p,h,f,m]=iee(i,r.shape,r.dtype,l,s.dtype,c,u);return[n.makeTensorInfo(p,r.dtype,d),n.makeTensorInfo([p[0]],s.dtype,h),n.makeTensorInfo([f.length],"bool",new Uint8Array(f.map(g=>Number(g)))),n.makeTensorInfo([m.length],r.dtype,new Int32Array(m))]}var lle={kernelName:Cd,backendName:"webgl",kernelFunc:ile};function ule(e){let{inputs:t,backend:n}=e,{inputIndices:r,inputShape:s,newShape:a}=t;if(r.shape.length!==2)throw new Error(`Input indices should be a matrix but received shape ${r.shape}`);if(s.shape.length!==1)throw new Error(`Input shape should be a vector but received shape ${s.shape}`);if(a.shape.length!==1)throw new Error(`Target shape should be a vector but received shape ${a.shape}`);let o=Array.from(n.readSync(s.dataId)),i=n.readSync(r.dataId),l=Array.from(n.readSync(a.dataId)),[c,u,d]=lee(i,r.shape,r.dtype,o,l);return[n.makeTensorInfo(u,r.dtype,c),n.makeTensorInfo([d.length],a.dtype,new Int32Array(d))]}var cle={kernelName:$u,backendName:"webgl",kernelFunc:ule};function dle(e){let{inputs:t,backend:n}=e,{data:r,indices:s,segmentIds:a}=t;if(r.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.shape.length!==1)throw new Error(`Indices should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Segment ids should be a vector but received shape
${a.shape}`);let o=n.readSync(r.dataId),i=n.readSync(s.dataId),l=n.readSync(a.dataId),[c,u]=TC(o,r.shape,r.dtype,i,l,!0);return n.makeTensorInfo(u,r.dtype,c)}var ple={kernelName:Td,backendName:"webgl",kernelFunc:dle};function hle(e){let{inputs:t,backend:n}=e,{data:r,indices:s,segmentIds:a}=t;if(r.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(s.shape.length!==1)throw new Error(`Indices should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Segment ids should be a vector but received shape
${a.shape}`);let o=n.readSync(r.dataId),i=n.readSync(s.dataId),l=n.readSync(a.dataId),[c,u]=TC(o,r.shape,r.dtype,i,l);return n.makeTensorInfo(u,r.dtype,c)}var fle={kernelName:Nd,backendName:"webgl",kernelFunc:hle};function mle(e){let{inputs:t,backend:n,attrs:r}=e,{sparseIndices:s,sparseValues:a,defaultValue:o}=t,{outputShape:i}=r,{sliceRank:l,numUpdates:c,strides:u,outputSize:d}=N.calculateShapes(a,s,i),p=!1,h=new I4(c,l,s.shape.length,a.shape.length,u,[d,1],p),f=n.runWebGLProgram(h,[a,s,o],a.dtype),m=ve({inputs:{x:f},backend:n,attrs:{shape:i}});return n.disposeIntermediateTensorInfo(f),m}var gle={kernelName:Ed,backendName:"webgl",kernelFunc:mle};function yle(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{numOrSizeSplits:a,axis:o}=r,i=w.parseAxisParam(o,s.shape)[0],l=N.prepareSplitSize(s,a,i),c=s.shape.length,u=new Array(c).fill(0),d=s.shape.slice();return l.map(p=>{let h=[...d];h[i]=p;let f=wc({inputs:{x:s},backend:n,attrs:{begin:u,size:h}});return u[i]+=p,f})}var Ale={kernelName:Ki,backendName:"webgl",kernelFunc:yle},S4="return sqrt(x);",xle=it({opSnippet:S4,packedOpSnippet:S4,cpuKernelImpl:uee}),ble={kernelName:bo,backendName:"webgl",kernelFunc:xle},vle="return x * x;",wle=it({opSnippet:vle}),kle={kernelName:Fu,backendName:"webgl",kernelFunc:wle},C4="return (a - b) * (a - b);",Ile=Tn({opSnippet:C4,packedOpSnippet:C4}),Sle={kernelName:ko,backendName:"webgl",kernelFunc:Ile};function Cle({inputs:e,attrs:t,backend:n}){let{x:r}=e,s=os+`
2021-11-08 13:36:26 +01:00
return x > 0.0 ? 1.0 : float(${t.alpha});
2022-01-16 15:49:55 +01:00
`,a=new ua(r.shape,s);return n.runWebGLProgram(a,[r],r.dtype)}var Tle={kernelName:To,backendName:"webgl",kernelFunc:Cle},Nle=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=n;let r=n.length,s=wt(n.length),a=wt(n.length),o="";if(r===1)o="coords * strides + begin";else{let i=0;o=n.map((l,c)=>(i++,n.length===1?`coords * strides[${c}] + begin[${c}]`:`coords[${i-1}] * strides[${c}] + begin[${c}]`)).join(",")}this.userCode=`
${s} begin = ${s}(${e});
${s} strides = ${s}(${t});
2021-11-08 13:36:26 +01:00
void main() {
${a} coords = getOutputCoords();
setOutput(getX(${o}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Ele(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{begin:a,end:o,strides:i,beginMask:l,endMask:c,ellipsisMask:u,newAxisMask:d,shrinkAxisMask:p}=r,{finalShapeSparse:h,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:x,end:A,strides:b}=zt.sliceInfo(s.shape,a,o,i,l,c,u,d,p),v;if(m)v=ve({inputs:{x:s},backend:n,attrs:{shape:f}});else if(g||y){w.assert(s.shape.length>=1,()=>`Input must have rank at least 1, got: ${s.shape.length}`);let I=zt.computeOutShape(x,A,b),E=wc({inputs:{x:s},backend:n,attrs:{begin:x,size:I}});v=ve({inputs:{x:E},backend:n,attrs:{shape:f}}),n.disposeIntermediateTensorInfo(E)}else if(n.shouldExecuteOnCPU([s])){let E=n.readSync(s.dataId),R=Le(s.shape,s.dtype,E),F=cee(h,R,b,x);v=n.makeTensorInfo(f,s.dtype,F.values)}else{let E=new Nle(x,b,h);v=n.runWebGLProgram(E,[s],s.dtype)}let C=ve({inputs:{x:v},backend:n,attrs:{shape:f}});return n.disposeIntermediateTensorInfo(v),C}var Rle={kernelName:Zi,backendName:"webgl",kernelFunc:Ele};function _le(e){let{inputs:t,backend:n,attrs:r}=e,{separator:s,nGramWidths:a,leftPad:o,rightPad:i,padWidth:l,preserveShortSequences:c}=r,{data:u,dataSplits:d}=t,p=n.readSync(u.dataId),h=n.readSync(d.dataId),[f,m]=dee(p,h,s,a,o,i,l,c);return[n.makeTensorInfo([f.length],"string",f),n.makeTensorInfo(d.shape,"int32",m)]}var Dle={kernelName:Rd,backendName:"webgl",kernelFunc:_le};function Ple(e){let{inputs:t,backend:n,attrs:r}=e,{skipEmpty:s}=r,{input:a,delimiter:o}=t;if(a.dtype!=="string")throw new Error("Input must be of datatype string");if(a.shape.length!==1)throw new Error(`Input must be a vector, got shape: ${a.shape}`);if(o.shape.length!==0)throw new Error(`Delimiter must be a scalar, got shape: ${o.shape}`);let i=n.readSync(a.dataId),l=n.readSync(o.dataId)[0],[c,u,d]=pee(i,l,s),p=u.length;return[n.makeTensorInfo([p,2],"int32",c),n.makeTensorInfo([p],"string",u),n.makeTensorInfo([2],"int32",new Int32Array(d))]}var $le={kernelName:uf,backendName:"webgl",kernelFunc:Ple};function Fle(e){let{inputs:t,backend:n,attrs:r}=e,{numBuckets:s}=r,{input:a}=t;if(a.dtype!=="string")throw new Error("Input must be of datatype string");if(s<=0)throw new Error("Number of buckets must be at least 1");let o=n.readSync(a.dataId),i=hee(o,s);return n.makeTensorInfo(a.shape,"int32",i)}var Ole={kernelName:cf,backendName:"webgl",kernelFunc:Fle},Mle="return tan(x);",zle=it({opSnippet:Mle}),Lle={kernelName:Yi,backendName:"webgl",kernelFunc:zle},Ble=`
2021-11-08 13:36:26 +01:00
float e2x = exp(-2.0 * abs(x));
return sign(x) * (1.0 - e2x) / (1.0 + e2x);
2022-01-16 15:49:55 +01:00
`,Wle=it({opSnippet:Ble}),Vle={kernelName:So,backendName:"webgl",kernelFunc:Wle},Ule=class{constructor(e,t){this.variableNames=["A"];let n=new Array(e.length);for(let a=0;a<n.length;a++)n[a]=e[a]*t[a];this.outputShape=n,this.rank=n.length;let r=wt(this.rank),s=Gle(e);this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
2022-01-16 15:49:55 +01:00
${r} resRC = getOutputCoords();
setOutput(getA(${s}));
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Gle(e){let t=e.length;if(t>5)throw Error(`Tile for rank ${t} is not yet supported`);if(t===1)return`imod(resRC, ${e[0]})`;let n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],r=[];for(let s=0;s<e.length;s++)r.push(`imod(${n[s]}, ${e[s]})`);return r.join()}function T4(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{reps:a}=r;if(s.dtype==="string"||s.shape.length>5){let l=n.readSync(s.dataId),c=s.dtype==="string"?l.map(p=>w.decodeString(p)):l,u=Le(s.shape,s.dtype,c),d=mee(u,a);return n.makeTensorInfo(d.shape,d.dtype,d.values)}let o=new Ule(s.shape,a);return n.runWebGLProgram(o,[s],s.dtype)}var Hle={kernelName:Js,backendName:"webgl",kernelFunc:T4},jle=class{constructor(e){this.variableNames=["x","indices"],this.customUniforms=[{name:"n",type:"int"},{name:"firstPass",type:"int"},{name:"negativeInf",type:"float"},{name:"dir",type:"int"},{name:"inc",type:"int"}],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int elemIdx = coords[1];
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
// We compare elements pair-wise within a group of size 2 * inc.
// The comparing rule for each group alternates between ascending
// and descending. Within each group, we compare each pair at
// positions i and i+inc. To decide whether an element at position i
// is x0 or x1, we mod it by 2 * inc, if the result is smaller than
// inc, it is in the first half of the group, we denote it as x0,
// otherwise we denote it as x1.
// For example, as shown in the Bitonic top K paper referenced above,
// Figure5(a) shows that element[1] is in the
// second half of the group when group size is 2, but it is in the
// first half of the group when group size is 4.
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
bool isFirstInPair = imod(elemIdx, 2 * inc) < inc;
int i = isFirstInPair ? elemIdx : elemIdx - inc;
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
int i0 = firstPass == 1 ? i : int(getIndices(batch, i));
int i1 = firstPass == 1 ? i + inc : int(getIndices(batch, i + inc));
float x0 = i0 < n ? getX(batch, i0) : negativeInf;
float x1 = i1 < n ? getX(batch, i1) : negativeInf;
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
// Denotes which direction indices are in (ascending or descending).
bool reverse = imod(elemIdx, 2 * dir) >= dir;
bool isGreater = x0 > x1 || (x0 == x1 && i1 > i0);
if (reverse == isGreater) { // Elements in opposite order of direction
int iTemp = i0;
i0 = i1;
i1 = iTemp;
}
if (isFirstInPair) {
setOutput(float(i0));
} else {
setOutput(float(i1));
}
}
2022-01-16 15:49:55 +01:00
`}},qle=class{constructor(e){this.variableNames=["x","indices"],this.customUniforms=[{name:"n",type:"int"},{name:"firstPass",type:"int"},{name:"k",type:"int"}],this.outputShape=e,this.userCode=`
2021-11-08 13:36:26 +01:00
void main() {
// Takes max of indices (0, k), (1, k + 1), (2, k + 2) ...
ivec2 coords = getOutputCoords();
int batch = coords[0];
int elemIdx = coords[1];
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
// The output size is half of the previous size.
// If the previous sequence is | | | | _ _ _ _ | | | | _ _ _ _ (k=4),
// we only need to output the indices at positions |, the indices at
// positions _ can be thrown away, see Figure5(b) After Phase 2
// (Merge phase) in the Bitonic Top K paper referenced above.
// For example, the paper shows we only need to output the orange bars.
// The output sequence should look like this | | | | | | | |.
// Because the sequence is halved, to map the output index back
// to the previous sequence to find the corresponding value,
// we need to double the index. When we double the index,
// we basically interpolate a position, so 2i looks like
// | _ | _ | _ | _ | _ | _ | _. We move the | to the first k position
// of each 2k positions by - elemIdx % k. E.g. for output at
// index 4,5,6,7, we want to get the corresponding element at
// original index 8,9,10,11, for output at index 8,9,10,11,
// we want to get the corresponding element at original index
// 16,17,18,19, so on and so forth.
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
int i = elemIdx < k ? elemIdx : (elemIdx * 2 - imod(elemIdx, k));
int i0 = firstPass == 1 ? i : int(getIndices(batch, i));
int i1 = firstPass == 1 ? i + k : int(getIndices(batch, i + k));
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
float x0 = getX(batch, i0);
float x1 = i1 < n ? getX(batch, i1) : x0;
setOutput(x0 >= x1 ? float(i0) : float(i1));
}
2022-01-16 15:49:55 +01:00
`}};function Ol(e,t){t!==null&&e.disposeIntermediateTensorInfo(t)}function N4(e){let t=1;for(;t<e;)t*=2;return t}function Xle(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{k:a,sorted:o}=r,i=Y().getNumber("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD"),l=Y().getNumber("TOPK_K_CPU_HANDOFF_THRESHOLD"),c=s.shape,u=c[c.length-1];if(n.shouldExecuteOnCPU([s])||u<i||a>l){let F=n.readSync(s.dataId),[_,P]=gee(F,c,s.dtype,a,o);return[n.makeTensorInfo(_.shape,_.dtype,_.values),n.makeTensorInfo(P.shape,P.dtype,P.values)]}if(a===0)return c[c.length-1]=0,[n.makeTensorInfo(c,s.dtype,[]),n.makeTensorInfo(c,"int32",[])];if(u===1)return[s,Fp({attrs:{shape:c,dtype:"int32",value:0},backend:n})];let d=n.texData.get(s.dataId),p=d!==null&&d.isPacked,h=p?n.unpackTensor(s):s,m=w.sizeFromShape(c)/u,g=ve({inputs:{x:h},attrs:{shape:[m,u]},backend:n});p&&Ol(n,h);let y=N4(a),x=N4(u),A=null,b=()=>A===null?[g,g]:[g,A],v=(F,_,P)=>{let T=b(),O=new jle(P),K=[[u],[A===null?1:0],[Number.NEGATIVE_INFINITY],[F],[_]],z=A;A=n.runWebGLProgram(O,T,"int32",K),Ol(n,z)};for(let F=1;F<y;F*=2){let _=F*2;for(let P=F;P>=1;P/=2)v(_,P,[m,x])}for(let F=x;F>y;F/=2){let _=b(),P=new qle([m,F/2]),O=[[u],[A===null?1:0],[y]],G=A;A=n.runWebGLProgram(P,_,"int32",O),Ol(n,G);let K=y/2,z=K*2;for(let j=K;j>=1;j/=2)v(z,j,A.shape)}let C=A;A=wc({inputs:{x:A},backend:n,attrs:{begin:0,size:[m,a]}}),Ol(n,C);let I=m4({inputs:{x:g,indices:A},backend:n,attrs:{axis:1,batchDims:1}});Ol(n,g);let E=c.slice(0,-1);E.push(a),C=A,A=ve({inputs:{x:A},attrs:{shape:E},backend:n}),Ol(n,C);let R=I;return I=ve({inputs:{x:I},attrs:{shape:E},backend:n}),Ol(n,R),[I,A]}var Kle={kernelName:Ji,backendName:"webgl",kernelFunc:Xle},Zle=class{constructor(e,t,n,r,s,a){this.variableNames=["Image","Transforms"],this.outputShape=a;let o=n==="nearest"?1:2,i;switch(r){case"constant":i=1;break;case"reflect":i=2;break;case"wrap":i=3;break;case"nearest":i=4;break;default:i=1;break}this.userCode=`
2021-11-08 13:36:26 +01:00
float mapCoord(float outCoord, float len) {
float inCoord = outCoord;
if(${i} == 2) {
if (inCoord < 0.0) {
if (len <= 1.0) {
inCoord = 0.0;
} else {
float sz2 = 2.0 * len;
if (inCoord < sz2) {
inCoord = sz2 * float(int(float(-inCoord / sz2))) +
inCoord;
}
inCoord = inCoord < -len ? inCoord + sz2 : -inCoord - 1.0;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
} else if (inCoord > len - 1.0) {
if (len <= 1.0) {
inCoord = 0.0;
2021-11-06 15:21:51 +01:00
} else {
2021-11-08 13:36:26 +01:00
float sz2 = 2.0 * len;
inCoord -= sz2 * float(int(float(inCoord / sz2)));
if (inCoord >= len) {
inCoord = sz2 - inCoord - 1.0;
}
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
return clamp(inCoord, 0.0, len - 1.0);
} else if (${i} == 3) {
if (inCoord < 0.0) {
if (len <= 1.0) {
inCoord = 0.0;
} else {
float sz = len - 1.0;
inCoord += len * (float(int(float(-inCoord / sz))) + 1.0);
}
} else if (inCoord > len - 1.0) {
if (len <= 1.0) {
inCoord = 0.0;
} else {
float sz = len - 1.0;
inCoord -= len * float(int(float(inCoord / sz)));
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
return clamp(inCoord, 0.0, len - 1.0);
} else if (${i} == 4) {
return clamp(outCoord, 0.0, len - 1.0);
} else {
return outCoord;
2021-11-06 15:21:51 +01:00
}
}
2021-11-08 13:36:26 +01:00
float readWithFillValue(int batch, int coordY, int coordX,
int channel) {
float outputValue;
if (0 <= coordY && coordY < ${e} && 0 <= coordX && coordX < ${t}) {
outputValue = getImage(batch, coordY, coordX, channel);
} else {
2022-01-16 15:49:55 +01:00
outputValue = float(${s});
2021-11-08 13:36:26 +01:00
}
return outputValue;
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
void main() {
ivec4 coords = getOutputCoords();
float outputValue;
int batch = coords[0];
int x = coords[2];
int y = coords[1];
int channel = coords[3];
float xf = float(x);
float yf = float(y);
float a1 = getTransforms(batch, 0);
float a2 = getTransforms(batch, 1);
float a3 = getTransforms(batch, 2);
float b1 = getTransforms(batch, 3);
float b2 = getTransforms(batch, 4);
float b3 = getTransforms(batch, 5);
float c1 = getTransforms(batch, 6);
float c2 = getTransforms(batch, 7);
float projection = c1 * xf + c2 * yf + 1.0;
2021-11-06 15:21:51 +01:00
if (projection == 0.0) {
2022-01-16 15:49:55 +01:00
outputValue = float(${s});
2021-11-06 15:21:51 +01:00
} else {
2021-11-08 13:36:26 +01:00
float inX = (a1 * xf + a2 * yf + a3) / projection;
float inY = (b1 * xf + b2 * yf + b3) / projection;
float mapX = mapCoord(inX, float(${t}));
float mapY = mapCoord(inY, float(${e}));
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
if (${o} == 1) {
int coordY = int(round(mapY));
int coordX = int(round(mapX));
2021-11-06 15:21:51 +01:00
outputValue = readWithFillValue(batch, coordY, coordX,
channel);
} else {
2021-11-08 13:36:26 +01:00
float yFloor = floor(mapY);
float xFloor = floor(mapX);
float yCeil = yFloor + 1.0;
float xCeil = xFloor + 1.0;
float valueYFloor = (xCeil - mapX) *
readWithFillValue(batch, int(yFloor), int(xFloor), channel) +
2021-11-06 15:21:51 +01:00
(mapX - xFloor) *
2021-11-08 13:36:26 +01:00
readWithFillValue(batch, int(yFloor), int(xCeil), channel);
float valueYCeil = (xCeil - mapX) *
readWithFillValue(batch, int(yCeil), int(xFloor), channel) +
2021-11-06 15:21:51 +01:00
(mapX - xFloor) *
2021-11-08 13:36:26 +01:00
readWithFillValue(batch, int(yCeil), int(xCeil), channel);
2021-11-06 15:21:51 +01:00
outputValue = (yCeil - mapY) * valueYFloor +
(mapY - yFloor) * valueYCeil;
}
}
2021-11-08 13:36:26 +01:00
setOutput(outputValue);
}
2022-01-16 15:49:55 +01:00
`}};function Yle(e){let{inputs:t,backend:n,attrs:r}=e,{image:s,transforms:a}=t,{interpolation:o,fillMode:i,fillValue:l,outputShape:c}=r,[u,d,p,h]=s.shape,[f,m]=c!=null?c:[d,p],g=[u,f,m,h],y=new Zle(d,p,o,i,l,g);return n.runWebGLProgram(y,[s,a],"float32")}var Jle={kernelName:Qi,backendName:"webgl",kernelFunc:Yle};function Qle(e){let{inputs:t,attrs:n,backend:r}=e,{axis:s}=n,{x:a}=t;hc(a,"unique"),console.warn("WARNING: ","UI might be locked temporarily as data is being downloaded");let o=r.readSync(a.dataId),{outputValues:i,outputShape:l,indices:c}=yee(o,s,a.shape,a.dtype);return[r.makeTensorInfo(l,a.dtype,i),r.makeTensorInfo([c.length],"int32",c)]}var eue={kernelName:df,backendName:"webgl",kernelFunc:Qle};function tue(e){let{inputs:t,backend:n,attrs:r}=e,{value:s}=t,{axis:a}=r;a<0&&(a+=s.shape.length);let o=s,i=o.shape.length,l=s.shape[a],c=new Array(i-1),u=0;for(let m=0;m<i;m++)m!==a&&(c[u++]=o.shape[m]);let d=[],p=new Array(i).fill(0),h=o.shape.slice();h[a]=1;let f=new Array(l);for(let m=0;m<f.length;m++){p[a]=m;let g=wc({inputs:{x:o},backend:n,attrs:{begin:p,size:h}}),y=ve({inputs:{x:g},backend:n,attrs:{shape:c}});f[m]=y,d.push(g)}return d.forEach(m=>n.disposeIntermediateTensorInfo(m)),f}var nue={kernelName:el,backendName:"webgl",kernelFunc:tue},rue=class{constructor(e,t){this.variableNames=["x","segmentIds"];let n=e.windowSize,r=e.batchSize,s=e.inSize,a=e.numSegments,o=a*Math.ceil(s/n);this.outputShape=[r,o];let i="0.0",l="sumValue",c=Math.floor(n/4)*4,u=n%4,d=`
2021-11-08 13:36:26 +01:00
sumValue += dot(values, segFilter);
2022-01-16 15:49:55 +01:00
`,p="";s%n>0&&(p=`
if (inIdx < 0 || inIdx >= ${s}) {
2021-11-08 13:36:26 +01:00
return initializationValue;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`);let h="";s%n>0&&(h=`
if (inIdx < 0 || inIdx >= ${s}) {
2021-11-08 13:36:26 +01:00
return -1.0;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
`),this.userCode=`
const float initializationValue = ${i};
float getValue(int batch, int inIdx) {
${p}
return getX(batch, inIdx);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
float getSegmentIdAtIndex(int inIdx) {
${h}
return getSegmentIds(inIdx);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = int(floor(float(outIdx) / float(
${a})) * float(${n}));
int currentSeg = int(mod(float(outIdx), float(${a})));
float sumValue = 0.0;
for (int i = 0; i < ${c}; i += 4) {
int inIdx = inOffset + i;
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0
);
${d}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
int inIdx = inOffset + ${c};
if (${u===1}) {
vec4 values = vec4(
getValue(batch, inIdx),
initializationValue,
initializationValue,
initializationValue
);
int inIdxSeg = int(getSegmentIdAtIndex(inIdx));
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
0,
0,
0
);
${d}
} else if (${u===2}) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
initializationValue,
initializationValue
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
0,
0
);
${d}
} else if (${u===3}) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
initializationValue
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
0
);
${d}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
setOutput(${l});
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function sue(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,segmentIds:a}=t,{numSegments:o}=r,i=s.shape.length,l=[],c=0,u=N.getAxesPermutation([c],i),d=s;u!=null&&(d=Xn({inputs:{x:s},backend:n,attrs:{perm:u}}),l.push(d),c=N.getInnerMostAxes(1,i)[0]);let p=N.segment_util.computeOutShape(d.shape,c,o),h=w.sizeFromShape([d.shape[c]]),f=ve({inputs:{x:d},backend:n,attrs:{shape:[-1,h]}});l.push(f);let m=Wd(s.dtype),g=(b,v,C,I,E)=>{let R=b.shape[0],F=b.shape[1],_=N.segment_util.segOpComputeOptimalWindowSize(F,E),P={windowSize:_,inSize:F,batchSize:R,numSegments:E},T=new rue(P,v),O=n.compileAndRun(T,[b,C],I);if(l.push(O),O.shape[1]===E)return O;let G=k4({backend:n,attrs:{start:0,stop:E,step:1,dtype:"float32"}}),K=T4({inputs:{x:G},backend:n,attrs:{reps:[F/_]}});return l.push(G),l.push(K),g(O,v,K,I,E)},y=g(f,"unsortedSegmentSum",a,m,o),x=ve({inputs:{x:y},backend:n,attrs:{shape:p}}),A=x;if(u!=null){l.push(x);let b=N.getUndoAxesPermutation(u);A=Xn({inputs:{x:A},backend:n,attrs:{perm:b}})}return l.forEach(b=>n.disposeIntermediateTensorInfo(b)),A}var aue={kernelName:_d,backendName:"webgl",kernelFunc:sue},oue=[pte,fte,yte,bte,wte,Ste,Tte,Ete,Pte,Fte,zte,Wte,Gte,Xte,Yte,Qte,tne,ane,ine,une,hne,bne,wne,Ine,Rne,Dne,One,qee,Lne,Gne,Xne,ere,nre,sre,ore,lre,dre,fre,yre,xre,vre,Ire,Cre,Rre,Dre,Fre,zre,Bre,Gre,Xre,Jre,tse,sse,ase,ise,use,dse,hse,mse,xse,wse,Sse,Tse,Rse,Pse,Mse,Wse,jee,Use,Vne,jse,Kse,Jse,Kee,nae,oae,lae,pae,mae,xae,wae,Cae,Rae,Pae,Fae,Lae,Wae,Uae,qae,Kae,Yae,Qae,toe,aoe,uoe,hoe,voe,ete,Soe,Noe,_oe,$oe,Cne,Moe,Loe,Woe,Goe,Xoe,Yee,Zoe,Yoe,Tne,yoe,eie,sie,lie,nte,pie,mie,xie,wie,Cie,Nie,_ie,$ie,Oie,Lie,Vie,jie,Kie,Jie,tle,Ane,xoe,sle,ole,lle,cle,ple,fle,gle,Ale,ble,kle,Sle,Tle,Rle,Dle,$le,Ole,Aoe,ute,Lle,Vle,Hle,Kle,Jle,cte,eue,nue,aue,zoe];for(let e of oue)Jr(e);var Gs=Y();Gs.registerFlag("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE",()=>15);Gs.registerFlag("WEBGPU_CPU_FORWARD",()=>!0);Gs.registerFlag("WEBGPU_MATMUL_WORK_PER_THREAD",()=>4);Gs.registerFlag("WEBGPU_USE_NAIVE_CONV2D",()=>!1);Gs.registerFlag("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE",()=>!1);Gs.registerFlag("WEBGPU_CONV_SEPARATE_IM2COL_SHADER",()=>!1);Gs.registerFlag("WEBGPU_USE_LOW_POWER_GPU",()=>!1);Gs.registerFlag("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD",()=>1e3);Gs.registerFlag("WEBGPU_USE_PROFILE_TOOL",()=>!1);Gs.registerFlag("WEBGPU_USE_IMPORT",()=>!1);function iue(e,t){if(Math.max(...e)>3)throw new Error("Cannot symbolically compute strides for rank > 4 tensor.");let n=e.length,r=e.map(a=>`${t}[${a}]`),s=new Array(n-1);s[n-2]=r[n-1];for(let a=n-3;a>=0;--a)s[a]=`(${s[a+1]} * ${r[a+1]})`;return s}function In(e){if(e<=1)return"i32";if(e===2)return"vec2<i32>";if(e===3)return"vec3<i32>";if(e===4)return"vec4<i32>";throw Error(`GPU for rank ${e} is not yet supported`)}function l0(e,t){return e==="float32"?t?"vec4<f32>":"f32":e==="int32"||e==="bool"?t?"vec4<i32>":"i32":e}function Bx(){return`
2021-11-08 13:36:26 +01:00
[[stage(compute), workgroup_size(workGroupSizeX, workGroupSizeY, workGroupSizeZ)]]
2022-01-08 18:43:44 +01:00
`}function ca(){return`
2022-01-16 15:49:55 +01:00
${Bx()}
2021-12-15 15:26:32 +01:00
fn main([[builtin(local_invocation_id)]] LocalId : vec3<u32>,
[[builtin(global_invocation_id)]] GlobalId : vec3<u32>,
[[builtin(num_workgroups)]] NumWorkgroups: vec3<u32>) {
localId = LocalId;
globalId = GlobalId;
numWorkgroups = NumWorkgroups;
`}function Je(){return`
2022-01-08 18:43:44 +01:00
${ca()}
2021-12-15 15:26:32 +01:00
let index = getGlobalIndex();
2022-01-16 15:49:55 +01:00
`}function lue(e,t,n,r=!1){let s=[];if(s.push(`
2021-11-08 13:36:26 +01:00
let workGroupSizeX = ${n.workGroupSize[0]}u;
let workGroupSizeY = ${n.workGroupSize[1]}u;
2022-01-08 18:43:44 +01:00
let workGroupSizeZ = ${n.workGroupSize[2]}u;
var<private> localId: vec3<u32>;
var<private> globalId: vec3<u32>;
var<private> numWorkgroups: vec3<u32>;
// Only used when the y/z dimension of workgroup size is 1.
fn getGlobalIndex() -> i32 {
if (numWorkgroups.y == 1u && numWorkgroups.z == 1u) {
return i32(globalId.x);
}
let localInvocationIndex = localId.z * workGroupSizeX * workGroupSizeY +
localId.y * workGroupSizeX + localId.x;
let workGroupID = (globalId - localId)/vec3<u32>(
workGroupSizeX, workGroupSizeY, workGroupSizeZ);
return i32((workGroupID.z * numWorkgroups.x * numWorkgroups.y +
workGroupID.y * numWorkgroups.x + workGroupID.x) *
(workGroupSizeX * workGroupSizeY * workGroupSizeZ) +
localInvocationIndex);
}
2022-01-16 15:49:55 +01:00
`),r===!0)return s.push(`
2021-12-14 21:45:43 +01:00
struct Matrix0 {
2022-01-16 15:49:55 +01:00
numbers: array<${l0(t.dtype,n.isVec4)}>;
2021-11-06 15:21:51 +01:00
};
2021-12-14 21:45:43 +01:00
struct Uniform {
2021-11-08 13:36:26 +01:00
size : i32;
numChannels : i32;
outShapeStrides : vec2<i32>;
dispatchSize : vec3<u32>;
};
[[group(0), binding(0)]] var<storage, write> result : Matrix0;
[[group(0), binding(2)]] var<uniform> uniforms: Uniform;
2022-01-16 15:49:55 +01:00
`),[E4,s.join(`
`),R4(t.shape),n.getUserCode()].join(`
`);let a="struct Uniforms { NAN : f32; ";n.variableNames.forEach((d,p)=>{a+=`${d.charAt(0).toLowerCase()+d.slice(1)}Shape : ${In(e[p].shape.length)}; `}),a+=`outShape : ${In(t.shape.length)} ; `;let o=t.shape.length-1;a+=`
outShapeStrides: ${In(o)}; `,n.size&&(a+="size : i32; "),n.uniforms&&(a+=n.uniforms),a+="};",s.push(a),n.atomic?s.push(`
2021-12-14 21:45:43 +01:00
struct Matrix0 {
2021-11-08 13:36:26 +01:00
numbers: array<atomic<i32>>;
};
[[group(0), binding(0)]] var<storage, read_write> result : Matrix0;
2022-01-16 15:49:55 +01:00
`):s.push(`
2021-12-14 21:45:43 +01:00
struct Matrix0 {
2022-01-16 15:49:55 +01:00
numbers: array<${l0(t.dtype,n.isVec4)}>;
2021-11-08 13:36:26 +01:00
};
[[group(0), binding(0)]] var<storage, write> result : Matrix0;
2022-01-16 15:49:55 +01:00
`),n.variableNames.forEach((d,p)=>{s.push(`
2022-01-08 18:43:44 +01:00
struct Matrix${1+p} {
2022-01-16 15:49:55 +01:00
numbers: array<${l0(e[p].dtype,n.isVec4)}>;
2021-11-08 13:36:26 +01:00
};
2022-01-08 18:43:44 +01:00
[[group(0), binding(${1+p})]] var<storage, read> ${d} : Matrix${1+p};
2022-01-16 15:49:55 +01:00
`)}),a!==""&&s.push(`
2021-11-08 13:36:26 +01:00
[[group(0), binding(${1+n.variableNames.length})]] var<uniform> uniforms : Uniforms;
2022-01-16 15:49:55 +01:00
`);let[i,l]=fue(t.shape,n.dispatchLayout),c=[E4,s.join(`
`),R4(t.shape),i,uue(t.shape.length)];if(n.atomic||c.push(cue(t.shape,t.dtype,n.isVec4)),l===t.shape.length){let d=e.map(p=>due(p,t.shape,n.isVec4,n.dispatchLayout.x.length===t.shape.length)).join(`
2022-01-08 18:43:44 +01:00
`);c.push(d)}return c.push(n.getUserCode()),c.join(`
2022-01-16 15:49:55 +01:00
`)}var E4=`
2022-01-08 18:43:44 +01:00
// Checks whether coordinates lie within the bounds of the shape.
fn coordsInBounds2D(coord : vec2<i32>, shape : vec2<i32>) -> bool {
return all(coord >= vec2<i32>(0)) && all(coord < shape);
}
fn coordsInBounds3D(coord : vec3<i32>, shape : vec3<i32>) -> bool {
return all(coord >= vec3<i32>(0)) && all(coord < shape);
}
fn coordsInBounds4D(coord : vec4<i32>, shape : vec4<i32>) -> bool {
return all(coord >= vec4<i32>(0)) && all(coord < shape);
}
fn getIndexFromCoords1D(coord : i32, shape : i32) -> i32 {
return coord;
}
fn getIndexFromCoords2D(coords : vec2<i32>, shape : vec2<i32>) -> i32 {
return dot(coords, vec2<i32>(shape.y, 1));
}
fn getIndexFromCoords3D(coords : vec3<i32>, shape : vec3<i32>) -> i32 {
return dot(coords, vec3<i32>(shape.y * shape.z, shape.z, 1));
}
fn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {
return dot(coords, vec4<i32>(
shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));
}
2021-12-15 15:26:32 +01:00
2021-11-08 13:36:26 +01:00
fn idiv(a: i32, b: i32, sign: f32) -> i32 {
var res: i32 = a / b;
let mod: i32 = a % b;
if (sign < 0. && mod != 0) {
res = res - 1;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
return res;
}
fn isNanCustom(val : f32) -> bool {
if (val > 0.0) {
return false;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (val < 0.0) {
return false;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (val == 0.0) {
return false;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return true;
}
2021-12-14 21:45:43 +01:00
fn isNanCustomVec4(val : vec4<f32>) -> vec4<bool> {
return vec4<bool>(isNanCustom(val[0]), isNanCustom(val[1]), isNanCustom(val[2]), isNanCustom(val[3]));
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;function uue(e){let t="";switch(e){case 0:case 1:t+=`
2022-01-08 18:43:44 +01:00
fn getOutputIndexFromCoords(coords : i32) -> i32 {
2021-11-08 13:36:26 +01:00
return coords;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`;break;case 2:t+=`
2022-01-08 18:43:44 +01:00
fn getOutputIndexFromCoords(coords : vec2<i32>) -> i32 {
2021-12-01 14:27:05 +01:00
return dot(coords, vec2<i32>(uniforms.outShapeStrides, 1));
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
`;break;case 3:t+=`
2022-01-08 18:43:44 +01:00
fn getOutputIndexFromCoords(coords : vec3<i32>) -> i32 {
2021-12-01 14:27:05 +01:00
return dot(coords, vec3<i32>(uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, 1));
2021-11-08 13:36:26 +01:00
}
`;break;case 4:t+=`
2022-01-08 18:43:44 +01:00
fn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {
2021-12-01 14:27:05 +01:00
return dot(coords, vec4<i32>(
uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, uniforms.outShapeStrides.z, 1));
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`;break;default:w.assert(!1,()=>`Unsupported ${e}D shape`);break}return t}function cue(e,t,n){let r=e.length,s=l0(t,n),a;if(n?a=`fn setOutputAtIndex(flatIndex : i32, value : vec4<f32>) {
result.numbers[flatIndex] = ${s}(value);
2021-11-06 15:21:51 +01:00
}
2022-01-08 18:43:44 +01:00
fn setOutputAtIndexI32(flatIndex : i32, value : vec4<i32>) {
2022-01-16 15:49:55 +01:00
result.numbers[flatIndex] = ${s}(value);
2022-01-08 18:43:44 +01:00
}`:a=`fn setOutputAtIndex(flatIndex : i32, value : f32) {
2022-01-16 15:49:55 +01:00
result.numbers[flatIndex] = ${s}(value);
2021-11-06 15:21:51 +01:00
}
2022-01-08 18:43:44 +01:00
fn setOutputAtIndexI32(flatIndex : i32, value : i32) {
2022-01-16 15:49:55 +01:00
result.numbers[flatIndex] = ${s}(value);
}`,r>=2){let o=["d0","d1","d2","d3"].slice(0,r),i=In(r);n?a+=`
2022-01-08 18:43:44 +01:00
fn setOutputAtCoords(${o.map(l=>`${l} : i32`).join(", ")}, value : vec4<f32>) {
let flatIndex = getOutputIndexFromCoords(${i}(${o.join(", ")}));
setOutputAtIndex(flatIndex / 4, value);
2021-11-06 15:21:51 +01:00
}
2022-01-08 18:43:44 +01:00
fn setOutputAtCoordsI32(${o.map(l=>`${l} : i32`).join(", ")}, value : vec4<i32>) {
let flatIndex = getOutputIndexFromCoords(${i}(${o.join(", ")}));
setOutputAtIndexI32(flatIndex / 4, value);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:a+=`
2022-01-08 18:43:44 +01:00
fn setOutputAtCoords(${o.map(l=>`${l} : i32`).join(", ")}, value : f32) {
let flatIndex = getOutputIndexFromCoords(${i}(${o.join(", ")}));
setOutputAtIndex(flatIndex, value);
2021-11-06 15:21:51 +01:00
}
2022-01-08 18:43:44 +01:00
fn setOutputAtCoordsI32(${o.map(l=>`${l} : i32`).join(", ")}, value : i32) {
let flatIndex = getOutputIndexFromCoords(${i}(${o.join(", ")}));
setOutputAtIndexI32(flatIndex, value);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}return a}function due(e,t,n,r){let s=pue(e,n);return e.shape.length<=t.length&&(s+=hue(e,t,n,r)),s}function pue(e,t){let n=e.name,r=e.shape.length,s=In(r),a="get"+n.charAt(0).toUpperCase()+n.slice(1),o=["d0","d1","d2","d3"].slice(0,r),i=o.map(u=>`${u} : i32`).join(", ");if(r<1)return t?`
2021-11-08 13:36:26 +01:00
fn ${a}() -> vec4<f32> {
return vec4<f32>(${n}.numbers[0]);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
`:`
fn ${a}() ->f32 {
return f32(${n}.numbers[0]);
}
2022-01-16 15:49:55 +01:00
`;let l=`uniforms.${n.charAt(0).toLowerCase()+n.slice(1)}Shape`,c=`${r}D`;return r===0&&(c="1D"),t?`
2021-11-08 13:36:26 +01:00
fn ${a}(${i}) -> vec4<f32> {
2022-01-16 15:49:55 +01:00
return vec4<f32>(${n}.numbers[getIndexFromCoords${c}(${s}(${o.join(",")}),
2021-11-08 13:36:26 +01:00
${l}) / 4]);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
`:`
fn ${a}(${i}) -> f32 {
2022-01-16 15:49:55 +01:00
return f32(${n}.numbers[getIndexFromCoords${c}(${s}(${o.join(",")}),
2021-11-08 13:36:26 +01:00
${l})]);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}function hue(e,t,n,r){let s=e.name,a=s.charAt(0).toUpperCase()+s.slice(1),o="get"+a+"ByOutput",i=e.shape.length,l=t.length,c=In(l);if(w.arraysEqual(e.shape,t)&&r)return n?`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> vec4<f32> {
2022-01-16 15:49:55 +01:00
return vec4<f32>(${s}.numbers[globalIndex]);
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coords : ${c}) -> vec4<f32> {
2022-01-16 15:49:55 +01:00
return vec4<f32>(${s}.numbers[${l>1?"getOutputIndexFromCoords(coords)":"coords"} / 4]);
2021-11-08 13:36:26 +01:00
}
`:`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> f32 {
2022-01-16 15:49:55 +01:00
return f32(${s}.numbers[globalIndex]);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coords : ${c}) -> f32 {
2022-01-16 15:49:55 +01:00
return f32(${s}.numbers[${l>1?"getOutputIndexFromCoords(coords)":"coords"}]);
2021-11-06 15:21:51 +01:00
}
2021-12-01 14:27:05 +01:00
`;let u=N.getBroadcastDims(e.shape,t),d=l-i,p="";if(i===0)return n?`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> vec4<f32> {
2021-11-08 13:36:26 +01:00
return get${a}();
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coords : ${c}) -> vec4<f32> {
2021-11-08 13:36:26 +01:00
return get${a}();
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> f32{
2021-11-08 13:36:26 +01:00
return get${a}();
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coords : ${c}) -> f32{
2021-11-08 13:36:26 +01:00
return get${a}();
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
`;l<2&&u.length>=1?p="coords = 0;":p=u.map(g=>`coords[${g+d}] = 0;`).join(`
2022-01-16 15:49:55 +01:00
`);let h="";if(l<2&&i>0)h="coords";else if(l>1){let g=In(i),y=e.shape.map((x,A)=>`coords[${A+d}]`).join(", ");h=`${g}(${y})`}else h="coords";let f=`uniforms.${s.charAt(0).toLowerCase()+s.slice(1)}Shape`,m=`${i}D`;return n?`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> vec4<f32> {
var coords = getCoordsFromIndex(globalIndex);
2021-11-08 13:36:26 +01:00
${p}
2022-01-16 15:49:55 +01:00
return ${s}.numbers[getIndexFromCoords${m}(${h}, ${f}) / 4];
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coordsIn : ${c}) -> vec4<f32> {
2021-11-08 13:36:26 +01:00
var coords = coordsIn;
${p}
2022-01-16 15:49:55 +01:00
return ${s}.numbers[getIndexFromCoords${m}(${h}, ${f}) / 4];
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
`:`
2022-01-08 18:43:44 +01:00
fn ${o}Index(globalIndex : i32) -> f32 {
var coords = getCoordsFromIndex(globalIndex);
2021-11-08 13:36:26 +01:00
${p}
2022-01-16 15:49:55 +01:00
return f32(${s}.numbers[getIndexFromCoords${m}(${h}, ${f})]);
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
fn ${o}Coords(coordsIn : ${c}) -> f32 {
2021-11-08 13:36:26 +01:00
var coords = coordsIn;
${p}
2022-01-16 15:49:55 +01:00
return f32(${s}.numbers[getIndexFromCoords${m}(${h}, ${f})]);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}function fue(e,t){let{x:n,y:r=[],z:s=[]}=t,a=e.length;if(n.length===a)return[`fn getOutputCoords() -> ${In(a)}{
2021-12-15 15:26:32 +01:00
let globalIndex = getGlobalIndex();
2022-01-08 18:43:44 +01:00
return getCoordsFromIndex(globalIndex);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`,a];let o="",i=[n,r,s],l=0;for(let p=0;p<i.length;p++){let h=i[p];if(h.length!==0)if(l+=h.length,h.length===1)o+=`let d${h[0]} = i32(globalId[${p}]);`;else{let f=iue(h,"uniforms.outShape");o+=`var index${p} = i32(globalId[${p}]);`;for(let m=0;m<f.length;m++)o+=`let d${h[m]} = index${p} / ${f[m]};`,m===f.length-1?o+=`let d${h[m+1]} = index${p} - d${h[m]} * ${f[m]};`:o+=`index${p} = index${p} - d${h[m]} * ${f[m]};`}}let c=[];for(let p=0;p<l;p++)c.push(`d${p}`);let u=In(l),d=`fn getOutputCoords() -> ${u} {
2021-11-08 13:36:26 +01:00
${o}
2022-01-16 15:49:55 +01:00
`;return c.length===0?d+=`return ${u}(0); }`:d+=`return ${u}(${c.join(",")}); }`,[d,l]}function R4(e){let t=e.length;if(t<=1)return"fn getCoordsFromIndex(index : i32) -> i32 { return index; }";let n=w.computeStrides(e),r=In(t),s=[];for(let o=0;o<t;o++)s.push(`d${o}`);if(n.length===1)return` fn getCoordsFromIndex(index : i32) -> vec2<i32> {
2021-11-08 13:36:26 +01:00
let d0 = index / uniforms.outShapeStrides; let d1 = index - d0 * uniforms.outShapeStrides;
return vec2<i32>(d0, d1);
2022-01-16 15:49:55 +01:00
}`;let a="var index2 = index;"+n.map((o,i)=>{let l=`let ${s[i]} = index2 / uniforms.outShapeStrides[${i}]`,c=i===n.length-1?`let ${s[i+1]} = index2 - ${s[i]} * uniforms.outShapeStrides[${i}]`:`index2 = index2 - ${s[i]} * uniforms.outShapeStrides[${i}]`;return`${l}; ${c};`}).join("");return`
fn getCoordsFromIndex(index : i32) -> ${r} {
2021-11-08 13:36:26 +01:00
${a}
2022-01-16 15:49:55 +01:00
return ${r}(${s.join(",")});
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}var _4={};Me(_4,{ArrayBufferToTypedArray:()=>D4,GPUBytesPerElement:()=>Gx,computeDispatch:()=>Oe,computeWorkGroupSizeForConv2d:()=>Wx,computeWorkGroupSizeForMatMul:()=>Vx,computeWorkPerThreadForConv2d:()=>Ux,flatDispatchLayout:()=>He,isWebGPUSupported:()=>Hx,tilesFitEvenlyIntoShape:()=>da});var Sc=65535,Ml=e=>{let t=1;for(let n=0;n<e.length;n++)t*=e[n];return t};function da(e,t){if(e.length!==t.length)throw new Error(`Cannot compute whether rank ${e.length} tiles fit evenly into rank ${t.length} shape - ranks must match.`);return t.every((n,r)=>n%e[r]===0)}function Oe(e,t,n=[1,1,1],r=[1,1,1]){let[s,a,o]=[Math.ceil(Ml(e.x.map(l=>t[l]))/(n[0]*r[0])),e.y?Math.ceil(Ml(e.y.map(l=>t[l]))/(n[1]*r[1])):1,e.z?Math.ceil(Ml(e.z.map(l=>t[l]))/(n[2]*r[2])):1];if(s<=Sc&&a<=Sc&&o<=Sc)return[s,a,o];w.assert(s>Sc&&e.y===void 0&&e.z===void 0,()=>"Dispatch size exceeds WebGPU limits in Y or Z dimension.");let i=Math.ceil(Math.sqrt(s));return i>Sc?(i=Math.ceil(Math.cbrt(s)),w.assert(i<=Sc,()=>"Total dispatch size exceeds WebGPU maximum."),[i,i,i]):[i,i,1]}function Wx(e,t){let n=Ml(e.x.map(s=>t[s])),r=Ml(e.y.map(s=>t[s]));return n<=4?[4,16,1]:r<=4?[16,4,1]:[16,16,1]}function Vx(e,t,n){return e===1?[32,1,1]:n===1?[1,32,1]:[8,8,1]}function Ux(e,t){let n=Ml(e.x.map(s=>t[s])),r=Ml(e.y.map(s=>t[s]));return n<=4?[1,2,1]:r<=4?[2,1,1]:[2,2,1]}function He(e){return{x:e.map((t,n)=>n)}}function Gx(e){if(e==="float32"||e==="int32"||e==="bool"||e==="string")return 4;if(e==="complex64")return 8;throw new Error(`Unknown dtype ${e}`)}function D4(e,t){if(t==="float32")return new Float32Array(e);if(t==="int32")return new Int32Array(e);if(t==="bool"||t==="string")return Uint8Array.from(new Int32Array(e));throw new Error(`Unknown dtype ${t}`)}function Hx(){return!!navigator.gpu}var qt=(e=>(e[e.MUL=0]="MUL",e[e.ADD=1]="ADD",e[e.SUB=2]="SUB",e[e.DIV=3]="DIV",e[e.EQUAL=4]="EQUAL",e[e.GREATER=5]="GREATER",e[e.GREATER_EQUAL=6]="GREATER_EQUAL",e[e.LESS=7]="LESS",e[e.LESS_EQUAL=8]="LESS_EQUAL",e[e.LOGICAL_AND=9]="LOGICAL_AND",e[e.NOT_EQUAL=10]="NOT_EQUAL",e[e.SQUARED_DIFFERENCE=11]="SQUARED_DIFFERENCE",e[e.INT_DIV=12]="INT_DIV",e[e.POW=13]="POW",e[e.PRELU=14]="PRELU",e[e.MAX=15]="MAX",e[e.MIN=16]="MIN",e[e.COMPLEX_MULTIPLY_REAL=17]="COMPLEX_MULTIPLY_REAL",e[e.COMPLEX_MULTIPLY_IMAG=18]="COMPLEX_MULTIPLY_IMAG",e))(qt||{}),mue="return a + b;",gue="return areal * breal - aimag * bimag;",yue="return areal * bimag + aimag * breal;",Aue="return a / b;",xue="return a * b;",bue="return (a - b) * (a - b);",vue="return a - b;",wue="return f32(a == b);",kue="return vec4<f32>(a == b);",Iue="return f32(a > b);",Sue="return vec4<f32>(a > b);",Cue="return f32(a >= b);",Tue="return vec4<f32>(a >= b);",Nue="return f32(a < b);",Eue="return vec4<f32>(a < b);",Rue="return f32(a <= b);",_ue="return vec4<f32>(a <= b);",Due="return f32(f32(a) >= 1.0 && f32(b) >= 1.0);",Pue=`return (vec4<f32>(a >= vec4<f32>(1.0)) *
vec4<f32>(b >= vec4<f32>(1.0)));`,$ue=`
2021-11-08 13:36:26 +01:00
if (isNanCustom(a)) { return a; }
if (isNanCustom(b)) { return b; }
2022-01-16 15:49:55 +01:00
`,P4=`
2021-12-14 21:45:43 +01:00
if (isNaN.r) {
2021-11-08 13:36:26 +01:00
resultTemp.r = uniforms.NAN;
}
2021-12-14 21:45:43 +01:00
if (isNaN.g) {
2021-11-08 13:36:26 +01:00
resultTemp.g = uniforms.NAN;
}
2021-12-14 21:45:43 +01:00
if (isNaN.b) {
2021-11-08 13:36:26 +01:00
resultTemp.b = uniforms.NAN;
}
2021-12-14 21:45:43 +01:00
if (isNaN.a) {
2021-11-08 13:36:26 +01:00
resultTemp.a = uniforms.NAN;
}
2022-01-16 15:49:55 +01:00
`,Fue=`
2021-11-08 13:36:26 +01:00
let s = sign(a) * sign(b);
let ia = i32(round(a));
let ib = i32(round(b));
return f32(idiv(ia, ib, s));
2022-01-16 15:49:55 +01:00
`,Oue=`
2021-11-08 13:36:26 +01:00
let ia = vec4<i32>(round(a));
let ib = vec4<i32>(round(b));
let cond = ib != vec4<i32>(0);
var resultTemp = vec4<i32>(0);
let s = sign(a) * sign(b);
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
if (cond[0]) {
resultTemp[0] = idiv(ia[0], ib[0], s[0]);
}
if (cond[1]) {
resultTemp[1] = idiv(ia[1], ib[1], s[1]);
}
if (cond[2]) {
resultTemp[2] = idiv(ia[2], ib[2], s[2]);
}
if (cond[3]) {
resultTemp[3] = idiv(ia[3], ib[3], s[3]);
}
return vec4<f32>(resultTemp);
2022-01-16 15:49:55 +01:00
`,Mue="return f32(a != b);",zue="return vec4<f32>(a != b);",Lue=`
2021-11-08 13:36:26 +01:00
if(a < 0.0 && floor(b) < b) {
return uniforms.NAN;
}
if (b == 0.0) {
return 1.0;
}
if (round(abs(b) % 2.0) != 1.0) {
return pow(abs(a), b);
}
return sign(a) * pow(abs(a), b);
2022-01-16 15:49:55 +01:00
`,Bue=`
2021-11-08 13:36:26 +01:00
let isModRound1Bool = vec4<i32>(round(abs(b) % vec4<f32>(2.0))) == vec4<i32>(1);
let isModRound1 = vec4<f32>(isModRound1Bool);
let multiplier = sign(a) * isModRound1 + (vec4<f32>(1.0) - isModRound1);
var resultTemp = multiplier * pow(abs(a), b);
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
let isExpZero = b == vec4<f32>(0.0);
if (isExpZero.r) {
resultTemp.r = 1.0;
}
if (isExpZero.g) {
resultTemp.g = 1.0;
}
if (isExpZero.b) {
resultTemp.b = 1.0;
}
if (isExpZero.a) {
resultTemp.a = 1.0;
}
2021-12-14 21:45:43 +01:00
let isNaN = a < vec4<f32>(0.0) & floor(b) < b;
2022-01-16 15:49:55 +01:00
${P4}
2021-11-08 13:36:26 +01:00
return resultTemp;
2022-01-16 15:49:55 +01:00
`,Wue="if (a < 0.0) { return b * a; } return a;",Vue=`
2021-11-08 13:36:26 +01:00
let aLessThanZero = vec4<f32>(a < vec4<f32>(0.0));
return (aLessThanZero * (b * a)) + ((vec4<f32>(1.0) - aLessThanZero) * a);
2022-01-16 15:49:55 +01:00
`;function $4(e,t){let n=t?P4:$ue;return t?`
2021-11-08 13:36:26 +01:00
var resultTemp = vec4<f32>(${e}(a, b));
2021-12-14 21:45:43 +01:00
let isNaN = isNanCustomVec4(a) | isNanCustomVec4(b);
2021-11-08 13:36:26 +01:00
`+n+`
return resultTemp;
`:n+`
return ${e}(a, b);
2022-01-16 15:49:55 +01:00
`}function Op(e,t){switch(e){case 0:return xue;case 1:return mue;case 2:return vue;case 3:return Aue;case 4:return t?kue:wue;case 5:return t?Sue:Iue;case 6:return t?Tue:Cue;case 7:return t?Eue:Nue;case 8:return t?_ue:Rue;case 9:return t?Pue:Due;case 10:return t?zue:Mue;case 11:return bue;case 12:return t?Oue:Fue;case 14:return t?Vue:Wue;case 15:return $4("max",t);case 16:return $4("min",t);case 13:return t?Bue:Lue;case 17:return gue;case 18:return yue;default:throw new Error(`BinaryType ${e} is not implemented!`)}}var kt=(e=>(e[e.ABS=0]="ABS",e[e.CEIL=1]="CEIL",e[e.COS=2]="COS",e[e.COSH=3]="COSH",e[e.ELU=4]="ELU",e[e.EXP=5]="EXP",e[e.EXPM1=6]="EXPM1",e[e.FLOOR=7]="FLOOR",e[e.LINEAR=8]="LINEAR",e[e.LOG=9]="LOG",e[e.LOGICAL_NOT=10]="LOGICAL_NOT",e[e.NEG=11]="NEG",e[e.PRELU=12]="PRELU",e[e.RELU=13]="RELU",e[e.RELU6=14]="RELU6",e[e.LEAKYRELU=15]="LEAKYRELU",e[e.RSQRT=16]="RSQRT",e[e.SIN=17]="SIN",e[e.SINH=18]="SINH",e[e.SIGMOID=19]="SIGMOID",e[e.SQRT=20]="SQRT",e[e.SQUARE=21]="SQUARE",e[e.TANH=22]="TANH",e[e.TO_INT=23]="TO_INT",e))(kt||{}),Uue="return abs(a);",Gue="return ceil(a);",Hue="return cos(a);",jue=`
2021-11-08 13:36:26 +01:00
let e2x = exp(-a);
return (e2x + 1.0 / e2x) / 2.0;
2022-01-16 15:49:55 +01:00
`,que="return exp(a) - 1.0;",Xue="if (a >= 0.0) { return a; } return (exp(a) - 1.0);",Kue=`
2021-11-08 13:36:26 +01:00
var resFloat = exp(a) - vec4<f32>(1.0);
if (a.r >= 0.0) {
resFloat.r = a.r;
}
if (a.g >= 0.0) {
resFloat.g = a.g;
}
if (a.b >= 0.0) {
resFloat.b = a.b;
}
if (a.a >= 0.0) {
resFloat.a = a.a;
}
return resFloat;
2022-01-16 15:49:55 +01:00
`,Zue="return exp(a);",Yue="return floor(a);",Jue="return a;",Que=`if (a < 0.0) { return 1.0/0.0; }
return log(a);`,ece="return f32(!(a >= 1.0));",tce="return -a;",nce="return (a < 0.0) ? b * a : a;",rce="if (a < 0.0) { return uniforms.alpha * a; } return a;",sce="if(a < 0.0) { return 0.0; } return a;",ace="return clamp(a, 0.0, 6.0);",oce="return clamp(a, vec4<f32>(0.0, 0.0, 0.0, 0.0), vec4<f32>(6.0, 6.0, 6.0, 6.0));",ice=`
2021-11-08 13:36:26 +01:00
var resFloat = a * vec4<f32>(a >= vec4<f32>(0.0));
2021-12-14 21:45:43 +01:00
let isNaN = isNanCustomVec4(a);
2021-11-08 13:36:26 +01:00
if (isNaN.r) {
resFloat.r = a.r;
}
if (isNaN.g) {
resFloat.g = a.g;
}
if (isNaN.b) {
resFloat.b = a.b;
}
if (isNaN.a) {
resFloat.a = a.a;
}
return resFloat;
2022-01-16 15:49:55 +01:00
`,lce="return 1.0/sqrt(a);",uce="return 1.0 / (1.0 + exp(-1.0 * a));",cce="return sin(a);",dce=`
2021-11-08 13:36:26 +01:00
let e2x = exp(a);
return (e2x - 1.0 / e2x) / 2.0;
2022-01-16 15:49:55 +01:00
`,pce="return sqrt(a);",hce="return a * a;",fce=`
2021-11-08 13:36:26 +01:00
let e2x = exp(-2.0 * abs(a));
return sign(a) * (1.0 - e2x) / (1.0 + e2x);
2022-01-16 15:49:55 +01:00
`,mce="return f32(i32((a)));";function Cc(e,t){switch(e){case 0:return Uue;case 2:return Hue;case 3:return jue;case 1:return Gue;case 4:return t?Kue:Xue;case 5:return Zue;case 6:return que;case 7:return Yue;case 8:return Jue;case 9:return Que;case 10:return ece;case 11:return tce;case 12:return nce;case 15:return rce;case 13:return t?ice:sce;case 14:return t?oce:ace;case 16:return lce;case 19:return uce;case 17:return cce;case 18:return dce;case 20:return pce;case 21:return hce;case 22:return fce;case 23:return mce;default:throw new Error(`BinaryType ${e} is not implemented!`)}}function pa(e,t=!1){if(e===null)return null;if(e==="linear")return Cc(kt.LINEAR);if(e==="relu")return Cc(kt.RELU,t);if(e==="elu")return Cc(kt.ELU,t);if(e==="relu6")return Cc(kt.RELU6,t);if(e==="prelu")return Op(qt.PRELU,t);if(e==="sigmoid")return Cc(kt.SIGMOID);throw new Error(`Activation ${e} has not been implemented for the WebGPU backend.`)}function F4(e,t){let n={RowPerThread:e[1],ColPerThread:e[0],TileAOuter:t[1]*e[1],TileBOuter:t[0]*e[0],TileInner:t[0]*e[0]};return`
2021-11-08 13:36:26 +01:00
var<workgroup> mm_Asub : array<array<vec4<f32>, ${n.TileInner/n.ColPerThread}>, ${n.TileAOuter}>;
var<workgroup> mm_Bsub : array<array<vec4<f32>, ${n.TileBOuter/n.ColPerThread}>, ${n.TileInner}>;
let RowPerThread = ${n.RowPerThread};
let ColPerThread = ${n.ColPerThread}; // only support ColPerThread = 4
let TileAOuter = ${n.TileAOuter};
let TileBOuter = ${n.TileBOuter};
let TileInner = ${n.TileInner};
2022-01-08 18:43:44 +01:00
${ca()}
2021-11-08 13:36:26 +01:00
let tileRow = i32(localId.y) * RowPerThread;
let tileCol = i32(localId.x);
let globalRow = i32(globalId.y) * RowPerThread;
let globalCol = i32(globalId.x);
let numTiles = (uniforms.dimInner - 1) / TileInner + 1;
var acc: array<vec4<f32>, ${n.RowPerThread}>;
var ACached : vec4<f32>;
var BCached : array<vec4<f32>, 4>;
// Loop over shared dimension.
var globalColA = tileCol;
let RowPerThreadB = TileInner / ${t[1]};
let tileRowB = i32(localId.y) * RowPerThreadB;
for (var t = 0; t < numTiles; 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;
mm_Asub[inputRow][inputCol] = mm_readA(globalRow + innerRow, globalColA, globalId);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
globalColA = globalColA + TileInner / ColPerThread;
// Load one tile of B into local memory.
for (var innerRow = 0; innerRow < RowPerThreadB; innerRow = innerRow + 1) {
let inputRow = tileRowB + innerRow;
let inputCol = tileCol;
mm_Bsub[inputRow][inputCol] = mm_readB(t * TileInner + inputRow, globalCol, globalId);
}
workgroupBarrier();
// Compute acc values for a single thread.
for (var k = 0; k < TileInner / ColPerThread; k = k + 1) {
BCached[0] = mm_Bsub[k * ColPerThread][tileCol];
BCached[1] = mm_Bsub[k * ColPerThread + 1][tileCol];
BCached[2] = mm_Bsub[k * ColPerThread + 2][tileCol];
BCached[3] = mm_Bsub[k * ColPerThread + 3][tileCol];
for (var i = 0; i < RowPerThread; i = i + 1) {
ACached = mm_Asub[tileRow + i][k];
acc[i] = BCached[0] * ACached.x + acc[i];
acc[i] = BCached[1] * ACached.y + acc[i];
acc[i] = BCached[2] * ACached.z + acc[i];
acc[i] = BCached[3] * ACached.w + acc[i];
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
}
for (var innerRow = 0; innerRow < RowPerThread; innerRow = innerRow + 1) {
mm_write(globalRow + innerRow,
globalCol,
acc[innerRow], globalId);
}
2022-01-16 15:49:55 +01:00
}`}function gce(e){return`
2021-11-08 13:36:26 +01:00
var<workgroup> mm_Asub : array<vec4<f32>, ${e[0]}>;
let tileSize = ${e[0]*4};
2022-01-08 18:43:44 +01:00
${ca()}
2021-11-08 13:36:26 +01:00
let tileCol = i32(localId.x);
let globalCol = i32(globalId.x);
let globalRow = i32(globalId.y);
let numTiles = (uniforms.dimInner - 1) / tileSize + 1;
// Without this initialization strange values show up in acc.
var acc = vec4<f32>(0.0);
// Loop over shared dimension.
for (var t = 0; t < numTiles; t = t + 1) {
// Load one tile of A into local memory.
let colA = t * tileSize / 4 + tileCol;
mm_Asub[tileCol] = mm_readA(globalRow, colA, globalId);
workgroupBarrier();
// Compute acc values for a single thread.
for (var k = 0; k < tileSize / 4; k = k + 1) {
let rowB = t * tileSize + k * 4;
let BCached0 = mm_readB(rowB, globalCol, globalId);
let BCached1 = mm_readB(rowB + 1, globalCol, globalId);
let BCached2 = mm_readB(rowB + 2, globalCol, globalId);
let BCached3 = mm_readB(rowB + 3, globalCol, globalId);
let ACached = mm_Asub[k];
acc = acc + BCached0 * ACached.x;
acc = acc + BCached1 * ACached.y;
acc = acc + BCached2 * ACached.z;
acc = acc + BCached3 * ACached.w;
}
workgroupBarrier();
}
if (globalRow < uniforms.dimAOuter && globalCol < uniforms.dimBOuter) {
mm_write(globalRow, globalCol, acc, globalId);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}var yce=class{constructor(e,t,n,r=null,s=null,a=null){this.variableNames=["A","B"],this.uniforms="dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.workGroupSize=[16,16,1],this.isVec4=!0,this.vecSize=4,this.outputShape=t,this.workGroupSize=Vx(t[1],e[2],t[2]),this.dispatchLayout={x:[2],y:[1],z:[0]},t[1]===1&&(n=1),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.vecSize,n,1]);let o=r!=null,i=a!=null;o&&this.variableNames.push("bias"),i&&this.variableNames.push("preluActivationWeights"),this.workPerThread=n,this.aShape=e,this.addBias=o,this.activation=s,this.hasPreluActivationWeights=i,[this.fitA,this.fitB]=this.getShapeFit(),this.shaderKey=`matMulPackedVec4_${n}_${this.activation}_${this.fitA}_${this.fitB}_${this.outputShape[1]>1}`}getShapeFit(){let e=this.aShape[2],t=this.outputShape[2],n=[this.outputShape[0],e,t],r=this.workGroupSize[1]*this.workPerThread,s=this.workGroupSize[0]*this.vecSize,a=s,o=[r,a],i=[a,s];return[da(o,this.aShape.slice(1)),da(i,n.slice(1))]}getUserCode(){let e=this.fitA?"return A.numbers[batch * batchASize + row * uniforms.dimInner / 4 + col]":`if (coordsInBounds2D(vec2<i32>(row, col * 4), vec2<i32>(uniforms.dimAOuter, uniforms.dimInner))) {
2021-11-08 13:36:26 +01:00
return A.numbers[batch * batchASize + row * uniforms.dimInner / 4 + col];
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return vec4<f32>(0.0)`,t=this.fitB?"return B.numbers[batch * batchBSize + row * uniforms.dimBOuter / 4 + col]":`if(coordsInBounds2D(vec2<i32>(row, col * 4), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
return B.numbers[batch * batchBSize + row * uniforms.dimBOuter / 4 + col];
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
return vec4<f32>(0.0)`,n="",r="";if(this.activation){let o=pa(this.activation,this.isVec4);this.hasPreluActivationWeights?n=`fn activation(a : vec4<f32>, outCoord : vec3<i32>) -> vec4<f32> {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${o}
}`:n=`
fn activation(a : vec4<f32>, outCoord : vec3<i32>) -> vec4<f32> {
${o}
2022-01-16 15:49:55 +01:00
}`,r="value = activation(value, outCoord);"}let s=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${n}
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> vec4<f32> {
let batchASize = uniforms.aShape[1] * uniforms.aShape[2] / ${this.vecSize};
let batch = i32(globalId.z);
${e};
}
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> vec4<f32> {
let batchBSize = uniforms.bShape[1] * uniforms.bShape[2] / ${this.vecSize};
let batch = i32(globalId.z);
${t};
}
fn mm_write(row : i32, col : i32, valueIn : vec4<f32>, globalId : vec3<u32>) {
if (row < uniforms.aShape[1] && col * 4 < uniforms.bShape[2])
{
var value = valueIn;
let batch = i32(globalId.z);
let outCoord = vec3<i32>(batch, row, col * 4);
${s}
2022-01-16 15:49:55 +01:00
${r}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(outCoord[0], outCoord[1], outCoord[2], value);
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
${this.outputShape[1]>1?F4([this.vecSize,this.workPerThread,1],this.workGroupSize):gce(this.workGroupSize)}
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
`}};function jx(e,t){let n=t[1]*e[1],r=t[0]*e[0],s=n>r?n:r;return`
var<workgroup> mm_Asub : array<array<f32, ${s}>, ${n}>;
var<workgroup> mm_Bsub : array<array<f32, ${r}>, ${s}>;
2022-01-08 18:43:44 +01:00
${ca()}
2021-11-08 13:36:26 +01:00
let tileRow = i32(localId.y) * ${e[1]};
let tileCol = i32(localId.x) * ${e[0]};
let globalRow = i32(globalId.y) * ${e[1]};
let globalCol = i32(globalId.x) * ${e[0]};
2022-01-16 15:49:55 +01:00
let numTiles = (uniforms.dimInner - 1) / ${s} + 1;
2021-11-08 13:36:26 +01:00
var acc : array<array<f32, ${e[0]}>, ${e[1]}>;
var ACached : f32;
var BCached : array<f32, ${e[0]}>;
// Without this initialization strange values show up in acc.
for (var innerRow = 0; innerRow < ${e[1]}; innerRow = innerRow + 1) {
for (var innerCol = 0; innerCol < ${e[0]}; innerCol = innerCol + 1) {
acc[innerRow][innerCol] = 0.0;
2021-10-30 18:21:54 +02:00
}
}
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
let ColPerThreadA = ${s} / ${t[0]};
2021-11-08 13:36:26 +01:00
let tileColA = i32(localId.x) * ColPerThreadA;
2022-01-16 15:49:55 +01:00
let RowPerThreadB = ${s} / ${t[1]};
2021-11-08 13:36:26 +01:00
let tileRowB = i32(localId.y) * RowPerThreadB;
// Loop over shared dimension.
for (var t = 0; t < numTiles; t = t + 1) {
// Load one tile of A into local memory.
for (var innerRow = 0; innerRow < ${e[1]}; innerRow = innerRow + 1) {
for (var innerCol = 0; innerCol < ColPerThreadA; innerCol = innerCol + 1) {
let inputRow = tileRow + innerRow;
let inputCol = tileColA + innerCol;
mm_Asub[inputRow][inputCol] = mm_readA(
globalRow + innerRow,
2022-01-16 15:49:55 +01:00
t * ${s} + inputCol, globalId);
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
// Load one tile of B into local memory.
for (var innerRow = 0; innerRow < RowPerThreadB; innerRow = innerRow + 1) {
for (var innerCol = 0; innerCol < ${e[0]}; innerCol = innerCol + 1) {
let inputRow = tileRowB + innerRow;
let inputCol = tileCol + innerCol;
mm_Bsub[inputRow][inputCol] = mm_readB(
2022-01-16 15:49:55 +01:00
t * ${s} + inputRow,
2021-11-08 13:36:26 +01:00
globalCol + innerCol, globalId);
}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
// Compute acc values for a single thread.
2022-01-16 15:49:55 +01:00
for (var k = 0; k < ${s}; k = k + 1) {
2021-11-08 13:36:26 +01:00
for (var inner = 0; inner < ${e[0]}; inner = inner + 1) {
BCached[inner] = mm_Bsub[k][tileCol + inner];
}
for (var innerRow = 0; innerRow < ${e[1]}; innerRow = innerRow + 1) {
ACached = mm_Asub[tileRow + innerRow][k];
for (var innerCol = 0; innerCol < ${e[0]}; innerCol = innerCol + 1) {
acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol];
2021-10-30 18:21:54 +02:00
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
for (var innerRow = 0; innerRow < ${e[1]}; innerRow = innerRow + 1) {
for (var innerCol = 0; innerCol < ${e[0]}; innerCol = innerCol + 1) {
if ((globalCol + innerCol) < uniforms.dimBOuter &&
(globalRow + innerRow) < uniforms.dimAOuter) {
mm_write(globalRow + innerRow,
globalCol + innerCol,
acc[innerRow][innerCol], globalId);
}
2021-11-06 15:21:51 +01:00
}
}
}
2022-01-16 15:49:55 +01:00
`}function Ace(e){return`
2021-11-08 13:36:26 +01:00
let TileSize = ${e[0]*4};
var<workgroup> mm_Asub : array<vec4<f32>, ${e[0]}>;
2022-01-08 18:43:44 +01:00
${ca()}
2021-11-08 13:36:26 +01:00
let tileCol = i32(localId.x);
let globalCol = i32(globalId.x);
let globalRow = i32(globalId.y);
let numTiles = (uniforms.dimInner - 1) / TileSize + 1;
// Without this initialization strange values show up in acc.
var acc = 0.0;
// Loop over shared dimension.
for (var t = 0; t < numTiles; t = t + 1) {
// Load one tile of A into local memory.
let colA = t * TileSize + tileCol * 4;
mm_Asub[tileCol] = vec4<f32>(mm_readA(globalRow, colA, globalId),
mm_readA(globalRow, colA + 1, globalId),
mm_readA(globalRow, colA + 2, globalId),
mm_readA(globalRow, colA + 3, globalId));
workgroupBarrier();
// Compute acc values for a single thread.
for (var k = 0; k < TileSize / 4; k = k + 1) {
let rowB = t * TileSize + k * 4;
let BCached = vec4<f32>(mm_readB(rowB, globalCol, globalId),
mm_readB(rowB + 1, globalCol, globalId),
mm_readB(rowB + 2, globalCol, globalId),
mm_readB(rowB + 3, globalCol, globalId));
let ACached = mm_Asub[k];
acc = acc + dot(ACached, BCached);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (globalRow < uniforms.dimAOuter && globalCol < uniforms.dimBOuter) {
mm_write(globalRow, globalCol, acc, globalId);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}var O4=class{constructor(e,t,n,r=!1,s=!1,a=null,o=null,i=null){this.variableNames=["A","B"],this.uniforms="dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.workGroupSize=[16,16,1],this.outputShape=t,this.dispatchLayout={x:[2],y:[1],z:[0]};let l=r?e[1]:e[2];this.workGroupSize=Vx(t[1],l,t[2]),(t[1]===1||t[2]===1)&&(n=1),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[n,n,1]),w.arraysEqual(this.dispatch,[1,1,1])&&(n=1,this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[n,n,1]));let c=a!=null,u=i!=null;c&&this.variableNames.push("bias"),u&&this.variableNames.push("preluActivationWeights"),this.workPerThread=n,this.aShape=e,this.transposeA=r,this.transposeB=s,this.addBias=c,this.activation=o,this.hasPreluActivationWeights=u;let d=this.outputShape[2],p=this.transposeB?[this.outputShape[0],d,l]:[this.outputShape[0],l,d];[this.fitA,this.fitB]=this.getShapeFit(p),this.shaderKey=`matMulPacked_${this.workPerThread}_${r}_${s}_${this.activation}_${this.fitA}_${this.fitB}_${this.outputShape[1]>1}`}getShapeFit(e){let t=this.workGroupSize[1]*this.workPerThread,n=this.workGroupSize[0]*this.workPerThread,r=t>n?t:n;this.outputShape[1]===1&&(r*=4),w.assert(r%this.workGroupSize[0]===0&&r%this.workGroupSize[1]===0,()=>"tileInner must be multiple of workgroupsize.x and workgroupsize.y");let s=[t,r],a=[r,n];return[da(s,this.aShape.slice(1)),da(a,e.slice(1))]}getUserCode(){let e;this.transposeA===!1?e=this.fitA?"return A.numbers[batch * batchASize + row * uniforms.dimInner + col];":`if(coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimAOuter, uniforms.dimInner))) {
2021-11-08 13:36:26 +01:00
return A.numbers[batch * batchASize + row * uniforms.dimInner + col];
}
return 0.0;`:e=this.fitA?"return A.numbers[batch * batchASize + col * uniforms.dimAOuter + row];":`if(coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimAOuter, uniforms.dimInner))) {
return A.numbers[batch* batchASize + col * uniforms.dimAOuter + row];
}
return 0.0;`;let t;this.transposeB===!1?t=this.fitB?"return B.numbers[batch * batchBSize + row * uniforms.dimBOuter + col];":`if(coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
return B.numbers[batch * batchBSize + row * uniforms.dimBOuter + col];
}
return 0.0;`:t=this.fitB?"return B.numbers[batch * batchBSize + col * uniforms.dimInner + row];":`if(coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
return B.numbers[batch * batchBSize + col * uniforms.dimInner + row];
}
2022-01-16 15:49:55 +01:00
return 0.0;`;let n="",r="";if(this.activation){let o=pa(this.activation,!1);this.hasPreluActivationWeights?n=`fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${o}
}`:n=`
fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
${o}
}
2022-01-16 15:49:55 +01:00
`,r="value = activation(value, outCoord);"}let s=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${n}
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
let batchASize = uniforms.aShape[1] * uniforms.aShape[2];
let batch = i32(globalId.z);
${e}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
let batch = i32(globalId.z);
let batchBSize = uniforms.bShape[1] * uniforms.bShape[2];
${t}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn mm_write(row : i32, col : i32, valueIn : f32, globalId : vec3<u32>) {
var value = valueIn;
let batch = i32(globalId.z);
let outCoord = vec3<i32>(batch, row, col);
${s}
2022-01-16 15:49:55 +01:00
${r}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(batch, row, col, value);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
${this.outputShape[1]>1?jx([this.workPerThread,this.workPerThread,1],this.workGroupSize):Ace(this.workGroupSize)}
`}};function xce(){return`
2021-11-08 13:36:26 +01:00
var<workgroup> sumValues : array<f32, workGroupSizeX>;
2022-01-08 18:43:44 +01:00
${ca()}
2021-12-15 15:26:32 +01:00
let coords = getOutputCoords();
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let row = coords[1];
let col = coords[2];
var sum = 0.0;
let Length = uniforms.dimInner;
for (var k = i32(localId.x); k < Length; k = k + i32(workGroupSizeX)) {
let dataA = mm_readA(batch, row, k);
let dataB = mm_readB(batch, k, col);
sum = sum + dataA * dataB;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
sumValues[localId.x] = sum;
workgroupBarrier();
for(var currentSize = workGroupSizeX / 2u; currentSize > 1u;
currentSize = currentSize / 2u) {
if (localId.x < currentSize)
{
sumValues[localId.x] = sumValues[localId.x] + sumValues[localId.x + currentSize];
}
workgroupBarrier();
}
if (localId.x == 0u) {
sum = sumValues[0] + sumValues[1];
mm_write(batch, row, col, sum);
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}var bce=class{constructor(e,t=!1,n=!1,r=null,s=null,a=null){this.variableNames=["A","B"],this.uniforms="dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.workGroupSize=[256,1,1],this.outputShape=e,this.dispatchLayout={x:[],y:[1,2],z:[0]},this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize);let o=r!=null,i=a!=null;o&&this.variableNames.push("bias"),i&&this.variableNames.push("preluActivationWeights"),this.transposeA=t,this.transposeB=n,this.addBias=o,this.activation=s,this.hasPreluActivationWeights=i,this.shaderKey=`matMulReduce_${this.activation}_${t}_${n}`}getUserCode(){let e;this.transposeA===!1?e="return A.numbers[batch * batchASize + row * uniforms.dimInner + col];":e="return A.numbers[batch * batchASize + col * uniforms.dimAOuter + row];";let t;this.transposeB===!1?t="return B.numbers[batch * batchBSize + row * uniforms.dimBOuter + col];":t="return B.numbers[batch * batchBSize + col * uniforms.dimInner + row];";let n="",r="";if(this.activation){let o=pa(this.activation,!1);this.hasPreluActivationWeights?n=`fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${o}
}`:n=`
fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
${o}
}
2022-01-16 15:49:55 +01:00
`,r="value = activation(value, outCoord);"}let s=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${n}
fn mm_readA(batch: i32, row : i32, col : i32) -> f32 {
let batchASize = uniforms.aShape[1] * uniforms.aShape[2];
${e}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn mm_readB(batch: i32, row : i32, col : i32) -> f32 {
let batchBSize = uniforms.bShape[1] * uniforms.bShape[2];
${t}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn mm_write(batch: i32, row : i32, col : i32, valueIn : f32) {
var value = valueIn;
let outCoord = vec3<i32>(batch, row, col);
${s}
2022-01-16 15:49:55 +01:00
${r}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(batch, row, col, value);
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
${xce()}
`}};function vce(e){let t=e[1]/2,n=e[0],r=t>n?t:n;return`
var<workgroup> mm_Asub1 : array<array<f32, ${r}>, ${t}>;
var<workgroup> mm_Bsub1 : array<array<f32, ${n}>, ${r}>;
var<workgroup> mm_Asub2 : array<array<f32, ${r}>, ${t}>;
var<workgroup> mm_Bsub2 : array<array<f32, ${n}>, ${r}>;
2021-11-08 13:36:26 +01:00
// If the output size is small for matrix multiplication, avoid to use vec4
// and handle some elements per thread to optimally utilize the ALU.
// Introduces two shared memory buffers, some logical threads could handle
// arithmetic operations and others handle IO operations between barrier api,
// makes ALUs and load/store units work simultaneously, could improves
// the performance.
2022-01-08 18:43:44 +01:00
${ca()}
2021-11-08 13:36:26 +01:00
let tileRow = i32(localId.y);
let tileCol = i32(localId.x);
let globalRow = i32(globalId.y);
let globalCol = i32(globalId.x);
// uniforms.dimInner should be greater than 0.
2022-01-16 15:49:55 +01:00
let numTiles = (uniforms.dimInner - 1) / ${r} + 1;
2021-11-08 13:36:26 +01:00
var acc = 0.0;
var globalColA = tileCol;
var globalRowB = tileRow;
for (var t = 0; t < numTiles; t = t + 1) {
if (t == 0) {
if (tileRow < ${t}) {
// Load one tile of A and B into local memory.
// globalRow is always greater than or equal tileRow.
mm_Asub1[tileRow][tileCol] =
mm_readA((globalRow - tileRow) / 2 + tileRow, globalColA, globalId);
2022-01-16 15:49:55 +01:00
globalColA = globalColA + ${r};
2021-11-08 13:36:26 +01:00
mm_Bsub1[tileRow][tileCol] = mm_readB(globalRowB, globalCol, globalId);
2022-01-16 15:49:55 +01:00
globalRowB = globalRowB + ${r};
2021-11-08 13:36:26 +01:00
}
} else {
if (tileRow < ${t}) {
// Load one tile of A and B into local memory.
// globalRow is always greater than or equal tileRow.
mm_Asub1[tileRow][tileCol] =
mm_readA((globalRow - tileRow) / 2 + tileRow, globalColA, globalId);
2022-01-16 15:49:55 +01:00
globalColA = globalColA + ${r};
2021-11-08 13:36:26 +01:00
mm_Bsub1[tileRow][tileCol] = mm_readB(globalRowB, globalCol, globalId);
2022-01-16 15:49:55 +01:00
globalRowB = globalRowB + ${r};
2021-11-08 13:36:26 +01:00
} else {
// Compute acc values for a single thread.
2022-01-16 15:49:55 +01:00
for (var k = 0; k < ${r}; k = k + 1) {
2021-11-08 13:36:26 +01:00
let subRow = tileRow - ${t};
if (subRow < 0) {
continue;
}
acc = acc + mm_Asub2[subRow][k] * mm_Bsub2[k][tileCol];
}
}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
if (t != 0) {
t = t + 1;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
if (t < numTiles) {
if (tileRow < ${t}) {
// Load one tile of A and B into local memory.
// globalRow is always greater than or equal tileRow.
mm_Asub2[tileRow][tileCol] =
mm_readA((globalRow - tileRow) / 2 + tileRow, globalColA, globalId);
2022-01-16 15:49:55 +01:00
globalColA = globalColA + ${r};
2021-11-08 13:36:26 +01:00
mm_Bsub2[tileRow][tileCol] = mm_readB(globalRowB, globalCol, globalId);
2022-01-16 15:49:55 +01:00
globalRowB = globalRowB + ${r};
2021-11-08 13:36:26 +01:00
} else {
// Compute acc values for a single thread.
2022-01-16 15:49:55 +01:00
for (var k = 0; k < ${r}; k = k + 1) {
2021-11-08 13:36:26 +01:00
let subRow = tileRow - ${t};
if (subRow < 0) {
continue;
}
acc = acc + mm_Asub1[subRow][k] * mm_Bsub1[k][tileCol];
}
}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
let writeCol = (globalRow - tileRow) / 2 + tileRow - ${t};
if (tileRow >= ${t} && writeCol >= 0) {
mm_write(writeCol, globalCol, acc, globalId);
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}var wce=class{constructor(e,t,n,r=null,s=null,a=null){this.variableNames=["A","B"],this.uniforms="dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.workGroupSize=[8,16,1],w.assert(e[1]<=16||t[2]<=16,()=>"This program can be only used when A width or B Height are small"),this.outputShape=n,this.dispatchLayout={x:[2],y:[1],z:[0]},this.dispatch=[Math.ceil(n[2]/this.workGroupSize[0]),Math.ceil(n[1]*2/this.workGroupSize[1]),n[0]];let o=r!=null;o&&this.variableNames.push("bias");let i=a!=null;i&&this.variableNames.push("preluActivationWeights"),this.addBias=o,this.activation=s,this.hasPreluActivationWeights=i,this.shaderKey=`matMulSmallOutputSize_${this.activation}`}getUserCode(){let e=`if (coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimAOuter, uniforms.dimInner))) {
2021-11-08 13:36:26 +01:00
return A.numbers[batch * batchASize + row * uniforms.dimInner + col];
}
return 0.0;`,t=`if (coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
return B.numbers[batch * batchBSize + row * uniforms.dimBOuter + col];
}
2022-01-16 15:49:55 +01:00
return 0.0;`,n="",r="";if(this.activation){let o=pa(this.activation,!1);this.hasPreluActivationWeights?n=`fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${o}
}`:n=`fn activation(a : f32, outCoord : vec3<i32>) -> f32 {
${o}
2022-01-16 15:49:55 +01:00
}`,r="value = activation(value, outCoord);"}let s=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${n}
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
let batchASize = uniforms.aShape[1] * uniforms.aShape[2];
let batch = i32(globalId.z);
${e}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
let batch = i32(globalId.z);
let batchBSize = uniforms.bShape[1] * uniforms.bShape[2];
${t}
}
fn mm_write(row : i32, col : i32, valueIn : f32, globalId : vec3<u32>) {
if (coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimAOuter, uniforms.dimBOuter))) {
let batch = i32(globalId.z);
let outCoord = vec3<i32>(batch, row, col);
var value = valueIn;
${s}
2022-01-16 15:49:55 +01:00
${r}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(batch, row, col, value);
2021-11-08 13:36:26 +01:00
}
}
2022-01-16 15:49:55 +01:00
${vce(this.workGroupSize)}
`}};function Xe(e){let{inputs:t,attrs:n}=e,{x:r}=t,{shape:s}=n,a=w.sizeFromShape(r.shape),o=w.inferFromImplicitShape(s,a),i=w.sizeFromShape(o);return w.assert(a===i,()=>`The new shape (${o}) has ${i} elements and the old shape (${r.shape}) has ${a} elements. The new shape and old shape must have the same number of elements.`),e.backend.incRef(r.dataId),{dataId:r.dataId,shape:o,dtype:r.dtype}}var kce={kernelName:Wi,backendName:"webgpu",kernelFunc:Xe};function qx({a:e,b:t,transposeA:n,transposeB:r,backend:s,bias:a=null,preluActivationWeights:o=null,leakyreluAlpha:i=0,activation:l=null}){let c=e.shape.length,u=t.shape.length,d=n?e.shape[c-2]:e.shape[c-1],p=r?t.shape[u-1]:t.shape[u-2],h=n?e.shape[c-1]:e.shape[c-2],f=r?t.shape[u-2]:t.shape[u-1],m=e.shape.slice(0,-2),g=t.shape.slice(0,-2),y=w.sizeFromShape(m),x=w.sizeFromShape(g),b=ll.assertAndGetBroadcastShape(e.shape.slice(0,-2),t.shape.slice(0,-2)).concat([h,f]);w.assert(d===p,()=>`Error in matMul: inner shapes (${d}) and (${p}) of Tensors with shapes ${e.shape} and ${t.shape} and transposeA=${n} and transposeB=${r} must match.`);let v=n?[y,d,h]:[y,h,d],C=r?[x,f,p]:[x,p,f],I=Xe({inputs:{x:e},backend:s,attrs:{shape:v}}),E=Xe({inputs:{x:t},backend:s,attrs:{shape:C}}),R=[I,E],F=Math.max(y,x),_=d%4===0&&f%4===0&&!n&&!r&&f>=32,P;h*f<=32?P=new bce([F,h,f],n,r,a,l,o):!n&&!r&&(h<=16&&(f<=512||p>=2*f)||f<=16&&(h<=512||d>=2*h))?P=new wce(v,C,[F,h,f],a,l,o):_?P=new yce(v,[F,h,f],Y().get("WEBGPU_MATMUL_WORK_PER_THREAD"),a,l,o):P=new O4(v,[F,h,f],Y().get("WEBGPU_MATMUL_WORK_PER_THREAD"),n,r,a,l,o);let T=[I,E];a&&T.push(a),o&&T.push(o);let O=[{type:"int32",data:[h]},{type:"int32",data:[f]},{type:"int32",data:[d]}],G=s.runWebGPUProgram(P,T,e.dtype,O),K=Xe({inputs:{x:G},backend:s,attrs:{shape:b}});R.push(G);for(let z of R)s.disposeData(z.dataId);return K}function Ice(e){let{inputs:t,backend:n,attrs:r}=e,{a:s,b:a,bias:o,preluActivationWeights:i}=t,{transposeA:l,transposeB:c,activation:u,leakyreluAlpha:d}=r;return qx({a:s,b:a,transposeA:l,transposeB:c,backend:n,bias:o,preluActivationWeights:i,leakyreluAlpha:d,activation:u})}var Sce={kernelName:No,backendName:"webgpu",kernelFunc:Ice},M4=class{constructor(e,t,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.workGroupSize=[128,1,1],this.size=!0,this.outputShape=N.assertAndGetBroadcastShape(t,n),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey=`binaryOpComplex_${e}`,this.op=e}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn binaryOpComplex(
areal : f32, aimag : f32, breal : f32, bimag : f32) -> f32 {
2022-01-16 15:49:55 +01:00
${Op(this.op,!1)}
2021-11-08 13:36:26 +01:00
}
${Je()}
2021-11-08 13:36:26 +01:00
if(index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let areal = getARealByOutputIndex(index);
let aimag = getAImagByOutputIndex(index);
let breal = getBRealByOutputIndex(index);
let bimag = getBImagByOutputIndex(index);
setOutputAtIndex(index, binaryOpComplex(areal, aimag, breal, bimag));
2021-11-08 13:36:26 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},Cce=class{constructor(e,t,n,r){this.variableNames=["A","B"],this.size=!0;let s=256;this.workGroupSize=[s,1,1],this.outputShape=N.assertAndGetBroadcastShape(t,n),this.dispatchLayout=He(this.outputShape),this.lastDimensionSize=r?n[0]:t[0],this.lastDimensionSize<256?this.workPerThread=1:this.lastDimensionSize<512?this.workPerThread=2:this.workPerThread=4,this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.useSharedMemoryWithB=r,this.op=e,this.shaderKey=`binaryShared_${e}_${this.lastDimensionSize}_${this.useSharedMemoryWithB}`}getUserCode(){let e=this.lastDimensionSize>1?`coords[${this.outputShape.length-1}]`:"0",t=this.useSharedMemoryWithB?`let a = getAByOutputCoords(coords);
2021-11-08 13:36:26 +01:00
let b = sharedBuf[${e}];`:`let a = sharedBuf[${e}];
2022-01-08 18:43:44 +01:00
let b = getBByOutputCoords(coords);`;return`
2021-11-08 13:36:26 +01:00
fn binaryOperation(a : f32, b : f32) -> f32 {
2022-01-16 15:49:55 +01:00
${Op(this.op,!1)}
2021-11-08 13:36:26 +01:00
}
var<workgroup> sharedBuf : array<f32, ${this.lastDimensionSize}>;
${Je()}
2021-11-08 13:36:26 +01:00
// Fill in the shared memory buffer. Here we need a loop to make sure
// that all data in A|B are uploaded when |sharedMemorySize| is larger
// than work group size.
for(var localIndex = i32(localId.x); localIndex < ${this.lastDimensionSize}; localIndex = localIndex + ${this.workGroupSize[0]}) {
sharedBuf[localIndex] = f32(${this.useSharedMemoryWithB?"B":"A"}.numbers[localIndex]);
}
workgroupBarrier();
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
let flatIndex = index * ${this.workPerThread} + i;
if(flatIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(flatIndex);
2021-11-08 13:36:26 +01:00
${t}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(flatIndex, binaryOperation(a, b));
2021-11-08 13:36:26 +01:00
}
}
}
2022-01-16 15:49:55 +01:00
`}},Tce=class{constructor(e,t,n){this.variableNames=["A","B"],this.workPerThread=4,this.isVec4=!0,this.size=!0;let r=128;this.workGroupSize=[r,1,1],this.outputShape=N.assertAndGetBroadcastShape(t,n),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.op=e,this.shaderKey=`binaryVec4_${e}`}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn binaryOperation(a : vec4<f32>, b : vec4<f32>) -> vec4<f32> {
2022-01-16 15:49:55 +01:00
${Op(this.op,this.isVec4)}
2021-11-06 15:21:51 +01:00
}
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let a = getAByOutputIndex(index);
let b = getBByOutputIndex(index);
setOutputAtIndex(index, binaryOperation(a, b));
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}},z4=class{constructor(e,t,n){this.variableNames=["A","B"],this.size=!0;let r=128;this.workGroupSize=[r,1,1],this.outputShape=N.assertAndGetBroadcastShape(t,n),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey=`binary_${e}`,this.op=e}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn binaryOperation(a : f32, b : f32) -> f32 {
2022-01-16 15:49:55 +01:00
${Op(this.op,!1)}
2021-10-30 18:21:54 +02:00
}
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let a = getAByOutputIndex(index);
let b = getBByOutputIndex(index);
setOutputAtIndex(index, binaryOperation(a, b));
2021-10-30 18:21:54 +02:00
}
}
2022-01-16 15:49:55 +01:00
`}};function L4(e,t,n){if(w.arraysEqual(t,n)&&w.sizeFromShape(t)%4===0)return new Tce(e,t,n);let s=t.length===1&&n.length>1&&t[0]<1024,a=n.length===1&&t.length>1&&n[0]<1024;return s||a?new Cce(e,t,n,a):new z4(e,t,n)}function is(e){let{inputs:t}=e,{x:n}=t;return e.backend.incRef(n.dataId),{dataId:n.dataId,shape:n.shape,dtype:n.dtype}}var Nce={kernelName:Qa,backendName:"webgpu",kernelFunc:is};function Tc(e){let{inputs:t,backend:n}=e,{real:r,imag:s}=t,a=n.makeTensorInfo(r.shape,"complex64"),o=n.tensorMap.get(a.dataId),i=is({inputs:{x:r},backend:n}),l=is({inputs:{x:s},backend:n});return o.complexTensorInfos={real:i,imag:l},a}var Ece={kernelName:gd,backendName:"webgpu",kernelFunc:Tc},Mp=class{constructor(e,t){this.variableNames=["A"],this.size=!0;let n=128;this.workGroupSize=[n,1,1],this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.op=t,this.shaderKey=`unary_${t}`}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn unaryOperation(a : f32) -> f32 {
2022-01-16 15:49:55 +01:00
${Cc(this.op,!1)}
2021-11-06 15:21:51 +01:00
}
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let a = getAByOutputIndex(index);
setOutputAtIndex(index, unaryOperation(a));
2021-11-08 13:36:26 +01:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Nn({opType:e,cpuKernelImpl:t,dtype:n}){return({inputs:r,backend:s})=>{let{x:a}=r,o=s,i=n||a.dtype;if(o.shouldExecuteOnCPU([a])&&t!=null){let c=o.tensorMap.get(a.dataId),u=t(c.values,i);return o.makeTensorInfo(a.shape,i,u)}let l=new Mp(a.shape,e);return o.runWebGPUProgram(l,[a],i)}}function Kn({opSnippet:e,cpuKernelImpl:t,supportsComplex:n=!1,dtype:r}){return({inputs:s,backend:a})=>{let{a:o,b:i}=s,l=a;if(n&&o.dtype==="complex64"){let d=l.tensorMap.get(o.dataId),p=l.tensorMap.get(i.dataId),h,f;if(e!==qt.MUL)[h,f]=[[d.complexTensorInfos.real,p.complexTensorInfos.real],[d.complexTensorInfos.imag,p.complexTensorInfos.imag]].map(g=>{let[y,x]=g,A={dataId:y.dataId,dtype:y.dtype,shape:o.shape},b={dataId:x.dataId,dtype:x.dtype,shape:i.shape},v=L4(e,o.shape,i.shape);return l.runWebGPUProgram(v,[A,b],Wn(y.dtype,x.dtype))});else{let g=new M4(qt.COMPLEX_MULTIPLY_REAL,o.shape,i.shape),y=new M4(qt.COMPLEX_MULTIPLY_IMAG,o.shape,i.shape),x=[{dataId:d.complexTensorInfos.real.dataId,dtype:d.complexTensorInfos.real.dtype,shape:o.shape},{dataId:d.complexTensorInfos.imag.dataId,dtype:d.complexTensorInfos.imag.dtype,shape:o.shape},{dataId:p.complexTensorInfos.real.dataId,dtype:p.complexTensorInfos.real.dtype,shape:i.shape},{dataId:p.complexTensorInfos.imag.dataId,dtype:p.complexTensorInfos.imag.dtype,shape:i.shape}];h=l.runWebGPUProgram(g,x,"float32"),f=l.runWebGPUProgram(y,x,"float32")}let m=Tc({inputs:{real:h,imag:f},backend:l});return l.disposeData(h.dataId),l.disposeData(f.dataId),m}let c=r||Wn(o.dtype,i.dtype);if((o.dtype==="string"||i.dtype==="string"||l.shouldExecuteOnCPU([o,i]))&&t!=null){let d=l.tensorMap.get(o.dataId).values,p=l.tensorMap.get(i.dataId).values,h=o.dtype==="string"?N.fromUint8ToStringArray(d):d,f=o.dtype==="string"?N.fromUint8ToStringArray(p):p,[m,g]=t(o.shape,i.shape,h,f,c);return l.makeTensorInfo(g,c,m)}let u=L4(e,o.shape,i.shape);return l.runWebGPUProgram(u,[o,i],c)}}var{addImpl:Rce,ceilImpl:_ce,concatImpl:Dce,equalImpl:Pce,expImpl:$ce,expm1Impl:Fce,floorImpl:Oce,gatherNdImpl:Mce,gatherV2Impl:zce,greaterEqualImpl:Lce,greaterImpl:Bce,lessEqualImpl:Wce,lessImpl:Vce,logImpl:Uce,maxImpl:Gce,maximumImpl:Hce,minimumImpl:jce,multiplyImpl:qce,negImpl:Xce,notEqualImpl:Kce,prodImpl:Zce,rangeImpl:Yce,rsqrtImpl:Jce,simpleAbsImpl:Qce,sliceImpl:ede,stridedSliceImpl:tde,stringNGramsImpl:nde,subImpl:rde,tileImpl:sde,topKImpl:ade,transposeImpl:ode,uniqueImpl:aAe}=Om,ide=Nn({opType:kt.ABS,cpuKernelImpl:Qce}),lde={kernelName:yi,backendName:"webgpu",kernelFunc:ide},ude=Kn({opSnippet:qt.ADD,cpuKernelImpl:Rce,supportsComplex:!0}),cde={kernelName:Zs,backendName:"webgpu",kernelFunc:ude},dde=class{constructor(e){this.workPerThread=4,this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e[0],this.variableNames=e.map((t,n)=>`T${n}`),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.shaderKey="addN"}getUserCode(){let e=[];this.variableNames.forEach(r=>{e.push(`let v${r} = get${r}ByOutputCoords(coords);`)});let t=this.variableNames.map(r=>`v${r}`).join(" + ");return`
${Je()}
2021-11-08 13:36:26 +01:00
for (var i = 0; i < ${this.workPerThread}; i = i + 1) {
let flatIndex = index * ${this.workPerThread} + i;
if (flatIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(flatIndex);
2021-11-08 13:36:26 +01:00
${e.join(`
`)}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(flatIndex, ${t});
2021-11-08 13:36:26 +01:00
}
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function pde(e){let{inputs:t,backend:n}=e,r=t;if(r.length===1)return is({inputs:{x:r[0]},backend:n});let s=r.map(i=>i.dtype).reduce((i,l)=>Wn(i,l)),a=r.map(i=>i.shape),o=new dde(a);return n.runWebGPUProgram(o,r,s)}var hde={kernelName:Fa,backendName:"webgpu",kernelFunc:pde},B4=class{constructor(e,t,n){this.workGroupSize=[64,1,1],this.variableNames=["x"],this.uniforms="axis : i32; infinityValue : f32;",this.size=!0;let r=[t];N.assertAxesAreInnerMostDims("arg"+n.charAt(0).toUpperCase()+n.slice(1),r,e.length),this.op=n==="min"?"<":">";let[s]=N.computeOutAndReduceShapes(e,r);this.outputShape=s.length===0?[1]:s,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,[1,1,1]),this.inputShape=e,this.shaderKey=`argMinMax${this.op}`}getUserCode(){let e=`
2021-11-08 13:36:26 +01:00
var<workgroup> xBestIndices : array<i32, ${this.workGroupSize[0]}>;
var<workgroup> xBestValues : array<f32, ${this.workGroupSize[0]}>;
2022-01-16 15:49:55 +01:00
`,t=(s,a)=>this.outputShape.length===1?s:`${s}[${a}]`,n=s=>this.inputShape.length===1?"uniforms.xShape":`uniforms.xShape[${s}]`;return`
2021-11-17 21:45:49 +01:00
fn DIV_CEIL(a : u32, b : u32) -> u32 {
return ((a - 1u) / b + 1u);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2021-11-17 21:45:49 +01:00
${e}
2021-11-08 13:36:26 +01:00
// In order to get a flattened index into the input tensor, we need to
// add back the index along the reduced dimension to |outputCoords|.
// This function outputs the offset to the first value along
// |axis| and the stride to get the next value of the input along |axis|.
2021-11-17 21:45:49 +01:00
fn getInputCoordInfo(outputIndex : i32) -> vec2<i32>{
2022-01-08 18:43:44 +01:00
let outputCoords = getCoordsFromIndex(outputIndex);
2021-11-08 13:36:26 +01:00
var i = ${this.outputShape.length-1};
var stride = 1;
var inputStride = 1;
var offset = 0;
for (var r = 1; r <= ${this.inputShape.length}; r = r + 1) {
2021-11-17 21:45:49 +01:00
let length = ${n(`${this.inputShape.length} - r`)};
2021-11-08 13:36:26 +01:00
if (${this.inputShape.length} - r == uniforms.axis) {
inputStride = stride;
} else {
2021-11-17 21:45:49 +01:00
offset = offset + ${t("outputCoords","i")} * stride;
2021-11-08 13:36:26 +01:00
i = i - 1;
}
stride = stride * length;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
return vec2<i32>(offset, inputStride);
}
fn getInputIndex(coordInfo : vec2<i32>, index : i32) -> i32{
return coordInfo[0] + coordInfo[1] * index;
}
${Je()}
2021-11-17 21:45:49 +01:00
let outputIndex = index / i32(workGroupSizeX);
let coordInfo = getInputCoordInfo(outputIndex);
let Length = ${n("uniforms.axis")};
2021-11-08 13:36:26 +01:00
2021-11-17 21:45:49 +01:00
var bestIndex = i32(localId.x);
var bestValue = uniforms.infinityValue;
2021-11-08 13:36:26 +01:00
2021-11-17 21:45:49 +01:00
for (var k = i32(localId.x); k < Length && outputIndex < uniforms.size;
k = k + i32(workGroupSizeX)) {
let candidate = f32(x.numbers[getInputIndex(coordInfo, k)]);
if (!isNanCustom(candidate) && candidate ${this.op} bestValue) {
bestValue = candidate;
bestIndex = k;
}
}
xBestValues[localId.x] = bestValue;
xBestIndices[localId.x] = bestIndex;
workgroupBarrier();
2021-11-08 13:36:26 +01:00
2021-11-17 21:45:49 +01:00
var reduceSize = min(u32(Length), workGroupSizeX);
for (var currentSize = reduceSize / 2u; reduceSize > 1u;
currentSize = reduceSize / 2u) {
let interval = DIV_CEIL(reduceSize, 2u);
if (localId.x < currentSize) {
let candidate = xBestValues[localId.x + interval];
if (candidate ${this.op} bestValue) {
2021-11-08 13:36:26 +01:00
bestValue = candidate;
2021-11-17 21:45:49 +01:00
xBestValues[localId.x] = bestValue;
xBestIndices[localId.x] = xBestIndices[localId.x + interval];
2021-11-08 13:36:26 +01:00
}
}
2021-11-17 21:45:49 +01:00
reduceSize = interval;
workgroupBarrier();
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
2021-11-17 21:45:49 +01:00
if (localId.x == 0u && outputIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
setOutputAtIndexI32(outputIndex, xBestIndices[localId.x]);
2021-11-17 21:45:49 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}},fde=class{constructor(e,t){this.variableNames=["A"],this.workGroupSize=[16,16,1];let n=new Array(e.length);for(let r=0;r<n.length;r++)n[r]=e[t[r]];this.outputShape=n,this.dispatchLayout={x:[0],y:[1]},this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[1,1,1]),this.shaderKey="transposeShared"}getUserCode(){return`
2021-11-08 13:36:26 +01:00
let TILE_DIM = ${this.workGroupSize[0]};
var<workgroup> tile : array<array<f32, ${this.workGroupSize[0]+1}>, ${this.workGroupSize[0]}>;
2022-01-16 15:49:55 +01:00
${Bx()}
2021-11-08 13:36:26 +01:00
fn main([[builtin(local_invocation_id)]] localId : vec3<u32>,
[[builtin(workgroup_id)]] workgroupId : vec3<u32>) {
var x = i32(workgroupId.x) * TILE_DIM + i32(localId.x);
var y = i32(workgroupId.y) * TILE_DIM + i32(localId.y);
let width = uniforms.outShape[0];
let height = uniforms.outShape[1];
if (x < width && y < height) {
tile[localId.y][localId.x] =
A.numbers[y * width + x];
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
workgroupBarrier();
x = i32(workgroupId.y) * TILE_DIM + i32(localId.x);
y = i32(workgroupId.x) * TILE_DIM + i32(localId.y);
if (x < height && y < width) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex((y * height + x), tile[localId.x]
2021-11-08 13:36:26 +01:00
[localId.y]);
2021-10-30 18:21:54 +02:00
}
}
2022-01-16 15:49:55 +01:00
`}},mde=class{constructor(e,t){this.variableNames=["A"],this.workPerThread=4,this.workGroupSize=[64,1,1],this.size=!0;let n=new Array(e.length);for(let r=0;r<n.length;r++)n[r]=e[t[r]];this.outputShape=n,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.newDim=t,this.shaderKey=`transpose_${t}`}getUserCode(){let e=In(this.outputShape.length),t=gde(this.newDim);return`
${Je()}
2021-11-08 13:36:26 +01:00
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
let flatIndex = index * ${this.workPerThread} + i;
if(flatIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
let resRC = getCoordsFromIndex(flatIndex);
setOutputAtIndex(flatIndex, A.numbers[getIndexFromCoords${this.outputShape.length}D(
2021-11-08 13:36:26 +01:00
${e}(${t}), uniforms.aShape)]);
}
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function gde(e){let t=e.length;if(t>4)throw Error(`Transpose for rank ${t} is not yet supported`);let n=new Array(t);for(let r=0;r<e.length;r++)n[e[r]]=`resRC[${r}]`;return n.join()}function zl(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{perm:a}=r,o=n,i=s.shape.length,l=new Array(i);for(let u=0;u<l.length;u++)l[u]=s.shape[a[u]];if(n.shouldExecuteOnCPU([s])){let d=o.tensorMap.get(s.dataId).values,p=ode(d,s.shape,s.dtype,a,l);return n.makeTensorInfo(l,s.dtype,p)}if(s.shape.length===2&&w.arraysEqual(a,[1,0])){let u=new fde(s.shape,a);return o.runWebGPUProgram(u,[s],s.dtype)}let c=new mde(s.shape,a);return o.runWebGPUProgram(c,[s],s.dtype)}var yde={kernelName:Co,backendName:"webgpu",kernelFunc:zl};function Ade(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a}=r,o=w.parseAxisParam(a,s.shape),i=N.getAxesPermutation(o,s.shape.length),l=s,c=[];i!=null&&(l=zl({inputs:{x:s},backend:n,attrs:{perm:i}}),c.push(l),o=N.getInnerMostAxes(o.length,l.shape.length)),N.assertAxesAreInnerMostDims("argMax",[o[0]],l.shape.length);let u=new B4(l.shape,o[0],"max"),d=[{type:"int32",data:[o[0]]},{type:"float32",data:[Number.NEGATIVE_INFINITY]}],p=n.runWebGPUProgram(u,[l],"int32",d);return c.forEach(h=>n.disposeData(h.dataId)),p}var xde={kernelName:Oa,backendName:"webgpu",kernelFunc:Ade};function bde(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a}=r,o=w.parseAxisParam(a,s.shape),i=N.getAxesPermutation(o,s.shape.length),l=s,c=[];i!=null&&(l=zl({inputs:{x:s},backend:n,attrs:{perm:i}}),c.push(l),o=N.getInnerMostAxes(o.length,l.shape.length)),N.assertAxesAreInnerMostDims("argMin",[o[0]],l.shape.length);let u=new B4(l.shape,o[0],"min"),d=[{type:"int32",data:[o[0]]},{type:"float32",data:[Number.POSITIVE_INFINITY]}],p=n.runWebGPUProgram(u,[l],"int32",d);return c.forEach(h=>n.disposeData(h.dataId)),p}var vde={kernelName:hu,backendName:"webgpu",kernelFunc:bde},W4=class{constructor(e,t){this.variableNames=["x"],this.uniforms="stride : vec2<i32>; pad : vec2<i32>; dilation : vec2<i32>; convDims : vec2<i32>; filterDims : vec2<i32>;",this.workGroupSize=[128,1,1],this.size=!0,this.outputShape=e.outShape,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey=`pool2D_${t}`,this.poolType=t}getUserCode(){let e="resultValue = max(value, resultValue);";this.poolType==="avg"&&(e="resultValue = resultValue + value; count = count + 1.0;");let t="resultValue";return this.poolType==="avg"&&(t="resultValue / count"),`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let xRCCorner = vec2<i32>(coords.yz) * uniforms.stride - uniforms.pad;
let xRCorner = xRCCorner.x;
let xCCorner = xRCCorner.y;
var resultValue = ${this.poolType==="avg"?"0.0":"-1.0 / pow(10.0, -20.0)"};
var count = 0.0;
for (var wR = 0; wR < uniforms.filterDims.x; wR = wR + uniforms.dilation.x) {
let xR = xRCorner + wR;
if (xR < 0 || xR >= uniforms.convDims.x) {
continue;
}
for (var wC = 0; wC < uniforms.filterDims.y; wC = wC + uniforms.dilation.y) {
let xC = xCCorner + wC;
if (xC < 0 || xC >= uniforms.convDims.y) {
continue;
}
let value = getX(batch, xR, xC, coords[3]);
${e}
}
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, ${t});
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}},V4=class{constructor(e){this.variableNames=["x"],this.uniforms="stride : vec2<i32>;",this.workGroupSize=[256,1,1],this.size=!0,this.outputShape=e.outShape,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="poolWithFilterSizeEqualsOne"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let d = coords[3];
let xRCCorner = coords.yz * uniforms.stride;
let xRCorner = xRCCorner.x;
let xCCorner = xRCCorner.y;
let value = getX(batch, xRCorner, xCCorner, d);
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, value);
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
`}};function wde(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{filterSize:a,strides:o,pad:i,dimRoundingMode:l}=r,c=1,u=N.computePool2DInfo(s.shape,a,o,c,i,l);if(u.filterWidth===1&&u.filterHeight===1&&w.arraysEqual(u.inShape,u.outShape))return is({inputs:{x:s},backend:n});let d,p=[{type:"int32",data:[u.strideHeight,u.strideWidth]}];return u.filterHeight===1&&u.filterWidth===1?d=new V4(u):(d=new W4(u,"avg"),p.push({type:"int32",data:[u.padInfo.top,u.padInfo.left]},{type:"int32",data:[u.dilationHeight,u.dilationWidth]},{type:"int32",data:[u.inHeight,u.inWidth]},{type:"int32",data:[u.effectiveFilterHeight,u.effectiveFilterWidth]})),n.runWebGPUProgram(d,[s],s.dtype,p)}var kde={kernelName:Ma,backendName:"webgpu",kernelFunc:wde};function Ide(e){let{inputs:t,backend:n,attrs:r}=e,{a:s,b:a}=t,{transposeA:o,transposeB:i}=r;return qx({a:s,b:a,transposeA:o,transposeB:i,backend:n})}var Sde={kernelName:za,backendName:"webgpu",kernelFunc:Ide},Cde=class{constructor(e,t){this.variableNames=["source"],this.workPerThread=1,this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=t,this.rank=t.length,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.start=e,this.uniforms=`start : ${In(e.length)}; `,this.shaderKey="slice"}getUserCode(){let e=In(this.rank),t=Tde(this.rank),n;return this.start.length===1?n=this.outputShape.map((s,a)=>"sourceLoc = uniforms.start + coords;"):n=this.outputShape.map((s,a)=>`sourceLoc.${Xx[a]} = uniforms.start[${a}] + coords.${Xx[a]};`),`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
var sourceLoc : ${e};
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
${n.join(`
`)}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getSource(${t}));
2021-11-08 13:36:26 +01:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},Xx=["x","y","z","w","u","v"];function Tde(e){if(e===1)return"sourceLoc";if(e<=6)return Xx.slice(0,e).map(t=>`sourceLoc.${t}`).join(",");throw Error(`Slicing for rank ${e} is not yet supported`)}function Nc(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{begin:a,size:o}=r,[i,l]=zt.parseSliceParams(s,a,o);if(zt.assertParamsValid(s,i,l),n.shouldExecuteOnCPU([s])||s.dtype==="string"){let d=n.tensorMap.get(s.dataId),p=ede(d.values,i,l,s.shape,s.dtype);return n.makeTensorInfo(l,s.dtype,p)}if(w.sizeFromShape(l)===0)return n.makeTensorInfo(l,s.dtype,[]);let c=new Cde(i,l),u=[{type:"int32",data:i}];return n.runWebGPUProgram(c,[s],s.dtype,u)}var Nde={kernelName:ji,backendName:"webgpu",kernelFunc:Nc},Ede=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockShape:a,crops:o}=r;w.assert(s.shape.length<=4,()=>"batchToSpaceND for rank > 4 with a WebGPU backend not implemented yet");let i=a.reduce((x,A)=>x*A),l=N.getReshaped(s.shape,a,i),c=N.getPermuted(l.length,a.length),u=N.getReshapedPermuted(s.shape,a,i),d=N.getSliceBeginCoords(o,a.length),p=N.getSliceSize(u,o,a.length),h=[],f=Xe({inputs:{x:s},backend:n,attrs:{shape:l}}),m=zl({inputs:{x:f},backend:n,attrs:{perm:c}}),g=Xe({inputs:{x:m},backend:n,attrs:{shape:u}}),y=Nc({inputs:{x:g},backend:n,attrs:{begin:d,size:p}});return h.push(f),h.push(m),h.push(g),h.forEach(x=>n.disposeData(x.dataId)),y},Rde={kernelName:Ai,backendName:"webgpu",kernelFunc:Ede},U4=Kn({opSnippet:qt.NOT_EQUAL,dtype:"bool",cpuKernelImpl:Kce}),_de={kernelName:$i,backendName:"webgpu",kernelFunc:U4};function zp(e){let{inputs:t,backend:n}=e,{input:r}=t,s=n.tensorMap.get(r.dataId);return is({inputs:{x:s.complexTensorInfos.real},backend:n})}var Dde={kernelName:Sd,backendName:"webgpu",kernelFunc:zp};function Pde(e,t){let n=new Mp(e.shape,kt.TO_INT),r=t.runWebGPUProgram(n,[e],"int32");return{dataId:r.dataId,shape:r.shape,dtype:r.dtype}}function Kx(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{dtype:a}=r;if(a==="complex64"){if(s.dtype==="complex64")return is({inputs:{x:s},backend:n});let o=Ht(s.shape),i=Kx({inputs:{x:s},backend:n,attrs:{dtype:"float32"}}),l=Tc({inputs:{real:i,imag:o},backend:n});return o.dispose(),n.disposeData(i.dataId),l}if(s.dtype==="complex64"){let o=zp({inputs:{input:s},backend:n}),i=Kx({inputs:{x:o},backend:n,attrs:{dtype:a}});return n.disposeData(o.dataId),i}if(!w.hasEncodingLoss(s.dtype,a)){let o=is({inputs:{x:s},backend:n});return{dataId:o.dataId,shape:o.shape,dtype:a}}if(a==="int32")return Pde(s,n);if(a==="bool"){let o=n.makeTensorInfo([],"bool",w.getTypedArrayFromDType("bool",1)),l=U4({inputs:{a:s,b:o},backend:n});return n.disposeData(o.dataId),l}throw new Error(`Error in Cast: failed to cast ${s.dtype} to ${a}`)}var $de={kernelName:La,backendName:"webgpu",kernelFunc:Kx},Fde=Nn({opType:kt.CEIL,cpuKernelImpl:_ce}),Ode={kernelName:Ba,backendName:"webgpu",kernelFunc:Fde},Mde=class{constructor(e){this.variableNames=["A"],this.uniforms="minVal : f32; maxVal : f32;",this.workPerThread=4,this.workGroupSize=[64,1,1],this.isVec4=!0,this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.shaderKey="clipVec4"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if(index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let value = getAByOutputIndex(index);
2021-11-08 13:36:26 +01:00
var clampedValue : vec4<f32>;
for (var i = 0; i < 4; i = i + 1) {
if (isNanCustom(value[i])) {
clampedValue[i] = value[i];
} else {
clampedValue[i] = clamp(value[i], uniforms.minVal, uniforms.maxVal);
}
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, clampedValue);
2021-11-08 13:36:26 +01:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},zde=class{constructor(e){this.variableNames=["A"],this.uniforms="minVal : f32; maxVal : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="clip"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if(index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let value = getAByOutputIndex(index);
2021-11-08 13:36:26 +01:00
if (isNanCustom(value)) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, value);
2021-11-08 13:36:26 +01:00
return;
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, clamp(value, uniforms.minVal, uniforms.maxVal));
2021-11-08 13:36:26 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Lde(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{clipValueMin:a,clipValueMax:o}=r,i,l=[{type:"float32",data:[a]},{type:"float32",data:[o]}];return w.sizeFromShape(s.shape)%4===0?i=new Mde(s.shape):i=new zde(s.shape),n.runWebGPUProgram(i,[s],s.dtype,l)}var Bde={kernelName:Ys,backendName:"webgpu",kernelFunc:Lde},Wde=class{constructor(e){this.uniforms="",this.workPerThread=4,this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=N.computeOutShape(e,1),this.variableNames=e.map((t,n)=>`T${n}`),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.offsetLength=e.length-1;for(let t=0;t<this.offsetLength;t++)this.uniforms+=`offset${t} : i32;`;this.shaderKey="concat"}getUserCode(){let e=[];if(this.offsetLength>0){e.push("if (yC < uniforms.offset0){ setOutputAtCoords(coords.x, coords.y, getT0(yR, yC)); }");for(let s=1;s<this.offsetLength;s++)e.push(`else if (yC < uniforms.offset${[s]}){ setOutputAtCoords(coords.x, coords.y, getT${s}(yR, yC - uniforms.offset${s-1})); }`);let n=this.offsetLength,r=this.offsetLength-1;e.push(`else { setOutputAtCoords(coords.x, coords.y, getT${n}(yR, yC - uniforms.offset${r})); }`)}else e.push("setOutputAtCoords(coords.x, coords.y, getT0(yR, yC));");return`
${Je()}
2021-11-08 13:36:26 +01:00
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
let flatIndex = index * ${this.workPerThread} + i;
if(flatIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(flatIndex);
2021-11-08 13:36:26 +01:00
let yR = coords.x;
let yC = coords.y;
2021-11-06 15:21:51 +01:00
2021-11-23 16:40:40 +01:00
${e.join(`
2021-11-08 13:36:26 +01:00
`)}
}
}
}
2022-01-16 15:49:55 +01:00
`}};function u0(e){let{inputs:t,backend:n}=e,{input:r}=t,s=n.tensorMap.get(r.dataId);return is({inputs:{x:s.complexTensorInfos.imag},backend:n})}var Vde={kernelName:vd,backendName:"webgpu",kernelFunc:u0};function Zx(e,t,n){let r=e[0].dtype;if(r==="complex64"){let h=e.map(x=>zp({inputs:{input:x},backend:n})),f=e.map(x=>u0({inputs:{input:x},backend:n})),m=Zx(h,t,n),g=Zx(f,t,n),y=Tc({inputs:{real:m,imag:g},backend:n});return h.forEach(x=>n.disposeData(x.dataId)),f.forEach(x=>n.disposeData(x.dataId)),n.disposeData(m.dataId),n.disposeData(g.dataId),y}let s=n.shouldExecuteOnCPU(e);if(r==="string"&&(s=!0),s){let h=e.map(b=>{let v=w.sizeFromShape(b.shape.slice(t));return Xe({inputs:{x:b},backend:n,attrs:{shape:[-1,v]}})}),f=h.map(b=>({vals:n.readSync(b.dataId),shape:b.shape})),m=N.computeOutShape(h.map(b=>b.shape),1),g=h[0].shape[0]===1,y=Dce(f,m,r,g),x=N.computeOutShape(e.map(b=>b.shape),t),A=n.makeTensorInfo(x,r,y);return h.forEach(b=>n.disposeData(b.dataId)),A}let{tensors2D:a,outShape:o}=Ude(e,t,n),i=a.map(h=>h.shape),l=new Wde(i),c=[],u=new Array(i.length-1);if(u.length>0){u[0]=i[0][1],c.push({type:"int32",data:[u[0]]});for(let h=1;h<u.length;h++)u[h]=u[h-1]+i[h][1],c.push({type:"int32",data:[u[h]]})}let d=n.runWebGPUProgram(l,a,a[0].dtype,c);a.forEach(h=>n.disposeData(h.dataId));let p=Xe({inputs:{x:d},backend:n,attrs:{shape:o}});return n.disposeData(d.dataId),p}function Ude(e,t,n){let r=N.computeOutShape(e.map(a=>a.shape),t);return{tensors2D:e.map(a=>Xe({inputs:{x:a},backend:n,attrs:{shape:[w.sizeFromShape(a.shape.slice(0,t)),w.sizeFromShape(a.shape.slice(t))]}})),outShape:r}}function G4(e){let{inputs:t,backend:n,attrs:r}=e,{axis:s}=r,a=w.parseAxisParam(s,t[0].shape)[0],o=N.computeOutShape(t.map(c=>c.shape),a);if(w.sizeFromShape(o)===0)return n.makeTensorInfo(o,t[0].dtype,[]);let i=t.filter(c=>w.sizeFromShape(c.shape)>0);if(i.length===1)return is({inputs:{x:i[0]},backend:n});let l=i.map(c=>c.shape);return N.assertParamsConsistent(l,a),Zx(i,a,n)}var Gde={kernelName:xi,backendName:"webgpu",kernelFunc:G4},Hde=class{constructor(e,t){this.variableNames=["A"],this.uniforms=`pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>; outWidth : i32; itemsPerBlockRow : i32;
inChannels : i32;`,this.workPerThread=4,this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]),this.isChannelsLast=t,this.shaderKey=`im2col_${this.isChannelsLast}`}getUserCode(){let e=this.isChannelsLast?0:1,t=this.isChannelsLast?1:2;return`
${Je()}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
for(var i = 0; i<${this.workPerThread}; i = i + 1) {
let flatIndex = index * ${this.workPerThread} + i;
2022-01-08 18:43:44 +01:00
let rc = getCoordsFromIndex(flatIndex);
2021-11-08 13:36:26 +01:00
if(flatIndex < uniforms.size) {
let blockIndex = rc[0];
let pos = rc[1];
let offsetY = blockIndex / uniforms.outWidth * uniforms.stride[1] - uniforms.pad[1];
let d0 = offsetY + uniforms.dilation[1] * pos / uniforms.itemsPerBlockRow;
var value = 0.0;
if(d0 < uniforms.aShape[${e}] && d0 >= 0) {
let offsetX = (blockIndex % uniforms.outWidth) * uniforms.stride[0] -
uniforms.pad[0];
let d1 = offsetX + uniforms.dilation[0] * ((pos %
uniforms.itemsPerBlockRow) / uniforms.inChannels);
let ch = pos % uniforms.inChannels;
if(d1 < uniforms.aShape[${t}] && d1 >= 0) {
value = getA(d0, d1, ch);
}
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(flatIndex, value);
2021-11-08 13:36:26 +01:00
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function H4({x:e,filter:t,convInfo:n,backend:r,bias:s=null,preluActivationWeights:a=null,leakyreluAlpha:o=0,activation:i=null}){let l=e.shape,c=n.dataFormat==="channelsLast",u=!1,d=!1,p=c?l[0]*l[1]*l[2]:l[0]*l[2]*l[3],h=Xe({inputs:{x:e},backend:r,attrs:{shape:[1,p,n.inChannels]}}),f=Xe({inputs:{x:t},backend:r,attrs:{shape:[1,n.inChannels,n.outChannels]}}),m=qx({a:h,b:f,transposeA:u,transposeB:d,backend:r,bias:s,activation:i,preluActivationWeights:a,leakyreluAlpha:o}),g=Xe({inputs:{x:m},backend:r,attrs:{shape:n.outShape}});return r.disposeData(h.dataId),r.disposeData(f.dataId),r.disposeData(m.dataId),g}function jde({x:e,filter:t,convInfo:n,backend:r,bias:s=null,preluActivationWeights:a=null,leakyreluAlpha:o=0,activation:i=null}){let{filterWidth:l,filterHeight:c,inChannels:u,strideWidth:d,strideHeight:p,padInfo:h,outWidth:f,outHeight:m,dilationWidth:g,dilationHeight:y,dataFormat:x}=n,A=x==="channelsLast",b=l*c*u,v=m*f,C=[v,b],I=!1,E=!1,R=[],F=Xe({inputs:{x:e},backend:r,attrs:{shape:e.shape.slice(1)}}),_=Xe({inputs:{x:t},backend:r,attrs:{shape:[1,b,-1]}});R.push(F),R.push(_);let P=new Hde(C,A),T=[{type:"int32",data:[h.left,h.top]},{type:"int32",data:[d,p]},{type:"int32",data:[g,y]},{type:"int32",data:[f]},{type:"int32",data:[u*l]},{type:"int32",data:[u]}],O=r.runWebGPUProgram(P,[F],F.dtype,T),G=Xe({inputs:{x:O},backend:r,attrs:{shape:[1,C[0],C[1]]}});R.push(O),R.push(G);let K=[1,C[0],C[1]],z=new O4(K,[1,v,n.outChannels],Y().get("WEBGPU_MATMUL_WORK_PER_THREAD"),I,E),j=K[1],W=K[2],Q=n.outChannels,ne=[{type:"int32",data:[j]},{type:"int32",data:[Q]},{type:"int32",data:[W]}],oe=r.runWebGPUProgram(z,[G,_],G.dtype,ne),Z=A?[1,m,f,n.outChannels]:[1,n.outChannels,m,f],ae=Xe({inputs:{x:oe},backend:r,attrs:{shape:Z}});R.push(oe);for(let se of R)r.disposeData(se.dataId);return ae}var j4=class{constructor(e,t=!1,n=null,r=!1,s=!1){this.variableNames=["x","W"],this.uniforms=`filterDims : vec2<i32>; pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>;
dimAOuter : i32; dimBOuter : i32; dimInner : i32;`,this.isVec4=!0,this.outputShape=e.outShape,w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),this.dispatchLayout={x:[3],y:[1,2],z:[0]},this.workGroupSize=[8,8,1];let a=[4,4,1];this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,a),this.convInfo=e,this.addBias=t,this.activation=n,this.hasPreluActivationWeights=r,this.hasLeakyreluAlpha=s,this.addBias&&this.variableNames.push("bias"),this.hasPreluActivationWeights&&this.variableNames.push("preluActivationWeights"),this.hasLeakyreluAlpha&&this.variableNames.push("leakyreluAlpha"),[this.fitA,this.fitB]=this.getShapeFit(a),this.shaderKey=`conv2DMMVec4_${this.activation}_${this.fitA}_${this.fitB}`}getShapeFit(e){let t=this.workGroupSize[1]*e[1],n=this.workGroupSize[0]*e[0],r=n,s=[t,r],a=[r,n],o=this.outputShape[1]*this.outputShape[2],i=this.outputShape[3],l=this.convInfo.filterHeight*this.convInfo.filterWidth*this.convInfo.inChannels;return[da(s,[o,l]),da(a,[l,i])]}getSampleAWithRemainder(e){return`let flatIndex${e} = getIndexFromCoords4D(coord, uniforms.xShape);
2021-11-08 13:36:26 +01:00
let divBy4Remainder${e} = flatIndex${e} % 4;
let divBy4Index${e} = flatIndex${e} / 4;
let curData${e} = x.numbers[divBy4Index${e}];
if (divBy4Remainder${e} == 0) {
temp = curData${e};
2021-11-06 15:21:51 +01:00
} else {
2021-11-08 13:36:26 +01:00
// TODO: This could end up being a redundant load with another one in
// the same shader invocation. Perhaps there's an opportunity for
// optimization
let nextData${e} = x.numbers[divBy4Index${e} + 1];
if (divBy4Remainder${e} == 1) {
temp = vec4<f32>(curData${e}.yzw, nextData${e}.x);
} else if (divBy4Remainder${e} == 2) {
2021-11-08 13:36:26 +01:00
temp = vec4<f32>(curData${e}.zw, nextData${e}.xy);
} else if (divBy4Remainder${e} == 3) {
2021-11-08 13:36:26 +01:00
temp = vec4<f32>(curData${e}.w, nextData${e}.xyz);
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}getUserCode(){let t=F4([4,4,1],this.workGroupSize),s=`let outRow = r / uniforms.outShape[2];
2021-11-08 13:36:26 +01:00
let outCol = r % uniforms.outShape[2];
let WRow = c / (uniforms.filterDims[1] * uniforms.xShape[3]);
let WCol = c / uniforms.xShape[3] % uniforms.filterDims[1];
let inChCoord = c % uniforms.xShape[3];
var coord = vec4<i32>(
batch,
outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0],
outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1],
inChCoord);
var resData = vec4<f32>(0.0);
${this.convInfo.inChannels%4===0?`// The bounds checking is always needed since we use it to pad zero for
// the 'same' padding type.
if (coordsInBounds4D(coord, uniforms.xShape)) {
2022-01-08 18:43:44 +01:00
resData = x.numbers[getIndexFromCoords4D(coord, uniforms.xShape) / 4];
2021-11-08 13:36:26 +01:00
} else {
resData = vec4<f32>(0.0); }`:`var temp = vec4<f32>(0.0);
${this.getSampleAWithRemainder(1)}
resData = temp;
if (WCol == (uniforms.filterDims[1] - 1)) {
coord = vec4<i32>(
coord.x, coord.y + 1, coord.z + 1 - uniforms.filterDims[1], 0);
${this.getSampleAWithRemainder(2)}
if (inChCoord == 0) {
resData = vec4<f32>(resData.xyz, temp.x);
} else if (inChCoord == 1) {
2021-11-08 13:36:26 +01:00
resData = vec4<f32>(resData.xy, temp.xy);
} else {
resData = vec4<f32>(resData.x, temp.xyz);
}
}
`}
2022-01-16 15:49:55 +01:00
return resData;`,a=this.fitA?`${s}`:`if (r < uniforms.dimAOuter && c < uniforms.dimInner) {
${s}
2021-11-08 13:36:26 +01:00
}
return vec4<f32>(0.0);
`,o=this.fitB?"return W.numbers[row * uniforms.dimBOuter / 4 + col];":`if(coordsInBounds2D(vec2<i32>(row, col * 4), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
return W.numbers[row * uniforms.dimBOuter / 4 + col];
}
return vec4<f32>(0.0);
2022-01-08 18:43:44 +01:00
`,i="",l="";if(this.activation){let d=pa(this.activation,this.isVec4);if(this.hasPreluActivationWeights)i=`fn activation(a : vec4<f32>, outCoord : vec4<i32>) -> vec4<f32> {
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${d}
2022-01-08 18:43:44 +01:00
}`;else{if(this.hasLeakyreluAlpha)throw i=`fn activation(outCoord: vec4<f32>) -> vec4<f32> {
let b = getLeakyreluAlphaByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${d}
}`,new Error("Leakyrelu is not supported.");i=`
fn activation(a : vec4<f32>, outCoord : vec4<i32>) -> vec4<f32> {
${d}
2022-01-08 18:43:44 +01:00
}`}l="value = activation(value, outCoord);"}let c=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${i}
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> vec4<f32> {
let r = row;
let c = col * 4;
var batch = i32(globalId.z);
${a}
}
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> vec4<f32> {
${o}
}
fn mm_write(row : i32, col : i32, valueInput : vec4<f32>, globalId : vec3<u32>) {
var batch = i32(globalId.z);
var value = valueInput;
if (row < uniforms.dimAOuter && col * 4 < uniforms.dimBOuter)
{
let outCoord = vec4<i32>(
batch,
row / uniforms.outShape[2],
row % uniforms.outShape[2],
col * 4);
${c}
${l}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(outCoord[0], outCoord[1], outCoord[2], outCoord[3],
2021-11-08 13:36:26 +01:00
value);
}
}
${t}
2022-01-16 15:49:55 +01:00
`}},q4=class{constructor(e,t=!1,n=null,r=!1){this.variableNames=["x","W"],this.uniforms="filterDims : vec2<i32>; pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>; dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.outputShape=e.outShape,w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),this.dispatchLayout={x:[3],y:[1,2],z:[0]},this.workGroupSize=Wx(this.dispatchLayout,this.outputShape),this.elementsPerThread=Ux(this.dispatchLayout,this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,this.elementsPerThread),t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.convInfo=e,this.addBias=t,this.activation=n,this.hasPreluActivationWeights=r,[this.fitA,this.fitB]=this.getShapeFit(),this.shaderKey=`conv2DMM_${this.elementsPerThread}_${this.activation}_${this.fitA}_${this.fitB}`}getShapeFit(){let e=this.workGroupSize[1]*this.elementsPerThread[1],t=this.workGroupSize[0]*this.elementsPerThread[0],n=e>t?e:t;w.assert(n%this.workGroupSize[0]===0&&n%this.workGroupSize[1]===0,()=>"tileInner must be multiple of workgroupsize.x and workgroupsize.y");let r=[e,n],s=[n,t],a=this.outputShape[1]*this.outputShape[2],o=this.outputShape[3],i=this.convInfo.filterHeight*this.convInfo.filterWidth*this.convInfo.inChannels;return[da(r,[a,i]),da(s,[i,o])]}getUserCode(){let e=jx(this.elementsPerThread,this.workGroupSize),t=`
2021-11-08 13:36:26 +01:00
let outRow = row / uniforms.outShape[2];
let outCol = row % uniforms.outShape[2];
let WRow = col / (uniforms.filterDims[1] * uniforms.xShape[3]);
let WCol = col / uniforms.xShape[3] % uniforms.filterDims[1];
let coord = vec4<i32>(
batch,
outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0],
outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1],
col % uniforms.xShape[3]);
// The bounds checking is always needed since we use it to pad zero for the
// 'same' padding type.
if(coordsInBounds4D(coord, uniforms.xShape)) {
2022-01-08 18:43:44 +01:00
return x.numbers[getIndexFromCoords4D(coord, uniforms.xShape)];
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return 0.0;`,n=this.fitA?`${t}`:`if (row < uniforms.dimAOuter && col < uniforms.dimInner) {
${t}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return 0.0;
2022-01-16 15:49:55 +01:00
`,r=this.fitB?"return W.numbers[row * uniforms.dimBOuter + col];":`if(coordsInBounds2D(vec2<i32>(row, col), vec2<i32>(uniforms.dimInner, uniforms.dimBOuter))) {
2021-11-08 13:36:26 +01:00
return W.numbers[row * uniforms.dimBOuter + col];
}
return 0.0;
2022-01-16 15:49:55 +01:00
`,s="",a="";if(this.activation){let l=pa(this.activation,!1);this.hasPreluActivationWeights?s=`fn activation(a: f32, outCoord : vec4<i32>) -> f32 {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2021-11-08 13:36:26 +01:00
${l}
2022-01-16 15:49:55 +01:00
}`:s=`
2021-11-08 13:36:26 +01:00
fn activation(a : f32, outCoord : vec4<i32>) -> f32 {
${l}
}
2022-01-08 18:43:44 +01:00
`,a="value = activation(value, outCoord);"}let o=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
var batch = i32(globalId.z);
${n}
}
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
2022-01-16 15:49:55 +01:00
${r}
2021-11-08 13:36:26 +01:00
}
fn mm_write(row : i32, col : i32, valueInput : f32, globalId : vec3<u32>) {
var batch = i32(globalId.z);
var value = valueInput;
let outCoord = vec4<i32>(
batch,
row / uniforms.outShape[2],
row % uniforms.outShape[2],
col);
${o}
${a}
2022-01-08 18:43:44 +01:00
result.numbers[getIndexFromCoords4D(outCoord, uniforms.outShape)] = value;
2021-11-08 13:36:26 +01:00
}
${e}
2022-01-16 15:49:55 +01:00
`}},X4=class{constructor(e,t=!1,n=null,r=!1){this.variableNames=["x","W"],this.uniforms="filterDims : vec2<i32>; pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>;",this.workGroupSize=[128,1,1],this.outputShape=e.outShape,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.convInfo=e,this.addBias=t,this.activation=n,this.hasPreluActivationWeights=r,this.shaderKey=`conv2DNaive_${this.activation}`}getUserCode(){let e="",t="";if(this.activation){let s=pa(this.activation);this.hasPreluActivationWeights?e=`fn activation(a : f32, outCoord : vec4<i32>) -> f32{
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
}`:e=`
fn activation(a : f32, outCoord : vec4<i32>) -> f32{
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
`,t="value = activation(value, outCoord);"}let n=this.addBias?"value = value + getBiasByOutputCoords(outCoord);":"";return`
2021-11-08 13:36:26 +01:00
${e}
fn readInp(batch : i32, row : i32, col : i32, chan : i32) -> f32 {
let coord = vec4<i32>(batch, row, col, chan);
if(coordsInBounds4D(coord, uniforms.xShape)) {
return getX(batch, row, col, chan);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
return 0.0;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn readFilt(row : i32, col : i32, xChannel : i32, outChannel : i32) -> f32{
let coord = vec4<i32>(row, col, xChannel, outChannel);
if(coordsInBounds4D(coord, uniforms.wShape)) {
return getW(row, col, xChannel, outChannel);
}
return 0.0;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
fn writeResult(batch : i32, row : i32, col : i32, chan : i32, value : f32) {
let coord = vec4<i32>(batch, row, col, chan);
if (coordsInBounds4D(coord, uniforms.outShape)) {
${n}
${t}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(batch, row, col, chan, value);
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
${ca()}
2021-12-15 15:26:32 +01:00
let coords = getOutputCoords();
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let outChannel = coords[3];
var acc = 0.0;
for (var row = 0; row < uniforms.filterDims[0]; row = row + 1) {
for (var col = 0; col < uniforms.filterDims[1]; col = col + 1) {
for (var xChannel = 0; xChannel < uniforms.xShape[3]; xChannel = xChannel + 1) {
let coordRow = coords[1] * uniforms.stride[0] + uniforms.dilation[0] * row - uniforms.pad[0];
let coordCol = coords[2] * uniforms.stride[1] + uniforms.dilation[1] * col - uniforms.pad[1];
let v = readInp(batch, coordRow, coordCol, xChannel);
let f = readFilt(row, col, xChannel, outChannel);
acc = acc + v * f;
}
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
writeResult(batch, coords[1], coords[2], outChannel, acc);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function qde(e){let{inputs:t,attrs:n,backend:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dataFormat:l,dilations:c,dimRoundingMode:u}=n,d=N.convertConv2DDataFormat(l),p=N.computeConv2DInfo(s.shape,a.shape,o,c,i,u,!1,d);if(p.filterHeight===1&&p.filterWidth===1&&p.dilationHeight===1&&p.dilationWidth===1&&p.strideHeight===1&&p.strideWidth===1&&(p.padInfo.type==="SAME"||p.padInfo.type==="VALID"))return H4({x:s,filter:a,convInfo:p,backend:r});if(Y().getBool("WEBGPU_CONV_SEPARATE_IM2COL_SHADER")&&s.shape[0]===1)return jde({x:s,filter:a,convInfo:p,backend:r});let h,f=[p.padInfo.top,p.padInfo.left],m=[{type:"int32",data:[p.filterHeight,p.filterWidth]},{type:"int32",data:[...f]},{type:"int32",data:[p.strideHeight,p.strideWidth]},{type:"int32",data:[p.dilationHeight,p.dilationWidth]}],g=Y().getBool("WEBGPU_USE_NAIVE_CONV2D");if(g?h=new X4(p):(p.inChannels%4===0||p.inChannels===3&&p.padInfo.type==="VALID")&&p.outChannels%4===0&&p.outChannels>=64?h=new j4(p):h=new q4(p),!g){let y=p.outShape[1]*p.outShape[2],x=p.outShape[3],A=p.filterHeight*p.filterWidth*p.inShape[3];m.push({type:"int32",data:[y]},{type:"int32",data:[x]},{type:"int32",data:[A]})}return r.runWebGPUProgram(h,[s,a],s.dtype,m)}var Xde={kernelName:Wa,backendName:"webgpu",kernelFunc:qde},Kde=class{constructor(e){this.variableNames=["x","W"],this.uniforms="filterDims : vec2<i32>; pads : vec2<i32>; stride : vec2<i32>; outBackprop : vec4<i32>; dimAOuter : i32; dimBOuter : i32; dimInner : i32;",this.outputShape=e.inShape,w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),this.dispatchLayout={x:[3],y:[1,2],z:[0]},this.workGroupSize=Wx(this.dispatchLayout,this.outputShape),this.elementsPerThread=Ux(this.dispatchLayout,this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,this.elementsPerThread),this.shaderKey=`conv2DDerInputMM_${this.elementsPerThread}`}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn mm_readA(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
var batch = i32(globalId.z);
if (row < uniforms.dimAOuter && col < uniforms.dimInner) {
let outRow = row / uniforms.outShape[2];
let outCol = row % uniforms.outShape[2];
let WRow = col / (uniforms.filterDims[1] * uniforms.outBackprop[3]);
let WCol = col / uniforms.outBackprop[3] % uniforms.filterDims[1];
let xR = f32(outRow - uniforms.pads[0] + WRow) / f32(uniforms.stride[0]);
let xC = f32(outCol - uniforms.pads[1] + WCol) / f32(uniforms.stride[1]);
if (xR < 0.0 || xR >= f32(uniforms.outBackprop[1]) || fract(xR) > 0.0) {
return 0.0;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
if (xC < 0.0 || xC >= f32(uniforms.outBackprop[2]) || fract(xC) > 0.0) {
return 0.0;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
let coord = vec4<i32>(
batch,
i32(xR),
i32(xC),
col % uniforms.outBackprop[3]);
2022-01-08 18:43:44 +01:00
return x.numbers[getIndexFromCoords4D(coord, uniforms.xShape)];
2021-11-07 16:03:33 +01:00
}
2021-11-08 13:36:26 +01:00
return 0.0;
2021-11-07 16:03:33 +01:00
}
2021-11-05 18:36:53 +01:00
2021-11-08 13:36:26 +01:00
fn mm_readB(row : i32, col : i32, globalId : vec3<u32>) -> f32 {
let coordX = uniforms.filterDims.x - 1 -
row / (uniforms.filterDims[1] * uniforms.outBackprop[3]);
let coordY = uniforms.filterDims.y - 1 -
(row / uniforms.outBackprop[3]) % uniforms.filterDims[1];
if (row < uniforms.dimInner && col < uniforms.dimBOuter &&
coordX >= 0 && coordY >= 0) {
let coord = vec4<i32>(coordX, coordY, col,
row % uniforms.outBackprop[3]);
2022-01-08 18:43:44 +01:00
return W.numbers[getIndexFromCoords4D(coord, uniforms.wShape)];
2021-11-05 18:36:53 +01:00
}
2021-11-08 13:36:26 +01:00
return 0.0;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
fn mm_write(row : i32, col : i32, valueInput : f32, globalId : vec3<u32>) {
var batch = i32(globalId.z);
var value = valueInput;
let outCoord = vec4<i32>(
batch,
row / uniforms.outShape[2],
row % uniforms.outShape[2],
col);
2022-01-08 18:43:44 +01:00
result.numbers[getIndexFromCoords4D(outCoord, uniforms.outShape)] = value;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
2022-01-16 15:49:55 +01:00
${jx(this.elementsPerThread,this.workGroupSize)}
`}},Zde=class{constructor(e){this.variableNames=["dy","W"],this.uniforms="filterDims : vec2<i32>; pads : vec2<i32>; stride : vec2<i32>; outBackprop : vec4<i32>;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e.inShape,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.isChannelsLast=e.dataFormat==="channelsLast",this.shaderKey=`conv2DDerInput_${this.isChannelsLast}`}getUserCode(){let e=this.isChannelsLast?1:2,t=this.isChannelsLast?2:3,n=this.isChannelsLast?3:1;return`
${Je()} {
2021-11-08 13:36:26 +01:00
if(index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let d1 = coords[${n}];
let dyCorner = vec2<i32>(coords[${e}]), coords[${t}]) - uniforms.pads;
let dyRCorner = dyCorner.x;
let dyCCorner = dyCorner.y;
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
// ? = to be determined. : = across all values in that axis.
var dotProd = 0.0;
for (var wR = 0; wR < uniforms.filterDims.x; wR = wR + 1) {
let dyR = (f32(dyRCorner) + f32(wR)) / f32(uniforms.stride.x);
let wRPerm = uniforms.filterDims.x - 1 - wR;
if (dyR < 0.0 || dyR >= f32(uniforms.outBackprop[1]) || fract(dyR) > 0.0 ||
wRPerm < 0) {
continue;
}
let idyR = dyR;
for (var wC = 0; wC < uniforms.filterDims.y; wC = wC + 1) {
let dyC = (f32(dyCCorner) + f32(wC)) / f32(uniforms.stride.y);
let wCPerm = uniforms.filterDims.y - 1 - wC;
if (dyC < 0.0 || dyC >= f32(uniforms.outBackprop[2]) ||
fract(dyC) > 0.0 || wCPerm < 0) {
continue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
let idyC = dyC;
for (var d2 = 0; d2 < uniforms.outBackprop[3]; d2 = d2 + 1) {
if (${this.isChannelsLast}) {
let xValue = getDy(batch, idyR, idyC, d2);
let wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd = dotProd + xValue * wValue;
} else {
let xValue = getDy(batch, d2, idyR, idyC);
let wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd = dotProd + xValue * wValue;
}
2021-10-30 18:21:54 +02:00
}
}
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, dotProd);
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Yde(e){let{inputs:t,backend:n,attrs:r}=e,{dy:s,filter:a}=t,{inputShape:o,strides:i,pad:l,dataFormat:c,dimRoundingMode:u}=r,d=N.convertConv2DDataFormat(c),p=N.computeConv2DInfo(o,a.shape,i,1,l,u,!1,d),h=[{type:"int32",data:[p.filterHeight,p.filterWidth]},{type:"int32",data:[p.filterHeight-1-p.padInfo.top,p.filterWidth-1-p.padInfo.left]},{type:"int32",data:[p.strideHeight,p.strideWidth]},{type:"int32",data:[p.batchSize,p.outHeight,p.outWidth,p.outChannels]}],f;if(Y().getBool("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE"))f=new Zde(p);else{f=new Kde(p);let m=p.inShape[1]*p.inShape[2],g=p.inShape[3],y=p.filterHeight*p.filterWidth*p.outChannels;h.push({type:"uint32",data:[m]},{type:"uint32",data:[g]},{type:"uint32",data:[y]})}return n.runWebGPUProgram(f,[s,a],"float32",h)}var Jde={kernelName:Va,backendName:"webgpu",kernelFunc:Yde},Qde=Nn({opType:kt.COS}),epe={kernelName:Ua,backendName:"webgpu",kernelFunc:Qde},tpe=Nn({opType:kt.COSH}),npe={kernelName:Ga,backendName:"webgpu",kernelFunc:tpe},rpe=class{constructor(e,t,n,r){this.variableNames=["Image","Boxes","BoxInd"],this.uniforms="extrapolationValue : f32;",this.workGroupSize=[64,1,1],this.size=!0;let[s]=t;this.outputShape=[s,n[0],n[1],e],this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.methodId=r==="bilinear"?1:0,this.cropHeightBiggerThan1=this.outputShape[1]>1,this.cropWidthBiggerThan1=this.outputShape[2]>1,this.shaderKey=`cropAndResize_${this.methodId}_${this.cropHeightBiggerThan1}_${this.cropWidthBiggerThan1}`}getUserCode(){let[e,t]=["f32(uniforms.imageShape[1] - 1)","f32(uniforms.imageShape[2] - 1)"],[n,r,s]=this.cropHeightBiggerThan1?[`(${e} / f32(uniforms.outShape[1] - 1))`,"(y2-y1) * height_ratio",`y1*${e} + f32(y)*(height_scale)`]:["0.0","0.0",`0.5 * (y1+y2) * ${e}`],[a,o,i]=this.cropWidthBiggerThan1?[`(${t} / f32(uniforms.outShape[2] - 1))`,"(x2-x1) * width_ratio",`x1*${t} + f32(x)*(width_scale)`]:["0.0","0.0",`0.5 * (x1+x2) * ${t}`];return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let height_ratio = f32(${n});
let width_ratio = f32(${a});
let b = coords[0];
let y = coords[1];
let x = coords[2];
let d = coords[3];
// get box vals
let y1 = getBoxes(b, 0);
let x1 = getBoxes(b, 1);
let y2 = getBoxes(b, 2);
let x2 = getBoxes(b, 3);
// get image in batch index
let bInd = i32(round(getBoxInd(b)));
if(bInd < 0 || bInd >= uniforms.outShape[0]) {
return;
}
2022-01-16 15:49:55 +01:00
let height_scale = ${r};
2021-11-08 13:36:26 +01:00
let width_scale = ${o};
2022-01-16 15:49:55 +01:00
let in_y = ${s};
2021-11-08 13:36:26 +01:00
if( in_y < 0.0 || in_y > ${e} ) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, uniforms.extrapolationValue);
2021-11-08 13:36:26 +01:00
return;
}
let in_x = ${i};
if( in_x < 0.0 || in_x > ${t} ) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, uniforms.extrapolationValue);
2021-11-08 13:36:26 +01:00
return;
}
let sourceFracIndexCR = vec2<f32>(in_x,in_y);
if(${this.methodId} == 1) {
// Compute the four integer indices.
let sourceFloorCR = vec2<i32>(sourceFracIndexCR);
let sourceCeilCR = vec2<i32>(ceil(sourceFracIndexCR));
let topLeft = getImage(bInd, sourceFloorCR.y, sourceFloorCR.x, d);
let bottomLeft = getImage(bInd, sourceCeilCR.y, sourceFloorCR.x, d);
let topRight = getImage(bInd, sourceFloorCR.y, sourceCeilCR.x, d);
let bottomRight = getImage(bInd, sourceCeilCR.y, sourceCeilCR.x, d);
let fracCR = sourceFracIndexCR - vec2<f32>(sourceFloorCR);
let top = topLeft + (topRight - topLeft) * fracCR.x;
let bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;
let newValue = top + (bottom - top) * fracCR.y;
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, newValue);
2021-11-08 13:36:26 +01:00
} else {
// Compute the coordinators of nearest neighbor point.
let sourceNearestCR = vec2<i32>(floor(
sourceFracIndexCR + vec2<f32>(0.5,0.5)));
let newValue = getImage(
bInd, sourceNearestCR.y, sourceNearestCR.x, d);
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, newValue);
2021-10-30 18:21:54 +02:00
}
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},spe=e=>{let{inputs:t,backend:n,attrs:r}=e,{image:s,boxes:a,boxInd:o}=t,{cropSize:i,method:l,extrapolationValue:c}=r,u=new rpe(s.shape[3],a.shape,i,l),d=[{type:"float32",data:[c]}];return n.runWebGPUProgram(u,[s,a,o],"float32",d)},ape={kernelName:vi,backendName:"webgpu",kernelFunc:spe},ope=class{constructor(e,t){this.variableNames=["x"],this.workGroupSize=[64,1,1],this.size=!0,this.uniforms="blockSize : i32;",this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey=`depthToSpace_${t}`,this.dataFormat=t}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let b = coords[0];
let h = ${this.getHeightCoordString()};
let w = ${this.getWidthCoordString()};
let d = ${this.getDepthCoordString()};
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let in_h = h / uniforms.blockSize;
let offset_h = h % uniforms.blockSize;
let in_w = w / uniforms.blockSize;
let offset_w = w % uniforms.blockSize;
let offset_d = (offset_h * uniforms.blockSize + offset_w) *
${this.getOutputDepthSize()};
let in_d = d + offset_d;
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let rlt = ${this.getInputSamplingString()};
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, rlt);
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
}`}getHeightCoordString(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"}getWidthCoordString(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"}getDepthCoordString(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"}getOutputDepthSize(){return this.dataFormat==="NHWC"?"uniforms.outShape[3]":"uniforms.outShape[1]"}getInputSamplingString(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"}};function ipe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockSize:a,dataFormat:o}=r,i=s.shape[0],l=o==="NHWC"?s.shape[1]:s.shape[2],c=o==="NHWC"?s.shape[2]:s.shape[3],u=o==="NHWC"?s.shape[3]:s.shape[1],d=l*a,p=c*a,h=u/(a*a),f=o==="NHWC"?[i,d,p,h]:[i,h,d,p],m=[{type:"int32",data:[a]}],g=new ope(f,o);return n.runWebGPUProgram(g,[s],s.dtype,m)}var lpe={kernelName:wi,backendName:"webgpu",kernelFunc:ipe},K4=class{constructor(e,t=!1,n=null,r=!1){this.variableNames=["x","W"],this.uniforms="pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>; inDims : vec2<i32>;",this.workGroupSize=[4,4,4],this.isVec4=!0,this.outputShape=e.outShape,this.dispatchLayout={x:[0,1],y:[2],z:[3]},this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[1,4,4]),w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.convInfo=e,this.addBias=t,this.activation=n,this.hasPreluActivation=r,this.shaderKey=`depthwise3x3_${n}`}getUserCode(){let e="",t="";if(this.activation){let s=pa(this.activation,this.isVec4);this.hasPreluActivation?e=`fn activation(a : vec4<f32>, outCoord : vec4<i32>) -> vec4<f32> {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
}`:e=`
fn activation(a : vec4<f32>, outCoord : vec4<i32>) -> vec4<f32> {
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
`,t="dotProd[i] = activation(dotProd[i], coords);"}let n=this.addBias?"dotProd[i] = dotProd[i] + getBiasByOutputCoords(coords);":"";return`
2021-11-08 13:36:26 +01:00
${e}
2021-10-30 18:21:54 +02:00
2022-01-16 15:49:55 +01:00
${Bx()}
2021-11-08 13:36:26 +01:00
fn main([[builtin(global_invocation_id)]] globalId: vec3<u32>) {
let batch = 0;
let r = i32(globalId.x);
let c = i32(globalId.y) * 4;
let d2 = i32(globalId.z) * 4;
let xRCCorner = vec2<i32>(r, c) * uniforms.stride - uniforms.pad;
let d1 = d2;
let q = 0;
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let xRCorner = xRCCorner.x;
let xCCorner = xRCCorner.y;
var wVals : array<vec4<f32>, 9>;
wVals[0] = getW(0, 0, d1, q);
wVals[1] = getW(0, 1, d1, q);
wVals[2] = getW(0, 2, d1, q);
wVals[3] = getW(1, 0, d1, q);
wVals[4] = getW(1, 1, d1, q);
wVals[5] = getW(1, 2, d1, q);
wVals[6] = getW(2, 0, d1, q);
wVals[7] = getW(2, 1, d1, q);
wVals[8] = getW(2, 2, d1, q);
var xVals : array<array<vec4<f32>, 6>, 3>;
for (var wR = 0; wR < 3; wR = wR + 1) {
let xR = xRCorner + wR * uniforms.dilation[0];
for (var wC = 0; wC < 6; wC = wC + 1) {
let xC = xCCorner + wC * uniforms.dilation[1];
if (xR < 0 || xR >= uniforms.inDims[0] || xC < 0 || xC >= uniforms.inDims[1]) {
xVals[wR][wC] = vec4<f32>(0.0);
} else {
xVals[wR][wC] = getX(batch, xR, xC, d1);
}
}
}
var dotProd : array<vec4<f32>, 4>;
dotProd[0] = vec4<f32>(0.0);
dotProd[1] = vec4<f32>(0.0);
dotProd[2] = vec4<f32>(0.0);
dotProd[3] = vec4<f32>(0.0);
for (var wR = 0; wR < 3; wR = wR + 1) {
for (var wC = 0; wC < 3; wC = wC + 1) {
let indexW = wR * 3 + wC;
dotProd[0] = dotProd[0] + xVals[wR][0 + wC] * wVals[indexW];
dotProd[1] = dotProd[1] + xVals[wR][1 + wC] * wVals[indexW];
dotProd[2] = dotProd[2] + xVals[wR][2 + wC] * wVals[indexW];
dotProd[3] = dotProd[3] + xVals[wR][3 + wC] * wVals[indexW];
2021-11-06 15:21:51 +01:00
}
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
for (var i = 0; i < 4; i = i + 1) {
let coords = vec4<i32>(batch, r, c + i, d2);
if (coordsInBounds4D(coords, uniforms.outShape)) {
${n}
${t}
2022-01-08 18:43:44 +01:00
setOutputAtCoords(coords[0], coords[1], coords[2], coords[3], dotProd[i]);
2021-11-08 13:36:26 +01:00
}
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},Z4=class{constructor(e,t=!1,n=null,r=!1){this.variableNames=["x","W"],this.uniforms=`pad : vec2<i32>; stride : vec2<i32>; dilation : vec2<i32>;
2021-12-01 14:27:05 +01:00
inDims : vec2<i32>; filterHeight : i32; filterWidth : i32;
2022-01-16 15:49:55 +01:00
channelMul : i32;`,this.workGroupSize=[256,1,1],this.outputShape=e.outShape,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),w.assert(e.dataFormat==="channelsLast",()=>"TODO: NCHW is unimplemented"),t&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.convInfo=e,this.addBias=t,this.activation=n,this.hasPreluActivation=r,this.shaderKey=`depthwise_${this.activation}`}getUserCode(){let e="",t="";if(this.activation){let s=pa(this.activation,!1);this.hasPreluActivation?e=`fn activation(a : f32, outCoord : vec4<i32>) -> f32 {
2022-01-08 18:43:44 +01:00
let b = getPreluActivationWeightsByOutputCoords(outCoord);
2022-01-16 15:49:55 +01:00
${s}
2021-12-01 14:27:05 +01:00
}`:e=`
2021-11-08 13:36:26 +01:00
fn activation(a : f32, outCoord : vec4<i32>) -> f32 {
2022-01-16 15:49:55 +01:00
${s}
2021-11-08 13:36:26 +01:00
}
2022-01-08 18:43:44 +01:00
`,t="dotProd = activation(dotProd, coords);"}let n=this.addBias?"dotProd = dotProd + getBiasByOutputCoords(coords);":"";return`
2021-12-01 14:27:05 +01:00
${e}
2021-10-30 18:21:54 +02:00
2021-12-01 14:27:05 +01:00
fn writeResult(batch : i32, row : i32, col : i32, chan : i32,
value : f32) {
2021-11-08 13:36:26 +01:00
let coord = vec4<i32>(batch, row, col, chan);
if (coordsInBounds4D(coord, uniforms.outShape)) {
2022-01-08 18:43:44 +01:00
setOutputAtCoords(batch, row, col, chan, value);
2021-11-06 15:21:51 +01:00
}
}
2021-10-30 18:21:54 +02:00
2022-01-08 18:43:44 +01:00
${ca()}
2021-12-15 15:26:32 +01:00
let coords = getOutputCoords();
2021-11-08 13:36:26 +01:00
let batch = coords[0];
let xRCCorner = vec2<i32>(coords.yz) * uniforms.stride - uniforms.pad;
let d2 = coords[3];
2021-12-01 14:27:05 +01:00
let d1 = d2 / uniforms.channelMul;
let q = d2 - d1 * uniforms.channelMul;
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let inputRowStart = xRCCorner.x;
let inputColStart = xRCCorner.y;
2021-12-01 14:27:05 +01:00
let inputRowEnd = inputRowStart + uniforms.filterHeight *
uniforms.dilation[0];
let inputColEnd = inputColStart + uniforms.filterWidth *
uniforms.dilation[1];
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
// Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
var dotProd = 0.0;
// Extract if checking out of for loop for performance.
if (inputRowStart >= 0 && inputColStart >= 0 &&
2021-12-01 14:27:05 +01:00
inputRowEnd < uniforms.inDims[0] &&
inputColEnd < uniforms.inDims[1]) {
2021-11-08 13:36:26 +01:00
// Here using a constant value |this.convInfo.filterHeight| instead
// of uniform value is in order to loop unrolling.
2021-12-01 14:27:05 +01:00
for (var wR = 0; wR < uniforms.filterHeight; wR = wR + 1) {
2021-11-08 13:36:26 +01:00
let xR = inputRowStart + wR * uniforms.dilation[0];
2021-12-01 14:27:05 +01:00
for (var wC = 0; wC < uniforms.filterWidth; wC = wC + 1) {
2021-11-08 13:36:26 +01:00
let xC = inputColStart + wC * uniforms.dilation[1];
let xVal = getX(batch, xR, xC, d1);
let wVal = getW(wR, wC, d1, q);
dotProd = dotProd + xVal * wVal;
}
}
2021-11-06 15:21:51 +01:00
} else {
2021-12-01 14:27:05 +01:00
for (var wR = 0; wR < uniforms.filterHeight; wR = wR + 1) {
2021-11-08 13:36:26 +01:00
let xR = inputRowStart + wR * uniforms.dilation[0];
if (xR < 0 || xR >= uniforms.inDims[0]) {
continue;
}
2021-12-01 14:27:05 +01:00
for (var wC = 0; wC < uniforms.filterWidth; wC = wC + 1) {
2021-11-08 13:36:26 +01:00
let xC = inputColStart + wC * uniforms.dilation[1];
if (xC < 0 || xC >= uniforms.inDims[1]) {
continue;
}
let xVal = getX(batch, xR, xC, d1);
let wVal = getW(wR, wC, d1, q);
dotProd = dotProd + xVal * wVal;
}
}
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
${n}
2021-12-01 14:27:05 +01:00
${t}
2021-11-08 13:36:26 +01:00
writeResult(batch, coords[1], coords[2], d2, dotProd);
}
2022-01-16 15:49:55 +01:00
`}};function upe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a}=t,{strides:o,pad:i,dilations:l,dimRoundingMode:c}=r,u=l;u==null&&(u=[1,1]);let d=N.computeConv2DInfo(s.shape,a.shape,o,u,i,c,!0),p=[{type:"int32",data:[d.padInfo.top,d.padInfo.left]},{type:"int32",data:[d.strideHeight,d.strideWidth]},{type:"int32",data:[d.dilationHeight,d.dilationWidth]},{type:"int32",data:[d.inHeight,d.inWidth]}],h;return d.batchSize===1&&d.inHeight===d.outHeight&&d.inWidth===d.outWidth&&d.strideHeight===1&&d.strideWidth===1&&d.filterHeight===d.filterWidth&&d.inChannels===d.outChannels&&d.filterHeight===3&&d.inChannels%4===0?h=new K4(d):(h=new Z4(d),p.push({type:"int32",data:[d.filterHeight]},{type:"int32",data:[d.filterWidth]},{type:"int32",data:[d.outChannels/d.inChannels]})),n.runWebGPUProgram(h,[s,a],s.dtype,p)}var cpe={kernelName:Ha,backendName:"webgpu",kernelFunc:upe},Y4=Kn({opSnippet:qt.MUL,cpuKernelImpl:qce,supportsComplex:!0}),dpe={kernelName:uo,backendName:"webgpu",kernelFunc:Y4},ppe=class{constructor(e,t){this.workGroupSize=[64,1,1],this.variableNames=["x"],this.uniforms="reduceSize : i32;",this.size=!0,this.inputShape=[e.batchSize,e.inSize];let[n]=N.computeOutAndReduceShapes(this.inputShape,[1]);this.outputShape=n.length===0?[1]:n,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,[1,1,1]),this.reduceType=t,this.shaderKey=`reduce_${t}`}getUserCode(){let e="",t="0.0";this.reduceType==="min"||this.reduceType==="max"?(e=`
2021-11-08 13:36:26 +01:00
if (isNanCustom(candidate)) {
bestValue = uniforms.NAN;
} else if (!isNanCustom(bestValue) && candidate ${this.reduceType==="min"?"<":">"} bestValue)
2022-01-08 18:43:44 +01:00
{ bestValue = candidate; }`,t="f32(x.numbers[offset])"):this.reduceType==="sum"||this.reduceType==="mean"?e=" bestValue = bestValue + candidate; ":this.reduceType==="prod"&&(e=" bestValue = bestValue * candidate; ",t="1.0");let n=this.reduceType==="mean"?"setOutputAtIndex(outputIndex, bestValue / f32(uniforms.reduceSize));":"setOutputAtIndex(outputIndex, bestValue);";return`
2021-11-21 22:55:17 +01:00
fn DIV_CEIL(a : u32, b : u32) -> u32 {
return ((a - 1u) / b + 1u);
2021-11-08 13:36:26 +01:00
}
2021-11-21 22:55:17 +01:00
${`
var<workgroup> xBestValues : array<f32, ${this.workGroupSize[0]}>;
`}
fn getOffset(outputIndex : i32) -> i32 {
2022-01-08 18:43:44 +01:00
let outputCoords = getCoordsFromIndex(outputIndex);
2021-11-08 13:36:26 +01:00
let offset = ${this.outputShape.length===1?"outputCoords":"outputCoords[0]"} * uniforms.reduceSize;
2021-11-21 22:55:17 +01:00
return offset;
2021-11-08 13:36:26 +01:00
}
${Je()}
2021-11-21 22:55:17 +01:00
let outputIndex = index / i32(workGroupSizeX);
let offset = getOffset(outputIndex);
var bestValue = ${t};
2021-11-08 13:36:26 +01:00
let Length = uniforms.reduceSize;
2021-11-21 22:55:17 +01:00
let WorkPerThread = DIV_CEIL(u32(Length), workGroupSizeX);
for (var k = i32(localId.x); k < Length && outputIndex < uniforms.size;
k = k + i32(workGroupSizeX)) {
let candidate = f32(x.numbers[offset + k]);
${e}
}
xBestValues[localId.x] = bestValue;
workgroupBarrier();
var reduceSize = min(u32(Length), workGroupSizeX);
for (var currentSize = reduceSize / 2u; reduceSize > 1u;
currentSize = reduceSize / 2u) {
let interval = DIV_CEIL(reduceSize, 2u);
if (localId.x < currentSize) {
let candidate = xBestValues[localId.x + interval];
${e}
xBestValues[localId.x] = bestValue;
2021-11-08 13:36:26 +01:00
}
2021-11-21 22:55:17 +01:00
reduceSize = interval;
workgroupBarrier();
2021-11-08 13:36:26 +01:00
}
2021-11-21 22:55:17 +01:00
if (localId.x == 0u && outputIndex < uniforms.size) {
${n}
}
2021-11-08 13:36:26 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function Lp(e,t,n,r,s){let a=e.shape.length,o=[],i=w.parseAxisParam(t,e.shape),l=i,c=N.getAxesPermutation(l,a),u=e;c!=null&&(u=zl({inputs:{x:e},attrs:{perm:c},backend:s}),l=N.getInnerMostAxes(l.length,a),o.push(u)),N.assertAxesAreInnerMostDims(r,l,a);let[d,p]=N.computeOutAndReduceShapes(u.shape,l),h=d;n&&(h=N.expandShapeToKeepDim(d,i));let f;if((r==="max"||r==="prod")&&s.shouldExecuteOnCPU([u])){let m=s.tensorMap.get(u.dataId).values;switch(r){case"max":let g=Gce(m,w.sizeFromShape(p),h,e.dtype);f=s.makeTensorInfo(h,e.dtype,g);break;case"prod":let{outVals:y,outShape:x,outDtype:A}=Zce(u.shape,u.dtype,m,l);f=s.makeTensorInfo(x,A,y);break;default:throw new Error(`${r} CPU implementation is not yet supported.`)}}else{let m=w.sizeFromShape(p),y=w.sizeFromShape(u.shape)/m,x={windowSize:m,inSize:m,batchSize:y,outSize:1},A=r==="mean"?"float32":Wd(e.dtype),b=[{type:"int32",data:[m]}],v=new ppe(x,r),C=s.runWebGPUProgram(v,[u],A,b);o.push(C),f=Xe({inputs:{x:C},attrs:{shape:h},backend:s})}return o.forEach(m=>s.disposeData(m.dataId)),f}function Yx(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r;return Lp(s,a,o,"sum",n)}var hpe={kernelName:vo,backendName:"webgpu",kernelFunc:Yx};function fpe(e){let{inputs:t,backend:n,attrs:r}=e,{equation:s}=r,a=t,{allDims:o,summedDims:i,idDims:l}=N.decodeEinsumEquation(s,a.length);N.checkEinsumDimSizes(o.length,l,a);let{path:c,steps:u}=N.getEinsumComputePath(i,l),d=u.length,p=null,h=o.length,f=[];for(let m=0;m<d;++m){for(let g of u[m]){let{permutationIndices:y,expandDims:x}=N.getEinsumPermutation(h,l[g]),A;N.isIdentityPermutation(y)?A=a[g]:(A=zl({inputs:{x:a[g]},backend:n,attrs:{perm:y}}),f.push(A));let b=A.shape.slice();for(let v=0;v<x.length;++v)b.splice(x[v],0,1);w.arraysEqual(A.shape,b)||(A=Xe({inputs:{x:A},backend:n,attrs:{shape:b}}),f.push(A)),p===null?p=A:(p=Y4({inputs:{a:A,b:p},backend:n}),f.push(p))}m<d-1&&(c[m]>=0&&(p=Yx({inputs:{x:p},backend:n,attrs:{axis:c[m]-(o.length-h),keepDims:!1}}),f.push(p)),h--)}for(let m of f)m!==p&&n.disposeData(m.dataId);return p}var mpe={kernelName:bd,backendName:"webgpu",kernelFunc:fpe},gpe=Nn({opType:kt.ELU}),ype={kernelName:qa,backendName:"webgpu",kernelFunc:gpe},Ape=Kn({opSnippet:qt.EQUAL,dtype:"bool",cpuKernelImpl:Pce}),xpe={kernelName:ki,backendName:"webgpu",kernelFunc:Ape},J4=Nn({opType:kt.EXP,cpuKernelImpl:$ce,dtype:"float32"}),bpe={kernelName:Xa,backendName:"webgpu",kernelFunc:J4};function Jx(e){let{inputs:t,attrs:n,backend:r}=e,{dim:s}=n,{input:a}=t,o=a.shape.length,i=a.shape.slice(),l=s;return s<0&&(w.assert(-(o+1)<=s,()=>`Axis must be in the interval [${-(o+1)}, ${o}]`),l=o+s+1),i.splice(l,0,1),Xe({inputs:{x:a},backend:r,attrs:{shape:i}})}var vpe={kernelName:Ii,backendName:"webgpu",kernelFunc:Jx},wpe=Nn({opType:kt.EXPM1,cpuKernelImpl:Fce}),kpe={kernelName:Si,backendName:"webgpu",kernelFunc:wpe},Ipe=class{constructor(e){this.variableNames=[],this.outputShape=[],this.uniforms="value : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="fill"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, uniforms.value);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Ec(e){let{backend:t,attrs:n}=e,{shape:r,value:s}=n,{dtype:a}=n;if(a=a||w.inferDtype(s),a==="string"){let o=w.getArrayFromDType(a,w.sizeFromShape(r));return o.fill(s),t.makeTensorInfo(r,a,o)}else{let o=new Ipe(r),i=[{type:"float32",data:[s]}];return t.runWebGPUProgram(o,[],a,i)}}var Spe={kernelName:bu,backendName:"webgpu",kernelFunc:Ec},Cpe=class{constructor(e){this.outputShape=[],this.variableNames=["x"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="flipLeftRight"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let coordX = uniforms.xShape[2] - coords[2] - 1;
let outputValue = getX(coords[0], coords[1], coordX, coords[3]);
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, outputValue);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},Tpe={kernelName:Ci,backendName:"webgpu",kernelFunc:({inputs:e,backend:t})=>{let{image:n}=e,r=t,s=new Cpe(n.shape);return r.runWebGPUProgram(s,[n],n.dtype)}},Npe=Nn({opType:kt.FLOOR,cpuKernelImpl:Oce}),Epe={kernelName:Ka,backendName:"webgpu",kernelFunc:Npe},Rpe=Kn({opSnippet:qt.INT_DIV,dtype:"int32"}),_pe={kernelName:Za,backendName:"webgpu",kernelFunc:Rpe},Dpe=(e,t,n,r,s)=>{let a=[r,...n];return s&&a.push(s),e.createBindGroup({layout:t,entries:a.map((o,i)=>({binding:i,resource:o}))})},Q4=(e,t,n,r,s,a=!1)=>{let o={dtype:s.dtype,shape:s.shape},i=lue(r,o,t,a),l=e.createShaderModule({code:i,label:t.constructor.name});return e.createComputePipeline({layout:n,compute:{module:l,entryPoint:"main"},label:t.constructor.name})};function e6(e,t,n,r="",s=""){return e.shaderKey+"_"+(e.workGroupSize?e.workGroupSize.join(","):"")+t.map(o=>o.length).join(",")+n.join(",")+e.variableNames.join(",")+r+s}function t6(e){let{externalImage:t,backend:n,attrs:r,outShape:s,useImport:a}=e,{numChannels:o}=r,i=w.sizeFromShape(s),l=w.computeStrides(s),c=n.makeTensorInfo(s,"int32"),u=n.getFromPixelsProgram(a?"import":"copyExternal");u.updateOutputShape(s);let d=[c.shape],p=[c.dtype,a?"import":"copyExternal"],h=e6(u,d,p),f=u.getLayout(n.device),m=n.getAndSavePipeline(h,()=>Q4(n.device,u,f.pipelineLayout,[],c,!0));u.setPipeline(m),a||n.queue.copyExternalImageToTexture({source:t,origin:{x:0,y:0}},{texture:u.makeInputTexture(n.device,s[1],s[0])},[s[1],s[0]]);let g=n.tensorMap.get(c.dataId);g.bufferInfo.buffer=n.acquireBuffer(g.bufferInfo.byteSize);let y=[i,o,...l,...u.dispatch];u.setUniform(n.device,y);let x;if(a){let A={source:t};x=n.device.importExternalTexture(A)}else x=u.inputTexture.createView();return n.runFromPixelsProgram(u,g.bufferInfo.buffer,f,x,c.dataId),c}var Ppe={kernelName:Dd,backendName:"webgpu",kernelFunc:$pe},Rc;function $pe(e){let{inputs:t,backend:n,attrs:r}=e,{pixels:s}=t,{numChannels:a}=r;if(s==null)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");let o=typeof HTMLVideoElement!="undefined"&&s instanceof HTMLVideoElement,i=typeof HTMLImageElement!="undefined"&&s instanceof HTMLImageElement,l=typeof HTMLCanvasElement!="undefined"&&s instanceof HTMLCanvasElement||typeof OffscreenCanvas!="undefined"&&s instanceof OffscreenCanvas,c=typeof ImageBitmap!="undefined"&&s instanceof ImageBitmap,[u,d]=o?[s.videoWidth,s.videoHeight]:[s.width,s.height],p=[d,u,a];if(Y().getBool("WEBGPU_USE_IMPORT")&&o)return t6({externalImage:s,backend:n,attrs:r,outShape:p,useImport:!0});if((o||i)&&(Rc==null&&(Rc=document.createElement("canvas").getContext("2d")),Rc.canvas.width=u,Rc.canvas.height=d,Rc.drawImage(s,0,0,u,d),s=Rc.canvas),c||l||o||i)return t6({externalImage:s,backend:n,attrs:r,outShape:p,useImport:!1});let h=s.data,f=h;if(a!=null&&a!==4){f=new Uint8Array(s.width*s.height*a);let y=h.length,x=0;for(let A=0;A<y;A++)A%4<a&&(f[x++]=h[A])}let m=n.makeTensorInfo(p,"int32"),g=n.tensorMap.get(m.dataId);return g.values=new Int32Array(f),n.maybeReleaseBuffer(m.dataId),n.uploadToGPU(m.dataId),m}var Fpe=class{constructor(e,t,n,r,s){this.uniforms="varianceEpsilon : f32;",this.workGroupSize=[128,1,1],this.size=!0,this.variableNames=["x","mean","variance"],N.assertAndGetBroadcastShape(e,t),N.assertAndGetBroadcastShape(e,n),this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),r!=null&&(N.assertAndGetBroadcastShape(e,r),this.variableNames.push("offset")),s!=null&&(N.assertAndGetBroadcastShape(e,s),this.variableNames.push("scale")),this.offsetShape=r,this.scaleShape=s,this.shaderKey="batchNorm"}getUserCode(){let e="0.0";this.offsetShape!=null&&(e="getOffsetByOutputIndex(index)");let t="1.0";return this.scaleShape!=null&&(t="getScaleByOutputIndex(index)"),`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size)
{
2022-01-08 18:43:44 +01:00
let xValue = getXByOutputIndex(index);
let meanValue = getMeanByOutputIndex(index);
let varianValue = getVarianceByOutputIndex(index);
2021-11-08 13:36:26 +01:00
let offsetValue = ${e};
let scaleValue = ${t};
let inv = scaleValue * inverseSqrt(varianValue + f32(uniforms.varianceEpsilon));
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index,dot(vec3<f32>(xValue, -meanValue, offsetValue), vec3<f32>(inv, inv, 1.0)));
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},Ope={kernelName:Ya,backendName:"webgpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{x:r,scale:s,offset:a,mean:o,variance:i}=e,{varianceEpsilon:l}=t,c=n,u=[r,o,i],d=null;a!=null&&(d=a.shape,u.push(a));let p=null;s!=null&&(p=s.shape,u.push(s));let h=new Fpe(r.shape,o.shape,i.shape,d,p),f=[{type:"float32",data:[l]}];return c.runWebGPUProgram(h,u,r.dtype,f)}};function Mpe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a,bias:o,preluActivationWeights:i}=t,{strides:l,pad:c,dataFormat:u,dilations:d,dimRoundingMode:p,activation:h,leakyreluAlpha:f}=r,m=N.convertConv2DDataFormat(u),g=N.computeConv2DInfo(s.shape,a.shape,l,d,c,p,!1,m),y=o!=null,x=i!=null,A;if(g.filterHeight===1&&g.filterWidth===1&&g.dilationHeight===1&&g.dilationWidth===1&&g.strideHeight===1&&g.strideWidth===1&&(g.padInfo.type==="SAME"||g.padInfo.type==="VALID"))return H4({x:s,filter:a,convInfo:g,backend:n,bias:o,activation:h,preluActivationWeights:i,leakyreluAlpha:f});let b=Y().getBool("WEBGPU_USE_NAIVE_CONV2D"),v=g.inChannels%4===0&&g.outChannels%4===0,C=[g.padInfo.top,g.padInfo.left],I=[{type:"int32",data:[g.filterHeight,g.filterWidth]},{type:"int32",data:[...C]},{type:"int32",data:[g.strideHeight,g.strideWidth]},{type:"int32",data:[g.dilationHeight,g.dilationWidth]}];if(b)A=new X4(g,y,h,x);else{v?A=new j4(g,y,h,x):A=new q4(g,y,h,x);let R=g.outShape[1]*g.outShape[2],F=g.outShape[3],_=g.filterHeight*g.filterWidth*g.inShape[3];I.push({type:"int32",data:[R]},{type:"int32",data:[F]},{type:"int32",data:[_]})}let E=[s,a];return y&&E.push(o),x&&E.push(i),n.runWebGPUProgram(A,E,s.dtype,I)}var zpe={kernelName:Eo,backendName:"webgpu",kernelFunc:Mpe};function Lpe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,filter:a,bias:o,preluActivationWeights:i}=t,{strides:l,pad:c,dilations:u,dimRoundingMode:d,activation:p}=r,h=u;h==null&&(h=[1,1]),w.assert(N.eitherStridesOrDilationsAreOne(l,h),()=>`Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${l} and dilations '${h}'`);let f=N.computeConv2DInfo(s.shape,a.shape,l,h,c,d,!0),m=[s,a],g=o!=null,y=i!=null;g&&m.push(o),y&&m.push(i);let x=[{type:"int32",data:[f.padInfo.top,f.padInfo.left]},{type:"int32",data:[f.strideHeight,f.strideWidth]},{type:"int32",data:[f.dilationHeight,f.dilationWidth]},{type:"int32",data:[f.inHeight,f.inWidth]}],A;return f.batchSize===1&&f.inHeight===f.outHeight&&f.inWidth===f.outWidth&&f.strideHeight===1&&f.strideWidth===1&&f.filterHeight===f.filterWidth&&f.inChannels===f.outChannels&&f.filterHeight===3&&f.inChannels%4===0?A=new K4(f,g,p,y):(A=new Z4(f,g,p,y),x.push({type:"int32",data:[f.filterHeight]},{type:"int32",data:[f.filterWidth]},{type:"int32",data:[f.outChannels/f.inChannels]})),n.runWebGPUProgram(A,m,"float32",x)}var Bpe={kernelName:Ro,backendName:"webgpu",kernelFunc:Lpe},Wpe=class{constructor(e,t){this.variableNames=["A","indices"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=t,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey=`gathernd_${e}`,this.sliceDim=e,this.uniforms=`sliceDim : i32; strides : ${In(e)};`}getUserCode(){let e;return this.sliceDim>1?e="uniforms.strides[j]":e="uniforms.strides",`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
var flattenIndex = 0;
for (var j = 0; j < uniforms.sliceDim; j = j + 1) {
let indexTemp = i32(round(getIndices(coords[0], j)));
let strideNum = ${e};
flattenIndex = flattenIndex + indexTemp * strideNum;
}
2021-10-30 18:21:54 +02:00
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getA(flattenIndex, coords[1]));
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Vpe(e){let{inputs:t,backend:n}=e,{params:r,indices:s}=t,a=s.shape,o=a[a.length-1],i=w.sizeFromShape(r.shape),[l,c,u,d]=N.prepareAndValidate(r,s),p=Xe({inputs:{x:s},backend:n,attrs:{shape:[c,o]}}),h=Xe({inputs:{x:r},backend:n,attrs:{shape:[w.sizeFromShape(r.shape)/u,u]}});if(n.shouldExecuteOnCPU([r,s])||r.dtype==="string"){let x=n.readSync(s.dataId),A=n.bufferSync(r),b=Mce(x,A,r.dtype,c,o,u,d,r.shape,i);return n.makeTensorInfo(l,r.dtype,b.values)}let f=new Wpe(o,[c,u]),m=[{type:"int32",data:[o]},{type:"int32",data:d}],g=n.runWebGPUProgram(f,[h,p],h.dtype,m),y=Xe({inputs:{x:g},backend:n,attrs:{shape:l}});return n.disposeData(p.dataId),n.disposeData(h.dataId),n.disposeData(g.dataId),y}var Upe={kernelName:Ni,backendName:"webgpu",kernelFunc:Vpe},Gpe=class{constructor(e,t){this.variableNames=["A","indices"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e.slice(),this.aShape=e,this.outputShape=t,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="gather"}getUserCode(){let e=Hpe(this.aShape,"i32");return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let resRC = getCoordsFromIndex(index);
setOutputAtIndex(index, getA(${e}));
2021-10-30 18:21:54 +02:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Hpe(e,t="int"){let n=["resRC.x","resRC.y","resRC.z","resRC.w"],r=[];for(let s=0;s<e.length;s++)s===2?r.push(`${t}(getIndices(resRC.x, resRC.z))`):r.push(`${n[s]}`);return r.join()}function n6(e){let{inputs:t,backend:n,attrs:r}=e,{x:s,indices:a}=t,{axis:o,batchDims:i}=r,l=w.parseAxisParam(o,s.shape)[0],c=N.segment_util.collectGatherOpShapeInfo(s,a,l,i),u=w.sizeFromShape(a.shape),d=[],p=Xe({inputs:{x:s},backend:n,attrs:{shape:[c.batchSize,c.outerSize,c.dimSize,c.sliceSize]}}),h=Xe({inputs:{x:a},backend:n,attrs:{shape:[c.batchSize,u/c.batchSize]}});d.push(p),d.push(h);let f=[c.batchSize,c.outerSize,u/c.batchSize,c.sliceSize];if(n.shouldExecuteOnCPU([s,a])){let A=n.tensorMap.get(h.dataId).values,b=Le(h.shape,h.dtype,A),C=n.tensorMap.get(p.dataId).values,I=Le(p.shape,p.dtype,C),E=zce(I,b,f);return d.forEach(R=>n.disposeData(R.dataId)),n.makeTensorInfo(c.outputShape,E.dtype,E.values)}let m=new Gpe(p.shape,f),g=n.runWebGPUProgram(m,[p,h],p.dtype);d.push(g);let y=Xe({inputs:{x:g},backend:n,attrs:{shape:c.outputShape}});return d.forEach(x=>n.disposeData(x.dataId)),y}var jpe={kernelName:Ti,backendName:"webgpu",kernelFunc:n6},qpe=Kn({opSnippet:qt.GREATER,cpuKernelImpl:Bce,dtype:"bool"}),Xpe={kernelName:Ei,backendName:"webgpu",kernelFunc:qpe},Kpe=Kn({opSnippet:qt.GREATER_EQUAL,dtype:"bool",cpuKernelImpl:Lce}),Zpe={kernelName:Ja,backendName:"webgpu",kernelFunc:Kpe};function Ype(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{alpha:a}=r,o=[{type:"float32",data:[a]}],i=new Mp(s.shape,kt.LEAKYRELU);return i.uniforms="alpha : f32;",n.runWebGPUProgram(i,[s],"float32",o)}var Jpe={kernelName:eo,backendName:"webgpu",kernelFunc:Ype},Qpe=Kn({opSnippet:qt.LESS,dtype:"bool",cpuKernelImpl:Vce}),ehe={kernelName:Ri,backendName:"webgpu",kernelFunc:Qpe},the=Kn({opSnippet:qt.LESS_EQUAL,dtype:"bool",cpuKernelImpl:Wce}),nhe={kernelName:_i,backendName:"webgpu",kernelFunc:the},rhe=Nn({opType:kt.LOG,cpuKernelImpl:Uce}),she={kernelName:to,backendName:"webgpu",kernelFunc:rhe},ahe=Kn({opSnippet:qt.LOGICAL_AND,dtype:"bool"}),ohe={kernelName:Di,backendName:"webgpu",kernelFunc:ahe},ihe=Nn({opType:kt.LOGICAL_NOT}),lhe={kernelName:Su,backendName:"webgpu",kernelFunc:ihe};function r6(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{reductionIndices:a,keepDims:o}=r;return Lp(s,a,o,"max",n)}var uhe={kernelName:no,backendName:"webgpu",kernelFunc:r6},che=Kn({opSnippet:qt.MAX,cpuKernelImpl:Hce}),dhe={kernelName:ro,backendName:"webgpu",kernelFunc:che};function phe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{filterSize:a,strides:o,pad:i,dimRoundingMode:l}=r,c=1,u=N.computePool2DInfo(s.shape,a,o,c,i,l),d,p=[];if(u.filterHeight===1&&u.filterWidth===1){if(w.arraysEqual(u.inShape,u.outShape))return is({inputs:{x:s},backend:n});d=new V4(u),p.push({type:"int32",data:[u.strideHeight,u.strideWidth]})}else d=new W4(u,"max"),p.push({type:"int32",data:[u.strideHeight,u.strideWidth]},{type:"int32",data:[u.padInfo.top,u.padInfo.left]},{type:"int32",data:[u.dilationHeight,u.dilationWidth]},{type:"int32",data:[u.inHeight,u.inWidth]},{type:"int32",data:[u.effectiveFilterHeight,u.effectiveFilterWidth]});return n.runWebGPUProgram(d,[s],s.dtype,p)}var hhe={kernelName:so,backendName:"webgpu",kernelFunc:phe};function fhe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{keepDims:a,axis:o}=r;return Lp(s,o,a,"mean",n)}var mhe={kernelName:ao,backendName:"webgpu",kernelFunc:fhe};function ghe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r;return Lp(s,a,o,"min",n)}var yhe={kernelName:oo,backendName:"webgpu",kernelFunc:ghe},Ahe=Kn({opSnippet:qt.MIN,cpuKernelImpl:jce}),xhe={kernelName:io,backendName:"webgpu",kernelFunc:Ahe},bhe=class{constructor(e,t,n){this.uniforms="",this.variableNames=["x"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=t.map((r,s)=>r[0]+e[s]+r[1]),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.xShape=e,t.map((r,s)=>{this.uniforms+=` pad${s} : vec2<i32>;`}),this.offset=n==="reflect"?0:1,this.shaderKey=`mirrorPad_${n}`}getUserCode(){let e=this.xShape.length,t=this.xShap
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
let start = ${o}(${t});
let end = ${o}(${n});
2022-01-08 18:43:44 +01:00
var outC = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
for (var i = 0; i < ${e}; i = i + 1) {
2022-01-16 15:49:55 +01:00
if (${a} < ${r}) {
${a} = ${r} * 2 - ${a} - ${this.offset};
} else if(${a} >= ${s}) {
${a} = (${s} - 1) * 2 - ${a} + ${this.offset};
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
let coords = outC - start;
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getX(${i}));
2021-10-30 18:21:54 +02:00
}
}
2022-01-16 15:49:55 +01:00
`}},vhe={kernelName:lo,backendName:"webgpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{x:r}=e,{paddings:s,mode:a}=t,o=n,i=s.map(u=>({type:"int32",data:[u[0],u[1]]})),l=new bhe(r.shape,s,a);return o.runWebGPUProgram(l,[r],r.dtype,i)}};function whe(e){let{inputs:t,backend:n}=e,{x:r}=t;if(n.shouldExecuteOnCPU([r])){let a=n.tensorMap.get(r.dataId),[o,i]=Xce(a.values,r.shape,r.dtype);return n.makeTensorInfo(i,r.dtype,o)}let s=new Mp(r.shape,kt.NEG);return n.runWebGPUProgram(s,[r],r.dtype)}var khe={kernelName:Pi,backendName:"webgpu",kernelFunc:whe};function Ihe(e){console.warn("tf.nonMaxSuppression() in webgpu locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:t,backend:n,attrs:r}=e,{boxes:s,scores:a}=t,{maxOutputSize:o,iouThreshold:i,scoreThreshold:l}=r,c=n.readSync(s.dataId),u=n.readSync(a.dataId),{selectedIndices:d}=ts.nonMaxSuppressionV3Impl(c,u,o,i,l);return n.makeTensorInfo([d.length],"int32",new Int32Array(d))}var She={kernelName:Fi,backendName:"webgpu",kernelFunc:Ihe};function Che(e){console.warn("tf.nonMaxSuppression() in webgpu locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:t,backend:n,attrs:r}=e,{boxes:s,scores:a}=t,{maxOutputSize:o,iouThreshold:i,scoreThreshold:l,softNmsSigma:c}=r,u=n.readSync(s.dataId),d=n.readSync(a.dataId),p=o,h=i,f=l,m=c,{selectedIndices:g,selectedScores:y}=ts.nonMaxSuppressionV5Impl(u,d,p,h,f,m);return[n.makeTensorInfo([g.length],"int32",new Int32Array(g)),n.makeTensorInfo([y.length],"float32",new Float32Array(y))]}var The={kernelName:Oi,backendName:"webgpu",kernelFunc:Che};function c0(e){let{inputs:t,backend:n}=e,{x:r}=t;if(r.dtype==="complex64"){let s=zp({inputs:{input:r},backend:n}),a=c0({inputs:{x:s},backend:n}),o=u0({inputs:{input:r},backend:n}),i=c0({inputs:{x:o},backend:n}),l=Tc({inputs:{real:a,imag:i},backend:n});return n.disposeData(s.dataId),n.disposeData(a.dataId),n.disposeData(o.dataId),n.disposeData(i.dataId),l}else return Ec({attrs:{shape:r.shape,dtype:r.dtype,value:r.dtype==="string"?"":0},backend:n})}var Nhe={kernelName:tl,backendName:"webgpu",kernelFunc:c0};function s6(e){let{inputs:t,backend:n}=e,{x:r}=t;if(r.dtype==="string")throw new Error("onesLike is not supported under string dtype");if(r.dtype==="complex64"){let s=zp({inputs:{input:r},backend:n}),a=s6({inputs:{x:s},backend:n}),o=u0({inputs:{input:r},backend:n}),i=c0({inputs:{x:o},backend:n}),l=Tc({inputs:{real:a,imag:i},backend:n});return n.disposeData(s.dataId),n.disposeData(a.dataId),n.disposeData(o.dataId),n.disposeData(i.dataId),l}else return Ec({attrs:{shape:r.shape,dtype:r.dtype,value:1},backend:n})}var Ehe={kernelName:Mi,backendName:"webgpu",kernelFunc:s6};function Rhe(e){let{inputs:t,backend:n,attrs:r}=e,{axis:s}=r;if(t.length===1)return Jx({inputs:{input:t[0]},backend:n,attrs:{dim:s}});let a=t[0].shape,o=t[0].dtype;t.forEach(u=>{w.assertShapesMatch(a,u.shape,"All tensors passed to stack must have matching shapes"),w.assert(o===u.dtype,()=>"All tensors passed to stack must have matching dtypes")});let i=[],l=t.map(u=>{let d=Jx({inputs:{input:u},backend:n,attrs:{dim:s}});return i.push(d),d}),c=G4({inputs:l,backend:n,attrs:{axis:s}});return i.forEach(u=>n.disposeData(u.dataId)),c}var _he={kernelName:Li,backendName:"webgpu",kernelFunc:Rhe},Dhe=class{constructor(e,t){this.variableNames=["x"],this.uniforms="constantValue : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=t.map((n,r)=>n[0]+e[r]+n[1]),this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),t.map((n,r)=>{this.uniforms+=` pad${r} : vec2<i32>;`}),this.xShape=e,this.shaderKey="pad"}getUserCode(){let e=this.xShape.length,t=In(e),n=this.xShape.map((u,d)=>`uniforms.pad${d}[0]`).join(","),r=this.xShape.map((u,d)=>`uniforms.pad${d}[0] + uniforms.xShape${e>1?`[${d}]`:""}`).join(","),s=e>1?`${t}(${n})`:`${n}`,a=e>1?`${t}(${r})`:`${r}`,o=e>1?"any(outC < start)":"outC < start",i=e>1?"any(outC >= end)":"outC >= end",l=e>1?["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,e):"coords";return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-16 15:49:55 +01:00
let start = ${s};
2021-11-08 13:36:26 +01:00
let end = ${a};
2022-01-08 18:43:44 +01:00
let outC = getCoordsFromIndex(index);
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
if (${o} || ${i}) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, uniforms.constantValue);
2021-11-08 13:36:26 +01:00
} else {
let coords = outC - start;
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getX(${l}));
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}},a6=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{paddings:a,constantValue:o}=r;if(a.every(c=>w.arraysEqual(c,[0,0])))return is({inputs:{x:s},backend:n});if(w.sizeFromShape(s.shape)===0){let c=a.map((u,d)=>u[0]+s.shape[d]+u[1]);return Ec({backend:n,attrs:{shape:c,value:o,dtype:s.dtype}})}let i=[{type:"float32",data:[o]}];a.map(c=>i.push({type:"int32",data:[c[0],c[1]]}));let l=new Dhe(s.shape,a);return n.runWebGPUProgram(l,[s],s.dtype,i)},Phe={kernelName:co,backendName:"webgpu",kernelFunc:a6},$he=Kn({opSnippet:qt.POW}),Fhe={kernelName:po,backendName:"webgpu",kernelFunc:$he};function Ohe(e){let{inputs:t,backend:n}=e,{x:r,alpha:s}=t,a=new z4(qt.PRELU,r.shape,s.shape);return n.runWebGPUProgram(a,[r,s],"float32")}var Mhe={kernelName:ho,backendName:"webgpu",kernelFunc:Ohe};function zhe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{axis:a,keepDims:o}=r;return Lp(s,a,o,"prod",n)}var Lhe={kernelName:Bi,backendName:"webgpu",kernelFunc:zhe},Bhe=e=>{let{backend:t,attrs:n}=e,{start:r,stop:s,step:a,dtype:o}=n,i=Yce(r,s,a,o);return t.makeTensorInfo([i.length],o,i)},Whe={kernelName:Nu,backendName:"webgpu",kernelFunc:Bhe},o6=Kn({opSnippet:qt.DIV}),Vhe={kernelName:ja,backendName:"webgpu",kernelFunc:o6},Uhe=Nn({opType:kt.RELU}),Ghe={kernelName:fo,backendName:"webgpu",kernelFunc:Uhe},Hhe=Nn({opType:kt.RELU6}),jhe={kernelName:go,backendName:"webgpu",kernelFunc:Hhe},qhe=class{constructor(e,t,n){this.variableNames=["x"],this.uniforms="adjustHeightWidth : vec2<f32>; halfPixelCenters : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=[e[0],t,n,e[3]],this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="resizeBilinear"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let b = coords[0];
let d = coords[3];
let rc = coords.yz;
let effectiveInSize = vec2<f32>(
2021-11-23 16:40:40 +01:00
f32(uniforms.xShape.y) - uniforms.adjustHeightWidth[0],
f32(uniforms.xShape.z) - uniforms.adjustHeightWidth[1]);
2021-11-08 13:36:26 +01:00
let effectiveOutSize = vec2<f32>(
2021-11-23 16:40:40 +01:00
f32(uniforms.outShape.y) - uniforms.adjustHeightWidth[0],
f32(uniforms.outShape.z) - uniforms.adjustHeightWidth[1]);
2021-11-08 13:36:26 +01:00
let effectiveInputOverOutputRatioRC =
effectiveInSize / effectiveOutSize;
// Fractional source index
2021-11-23 16:40:40 +01:00
let sourceFracIndexRC =
(vec2<f32>(rc) + vec2<f32>(uniforms.halfPixelCenters)) *
effectiveInputOverOutputRatioRC - vec2<f32>(uniforms.halfPixelCenters);
2021-11-08 13:36:26 +01:00
// Compute the four integer indices.
let sourceFloorRC = vec2<i32>(sourceFracIndexRC);
let sourceCeilRC = vec2<i32>(
min(vec2<f32>(uniforms.xShape.yz) - vec2<f32>(1.0), ceil(sourceFracIndexRC)));
let topLeft = getX(b, sourceFloorRC.x, sourceFloorRC.y, d);
let bottomLeft = getX(b, sourceCeilRC.x, sourceFloorRC.y, d);
let topRight = getX(b, sourceFloorRC.x, sourceCeilRC.y, d);
let bottomRight = getX(b, sourceCeilRC.x, sourceCeilRC.y, d);
let fracRC = sourceFracIndexRC - vec2<f32>(sourceFloorRC);
let top = topLeft + (topRight - topLeft) * fracRC.y;
let bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;
let newValue = top + (bottom - top) * fracRC.x;
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, newValue);
2021-10-30 18:21:54 +02:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Xhe(e){let{inputs:t,backend:n,attrs:r}=e,{images:s}=t,{alignCorners:a,size:o,halfPixelCenters:i}=r,[l,c]=o,u=a&&l>1?1:0,d=a&&c>1?1:0,h=[{type:"float32",data:[u,d]},{type:"float32",data:[i?.5:0]}],f=new qhe(s.shape,l,c);return n.runWebGPUProgram(f,[s],"float32",h)}var Khe={kernelName:mo,backendName:"webgpu",kernelFunc:Xhe},Zhe=class{constructor(e,t,n,r){this.variableNames=["x"],this.uniforms="adjustHeightWidth : vec2<f32>; roundBase : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=[e[0],t,n,e[3]],this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.halfPixelCenters=r,this.shaderKey=`resizeNearest_${r}`}getUserCode(){let e;return this.halfPixelCenters?e="max((vec2<f32>(rc) + vec2<f32>(0.5)) * effectiveInputOverOutputRatioRC, vec2<f32>(0.0))":e="vec2<f32>(rc) * effectiveInputOverOutputRatioRC",`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let b = coords[0];
let d = coords[3];
let rc = coords.yz;
let effectiveInSize = vec2<f32>(
2021-11-23 16:40:40 +01:00
f32(uniforms.xShape.y) - uniforms.adjustHeightWidth[0],
f32(uniforms.xShape.z) - uniforms.adjustHeightWidth[1]);
2021-11-08 13:36:26 +01:00
let effectiveOutSize = vec2<f32>(
2021-11-23 16:40:40 +01:00
f32(uniforms.outShape.y) - uniforms.adjustHeightWidth[0],
f32(uniforms.outShape.z) - uniforms.adjustHeightWidth[1]);
2021-11-08 13:36:26 +01:00
let effectiveInputOverOutputRatioRC =
effectiveInSize / effectiveOutSize;
// Fractional source index
2021-11-23 16:40:40 +01:00
let sourceFracIndexRC = ${e};
2021-11-08 13:36:26 +01:00
// Compute the coordinators of nearest neighbor point.
let inputShapeRC = vec2<f32>(f32(uniforms.xShape.y), f32(uniforms.xShape.z));
let sourceNearestRC = vec2<i32>(
2021-11-23 16:40:40 +01:00
min(inputShapeRC - 1.0, floor(sourceFracIndexRC + uniforms.roundBase)));
2021-11-08 13:36:26 +01:00
let newValue = getX(b, sourceNearestRC.x, sourceNearestRC.y, d);
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, newValue);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function Yhe(e){let{inputs:t,backend:n,attrs:r}=e,{images:s}=t,{alignCorners:a,halfPixelCenters:o,size:i}=r,[l,c]=i,u=a&&l>1?1:0,d=a&&c>1?1:0,h=[{type:"float32",data:[u,d]},{type:"float32",data:[a?.5:0]}],f=new Zhe(s.shape,l,c,o);return n.runWebGPUProgram(f,[s],s.dtype,h)}var Jhe={kernelName:Ru,backendName:"webgpu",kernelFunc:Yhe},Qhe=class{constructor(e,t){this.outputShape=[],this.variableNames=["x"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.uniforms=`centerX : f32; centerY : f32; sinRadians : f32;
2021-11-08 13:36:26 +01:00
cosRadians : f32;`,this.shaderKey="rotate",this.outputShape=e,typeof t=="number"?(this.uniforms+=" fillValue : f32;",this.fillSnippet="var outputValue = uniforms.fillValue;",this.shaderKey+="_float"):(this.uniforms+=" fillValue : vec3<f32>;",this.fillSnippet="var outputValue = uniforms.fillValue[coords[3]];",this.shaderKey+="_vec3")}getUserCode(){return`
${Je()}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let coordXFloat = (f32(coords[2]) - uniforms.centerX) *
uniforms.cosRadians - (f32(coords[1]) - uniforms.centerY) *
uniforms.sinRadians;
let coordYFloat = (f32(coords[2]) - uniforms.centerX) *
uniforms.sinRadians + (f32(coords[1]) - uniforms.centerY) *
uniforms.cosRadians;
let coordX = i32(round(coordXFloat + uniforms.centerX));
let coordY = i32(round(coordYFloat + uniforms.centerY));
${this.fillSnippet}
if(coordX >= 0 && coordX < uniforms.xShape[2] && coordY >= 0 &&
coordY < uniforms.xShape[1]) {
outputValue = getX(coords[0], coordY, coordX, coords[3]);
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, outputValue);
2021-11-08 13:36:26 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}},efe={kernelName:nl,backendName:"webgpu",kernelFunc:({inputs:e,attrs:t,backend:n})=>{let{image:r}=e,{radians:s,fillValue:a,center:o}=t,i=n,l=new Qhe(r.shape,a),[c,u]=N.getImageCenter(o,r.shape[1],r.shape[2]),d=[{type:"float32",data:[c]},{type:"float32",data:[u]},{type:"float32",data:[Math.sin(s)]},{type:"float32",data:[Math.cos(s)]}];return typeof a=="number"?d.push({type:"float32",data:[Number.parseFloat(a.toFixed(2))]}):d.push({type:"float32",data:a}),i.runWebGPUProgram(l,[r],r.dtype,d)}},tfe=Nn({opType:kt.RSQRT,cpuKernelImpl:Jce}),nfe={kernelName:yo,backendName:"webgpu",kernelFunc:tfe},rfe=class{constructor(e,t,n,r,s,a,o){this.variableNames=["updates","indices"],this.workGroupSize=[64,1,1],this.atomic=!0,this.outputShape=a,this.type=o,this.dispatchLayout=He(e),this.dispatch=Oe(this.dispatchLayout,e,this.workGroupSize),this.sliceDimGreaterThanOne=t>1,this.shaderKey=`scatter_${n}_${r}_${this.sliceDimGreaterThanOne}_${o}`;let i=In(s.length);this.uniforms=`sliceDim : i32; strides: ${i}; size: i32;`,this.updatesRank=r,this.indicesRank=n}getUserCode(){let e="";this.indicesRank===1?e="coords[0]":this.indicesRank===2&&(e="coords[0], j");let t=`getIndices(${e})`,n=this.sliceDimGreaterThanOne?"uniforms.strides[j]":"uniforms.strides",r="",s="",a="";this.updatesRank===1?(r="coords[0]",s="flattenedIndex",a=`
2021-11-08 13:36:26 +01:00
fn getUpdatesCoordsFromFlatIndex(index : i32) -> i32 {
return index;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`):this.updatesRank===2&&(r="coords[0], coords[1]",s="vec2<i32>(flattenedIndex, coords[1])",a=`
2021-11-08 13:36:26 +01:00
fn getUpdatesCoordsFromFlatIndex(index : i32) -> vec2<i32> {
let d0 = index / uniforms.updatesShape[1];
let d1 = index - d0 * uniforms.updatesShape[1];
return vec2<i32>(d0, d1);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`);let o=`getUpdates(${r})`,i=this.type==="int32"?"atomicAdd(&(result.numbers[flatIndex]), i32(updateValue));":`
2021-11-08 13:36:26 +01:00
var assumed = atomicLoad(&(result.numbers[flatIndex]));
var success = 0;
for (; success == 0;) {
let new = bitcast<f32>(assumed) + updateValue;
let newI32 = bitcast<i32>(new);
let resValue = atomicCompareExchangeWeak(&(result.numbers[flatIndex]), assumed, newI32);
assumed = resValue[0];
success = resValue[1];
}
`;return`
${a}
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
let coords = getUpdatesCoordsFromFlatIndex(index);
var flattenedIndex = 0;
for (var j = 0; j < uniforms.sliceDim; j = j + 1) {
let indexInside = i32(round(${t}));
flattenedIndex = flattenedIndex + indexInside * ${n};
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
let updateValue = ${o};
2022-01-16 15:49:55 +01:00
let flatIndex = getOutputIndexFromCoords(${s});
2021-11-08 13:36:26 +01:00
${i}
2021-10-30 18:21:54 +02:00
}
2022-01-16 15:49:55 +01:00
}`}};function sfe(e){let{inputs:t,backend:n,attrs:r}=e,{indices:s,updates:a}=t,{shape:o}=r,{sliceRank:i,numUpdates:l,sliceSize:c,strides:u,outputSize:d}=N.calculateShapes(a,s,o),p=[d/c,c];if(d===0)return n.makeTensorInfo(o,s.dtype);let h=Xe({inputs:{x:s},backend:n,attrs:{shape:[l,i]}}),f=Xe({inputs:{x:a},backend:n,attrs:{shape:[l,c]}}),m=f.dtype,g=Ec({backend:n,attrs:{shape:p,value:0,dtype:m}}),y=w.sizeFromShape(f.shape),x=[{type:"int32",data:[i]},{type:"int32",data:u},{type:"int32",data:[y]}],A=new rfe(f.shape,i,h.shape.length,f.shape.length,u,p,m),b=n.runWebGPUProgram(A,[f,h],m,x,g),v=Xe({inputs:{x:b},backend:n,attrs:{shape:o}});return n.disposeData(h.dataId),n.disposeData(f.dataId),n.disposeData(b.dataId),v}var afe={kernelName:Gi,backendName:"webgpu",kernelFunc:sfe},ofe=class{constructor(e,t,n){this.variableNames=["c","a","b"],this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=t,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.cRank=e,this.rank=n,this.shaderKey="select"}getUserCode(){let e,t;if(this.rank>4)throw Error(`Where for rank ${this.rank} is not yet supported`);if(this.rank===1)t="resRC",e="resRC";else{let r=["resRC.x","resRC.y","resRC.z","resRC.w"],s=[],a=[];for(let o=0;o<this.outputShape.length;o++)a.push(`${r[o]}`),o<this.cRank&&s.push(`${r[o]}`);e=s.join(),t=a.join()}return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let resRC = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let cVal = getC(${e});
if (cVal >= 1.0) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getA(${t}));
2021-11-08 13:36:26 +01:00
} else {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, getB(${t}));
2021-11-06 15:21:51 +01:00
}
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function ife(e){let{inputs:t,backend:n}=e,{condition:r,t:s,e:a}=t,o=new ofe(r.shape.length,s.shape,s.shape.length);return n.runWebGPUProgram(o,[r,s,a],Wn(s.dtype,a.dtype))}var lfe={kernelName:Hi,backendName:"webgpu",kernelFunc:ife},ufe=Nn({opType:kt.SIGMOID}),cfe={kernelName:xo,backendName:"webgpu",kernelFunc:ufe},dfe=Nn({opType:kt.SIN}),pfe={kernelName:Ao,backendName:"webgpu",kernelFunc:dfe},hfe=Nn({opType:kt.SINH}),ffe={kernelName:qi,backendName:"webgpu",kernelFunc:hfe},i6=Kn({opSnippet:qt.SUB,cpuKernelImpl:rde,supportsComplex:!0}),mfe={kernelName:Io,backendName:"webgpu",kernelFunc:i6};function gfe(e){let{inputs:t,backend:n,attrs:r}=e,{logits:s}=t,{dim:a}=r,o=w.parseAxisParam([a],s.shape),i=r6({inputs:{x:s},backend:n,attrs:{reductionIndices:o,keepDims:!1}}),l=N.expandShapeToKeepDim(i.shape,o),c=Xe({inputs:{x:i},backend:n,attrs:{shape:l}}),u=i6({inputs:{a:s,b:c},backend:n}),d=J4({inputs:{x:u},backend:n}),p=Yx({inputs:{x:d},backend:n,attrs:{axis:o,keepDims:!1}}),h=Xe({inputs:{x:p},backend:n,attrs:{shape:l}}),f=o6({inputs:{a:d,b:h},backend:n});return n.disposeData(i.dataId),n.disposeData(c.dataId),n.disposeData(u.dataId),n.disposeData(d.dataId),n.disposeData(p.dataId),n.disposeData(h.dataId),f}var yfe={kernelName:wo,backendName:"webgpu",kernelFunc:gfe},Afe=e=>{let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{blockShape:a,paddings:o}=r;w.assert(s.shape.length<=4,()=>"spaceToBatchND for rank > 4 with a WebGPU backend not implemented yet");let i=a.reduce((y,x)=>y*x),l=[[0,0]];l.push(...o);for(let y=1+a.length;y<s.shape.length;++y)l.push([0,0]);let c=[],u=a6({inputs:{x:s},backend:n,attrs:{paddings:l,constantValue:0}}),d=N.getReshaped(u.shape,a,i,!1),p=N.getPermuted(d.length,a.length,!1),h=N.getReshapedPermuted(u.shape,a,i,!1),f=Xe({inputs:{x:u},backend:n,attrs:{shape:d}}),m=zl({inputs:{x:f},backend:n,attrs:{perm:p}}),g=Xe({inputs:{x:m},backend:n,attrs:{shape:h}});return c.push(u),c.push(f),c.push(m),c.forEach(y=>n.disposeData(y.dataId)),g},xfe={kernelName:Xi,backendName:"webgpu",kernelFunc:Afe},bfe=class{constructor(e,t,n,r,s,a,o=!0){this.variableNames=["updates","indices","defaultValue"],this.workGroupSize=[64,1,1],this.workPerThread=4,this.size=!0,this.outputShape=a,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]);let i=t>1;this.shaderKey=`scatter_${n}_${r}_${i}`;let l=In(s.length);this.uniforms=`updateSize : i32; sliceDim : i32; strides: ${l};`;let c="";n===1?c="i":n===2&&(c="i, j"),this.indicesSnippet=`getIndices(${c})`;let u="";r===1?u="i":r===2&&(u="i, coords[1]"),this.updatesSnippet=`getUpdates(${u})`,this.strideString=i?"uniforms.strides[j]":"uniforms.strides"}getUserCode(){return`
${Je()}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let globalIndex = index * ${this.workPerThread};
if (globalIndex < uniforms.size) {
var sum = vec4<f32>(0.0);
var found = vec4<bool>(false);
for (var i = 0; i < uniforms.updateSize; i = i + 1) {
var flattenedIndex = 0;
for (var j = 0; j < uniforms.sliceDim; j = j + 1) {
let indexInside = i32(round(${this.indicesSnippet}));
flattenedIndex = flattenedIndex + indexInside * ${this.strideString};
}
for (var innerIndex = 0; innerIndex < ${this.workPerThread}; innerIndex = innerIndex + 1) {
let curIndex = globalIndex + innerIndex;
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(curIndex);
2021-11-08 13:36:26 +01:00
if (flattenedIndex == coords[0]) {
sum[innerIndex] = sum[innerIndex] + ${this.updatesSnippet};
found[innerIndex] = true;
}
}
}
for (var innerIndex = 0; innerIndex < ${this.workPerThread}; innerIndex = innerIndex + 1) {
let curIndex = globalIndex + innerIndex;
if (curIndex < uniforms.size)
{
2022-01-08 18:43:44 +01:00
setOutputAtIndex(curIndex, mix(getDefaultValue(), sum[innerIndex], f32(found[innerIndex])));
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
}`}};function vfe(e){let{inputs:t,backend:n,attrs:r}=e,{sparseIndices:s,sparseValues:a,defaultValue:o}=t,{outputShape:i}=r,{sliceRank:l,numUpdates:c,strides:u,outputSize:d}=N.calculateShapes(a,s,i),p=!1,h=[{type:"int32",data:[c]},{type:"int32",data:[l]},{type:"int32",data:u}],f=new bfe(c,l,s.shape.length,a.shape.length,u,[d,1],p),m=n.runWebGPUProgram(f,[a,s,o],a.dtype,h),g=Xe({inputs:{x:m},backend:n,attrs:{shape:i}});return n.disposeData(m.dataId),g}var wfe={kernelName:Ed,backendName:"webgpu",kernelFunc:vfe};function kfe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{numOrSizeSplits:a,axis:o}=r,i=w.parseAxisParam(o,s.shape)[0],l=N.prepareSplitSize(s,a,i),c=s.shape.length,u=new Array(c).fill(0),d=s.shape.slice();return l.map(p=>{let h=[...d];h[i]=p;let f=Nc({inputs:{x:s},backend:n,attrs:{begin:u,size:h}});return u[i]+=p,f})}var Ife={kernelName:Ki,backendName:"webgpu",kernelFunc:kfe},Sfe=Nn({opType:kt.SQRT}),Cfe={kernelName:bo,backendName:"webgpu",kernelFunc:Sfe},Tfe={kernelName:Fu,backendName:"webgpu",kernelFunc:({inputs:e,backend:t})=>{let{x:n}=e,r=t,s=new Mp(n.shape,kt.SQUARE);return r.runWebGPUProgram(s,[n],n.dtype)}},Nfe=Kn({opSnippet:qt.SQUARED_DIFFERENCE}),Efe={kernelName:ko,backendName:"webgpu",kernelFunc:Nfe},Rfe=class{constructor(e){this.variableNames=["x"],this.workPerThread=1,this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]);let t=In(this.outputShape.length);this.uniforms=`begin : ${t}; strides : ${t}; `,this.shaderKey="stridedSlice"}getUserCode(){let e=this.outputShape.length,t="";if(e===1)t="coords * uniforms.strides + uniforms.begin";else{let r=0;t=this.outputShape.map((s,a)=>(r++,this.outputShape.length===1?`coords * uniforms.strides[${a}] + uniforms.begin[${a}]`:`coords[${r-1}] * uniforms.strides[${a}] + uniforms.begin[${a}]`)).join(",")}return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
setOutputAtIndex(index, getX(${t}));
2021-11-08 13:36:26 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function _fe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{begin:a,end:o,strides:i,beginMask:l,endMask:c,ellipsisMask:u,newAxisMask:d,shrinkAxisMask:p}=r,{finalShapeSparse:h,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:x,end:A,strides:b}=zt.sliceInfo(s.shape,a,o,i,l,c,u,d,p),v;if(m)v=Xe({inputs:{x:s},backend:n,attrs:{shape:f}});else if(g||y){w.assert(s.shape.length>=1,()=>`Input must have rank at least 1, got: ${s.shape.length}`);let C=zt.computeOutShape(x,A,b),I=Nc({inputs:{x:s},backend:n,attrs:{begin:x,size:C}});v=Xe({inputs:{x:I},backend:n,attrs:{shape:f}}),n.disposeData(I.dataId)}else if(n.shouldExecuteOnCPU([s])){let I=n.readSync(s.dataId),E=Le(s.shape,s.dtype,I),R=tde(h,E,b,x);v=n.makeTensorInfo(f,s.dtype,R.values)}else{let I=new Rfe(h),E=[{type:"int32",data:x},{type:"int32",data:b}],R=n.runWebGPUProgram(I,[s],s.dtype,E);v=Xe({inputs:{x:R},backend:n,attrs:{shape:f}}),n.disposeData(R.dataId)}return v}var Dfe={kernelName:Zi,backendName:"webgpu",kernelFunc:_fe};function Pfe(e){let{inputs:t,backend:n,attrs:r}=e,{separator:s,nGramWidths:a,leftPad:o,rightPad:i,padWidth:l,preserveShortSequences:c}=r,{data:u,dataSplits:d}=t,p=n.readSync(u.dataId),h=n.readSync(d.dataId),[f,m]=nde(p,h,s,a,o,i,l,c);return[n.makeTensorInfo([f.length],"string",f),n.makeTensorInfo(d.shape,"int32",m)]}var $fe={kernelName:Rd,backendName:"webgpu",kernelFunc:Pfe},Ffe=Nn({opType:kt.TANH}),Ofe={kernelName:So,backendName:"webgpu",kernelFunc:Ffe},Mfe=class{constructor(e,t){this.variableNames=["A"],this.workGroupSize=[64,1,1],this.size=!0;let n=new Array(e.length);for(let r=0;r<n.length;r++)n[r]=e[r]*t[r];this.outputShape=n,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.rank=this.outputShape.length,this.shaderKey="tile"}getUserCode(){let e=zfe(this.rank,"uniforms.");return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let resRC = getCoordsFromIndex(index);
setOutputAtIndex(index, getA(${e}));
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function zfe(e,t=""){if(e>=5)throw Error(`Tile for rank ${e} is not yet supported`);if(e===1)return`(resRC % ${t}aShape)`;let n=["resRC.x","resRC.y","resRC.z","resRC.w"],r=[];for(let s=0;s<e;s++)r.push(`(${n[s]} % ${t}aShape[${s}])`);return r.join()}function Lfe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{reps:a}=r;if(n.shouldExecuteOnCPU([s])||s.dtype==="string"||s.shape.length>=5){let l=n.readSync(s.dataId),c=s.dtype==="string"?l.map(p=>w.decodeString(p)):l,u=Le(s.shape,s.dtype,c),d=sde(u,a);return n.makeTensorInfo(d.shape,d.dtype,d.values)}let o=new Mfe(s.shape,a);return n.runWebGPUProgram(o,[s],s.dtype)}var Bfe={kernelName:Js,backendName:"webgpu",kernelFunc:Lfe},Wfe=class{constructor(e){this.variableNames=["x","indices"],this.workGroupSize=[256,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.uniforms=`inputSize : i32; firstPass : i32; negativeInf : f32;
2021-11-08 13:36:26 +01:00
dir : i32; inc : i32;`,this.shaderKey="swap"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let outC = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let batch = outC[0];
let elemIdx = outC[1];
// We compare elements pair-wise within a group of size 2 * inc.
// The comparing rule for each group alternates between ascending
// and descending. Within each group, we compare each pair at
// positions i and i+inc. To decide whether an element at position i
// is x0 or x1, we mod it by 2 * inc, if the result is smaller than
// inc, it is in the first half of the group, we denote it as x0,
// otherwise we denote it as x1.
// For example, as shown in the Bitonic top K paper referenced
// above, Figure5(a) shows that element[1] is in the second half of
// the group when group size is 2, but it is in the first half of
// the group when group size is 4.
let isFirstInPair = elemIdx % (2 * uniforms.inc) < uniforms.inc;
var i = 0;
if (isFirstInPair) {
i = elemIdx;
} else {
i = elemIdx - uniforms.inc;
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
var i0 = 0;
if (uniforms.firstPass == 1) {
i0 = i;
} else {
i0 = i32(getIndices(batch, i));
}
var i1 = 0;
if (uniforms.firstPass == 1) {
i1 = i + uniforms.inc;
} else {
i1 = i32(getIndices(batch, i + uniforms.inc));
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
var x0 = f32(0.0);
var x1 = f32(0.0);
if (i0 < uniforms.inputSize) {
x0 = getX(batch, i0);
} else {
x0 = uniforms.negativeInf;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
if (i1 < uniforms.inputSize) {
x1 = getX(batch, i1);
} else {
x1 = uniforms.negativeInf;
}
let reverse = elemIdx % (2 * uniforms.dir) >= uniforms.dir;
let isGreater = x0 > x1 || (x0 == x1 && i1 > i0);
if (reverse == isGreater) {
// Elements in opposite order of direction
let iTemp = i0;
i0 = i1;
i1 = iTemp;
}
if (isFirstInPair) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, f32(i0));
2021-11-08 13:36:26 +01:00
} else {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, f32(i1));
2021-10-30 18:21:54 +02:00
}
}
}
2022-01-16 15:49:55 +01:00
`}},Vfe=class{constructor(e){this.variableNames=["x","indices"],this.workGroupSize=[256,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.uniforms="inputSize : i32; firstPass : i32; k : i32;",this.shaderKey="merge"}getUserCode(){return`
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let outC = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
let batch = outC[0];
let elemIdx = outC[1];
// The output size is half of the previous size.
// If the previous sequence is | | | | _ _ _ _ | | | | _ _ _ _
// (k=4), we only need to output the indices at positions |, the
// indices at positions _ can be thrown away, see Figure5(b) After
// Phase 2 (Merge phase) in the Bitonic Top K paper referenced
// above.
// For example, the paper shows we only need to output the orange
// bars. The output sequence should look like this | | | | | | | |.
// Because the sequence is halved, to map the output index back to
// the previous sequence to find the corresponding value, we need
// to double the index. When we double the index, we basically
// interpolate a position, so 2i looks like
// | _ | _ | _ | _ | _ | _ | _. We move the | to the first k
// position of each 2k positions by - elemIdx % k. E.g. for output
// at index 4,5,6,7, we want to get the corresponding element at
// original index 8,9,10,11, for output at index 8,9,10,11,
// we want to get the corresponding element at original index
// 16,17,18,19, so on and so forth.
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
var i = 0;
if (elemIdx < uniforms.k) {
i = elemIdx;
} else {
i = elemIdx * 2 - elemIdx % uniforms.k;
}
var i0 = 0;
if (uniforms.firstPass == 1) {
i0 = i;
} else {
i0 = i32(getIndices(batch, i));
}
var i1 = 0;
if (uniforms.firstPass == 1) {
i1 = i + uniforms.k;
} else {
i1 = i32(getIndices(batch, i + uniforms.k));
}
2021-10-30 18:21:54 +02:00
2021-11-08 13:36:26 +01:00
let x0 = getX(batch, i0);
var x1 = f32(0.0);
if (i1 < uniforms.inputSize) {
x1 = getX(batch, i1);
} else {
x1 = x0;
}
2021-11-06 15:21:51 +01:00
2021-11-08 13:36:26 +01:00
if (x0 >= x1) {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, f32(i0));
2021-11-08 13:36:26 +01:00
} else {
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, f32(i1));
2021-11-08 13:36:26 +01:00
}
2021-10-30 18:21:54 +02:00
}
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`}};function _c(e,t){t!==null&&e.disposeData(t.dataId)}function l6(e){let t=1;for(;t<e;)t*=2;return t}function Ufe(e){let{inputs:t,backend:n,attrs:r}=e,{x:s}=t,{k:a,sorted:o}=r,i=s.shape,l=i[i.length-1];if(n.shouldExecuteOnCPU([s])){let v=n.readSync(s.dataId),[C,I]=ade(v,i,s.dtype,a,o);return[n.makeTensorInfo(C.shape,C.dtype,C.values),n.makeTensorInfo(I.shape,I.dtype,I.values)]}if(a===0)return i[i.length-1]=0,[n.makeTensorInfo(i,s.dtype,[]),n.makeTensorInfo(i,"int32",[])];if(l===1)return[s,Ec({attrs:{shape:i,dtype:"int32",value:0},backend:n})];let u=w.sizeFromShape(i)/l,d=Xe({inputs:{x:s},attrs:{shape:[u,l]},backend:n}),p=l6(a),h=l6(l),f=null,m=()=>f===null?[d,d]:[d,f],g=(v,C,I)=>{let E=m(),R=new Wfe(I),_=[{type:"int32",data:[l]},{type:"int32",data:[f===null?1:0]},{type:"float32",data:[Number.NEGATIVE_INFINITY]},{type:"int32",data:[v]},{type:"int32",data:[C]}],P=f;f=n.runWebGPUProgram(R,E,"int32",_),_c(n,P)};for(let v=1;v<p;v*=2){let C=v*2;for(let I=v;I>=1;I/=2)g(C,I,[u,h])}for(let v=h;v>p;v/=2){let C=m(),I=new Vfe([u,v/2]),R=[{type:"int32",data:[l]},{type:"int32",data:[f===null?1:0]},{type:"int32",data:[p]}],F=f;f=n.runWebGPUProgram(I,C,"int32",R),_c(n,F);let _=p/2,P=_*2;for(let T=_;T>=1;T/=2)g(P,T,f.shape)}let y=f;f=Nc({inputs:{x:f},backend:n,attrs:{begin:0,size:[u,a]}}),_c(n,y);let x=n6({inputs:{x:d,indices:f},backend:n,attrs:{axis:1,batchDims:1}});_c(n,d);let A=i.slice(0,-1);A.push(a),y=f,f=Xe({inputs:{x:f},attrs:{shape:A},backend:n}),_c(n,y);let b=x;return x=Xe({inputs:{x},attrs:{shape:A},backend:n}),_c(n,b),[x,f]}var Gfe={kernelName:Ji,backendName:"webgpu",kernelFunc:Ufe},Hfe=class{constructor(e){this.variableNames=["Image","Transforms"],this.uniforms="interpolationModeId : i32; fillModeId : i32; fillValue : f32;",this.workGroupSize=[64,1,1],this.size=!0,this.outputShape=e,this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize),this.shaderKey="transform"}getUserCode(){return`
2021-11-08 13:36:26 +01:00
fn mapCoord(outCoord : f32, len : f32) -> f32{
var inCoord = outCoord;
if(uniforms.fillModeId == 2) {
if (inCoord < 0.0) {
if (len <= 1.0) {
inCoord = 0.0;
} else {
let sz2 = 2.0 * len;
if (inCoord < sz2) {
inCoord = sz2 * f32(i32(f32(-inCoord / sz2))) +
inCoord;
}
if (inCoord < -len) {
inCoord = inCoord + sz2;
} else {
inCoord = -inCoord - 1.0;
}
}
} else if (inCoord > len - 1.0) {
2021-11-08 13:36:26 +01:00
if (len <= 1.0) {
inCoord = 0.0;
} else {
let sz2 = 2.0 * len;
inCoord = inCoord - sz2 * f32(i32(f32(inCoord / sz2)));
if (inCoord >= len) {
inCoord = sz2 - inCoord - 1.0;
}
}
}
return clamp(inCoord, 0.0, len - 1.0);
} else if (uniforms.fillModeId == 3) {
2021-11-08 13:36:26 +01:00
if (inCoord < 0.0) {
if (len <= 1.0) {
inCoord = 0.0;
} else {
let sz = len - 1.0;
inCoord = inCoord + len * (f32(i32(f32(-inCoord / sz))) + 1.0);
}
} else if (inCoord > len - 1.0) {
2021-11-08 13:36:26 +01:00
if (len <= 1.0) {
inCoord = 0.0;
} else {
let sz = len - 1.0;
inCoord = inCoord - len * f32(i32(f32(inCoord / sz)));
}
}
return clamp(inCoord, 0.0, len - 1.0);
} else if (uniforms.fillModeId == 4) {
2021-11-08 13:36:26 +01:00
return clamp(outCoord, 0.0, len - 1.0);
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
return outCoord;
2021-10-30 18:21:54 +02:00
}
2021-11-08 13:36:26 +01:00
fn readWithFillValue(batch : i32, coordY : i32, coordX : i32,
channel : i32) -> f32 {
var outputValue : f32;
if (0 <= coordY && coordY < uniforms.imageShape[1] && 0 <= coordX && coordX < uniforms.imageShape[2]) {
outputValue = getImage(batch, coordY, coordX, channel);
} else {
outputValue = uniforms.fillValue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
return outputValue;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
${Je()}
2021-11-08 13:36:26 +01:00
if (index < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(index);
2021-11-08 13:36:26 +01:00
var outputValue : f32;
let batch = coords[0];
let x = coords[2];
let y = coords[1];
let channel = coords[3];
let xf = f32(x);
let yf = f32(y);
let a1 = getTransforms(batch, 0);
let a2 = getTransforms(batch, 1);
let a3 = getTransforms(batch, 2);
let b1 = getTransforms(batch, 3);
let b2 = getTransforms(batch, 4);
let b3 = getTransforms(batch, 5);
let c1 = getTransforms(batch, 6);
let c2 = getTransforms(batch, 7);
let projection = c1 * xf + c2 * yf + 1.0;
if (projection == 0.0) {
outputValue = uniforms.fillValue;
} else {
let inX = (a1 * xf + a2 * yf + a3) / projection;
let inY = (b1 * xf + b2 * yf + b3) / projection;
let mapX = mapCoord(inX, f32(uniforms.imageShape[2]));
let mapY = mapCoord(inY, f32(uniforms.imageShape[1]));
if (uniforms.interpolationModeId == 1) {
let coordY = i32(round(mapY));
let coordX = i32(round(mapX));
outputValue = readWithFillValue(batch, coordY, coordX,
channel);
} else {
let yFloor = floor(mapY);
let xFloor = floor(mapX);
let yCeil = yFloor + 1.0;
let xCeil = xFloor + 1.0;
let valueYFloor = (xCeil - mapX) *
readWithFillValue(batch, i32(yFloor), i32(xFloor), channel) +
(mapX - xFloor) *
readWithFillValue(batch, i32(yFloor), i32(xCeil), channel);
let valueYCeil = (xCeil - mapX) *
readWithFillValue(batch, i32(yCeil), i32(xFloor), channel) +
(mapX - xFloor) *
readWithFillValue(batch, i32(yCeil), i32(xCeil), channel);
outputValue = (yCeil - mapY) * valueYFloor +
(mapY - yFloor) * valueYCeil;
}
}
2022-01-08 18:43:44 +01:00
setOutputAtIndex(index, outputValue);
2021-11-06 15:21:51 +01:00
}
}
2022-01-16 15:49:55 +01:00
`}};function jfe(e){let{inputs:t,backend:n,attrs:r}=e,{image:s,transforms:a}=t,{interpolation:o,fillMode:i,fillValue:l,outputShape:c}=r,[u,d,p,h]=s.shape,[f,m]=c!=null?c:[d,p],g=[u,f,m,h],y=new Hfe(g),x=o==="nearest"?1:2,A;switch(i){case"constant":A=1;break;case"reflect":A=2;break;case"wrap":A=3;break;case"nearest":A=4;break;default:A=1;break}let b=[{type:"int32",data:[x]},{type:"int32",data:[A]},{type:"float32",data:[l]}];return n.runWebGPUProgram(y,[s,a],"float32",b)}var qfe={kernelName:Qi,backendName:"webgpu",kernelFunc:jfe};function Xfe(e){let{inputs:t,backend:n,attrs:r}=e,{value:s}=t,{axis:a}=r;a<0&&(a+=s.shape.length);let o=s,i=o.shape.length,l=s.shape[a],c=new Array(i-1),u=0;for(let m=0;m<i;m++)m!==a&&(c[u++]=o.shape[m]);let d=[],p=new Array(i).fill(0),h=o.shape.slice();h[a]=1;let f=new Array(l);for(let m=0;m<f.length;m++){p[a]=m;let g=Nc({inputs:{x:o},backend:n,attrs:{begin:p,size:h}}),y=Xe({inputs:{x:g},backend:n,attrs:{shape:c}});f[m]=y,d.push(g)}return d.forEach(m=>n.disposeData(m.dataId)),f}var Kfe={kernelName:el,backendName:"webgpu",kernelFunc:Xfe},Zfe=[Sce,lde,cde,hde,xde,vde,kde,Sde,Rde,$de,Ode,Bde,Ece,Gde,Xde,Jde,epe,npe,ape,lpe,cpe,mpe,ype,xpe,bpe,vpe,kpe,Spe,Tpe,Ppe,Epe,_pe,Ope,zpe,Bpe,Upe,jpe,Xpe,Zpe,Nce,Vde,Jpe,ehe,nhe,she,ohe,lhe,uhe,dhe,hhe,mhe,yhe,xhe,vhe,dpe,khe,She,The,_de,Ehe,_he,Phe,Fhe,Mhe,Lhe,Whe,Dde,Vhe,Ghe,jhe,kce,Khe,Jhe,efe,nfe,afe,lfe,cfe,pfe,ffe,Nde,Dfe,$fe,yfe,xfe,wfe,Ife,Cfe,Tfe,Efe,mfe,hpe,Ofe,Bfe,Gfe,qfe,yde,Kfe,Nhe];for(let e of Zfe)Jr(e);var Yfe=class{constructor(e){this.device=e,this.numUsedBuffers=0,this.numFreeBuffers=0,this.freeBuffers=new Map,this.usedBuffers=new Map,this.numBytesUsed=0,this.numBytesAllocated=0}acquireUploadBuffer(e,t){return this.acquireBuffer(e,t,!0)}acquireBuffer(e,t,n=!1){let r=u6(e,t);if(this.freeBuffers.has(r)||this.freeBuffers.set(r,[]),this.usedBuffers.has(r)||this.usedBuffers.set(r,[]),this.numBytesUsed+=e,this.numUsedBuffers++,this.freeBuffers.get(r).length>0){this.numFreeBuffers--;let a=this.freeBuffers.get(r).shift();return this.usedBuffers.get(r).push(a),a}this.numBytesAllocated+=e;let s=this.device.createBuffer({mappedAtCreation:n,size:e,usage:t});return this.usedBuffers.get(r).push(s),s}releaseBuffer(e,t,n){if(this.freeBuffers.size===0)return;let r=u6(t,n);this.freeBuffers.has(r)||this.freeBuffers.set(r,[]),this.freeBuffers.get(r).push(e),this.numFreeBuffers++,this.numUsedBuffers--;let s=this.usedBuffers.get(r),a=s.indexOf(e);if(a<0)throw new Error("Cannot release a buffer that was never provided by this buffer manager");s.splice(a,1),this.numBytesUsed-=t}releaseUploadBuffer(e,t,n){e.mapAsync(GPUMapMode.WRITE).then(()=>{this.releaseBuffer(e,t,n)},r=>{})}getNumUsedBuffers(){return this.numUsedBuffers}getNumFreeBuffers(){return this.numFreeBuffers}dispose(){this.freeBuffers.forEach((e,t)=>{e.forEach(n=>{n.destroy()})}),this.usedBuffers.forEach((e,t)=>{e.forEach(n=>{n.destroy()})}),this.freeBuffers=new Map,this.usedBuffers=new Map,this.numUsedBuffers=0,this.numFreeBuffers=0,this.numBytesUsed=0,this.numBytesAllocated=0}};function u6(e,t){return`${e}_${t}`}var c6=class{constructor(){this.outputShape=[0],this.variableNames=[],this.workGroupSize=[256,1,1],this.lastUniformData=[],this.inputTexture=null,this.layout=null,this.lastPixelSize={width:0,height:0},this.disposed=!1,this.shaderKey="fromPixels",this.useImport=!1}updateOutputShape(e){w.arraysEqual(this.outputShape,e)||(this.outputShape=e,this.workPerThread=e[2],this.dispatchLayout=He(this.outputShape),this.dispatch=Oe(this.dispatchLayout,this.outputShape,this.workGroupSize,[this.workPerThread,1,1]))}makeFromPixelsSource(){let e=this.useImport?"textureLoad(src, vec2<i32>(coords.yx));":"textureLoad(src, vec2<i32>(coords.yx), 0)";return`
2021-11-08 13:36:26 +01:00
[[binding(1), group(0)]] var src: ${this.useImport?"texture_external":"texture_2d<f32>"};
${Je()}
2021-11-08 13:36:26 +01:00
let flatIndexBase = index * uniforms.numChannels;
for (var i = 0; i < uniforms.numChannels; i = i + 1) {
let flatIndex = flatIndexBase + i;
if (flatIndex < uniforms.size) {
2022-01-08 18:43:44 +01:00
let coords = getCoordsFromIndex(flatIndexBase);
2021-11-08 13:36:26 +01:00
let values = ${e};
result.numbers[flatIndex] = i32(floor(255.0 * values[i]));
2021-11-06 15:21:51 +01:00
}
}
}
2022-01-16 15:49:55 +01:00
`}getUserCode(){return this.makeFromPixelsSource()}setPipeline(e){this.pipeline=e}setUniform(e,t){if(!this.uniform){let n=e.createBuffer({size:t.length*4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});this.uniform=n}!t||t.length===this.lastUniformData.length&&t.every((n,r)=>n===this.lastUniformData[r])||(e.queue.writeBuffer(this.uniform,0,new Uint32Array(t)),this.lastUniformData=t)}makeInputTexture(e,t,n){return(!this.inputTexture||this.lastPixelSize.width!==t||this.lastPixelSize.height!==n)&&(this.inputTexture&&this.inputTexture.destroy(),this.inputTexture=e.createTexture({size:[t,n],format:"rgba8unorm",usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),this.lastPixelSize.width=t,this.lastPixelSize.height=n),this.inputTexture}dispose(){this.disposed||(this.uniform&&this.uniform.destroy(),this.inputTexture&&this.inputTexture.destroy(),this.disposed=!0)}getLayout(e){return this.layout===null&&(this.layout=this.createTextureLayout(e)),this.layout}createTextureLayout(e){let t=[];t.push({binding:0,visibility:GPUShaderStage.COMPUTE,buffer:{type:"storage"}}),t.push({binding:1,visibility:GPUShaderStage.COMPUTE,texture:{}}),t.push({binding:2,visibility:GPUShaderStage.COMPUTE,buffer:{}});let n=e.createBindGroupLayout({entries:t}),r=e.createPipelineLayout({bindGroupLayouts:[n]});return{bindGroupLayout:n,pipelineLayout:r}}},Jfe=class extends c6{constructor(){super(...arguments);this.layout=null,this.useImport=!0}getUserCode(){return this.makeFromPixelsSource()}getLayout(e){return this.layout===null&&(this.layout=this.createTextureImportLayout(e)),this.layout}createTextureImportLayout(e){let t=[];t.push({binding:0,visibility:GPUShaderStage.COMPUTE,buffer:{type:"storage"}}),t.push({binding:1,visibility:GPUShaderStage.COMPUTE,externalTexture:{}}),t.push({binding:2,visibility:GPUShaderStage.COMPUTE,buffer:{}});let n=e.createBindGroupLayout({entries:t}),r=e.createPipelineLayout({bindGroupLayouts:[n]});return{bindGroupLayout:n,pipelineLayout:r}}},Qfe=Y().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"),d6=class extends au{constructor(e,t=!1){super();if(this.commandQueueOwnedIds=new WeakSet,this.tensorDisposalQueue=[],this.uniformDisposalQueue=[],this.stagingDisposalQueue=[],this.disposed=!1,this.uploadWaitMs=0,this.downloadWaitMs=0,this.dispatchNumberInEncoder=0,!Hx())throw new Error("WebGPU is not supported on this device");this.layoutCache={},this.pipelineCache={},this.device=e,this.queue=e.queue,this.currentCommandEncoder=null,this.currentComputePass=null,this.supportTimeQuery=t,this.bufferManager=new Yfe(this.device),this.tensorMap=new pd(this,Dn()),this.supportTimeQuery&&(this.querySet=this.device.createQuerySet({type:"timestamp",count:2})),Y().getBool("WEBGPU_USE_PROFILE_TOOL")&&(this.dummyCanvas=document.createElement("canvas"),this.dummyCanvas.width=1,this.dummyCanvas.height=1,this.dummyContext=this.dummyCanvas.getContext("webgpu"),this.dummyContext.configure({device:e,format:"bgra8unorm"}),document.body.appendChild(this.dummyCanvas))}nextDataId(){return d6.nextDataId++}floatPrecision(){return 32}defaultGpuBufferUsage(){return GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST}flushDisposalQueue(){this.tensorDisposalQueue.forEach(e=>{this.maybeReleaseBuffer(e),this.tensorMap.delete(e)}),this.uniformDisposalQueue.forEach(e=>this.bufferManager.releaseBuffer(e.buffer,e.byteSize,e.usage)),this.stagingDisposalQueue.forEach(e=>this.bufferManager.releaseUploadBuffer(e.buffer,e.byteSize,e.usage)),this.tensorDisposalQueue=[],this.uniformDisposalQueue=[],this.stagingDisposalQueue=[]}disposeData(e,t=!1){if(this.tensorMap.has(e)){let n=this.tensorMap.get(e);if(n.refCount--,!t&&n.refCount>0)return!1;if(this.commandQueueOwnedIds.has(e))return this.tensorDisposalQueue.push(e),!1;this.maybeReleaseBuffer(e);let{complexTensorInfos:r}=this.tensorMap.get(e);r!=null&&(this.disposeData(r.real.dataId,!0),this.disposeData(r.imag.dataId,!0)),this.tensorMap.delete(e)}return!0}memory(){return{numBytesInGPU:this.bufferManager.numBytesUsed,numBytesAllocatedInGPU:this.bufferManager.n
${r.shape}`);if(s.shape.length!==1)throw new Error(`Input shape should be a vector but received shape
${s.shape}`);if(a.shape.length!==1)throw new Error(`Target shape should be a vector but received shape ${a.shape}`);let o=t.dataIdMap.get(r.dataId).id,i=t.dataIdMap.get(s.dataId).id,l=t.dataIdMap.get(a.dataId).id,c=r.shape[0],u=w.sizeFromShape(a.shape),d=t.makeOutput([c,u],r.dtype),p=t.dataIdMap.get(d.dataId).id,h=t.makeOutput([u],a.dtype),f=t.dataIdMap.get(h.dataId).id,m=t.makeOutput([3],"int32"),g=t.dataIdMap.get(m.dataId).id;oT(o,i,l,c,p,f,g);let y=t.readSync(m.dataId),x;switch(y[0]){case 0:{x=N.getSparseReshapeMultipleNegativeOneOutputDimErrorMessage(y[1],y[2]);break}case 1:{x=N.getSparseReshapeNegativeOutputDimErrorMessage(y[1],y[2]);break}case 2:x=N.getSparseReshapeEmptyTensorZeroOutputDimErrorMessage();break;case 3:{let A=Array.from(t.readSync(s.dataId)),b=Array.from(t.readSync(h.dataId));x=N.getSparseReshapeInputOutputMultipleErrorMessage(A,b);break}case 4:{let A=Array.from(t.readSync(s.dataId)),b=Array.from(t.readSync(h.dataId));x=N.getSparseReshapeInputOutputMismatchErrorMessage(A,b);break}default:x=""}if(t.disposeData(m.dataId),x)throw t.disposeData(d.dataId),t.disposeData(h.dataId),new Error(x);return[d,h]}var N2e={kernelName:$u,backendName:"wasm",setupFunc:C2e,kernelFunc:T2e},iT;function lT(e){iT=e.wasm.cwrap("SparseSegmentReduction",null,["number","number","number","number","number","number","number","number","number"])}function uT(e,t){let{backend:n,inputs:r}=e,{data:s,indices:a,segmentIds:o}=r,i=a.shape[0],l=n.readSync(o.dataId,i-1,i)[0],u=i>0?l+1:0;if(u<0)throw new Error(N.getSparseSegmentReductionNegativeSegmentIdsErrorMessage());let d=s.shape.slice();d[0]=u;let p=n.dataIdMap.get(s.dataId).id,h=n.dataIdMap.get(a.dataId).id,f=n.dataIdMap.get(o.dataId).id,m=n.makeOutput(d,s.dtype),g=n.dataIdMap.get(m.dataId).id,y=n.makeOutput([4],"int32"),x=n.dataIdMap.get(y.dataId).id;iT(p,Xt[s.dtype],s.shape[0],h,f,g,x,t,0);let A=n.readSync(y.dataId),b;switch(A[0]){case 0:{b=N.getSparseSegmentReductionNegativeSegmentIdsErrorMessage();break}case 1:{b=N.getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage();break}case 2:b=N.getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage(A[1],A[2]);break;case 3:b=N.getSparseSegmentReductionIndicesOutOfRangeErrorMessage(A[1],A[2],A[3]);break;default:b=""}if(n.disposeData(y.dataId),b)throw n.disposeData(m.dataId),new Error(b);return m}function E2e(e){return uT(e,!0)}var R2e={kernelName:Td,backendName:"wasm",setupFunc:lT,kernelFunc:E2e};function _2e(e){return uT(e,!1)}var D2e={kernelName:Nd,backendName:"wasm",setupFunc:lT,kernelFunc:_2e};function P2e(e){let{inputs:t,attrs:n,backend:r}=e,{x:s}=t,{numOrSizeSplits:a,axis:o}=n,i=w.parseAxisParam(o,s.shape)[0],l=N.prepareSplitSize(s,a,i),c=new Array(s.shape.length).fill(0),u=s.shape.slice();return l.map(d=>{let p=[...u];p[i]=d;let h=Ll({inputs:{x:s},attrs:{begin:c,size:p},backend:r});return c[i]+=d,h})}var $2e={kernelName:Ki,backendName:"wasm",kernelFunc:P2e},F2e=En(bo),O2e=En(Fu),M2e=!0,z2e=Zn(ko,M2e),cT;function L2e(e){cT=e.wasm.cwrap(To,null,["number","number","number","number"])}function B2e(e){let{backend:t,inputs:n,attrs:r}=e,{alpha:s}=r,{x:a}=n,o=t.dataIdMap.get(a.dataId).id,i=t.makeOutput(a.shape,a.dtype),l=t.dataIdMap.get(i.dataId).id;return cT(o,s,Xt[a.dtype],l),i}var W2e={kernelName:To,backendName:"wasm",setupFunc:L2e,kernelFunc:B2e},dT;function V2e(e){dT=e.wasm.cwrap(Zi,null,["number","array","number","array","array","array","array","array","number","number"])}function U2e(e){let{backend:t,inputs:n,attrs:r}=e,{x:s}=n,{begin:a,end:o,strides:i,beginMask:l,endMask:c,ellipsisMask:u,newAxisMask:d,shrinkAxisMask:p}=r,{finalShapeSparse:h,finalShape:f,isIdentity:m,sliceDim0:g,isSimpleSlice:y,begin:x,end:A,strides:b}=zt.sliceInfo(s.shape,a,o,i,l,c,u,d,p),v;if(m)v=hr({inputs:{x:s},backend:t,attrs:{shape:f}});else if(g||y){w.assert(s.shape.length>=1,()=>`Input must have rank at least 1, got: ${s.shape.length}`);let C=zt.computeOutShape(x,A,b),I=Ll({inputs:{x:s},backend:t,attrs:{begin:x,size:C}});v=hr({inputs:{x:I},backend:t,attrs:{shape:f}}),t.disposeData(I.dataId)}else{let C=t.makeOutput(h,"float32"),I=t.dataIdMap.get(
2021-11-08 13:36:26 +01:00
precision highp float;
attribute vec2 pos;
attribute vec2 uv;
varying vec2 vUv;
uniform float flipY;
void main(void) {
vUv = uv;
gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.);
2021-10-12 15:48:00 +02:00
}
2022-01-16 15:49:55 +01:00
`;var vT=`
2021-11-08 13:36:26 +01:00
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform float m[20];
void main(void) {
vec4 c = texture2D(texture, vUv);
gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4];
gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9];
gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14];
gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19];
2021-10-12 15:48:00 +02:00
}
2022-01-16 15:49:55 +01:00
`,wT=`
2021-11-08 13:36:26 +01:00
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform float m[20];
void main(void) {
vec4 c = texture2D(texture, vUv);
gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4];
gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9];
gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14];
gl_FragColor.a = c.a;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`,kT=`
2021-11-08 13:36:26 +01:00
precision highp float;
varying vec2 vUv;
uniform vec2 size;
uniform sampler2D texture;
vec2 pixelate(vec2 coord, vec2 size) {
return floor( coord / size ) * size;
2021-11-06 15:21:51 +01:00
}
2021-11-08 13:36:26 +01:00
void main(void) {
gl_FragColor = vec4(0.0);
vec2 coord = pixelate(vUv, size);
gl_FragColor += texture2D(texture, coord);
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`,IT=`
2021-11-08 13:36:26 +01:00
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform vec2 px;
void main(void) {
gl_FragColor = vec4(0.0);
gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265;
gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794;
gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053;
gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718;
gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933;
gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105;
gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121;
gl_FragColor += texture2D(texture, vUv )*0.159576912161;
gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121;
gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105;
gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933;
gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718;
gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053;
gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794;
gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`,ST=`
2021-11-08 13:36:26 +01:00
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform vec2 px;
uniform float m[9];
void main(void) {
vec4 c11 = texture2D(texture, vUv - px); // top left
vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y)); // top center
vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y)); // top right
vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) ); // mid left
vec4 c22 = texture2D(texture, vUv); // mid center
vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) ); // mid right
vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) ); // bottom left
vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) ); // bottom center
vec4 c33 = texture2D(texture, vUv + px ); // bottom right
gl_FragColor =
c11 * m[0] + c12 * m[1] + c22 * m[2] +
c21 * m[3] + c22 * m[4] + c23 * m[5] +
c31 * m[6] + c32 * m[7] + c33 * m[8];
gl_FragColor.a = c22.a;
2021-11-06 15:21:51 +01:00
}
2022-01-16 15:49:55 +01:00
`;var ob=(e,t,n)=>{let r=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(r,(s,a)=>(n[a]=0,s))},CT=class{constructor(t,n,r){fe(this,"uniform",{});fe(this,"attribute",{});fe(this,"gl");fe(this,"id");fe(this,"compile",(t,n)=>{let r=this.gl.createShader(n);return r?(this.gl.shaderSource(r,t),this.gl.compileShader(r),this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)?r:(J(`filter: gl compile failed: ${this.gl.getShaderInfoLog(r)}`),null)):(J("filter: could not create shader"),null)});this.gl=t;let s=this.compile(n,this.gl.VERTEX_SHADER),a=this.compile(r,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!s||!a)){if(!this.id){J("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,s),this.gl.attachShader(this.id,a),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){J(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)}`);return}this.gl.useProgram(this.id),ob(n,"attribute",this.attribute);for(let o in this.attribute)this.attribute[o]=this.gl.getAttribLocation(this.id,o);ob(n,"uniform",this.uniform),ob(r,"uniform",this.uniform);for(let o in this.uniform)this.uniform[o]=this.gl.getUniformLocation(this.id,o)}}};function TT(){let e=0,t=null,n=!1,r=-1,s=[null,null],a=[],o=null,i=null,l=Yn(100,100),c={},u={INTERMEDIATE:1},d=l.getContext("webgl");if(this.gl=d,!d){J("filter: cannot get webgl context");return}function p(x,A){if(!(x===l.width&&A===l.height)){if(l.width=x,l.height=A,!o){let b=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,-1,1,0,0,1,-1,1,1,1,1,1,0]);o=d.createBuffer(),d.bindBuffer(d.ARRAY_BUFFER,o),d.bufferData(d.ARRAY_BUFFER,b,d.STATIC_DRAW),d.pixelStorei(d.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}d.viewport(0,0,l.width,l.height),s=[null,null]}}function h(x,A){let b=d.createFramebuffer();d.bindFramebuffer(d.FRAMEBUFFER,b);let v=d.createRenderbuffer();d.bindRenderbuffer(d.RENDERBUFFER,v);let C=d.createTexture();return d.bindTexture(d.TEXTURE_2D,C),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,x,A,0,d.RGBA,d.UNSIGNED_BYTE,null),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,C,0),d.bindTexture(d.TEXTURE_2D,null),d.bindFramebuffer(d.FRAMEBUFFER,null),{fbo:b,texture:C}}function f(x){return s[x]=s[x]||h(l.width,l.height),s[x]}function m(x=0){if(!i)return;let A=null,b=null,v=!1;e===0?A=t:A=f(r).texture||null,e++,n&&!(x&u.INTERMEDIATE)?(b=null,v=e%2===0):(r=(r+1)%2,b=f(r).fbo||null),d.bindTexture(d.TEXTURE_2D,A),d.bindFramebuffer(d.FRAMEBUFFER,b),d.uniform1f(i.uniform.flipY,v?-1:1),d.drawArrays(d.TRIANGLES,0,6)}function g(x){if(c[x])return i=c[x],d.useProgram((i?i.id:null)||null),i;if(i=new CT(d,bT,x),!i)return J("filter: could not get webgl program"),null;let A=Float32Array.BYTES_PER_ELEMENT,b=4*A;return d.enableVertexAttribArray(i.attribute.pos),d.vertexAttribPointer(i.attribute.pos,2,d.FLOAT,!1,b,0*A),d.enableVertexAttribArray(i.attribute.uv),d.vertexAttribPointer(i.attribute.uv,2,d.FLOAT,!1,b,2*A),c[x]=i,i}let y={colorMatrix:x=>{let A=new Float32Array(x);A[4]/=255,A[9]/=255,A[14]/=255,A[19]/=255;let b=A[18]===1&&A[3]===0&&A[8]===0&&A[13]===0&&A[15]===0&&A[16]===0&&A[17]===0&&A[19]===0?wT:vT,v=g(b);!v||(d.uniform1fv(v.uniform.m,A),m())},brightness:x=>{let A=(x||0)+1;y.colorMatrix([A,0,0,0,0,0,A,0,0,0,0,0,A,0,0,0,0,0,1,0])},saturation:x=>{let A=(x||0)*2/3+1,b=(A-1)*-.5;y.colorMatrix([A,b,b,0,0,b,A,b,0,0,b,b,A,0,0,0,0,0,1,0])},desaturate:()=>{y.saturation(-1)},contrast:x=>{let A=(x||0)+1,b=-128*(A-1);y.colorMatrix([A,0,0,0,b,0,A,0,0,b,0,0,A,0,b,0,0,0,1,0])},negative:()=>{y.contrast(-2)},hue:x=>{x=(x||0)/180*Math.PI;let A=Math.cos(x),b=Math.sin(x),v=.213,C=.715,I=.072;y.colorMatrix([v+A*(1-v)+b*-v,C+A*-C+b*-C,I+A*-I+b*(1-I),0,0,v+A*-v+b*.143,C+A*(1-C)+b*.14,I+A*-I+b*-.283,0,0,v+A*-v+b*-(1-v),C+A*-C+b*C,I+A*(1-I)+b*I,0,0,0,0,0,1,0])},desaturateLuminance:()=>{y.colorMatrix([.2764723,.929708,.0938
2021-11-08 13:36:26 +01:00
M ${u.box[0]+u.box[2]/2} ${u.box[1]}
C
${d} ${u.box[1]},
${d} ${u.box[1]+u.box[3]},
${u.box[0]+u.box[2]/2} ${u.box[1]+u.box[3]}
`),f=new Path2D(`
M ${u.box[0]} ${u.box[1]+u.box[3]/2}
C
${u.box[0]} ${p},
${u.box[0]+u.box[2]} ${p},
${u.box[0]+u.box[2]} ${u.box[1]+u.box[3]/2}
2022-01-16 15:49:55 +01:00
`);s.stroke(f),s.stroke(h)}if(r.drawGaze&&((i=(o=u.rotation)==null?void 0:o.gaze)==null?void 0:i.strength)&&((c=(l=u.rotation)==null?void 0:l.gaze)==null?void 0:c.bearing)&&u.annotations.leftEyeIris&&u.annotations.rightEyeIris&&u.annotations.leftEyeIris[0]&&u.annotations.rightEyeIris[0]){s.strokeStyle="pink",s.fillStyle="pink";let d=[u.annotations.leftEyeIris[0][0]+Math.sin(u.rotation.gaze.bearing)*u.rotation.gaze.strength*u.box[3],u.annotations.leftEyeIris[0][1]+Math.cos(u.rotation.gaze.bearing)*u.rotation.gaze.strength*u.box[2]];XN(s,[u.annotations.leftEyeIris[0][0],u.annotations.leftEyeIris[0][1]],[d[0],d[1]],4);let p=[u.annotations.rightEyeIris[0][0]+Math.sin(u.rotation.gaze.bearing)*u.rotation.gaze.strength*u.box[3],u.annotations.rightEyeIris[0][1]+Math.cos(u.rotation.gaze.bearing)*u.rotation.gaze.strength*u.box[2]];XN(s,[u.annotations.rightEyeIris[0][0],u.annotations.rightEyeIris[0][1]],[p[0],p[1]],4)}}}}}async function R5(e,t,n){var a;let r=yn(wa,n);if(!t||!e)return;let s=Xl(e);if(!!s){s.lineJoin="round";for(let o=0;o<t.length;o++){if(s.strokeStyle=r.color,s.fillStyle=r.color,s.lineWidth=r.lineWidth,s.font=r.font,r.drawBoxes&&t[o].box&&((a=t[o].box)==null?void 0:a.length)===4&&(eh(s,t[o].box[0],t[o].box[1],t[o].box[2],t[o].box[3],r),r.drawLabels&&(r.shadowColor&&r.shadowColor!==""&&(s.fillStyle=r.shadowColor,s.fillText(`body ${100*t[o].score}%`,t[o].box[0]+3,1+t[o].box[1]+r.lineHeight,t[o].box[2])),s.fillStyle=r.labelColor,s.fillText(`body ${100*t[o].score}%`,t[o].box[0]+2,0+t[o].box[1]+r.lineHeight,t[o].box[2]))),r.drawPoints&&t[o].keypoints)for(let i=0;i<t[o].keypoints.length;i++)!t[o].keypoints[i].score||t[o].keypoints[i].score===0||(s.fillStyle=r.useDepth&&t[o].keypoints[i].position[2]?`rgba(${127.5+2*(t[o].keypoints[i].position[2]||0)}, ${127.5-2*(t[o].keypoints[i].position[2]||0)}, 255, 0.5)`:r.color,T5(s,t[o].keypoints[i].position[0],t[o].keypoints[i].position[1],0,r));if(r.drawLabels&&t[o].keypoints){s.font=r.font;for(let i of t[o].keypoints)!i.score||i.score===0||(s.fillStyle=r.useDepth&&i.position[2]?`rgba(${127.5+2*i.position[2]}, ${127.5-2*i.position[2]}, 255, 0.5)`:r.color,s.fillText(`${i.part} ${Math.trunc(100*i.score)}%`,i.position[0]+4,i.position[1]+4))}if(r.drawPolygons&&t[o].keypoints&&t[o].annotations)for(let i of Object.values(t[o].annotations))for(let l of i)B1e(s,l,r)}}}async function _5(e,t,n){let r=yn(wa,n);if(!t||!e)return;let s=Xl(e);if(!!s){s.lineJoin="round",s.font=r.font;for(let a of t){if(r.drawBoxes&&(s.strokeStyle=r.color,s.fillStyle=r.color,eh(s,a.box[0],a.box[1],a.box[2],a.box[3],r),r.drawLabels&&(r.shadowColor&&r.shadowColor!==""&&(s.fillStyle=r.shadowColor,s.fillText(`hand:${Math.trunc(100*a.score)}%`,a.box[0]+3,1+a.box[1]+r.lineHeight,a.box[2])),s.fillStyle=r.labelColor,s.fillText(`hand:${Math.trunc(100*a.score)}%`,a.box[0]+2,0+a.box[1]+r.lineHeight,a.box[2])),s.stroke()),r.drawPoints&&a.keypoints&&a.keypoints.length>0)for(let o of a.keypoints)s.fillStyle=r.useDepth?`rgba(${127.5+2*(o[2]||0)}, ${127.5-2*(o[2]||0)}, 255, 0.5)`:r.color,T5(s,o[0],o[1],0,r);if(r.drawLabels&&a.annotations){let o=(i,l)=>{if(!i||i.length===0||!i[0])return;let c=i[i.length-1][2]||0;s.fillStyle=r.useDepth?`rgba(${127.5+2*c}, ${127.5-2*c}, 255, 0.5)`:r.color,s.fillText(l,i[i.length-1][0]+4,i[i.length-1][1]+4)};s.font=r.font,o(a.annotations.index,"index"),o(a.annotations.middle,"middle"),o(a.annotations.ring,"ring"),o(a.annotations.pinky,"pinky"),o(a.annotations.thumb,"thumb"),o(a.annotations.palm,"palm")}if(r.drawPolygons&&a.annotations){let o=i=>{if(!(!i||i.length===0||!i[0]))for(let l=0;l<i.length;l++){s.beginPath();let c=i[l][2]||0;s.strokeStyle=r.useDepth?`rgba(${127.5+l*c}, ${127.5-l*c}, 255, 0.5)`:r.color,s.moveTo(i[l>0?l-1:0][0],i[l>0?l-1:0][1]),s.lineTo(i[l][0],i[l][1]),s.stroke()}};s.lineWidth=r.lineWidth,o(a.annotations.index),o(a.annotations.middle),o(a.annotations.ring),o(a.annotations.pinky),o(a.annotations.thumb)}}}}async function D5(e,t,n){let r=yn(wa,n);if(!t||!e)return;let s=Xl(e);if(!!s){s.lineJoin="round",s.font=r.font;for(let a of t)if(r.drawBoxes){if(s.strokeStyle=r.color,
/9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA
AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu
bmV0IDQuMi4xMwAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob
IxwWFiAsICMmJykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgo
KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8AAEQgBAAEAAwEhAAIRAQMRAf/E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAE
EQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZH
SElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1
tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEB
AQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXET
IjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFla
Y2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJip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yv55Le9afznqcOvO4tBreMTHu30unnva0bWt8on+70nDuE4OHYYx4Kbesz3tPrMuhGO
IjpDOKrK9YVpsyiGUQnYGOyUgI2SlAIEmwMWMs9kTAMJYzDOYRMArmGErZhhMArlHmzmGMwDE3Ts
bAbs4swj5pgFkSziVcM4BZEsolXDKAZwyhjCYBkACQhIAAAAAAAJAAAAAAAAAAAAAAAAAAAShIAA
AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA
BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2
SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T
lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/
2022-01-16 15:49:55 +01:00
2Q==`;async function Y1e(e){let t=(s,a="application/octet-stream")=>fetch(`data:${a};base64,${s}`).then(o=>o.blob()),n,r;switch(e.config.warmup){case"face":n=await t(X0);break;case"body":case"full":n=await t(K0);break;default:n=null}if(n){let s=await createImageBitmap(n);r=await e.detect(s,e.config),s.close()}return r}async function J1e(e){return new Promise(t=>{let n;switch(e.config.warmup){case"face":n="data:image/jpeg;base64,"+X0;break;case"full":case"body":n="data:image/jpeg;base64,"+K0;break;default:n=null}let r;if(typeof Image!="undefined")r=new Image;else if(he.Image)r=new he.Image;else return;r.onload=async()=>{let s=Yn(r.naturalWidth,r.naturalHeight);if(!s)J("Warmup: Canvas not found"),t(void 0);else{let a=s.getContext("2d");a&&a.drawImage(r,0,0);let o=await e.image(s),i=await e.detect(o.tensor,e.config);t(i)}},n?r.src=n:t(void 0)})}async function Q1e(e){let t=s=>Buffer.from(s,"base64"),n;e.config.warmup==="face"?n=t(X0):n=t(K0);let r;if("node"in We){let s=(void 0).decodeJpeg(n),a=s.expandDims(0);e.tf.dispose(s),r=await e.detect(a,e.config),e.tf.dispose(a)}else e.config.debug&&J("Warmup tfjs-node not loaded");return r}async function uE(e,t){let n=ie();if(e.state="warmup",t&&(e.config=yn(e.config,t)),!e.config.warmup||e.config.warmup.length===0||e.config.warmup==="none")return{face:[],body:[],hand:[],gesture:[],object:[],performance:e.performance,timestamp:ie(),persons:[],error:null};let r;return new Promise(async s=>{typeof createImageBitmap=="function"?r=await Y1e(e):typeof Image!="undefined"||he.Canvas!==void 0?r=await J1e(e):r=await Q1e(e);let a=ie();e.config.debug&&J("Warmup",e.config.warmup,Math.round(a-n),"ms"),e.emit("warmup"),s(r)})}var qc,th,nh,Z0,cE=class{constructor(t){fe(this,"version");fe(this,"config");fe(this,"result");fe(this,"state");fe(this,"process");fe(this,"tf");fe(this,"env");fe(this,"draw");fe(this,"models");fe(this,"events");fe(this,"faceTriangulation");fe(this,"faceUVMap");fe(this,"performance");ud(this,qc,void 0);ud(this,th,void 0);ud(this,nh,void 0);fe(this,"gl");fe(this,"analyze",(...t)=>{if(!ld(this,th))return;let n=this.tf.engine().state.numTensors,r=ld(this,qc);cd(this,qc,n);let s=n-r;s!==0&&J(...t,s)});ud(this,Z0,t=>{if(!ld(this,nh))return null;if(!t)return"input is not defined";if(this.env.node&&!(t instanceof nt))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});fe(this,"similarity",oE);fe(this,"distance",q0);fe(this,"match",iE);fe(this,"emit",t=>{var n;this.events&&this.events.dispatchEvent&&((n=this.events)==null||n.dispatchEvent(new Event(t)))});this.env=he,_a.wasmPath=Gp["tfjs-core"].includes("-")?"https://vladmandic.github.io/tfjs/dist/":`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${oy}/dist/`,_a.modelBasePath=he.browser?"../models/":"file://models/",_a.backend=he.browser?"humangl":"tensorflow",this.version=lb,Object.defineProperty(this,"version",{value:lb}),this.config=JSON.parse(JSON.stringify(_a)),Object.seal(this.config),t&&(this.config=yn(this.config,t)),this.tf=We,this.state="idle",cd(this,qc,0),cd(this,th,!1),cd(this,nh,!1),this.performance={},this.events=typeof EventTarget!="undefined"?new EventTarget:void 0,this.models=new I5,this.draw={options:wa,canvas:(n,r)=>ZN(n,r),face:(n,r,s)=>E5(n,r,s),body:(n,r,s)=>R5(n,r,s),hand:(n,r,s)=>_5(n,r,s),gesture:(n,r,s)=>N5(n,r,s),object:(n,r,s)=>D5(n,r,s),person:(n,r,s)=>KN(n,r,s),all:(n,r,s)=>YN(n,r,s)},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[],error:null},this.process={tensor:null,canvas:null},this.faceTriangulation=B8,this.faceUVMap=W8,this.gl=_t,this.emit("create")}reset(){let t=this.config.backend;this.config=JSON.parse(JSON.stringify(_a)),this.config.backend=t}validate(t){return k2(_a,t||this.config)}now(){return ie()}image(t,n=!0){return $c(t,this.config,n)}async segmentation(t,n){return BN(t,n,this.config)}enhance(t){return jb(t)}compare(t,n){return ET(this.config,t,n)}async init(){await j0(this,!0),await this.tf.ready()}async load(t){this.state="load";let n=ie(),r=Object.values(this.models).filt
2021-04-28 14:58:21 +02:00
/**
* @license
* Copyright 2017 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 2018 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* @license
* Copyright 2018 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 2018 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
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* @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.
*
* =============================================================================
*/
/**
* @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.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google Inc. 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
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
2021-10-30 18:21:54 +02:00
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use backend 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.
* =============================================================================
*/
2021-04-28 14:58:21 +02:00
/**
* @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 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 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 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
*
* https://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.
2021-10-30 18:21:54 +02:00
* =============================================================================
*/
/**
* @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.
* =============================================================================
*/
2021-10-27 15:45:38 +02:00
/**
* Human main module
* @default Human Library
* @summary <https://github.com/vladmandic/human>
* @author <https://github.com/vladmandic>
* @copyright <https://github.com/vladmandic>
* @license MIT
*/
2021-08-31 19:00:06 +02:00
/**
* @license
* Copyright 2018 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.
* =============================================================================
*/
2021-04-28 14:58:21 +02:00
/** @license See the LICENSE file. */