Skip to content

Commit

Permalink
Add const qualifier to IsPassPipeline()
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 685899212
  • Loading branch information
toli-y authored and Google-ML-Automation committed Oct 15, 2024
1 parent f4a2aa1 commit 9b52463
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
15 changes: 15 additions & 0 deletions xla/hlo/ir/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ cc_library(
],
)

xla_cc_test(
name = "hlo_module_test",
srcs = ["hlo_module_test.cc"],
deps = [
":hlo",
"//xla/tests:hlo_test_base",
"//xla/tests:verified_hlo_module",
"@com_google_absl//absl/hash",
"@com_google_googletest//:gtest_main",
"@tsl//tsl/platform:statusor",
"@tsl//tsl/platform:test",
"@tsl//tsl/platform:test_main",
],
)

cc_library(
name = "backend_config",
srcs = ["backend_config.cc"],
Expand Down
3 changes: 2 additions & 1 deletion xla/hlo/ir/hlo_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ class HloModule {
// with respect to HloInstruction::Identical() method.
template <typename H>
friend H AbslHashValue(H h, const HloModule& module) {
h = H::combine(std::move(h), module.entry_computation_layout());
if (module.config().has_entry_computation_layout())
h = H::combine(std::move(h), module.entry_computation_layout());
// Use MakeComputationSorted() instead of MakeComputationPostOrder()
// because naming may affect the order of MakeComputationPostOrder() but not
// MakeComputationSorted().
Expand Down
54 changes: 54 additions & 0 deletions xla/hlo/ir/hlo_module_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Copyright 2024 The OpenXLA Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "xla/hlo/ir/hlo_module.h"

#include <memory>
#include <string_view>

#include <gtest/gtest.h>
#include "absl/hash/hash.h"
#include "xla/tests/hlo_test_base.h"
#include "xla/tests/verified_hlo_module.h"
#include "tsl/platform/statusor.h"
#include "tsl/platform/test.h"

namespace xla {
namespace {

using HloModuleTest = HloTestBase;

TEST_F(HloModuleTest, AbslHashValue) {
std::unique_ptr<HloModule> module1 = CreateNewVerifiedModule();
std::unique_ptr<HloModule> module2 = CreateNewVerifiedModule();
EXPECT_EQ(absl::HashOf(*module1), absl::HashOf(*module2));

std::string_view hlo = R"(
HloModule m1
ENTRY main {
a = f32[] parameter(0)
b = f32[] parameter(1)
ROOT res = f32[] multiply(a, b)
})";
TF_ASSERT_OK_AND_ASSIGN(std::unique_ptr<VerifiedHloModule> module3,
ParseAndReturnVerifiedModule(hlo));
TF_ASSERT_OK_AND_ASSIGN(std::unique_ptr<VerifiedHloModule> module4,
ParseAndReturnVerifiedModule(hlo));
EXPECT_EQ(absl::HashOf(*module3), absl::HashOf(*module4));
EXPECT_NE(absl::HashOf(*module1), absl::HashOf(*module4));
}

} // namespace
} // namespace xla
2 changes: 1 addition & 1 deletion xla/hlo/pass/hlo_pass_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HloPassInterface {
HloModuleGroup* module_group,
const absl::flat_hash_set<absl::string_view>& execution_threads) = 0;

virtual bool IsPassPipeline() { return false; }
virtual bool IsPassPipeline() const { return false; }
};

// Base class for passes which are module-scoped.
Expand Down

0 comments on commit 9b52463

Please sign in to comment.