message: Add test for proper selection of MatrixMultiply layer vs FullyConnected layer in INT8 mode
diff: @@ -1771,6 +1771,18 @@ void TestMatMulHelper(
  }
  }
  +template <typename LayerType>
  +void CheckAddedLayers(OpConverterTest* test, bool expect_found) {
  + bool layer_found = false;
  + for (int i = 0; i < test->converter_->network()->getNbLayers(); i++) {
  + nvinfer1::ILayer* layer = test->converter_->network()->getLayer(i);
  + if (dynamic_cast<LayerType*>(layer)) {
  + layer_found = true;
  + }
  + }
  + EXPECT_EQ(expect_found, layer_found);
  +}
  +
  TEST_F(OpConverterTest, ConvertMatMul) {
  {
  // Input list is empty, should fail.
  @@ -1826,6 +1838,31 @@ TEST_F(OpConverterTest, ConvertMatMul) {
  node_def, error::INVALID_ARGUMENT,
  "Cannot currently transpose constant input if it is not 2 dimensional");
  }
  + {
  + // Make sure that INT8 mode uses IFullyConnectedLayer when possible.
  + precision_mode_to_test_ = TrtPrecisionMode::INT8;
  + Reset();
  + NodeDef node_def = get_matmul_nodedef(DT_FLOAT, false, false);
  + AddTestTensor("input", {2, 1, 1});
  + AddTestWeights<float>("weights", {2, 2}, {0, 1, 2, 3});
  + RunValidationAndConversion(node_def);
  + CheckAddedLayers<nvinfer1::IMatrixMultiplyLayer>(this, false);
  + CheckAddedLayers<nvinfer1::IFullyConnectedLayer>(this, true);
  + precision_mode_to_test_ = TrtPrecisionMode::FP32;
  + }
  + {
  + // Make sure that INT8 mode doesn't try to use IFullyConnectedLayer when not
  + // compatible. In this case we can't use FC because weights is a tensor.
  + precision_mode_to_test_ = TrtPrecisionMode::INT8;
  + Reset();
  + NodeDef node_def = get_matmul_nodedef(DT_FLOAT, false, false);
  + AddTestTensor("input", {2, 1, 1});
  + AddTestTensor("weights", {2, 2});
  + RunValidationAndConversion(node_def);
  + CheckAddedLayers<nvinfer1::IMatrixMultiplyLayer>(this, true);
  + CheckAddedLayers<nvinfer1::IFullyConnectedLayer>(this, false);
  + precision_mode_to_test_ = TrtPrecisionMode::FP32;
  + }
  TestMatMulHelper(this, get_matmul_nodedef, "MatMul");
  }
  @@ -1988,21 +2025,6 @@ NodeDef GetBinaryOpNodeDef(const string& input_name_l,
  return op.operation.node()->def();
  }
  -void CheckAddedLayers(OpConverterTest* test, bool expect_scale_layer) {
  - bool element_wise_layer_found = false;
  - bool scale_layer_found = false;
  - for (int i = 0; i < test->converter_->network()->getNbLayers(); i++) {
  - nvinfer1::ILayer* layer = test->converter_->network()->getLayer(i);
  - if (dynamic_cast<nvinfer1::IScaleLayer*>(layer)) {
  - scale_layer_found = true;
  - } else if (dynamic_cast<nvinfer1::IElementWiseLayer*>(layer)) {
  - element_wise_layer_found = true;
  - }
  - }
  - EXPECT_EQ(expect_scale_layer, scale_layer_found);
  - EXPECT_NE(expect_scale_layer, element_wise_layer_found);
  -}
  -
  template <typename OpType, DataType dtype>
  void TestBinaryOp(OpConverterTest* test, bool operand_1_is_tensor,
  bool operand_2_is_tensor) {
  