({
x,
filter,
convInfo,
backend,
bias = null,
preluActivationWeights = null,
leakyreluAlpha = 0,
activation = null
}: Conv2DConfig)
| 273 | } |
| 274 | |
| 275 | export 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 | }); |
no test coverage detected
searching dependent graphs…