| 3510 | })); |
| 3511 | |
| 3512 | TEST_P(ConvInputPaddingTest, DoTest) { |
| 3513 | ConvPaddingTestcase testcase = GetParam(); |
| 3514 | |
| 3515 | // It would be better to put the testcase's ToString into the test name, but |
| 3516 | // gUnit has constraints on what can go into test names, and any reasonable |
| 3517 | // implementation of ToString() seems to violate them. |
| 3518 | SCOPED_TRACE(testcase.ToString()); |
| 3519 | |
| 3520 | auto builder = HloComputation::Builder(TestName()); |
| 3521 | auto* input = builder.AddInstruction(HloInstruction::CreateParameter( |
| 3522 | 0, ShapeUtil::MakeShape(F32, {1024, 128, 100, 100}), // bf01 |
| 3523 | "input")); |
| 3524 | auto* pad_value = builder.AddInstruction(HloInstruction::CreateConstant( |
| 3525 | LiteralUtil::CreateR0(testcase.pad_value))); |
| 3526 | |
| 3527 | PaddingConfig padding_config = |
| 3528 | ParsePaddingConfig(testcase.padding).ValueOrDie(); |
| 3529 | auto* lhs_pad = builder.AddInstruction(HloInstruction::CreatePad( |
| 3530 | ShapeInference::InferPadShape(input->shape(), pad_value->shape(), |
| 3531 | padding_config) |
| 3532 | .ValueOrDie(), |
| 3533 | input, pad_value, padding_config)); |
| 3534 | |
| 3535 | auto* filter = builder.AddInstruction(HloInstruction::CreateParameter( |
| 3536 | 1, |
| 3537 | ShapeUtil::MakeShape( |
| 3538 | F32, {lhs_pad->shape().dimensions(1), 256, 3, 3}), // io01 |
| 3539 | "input")); |
| 3540 | |
| 3541 | ConvolutionDimensionNumbers dnums = |
| 3542 | ParseConvolutionDimensionNumbers("bf01_io01->bf01").ValueOrDie(); |
| 3543 | Window window = |
| 3544 | ParseWindow(absl::StrCat("size=3x3 ", testcase.orig_conv_window)) |
| 3545 | .ValueOrDie(); |
| 3546 | builder.AddInstruction(HloInstruction::CreateConvolve( |
| 3547 | ShapeInference::InferConvolveShape(lhs_pad->shape(), filter->shape(), |
| 3548 | /*feature_group_count=*/1, |
| 3549 | /*batch_group_count=*/1, window, dnums) |
| 3550 | .ValueOrDie(), |
| 3551 | lhs_pad, filter, /*feature_group_count=*/1, /*batch_group_count=*/1, |
| 3552 | window, dnums, DefaultPrecisionConfig(2))); |
| 3553 | auto module = CreateNewVerifiedModule(); |
| 3554 | module->AddEntryComputation(builder.Build()); |
| 3555 | |
| 3556 | AlgebraicSimplifier simplifier(default_options_); |
| 3557 | if (testcase.expected_conv_window.empty()) { |
| 3558 | ASSERT_FALSE(simplifier.Run(module.get()).ValueOrDie()); |
| 3559 | } else { |
| 3560 | ASSERT_TRUE(simplifier.Run(module.get()).ValueOrDie()); |
| 3561 | auto* conv = module->entry_computation()->root_instruction(); |
| 3562 | SCOPED_TRACE(module->ToString()); |
| 3563 | ASSERT_THAT(conv, |
| 3564 | GmockMatch(m::Convolution(m::Parameter(), m::Parameter()))); |
| 3565 | EXPECT_EQ(window_util::ToString(conv->window()), |
| 3566 | absl::StrCat("size=3x3 ", testcase.expected_conv_window)); |
| 3567 | } |
| 3568 | } |
| 3569 |
nothing calls this directly
no test coverage detected