Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hlo] Do not overwrite derived instruction backend config #18399

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions xla/hlo/ir/hlo_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2216,9 +2216,11 @@ void HloInstruction::SetupDerivedInstruction(
derived_instruction->mutable_rare()->frontend_attributes.Clear();
derived_instruction->mutable_rare()->statistics_viz.Clear();
}
// If the derived instruction has the same opcode as current,
// then the backend config is also applicable.
if (opcode() == derived_instruction->opcode() && has_backend_config()) {
// If the derived instruction has the same opcode as current, then the backend
// config is also applicable (only if derived instruction doesn't have its own
// backend config which might be different from the original one).
if (opcode() == derived_instruction->opcode() && has_backend_config() &&
!derived_instruction->has_backend_config()) {
derived_instruction->CopyBackendConfigFrom(this);
}
}
Expand Down
24 changes: 24 additions & 0 deletions xla/service/hlo_instruction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,30 @@ TEST_F(HloInstructionTest, BackendConfigNotCopiedToDerivedWithDiffOpcode) {
EXPECT_FALSE(add2->has_backend_config());
}

TEST_F(HloInstructionTest, BackendConfigNotCopiedToDerivedWithConfig) {
HloComputation::Builder b(TestName());
Shape shape = ShapeUtil::MakeShape(F32, {2, 2});
auto p0 = b.AddInstruction(HloInstruction::CreateParameter(0, shape, "p0"));
auto p1 = b.AddInstruction(HloInstruction::CreateParameter(0, shape, "p1"));
auto add = b.AddInstruction(
HloInstruction::CreateBinary(shape, HloOpcode::kAdd, p0, p1));

gpu::GpuBackendConfig gpu_config0;
gpu::GpuBackendConfig gpu_config1;
gpu_config0.set_operation_queue_id(2);
gpu_config1.set_operation_queue_id(3);

TF_ASSERT_OK(add->set_backend_config(gpu_config0));
auto add2 = b.AddInstruction(
HloInstruction::CreateBinary(shape, HloOpcode::kAdd, p0, p0));
TF_ASSERT_OK(add2->set_backend_config(gpu_config1));

add->SetupDerivedInstruction(add2);
auto backend_config = add2->backend_config<gpu::GpuBackendConfig>();
EXPECT_TRUE(backend_config.ok());
EXPECT_EQ(backend_config->operation_queue_id(), 3);
}

TEST_F(HloInstructionTest,
MergeMultiOutputProducerFusionIntoMultiOutputFusion) {
const std::string& hlo_string = R"(
Expand Down
Loading