[js/webgpu] fix Conv2DMatMul shader's out-of-bound read (#23085)

### Description
<!-- Describe your changes. -->

Fix a bug caused by potential out-of-bound reads of `W` in the
Conv2DMatMul shader.

### Motivation and Context

Fixes #22983
This commit is contained in:
Yulong Wang 2024-12-12 11:33:53 -08:00 committed by GitHub
parent 890a719c91
commit 01539ee7ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,7 +143,21 @@ const conv2dCommonSnippet = (
}
return ${typeSnippet(innerElementSizeX, dataType)}(0.0);`;
const sampleW = `${getWSnippet(innerElementSizeW)}`;
const sampleW = isChannelsLast
? fitInner && fitBOuter
? getWSnippet(innerElementSizeW)
: `
let col = colIn * ${innerElementSizeW};
if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) {
${getWSnippet(innerElementSizeW)}
}
return ${typeSnippet(innerElementSizeW, dataType)}(0.0);`
: `
let col = colIn * ${innerElementSizeW};
if (row < uniforms.dim_inner && col < uniforms.dim_a_outer) {
${getWSnippet(innerElementSizeW)}
}
return ${typeSnippet(innerElementSizeW, dataType)}(0.0);`;
const resType = typeSnippet(innerElementSize, dataType);
const aType = isChannelsLast ? typeSnippet(innerElementSizeX, dataType) : typeSnippet(innerElementSizeW, dataType);