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

Include all headers explicitly. #18511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions xla/hlo/ir/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ xla_cc_test(
srcs = ["hlo_module_test.cc"],
deps = [
":hlo",
"//xla/hlo/parser:hlo_parser",
"//xla/hlo/testlib:verified_hlo_module",
"//xla/service:hlo_module_config",
"//xla/tests:hlo_test_base",
"//xla/tsl/lib/core:status_test_util",
"@com_google_absl//absl/hash",
"@com_google_googletest//:gtest_main",
"@tsl//tsl/platform:statusor",
Expand Down
17 changes: 14 additions & 3 deletions xla/hlo/ir/hlo_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#define XLA_HLO_IR_HLO_MODULE_H_

#include <atomic>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
Expand All @@ -29,23 +30,29 @@ limitations under the License.

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/span.h"
#include "xla/hlo/ir/dynamic_parameter_binding.h"
#include "xla/hlo/ir/hlo_clone_context.h"
#include "xla/hlo/ir/hlo_computation.h"
#include "xla/hlo/ir/hlo_input_output_alias_config.h"
#include "xla/hlo/ir/hlo_instruction.h"
#include "xla/hlo/ir/hlo_module_metadata.h"
#include "xla/hlo/ir/hlo_opcode.h"
#include "xla/hlo/ir/hlo_schedule.h"
#include "xla/hlo/ir/hlo_sharding.h"
#include "xla/iterator_util.h"
#include "xla/printer.h"
#include "xla/service/compilation_environments.h"
#include "xla/service/computation_layout.h"
#include "xla/service/hlo.pb.h"
#include "xla/service/hlo_module_config.h"
#include "xla/service/name_uniquer.h"
#include "xla/shape.h"
#include "xla/shape_util.h"
#include "xla/status_macros.h"
#include "xla/tsl/lib/gtl/iterator_range.h"
#include "xla/xla.pb.h"
#include "tsl/platform/logging.h"
Expand All @@ -58,6 +65,8 @@ using LayoutCanonicalizationCallback =

// Helper class to maintain a copy-on-write storage of an object of the
// specified type. Logically Variant<MutableOwned, ImmutableShared>.
// The class's purpose is to share (shared_ptr) underlying storage (when it's
// not changed) thus reducing memory footprint.
template <typename T>
class CopyOnWrite {
public:
Expand Down Expand Up @@ -137,6 +146,9 @@ class HloModule {
// - comp_envs must not be null.
HloModule(const std::string& name, HloModuleConfig config,
std::unique_ptr<CompilationEnvironments> comp_envs);

// You can share a config from other modules by passing
// HloModule::shared_config()
HloModule(const std::string& name,
std::variant<std::unique_ptr<HloModuleConfig>,
std::shared_ptr<const HloModuleConfig>>
Expand Down Expand Up @@ -817,8 +829,7 @@ class HloModule {

// Compilation environments (protos that carry command line flags and
// environment variables).
std::unique_ptr<CompilationEnvironments> comp_envs_ =
std::make_unique<CompilationEnvironments>();
std::unique_ptr<CompilationEnvironments> comp_envs_;

// Stack frame indexes flat representation.
std::optional<StackFrameIndexProto> stack_frame_index_;
Expand Down
41 changes: 28 additions & 13 deletions xla/hlo/ir/hlo_module_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ 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/hlo/testlib/verified_hlo_module.h"
#include "xla/tests/hlo_test_base.h"
#include "xla/hlo/parser/hlo_parser.h"
#include "xla/service/hlo_module_config.h"
#include "tsl/platform/statusor.h"
#include "tsl/platform/test.h"

namespace xla {
namespace {

using HloModuleTest = HloTestBase;

TEST_F(HloModuleTest, AbslHashValue) {
std::unique_ptr<VerifiedHloModule> module1 = CreateNewVerifiedModule();
std::unique_ptr<VerifiedHloModule> module2 = CreateNewVerifiedModule();
EXPECT_EQ(absl::HashOf(*module1), absl::HashOf(*module2));
TEST(HloModuleTest, AbslHashValue) {
HloModule module1("temp_module", HloModuleConfig());
HloModule module2("temp_module3", HloModuleConfig());
EXPECT_EQ(absl::HashOf(module1), absl::HashOf(module2));

std::string_view hlo = R"(
HloModule m1
Expand All @@ -40,12 +40,27 @@ TEST_F(HloModuleTest, AbslHashValue) {
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));
TF_ASSERT_OK_AND_ASSIGN(auto module3, ParseAndReturnUnverifiedModule(hlo));
TF_ASSERT_OK_AND_ASSIGN(auto module4, ParseAndReturnUnverifiedModule(hlo));
EXPECT_EQ(absl::HashOf(*module3), absl::HashOf(*module4));
EXPECT_NE(absl::HashOf(*module1), absl::HashOf(*module4));
EXPECT_NE(absl::HashOf(module1), absl::HashOf(*module4));
}

TEST(HloModuleTest, MutableOwnedImmutableSharedConfig) {
HloModuleConfig config1;
config1.set_device_type("first");
config1.set_device_memory_size(7);
HloModule m1("-", config1);
HloModule m2("-", m1.shared_config(),
std::make_unique<CompilationEnvironments>());
EXPECT_TRUE(&m1.config() == &m2.config())
<< "Shared config referres to the same object.";
m1.mutable_config().set_device_type("second");
EXPECT_TRUE(&m1.config() != &m2.config())
<< "Config is copied on modification.";
EXPECT_EQ(m1.config().device_type(), "second");
EXPECT_EQ(m2.config().device_type(), "first");
EXPECT_EQ(m1.config().device_memory_size(), m2.config().device_memory_size());
}

} // namespace
Expand Down
Loading