MCPcopy Create free account
hub / github.com/tensorflow/tfjs / getBinaryOpString

Function getBinaryOpString

tfjs-backend-webgpu/src/binary_op_util.ts:165–282  ·  view source on GitHub ↗
(
    type: BinaryOpType, useVec4?: boolean)

Source from the content-addressed store, hash-verified

163const SUB = 'let resultTemp = a - b;';
164
165export function getBinaryOpString(
166 type: BinaryOpType, useVec4?: boolean): string {
167 let doOpSnippet: string;
168
169 // Ops with NaN check
170 do {
171 switch (type) {
172 case BinaryOpType.ATAN2:
173 doOpSnippet = ATAN2;
174 break;
175 case BinaryOpType.MAX:
176 doOpSnippet = MAX;
177 break;
178 case BinaryOpType.MIN:
179 doOpSnippet = MIN;
180 break;
181 case BinaryOpType.MOD:
182 doOpSnippet = useVec4 ? MOD_VEC4 : MOD;
183 break;
184 case BinaryOpType.NOT_EQUAL:
185 doOpSnippet = useVec4 ? NOT_EQUAL_VEC4 : NOT_EQUAL;
186 break;
187 case BinaryOpType.POW:
188 doOpSnippet = useVec4 ? POW_VEC4 : POW;
189 break;
190 default:
191 continue;
192 }
193
194 let isNaN: string;
195 let dTypeN: string;
196 let boolN: string;
197 if (useVec4) {
198 isNaN = 'isnanVec4';
199 dTypeN = 'vec4<f32>';
200 boolN = 'vec4<bool>';
201 } else {
202 isNaN = 'isnan';
203 dTypeN = 'f32';
204 boolN = 'bool';
205 }
206
207 return `
208 let aIsNaN = ${isNaN}(a);
209 let aPostLegalization = select(a, ${dTypeN}(42), aIsNaN);
210 let bIsNaN = ${isNaN}(b);
211 let bPostLegalization = select(b, ${dTypeN}(42), bIsNaN);
212 let isNaN = false;
213 let valueForNaN = uniforms.NAN;
214 {
215 let a = aPostLegalization;
216 let b = bPostLegalization;
217 ${doOpSnippet}
218 return select(
219 resultTemp, ${dTypeN}(valueForNaN),
220 ${boolN}(isNaN) | aIsNaN | bIsNaN);
221 }
222 `;

Callers 3

getUserCodeMethod · 0.90
activationFnSnippetFunction · 0.90
getUserCodeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…