Skip to content

Commit d819dee

Browse files
committed
remove the condition M < 128
1 parent 5f7f673 commit d819dee

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

onnxruntime/core/providers/webgpu/math/matmul.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,19 @@ Status ComputeMatMul(ComputeContext* context,
190190
int64_t batchB = b_shape.SizeToDimension(b_shape.NumDimensions() - 2);
191191

192192
TensorShape output_shape = helper.OutputShape();
193-
const int64_t dim_output_outer = output_shape[output_shape.NumDimensions() - 2];
193+
194194
// When B is a matrix (batch is 1), we fold batchA into the M dimension for better
195195
// performance (e.g., [2,3,5] → [1,6,5]).
196-
// This is especially beneficial when M is small:
197-
// workgroups containing invalid (out-of-bounds) threads make up a large proportion of all
198-
// dispatched workgroups when M is small, so folding reduces that waste significantly.
199-
// When M is large, the proportion of such wasteful workgroups is already small, so
200-
// folding yields negligible gains and is skipped.
201-
if (dim_output_outer < 128 && batchA != 1 && batchB == 1) {
196+
if (batchA != 1 && batchB == 1) {
202197
// dimensions of A: [1,`batchA`, M, K]
203198
int64_t batchAndM = a_shape.SizeToDimension(a_shape.NumDimensions() - 1);
204-
TensorShapeVector dims_a = {1, batchAndM, helper.K()};
199+
TensorShapeVector dims_a = {batchAndM, helper.K()};
205200
// dimensions of B: [1,K,N]
206-
TensorShapeVector dims_b = {1, helper.K(), helper.N()};
201+
TensorShapeVector dims_b = {helper.K(), helper.N()};
207202

208203
a_shape = TensorShape(dims_a);
209204
b_shape = TensorShape(dims_b);
210-
output_shape = {1, batchAndM, helper.N()};
205+
output_shape = {batchAndM, helper.N()};
211206
}
212207

213208
// helpful dimension variables

onnxruntime/core/providers/webgpu/vendor/intel/math/matmul.cc

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,25 @@ Status ApplyMatMulIntel(ComputeContext& context,
5555

5656
TensorShape output_shape = helper.OutputShape();
5757

58-
const auto& arch = context.AdapterInfo().architecture;
59-
const bool is_xe_lpg = arch == std::string_view("xe-lpg");
60-
const bool is_xe_3lpg = arch == std::string_view("xe-3lpg");
6158
// When B is a matrix (batch is 1), we fold batchA into the M dimension for better
6259
// performance (e.g., [2,3,5] → [1,6,5]).
63-
// This is especially beneficial when M is small:
64-
// workgroups containing invalid (out-of-bounds) threads make up a large proportion of all
65-
// dispatched workgroups when M is small, so folding reduces that waste significantly.
66-
// When M is large, the proportion of such wasteful workgroups is already small, so
67-
// folding yields negligible gains and is skipped.
68-
// Don't fold to workaround for Xe-LPG/Xe-3LPG when M is small and the proportion is relatively small .
60+
// Don't fold to workaround for Xe-LPG/Xe-3LPG when M is small and the proportion of workgroups
61+
// containing invalid (out-of-bounds) threads is relatively small .
6962
const int64_t M = output_shape[output_shape.NumDimensions() - 2];
7063
const int64_t m_mod_32 = M % 32;
71-
if (batchA != 1 && batchB == 1 && M < 128 && (!(is_xe_lpg || is_xe_3lpg) || (m_mod_32 > 0 && m_mod_32 <= 24))) {
64+
if (batchA != 1 && batchB == 1 &&
65+
(!(context.AdapterInfo().architecture == std::string_view("xe-lpg") ||
66+
context.AdapterInfo().architecture == std::string_view("xe-3lpg")) ||
67+
(m_mod_32 > 0 && m_mod_32 <= 24))) {
7268
// dimensions of A: [1,`batchA`, M, K]
7369
int64_t batchAndM = a_shape.SizeToDimension(a_shape.NumDimensions() - 1);
74-
TensorShapeVector dims_a = {1, batchAndM, helper.K()};
70+
TensorShapeVector dims_a = {batchAndM, helper.K()};
7571
// dimensions of B: [1,K,N]
76-
TensorShapeVector dims_b = {1, helper.K(), helper.N()};
72+
TensorShapeVector dims_b = {helper.K(), helper.N()};
7773

7874
a_shape = TensorShape(dims_a);
7975
b_shape = TensorShape(dims_b);
80-
output_shape = {1, batchAndM, helper.N()};
76+
output_shape = {batchAndM, helper.N()};
8177
}
8278

8379
// helpful dimension variables

0 commit comments

Comments
 (0)