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

Function conv2DImpl

tfjs-backend-webgpu/src/kernels/Conv2D_impl.ts:275–394  ·  view source on GitHub ↗
({
  x,
  filter,
  convInfo,
  backend,
  bias = null,
  preluActivationWeights = null,
  leakyreluAlpha = 0,
  activation = null
}: Conv2DConfig)

Source from the content-addressed store, hash-verified

273}
274
275export function conv2DImpl({
276 x,
277 filter,
278 convInfo,
279 backend,
280 bias = null,
281 preluActivationWeights = null,
282 leakyreluAlpha = 0,
283 activation = null
284}: Conv2DConfig) {
285 const hasBias = bias != null;
286 const hasPreluActivationWeights = preluActivationWeights != null;
287 const isChannelsLast = convInfo.dataFormat === 'channelsLast';
288 const sameSize = isChannelsLast &&
289 convInfo.filterHeight === convInfo.inHeight &&
290 convInfo.filterWidth === convInfo.inWidth &&
291 convInfo.padInfo.type === 'VALID';
292 const useNaiveConv2d = env().getBool('WEBGPU_USE_NAIVE_CONV2D_DEBUG');
293
294 if (!useNaiveConv2d &&
295 (sameSize ||
296 (convInfo.filterHeight === 1 && convInfo.filterWidth === 1 &&
297 convInfo.dilationHeight === 1 && convInfo.dilationWidth === 1 &&
298 convInfo.strideHeight === 1 && convInfo.strideWidth === 1 &&
299 (convInfo.padInfo.type === 'SAME' ||
300 convInfo.padInfo.type === 'VALID')))) {
301 return conv2dByMatMul({
302 x,
303 filter,
304 convInfo,
305 backend,
306 bias,
307 activation,
308 preluActivationWeights,
309 leakyreluAlpha
310 });
311 }
312
313 const thresholdFlagValue =
314 env().getNumber('WEBGPU_THRESHOLD_TO_INCREASE_WORKGROUPS_FOR_MATMUL');
315 const thresholdToIncreaseWorkgroups = thresholdFlagValue > -1 ?
316 thresholdFlagValue :
317 backend.thresholdToIncreaseWorkgroups;
318 const workgroupsBy32x32 = convInfo.batchSize *
319 Math.ceil((convInfo.outHeight * convInfo.outWidth) / 32) *
320 Math.ceil(convInfo.outChannels / 32);
321 if (env().getBool('WEBGPU_CONV_SEPARATE_IM2COL_SHADER') ||
322 workgroupsBy32x32 <= thresholdToIncreaseWorkgroups) {
323 return conv2dWithIm2Col({
324 x,
325 filter,
326 convInfo,
327 backend,
328 bias,
329 preluActivationWeights,
330 leakyreluAlpha,
331 activation
332 });

Callers 2

fusedConv2dFunction · 0.90
conv2dFunction · 0.90

Calls 11

envFunction · 0.90
reshapeFunction · 0.90
conv2dWithIm2ColFunction · 0.85
getBoolMethod · 0.80
getNumberMethod · 0.80
ceilMethod · 0.80
isIntelMethod · 0.80
runWebGPUProgramMethod · 0.80
conv2dByMatMulFunction · 0.70
disposeDataMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…