@@ -504,28 +504,33 @@ TEST(MatmulIntegerOpTest, SharedPrepackedWeights) {
504504}
505505#endif
506506
507- // Regression test: 1D inputs with mismatched K dimensions must fail
507+ // Regression test: inputs with mismatched K dimensions must fail
508508// instead of causing an out-of-bounds read in the MLAS backend.
509- TEST (MatmulIntegerOpTest, MatMulInteger_1D_DimensionMismatch ) {
509+ TEST (MatmulIntegerOpTest, MatMulInteger_DimensionMismatch ) {
510510 OpTester test (" MatMulInteger" , 10 );
511- // A is 1D with K=5, B is 1D with K=1 — dimensions don't match.
512- test.AddInput <uint8_t >(" T1" , {5 }, {11 , 7 , 3 , 10 , 6 });
513- test.AddInput <uint8_t >(" T2" , {1 }, {1 });
511+ // A is [1,5] ( K=5) , B is [1,1] ( K=1) — K dimensions don't match.
512+ test.AddInput <uint8_t >(" T1" , {1 , 5 }, {11 , 7 , 3 , 10 , 6 });
513+ test.AddInput <uint8_t >(" T2" , {1 , 1 }, {1 });
514514 test.AddInput <uint8_t >(" a_zero_point" , {}, {0 });
515515 test.AddInput <uint8_t >(" b_zero_point" , {}, {0 });
516- test.AddOutput <int32_t >(" T3" , {}, {0 });
517- test.Run (OpTester::ExpectResult::kExpectFailure , " MatMul dimension mismatch" );
516+ test.AddOutput <int32_t >(" T3" , {1 , 1 }, {0 });
517+
518+ // Restrict to CPU — other EPs may not support this configuration.
519+ std::vector<std::unique_ptr<IExecutionProvider>> cpu_only;
520+ cpu_only.push_back (DefaultCpuExecutionProvider ());
521+ test.Run (OpTester::ExpectResult::kExpectFailure , " MatMul dimension mismatch" ,
522+ {}, nullptr , &cpu_only);
518523}
519524
520- // Valid 1D × 1D dot product: both vectors have the same K .
521- TEST (MatmulIntegerOpTest, MatMulInteger_1D_Valid ) {
525+ // Valid 2D dot product: K dimensions match .
526+ TEST (MatmulIntegerOpTest, MatMulInteger_SmallValid ) {
522527 OpTester test (" MatMulInteger" , 10 );
523- // A=[2,3 ], B=[4,5 ] => dot = 2*4 + 3*5 = 23
524- test.AddInput <uint8_t >(" T1" , {2 }, {2 , 3 });
525- test.AddInput <uint8_t >(" T2" , {2 }, {4 , 5 });
528+ // A=[1,2 ], B=[2,1 ] => [1,1] with value 2*4 + 3*5 = 23
529+ test.AddInput <uint8_t >(" T1" , {1 , 2 }, {2 , 3 });
530+ test.AddInput <uint8_t >(" T2" , {2 , 1 }, {4 , 5 });
526531 test.AddInput <uint8_t >(" a_zero_point" , {}, {0 });
527532 test.AddInput <uint8_t >(" b_zero_point" , {}, {0 });
528- test.AddOutput <int32_t >(" T3" , {}, {23 });
533+ test.AddOutput <int32_t >(" T3" , {1 , 1 }, {23 });
529534 test.Run ();
530535}
531536
0 commit comments