Skip to content

Commit

Permalink
Make FindInstruction methods public.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 712983498
  • Loading branch information
toli-y authored and Google-ML-Automation committed Jan 7, 2025
1 parent 43e5b9c commit f221555
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
7 changes: 5 additions & 2 deletions xla/hlo/testlib/hlo_hardware_independent_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ limitations under the License.

#include "absl/algorithm/container.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_replace.h"
Expand Down Expand Up @@ -119,7 +120,7 @@ HloHardwareIndependentTestBase::ParseAndReturnVerifiedModule(
allow_mixed_precision_in_hlo_verifier_, ShapeUtil::ByteSizeOfElements,
instruction_can_change_layout_func_);
TF_RETURN_IF_ERROR(module->ParseHloStringAndVerifyModule(hlo_text));
return std::move(module);
return module;
}

/* static */
Expand Down Expand Up @@ -258,9 +259,11 @@ HloHardwareIndependentTestBase::RunAndCheckHloRewrite(
VLOG(7) << "Input HLO: " << hlo_string;
TF_ASSIGN_OR_RETURN(std::unique_ptr<HloModule> module,
ParseAndReturnVerifiedModule(hlo_string));
VLOG(7) << "Input HLO parsed. Running the pass: + " << hlo_pass.name();
TF_ASSIGN_OR_RETURN(bool changed, RunHloPass(hlo_pass, module.get()));
VLOG(7) << "Output HLO: "
<< module->ToString(HloPrintOptions::ShortParsable());
<< module->ToString(HloPrintOptions::ShortParsable()
.set_print_control_dependencies(true));
EXPECT_EQ(changed, expect_change);
return module;
}
Expand Down
33 changes: 17 additions & 16 deletions xla/hlo/testlib/hlo_hardware_independent_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ class HloHardwareIndependentTestBase : public ::testing::Test {
public:
static PrecisionConfig DefaultPrecisionConfig(int operands);

// Gets the computation/instruction from the given module with the given name.
// Note that it is encouraged to use these functions directly via the
// hlo_query.h header instead since they are independent from any test-time
// variables or contexts.

// This is useful for tests which create HLOs from a string and then want to
// inspect a particular computation or instruction.
static HloComputation* FindComputation(HloModule* module,
absl::string_view name);
static HloInstruction* FindInstruction(HloModule* module,
absl::string_view name);
// Gets the instruction from the given module with the given opcode.
static HloInstruction* FindInstruction(HloModule* module, HloOpcode opcode);
// Gets all the instructions from the given module with the given opcode.
static std::vector<HloInstruction*> FindInstructions(HloModule* module,
HloOpcode opcode);

protected:
explicit HloHardwareIndependentTestBase(
bool verifier_layout_sensitive = false,
Expand Down Expand Up @@ -199,22 +216,6 @@ class HloHardwareIndependentTestBase : public ::testing::Test {
->Clear();
}

// Gets the computation/instruction from the given module with the given name.
// Note that it is encouraged to use these functions directly via the
// hlo_query.h header instead since they are independent from any test-time
// variables or contexts.

// This is useful for tests which create HLOs from a string and then want to
// inspect a particular computation or instruction.
static HloComputation* FindComputation(HloModule* module,
absl::string_view name);
static HloInstruction* FindInstruction(HloModule* module,
absl::string_view name);
// Gets the instruction from the given module with the given opcode.
static HloInstruction* FindInstruction(HloModule* module, HloOpcode opcode);
// Gets all the instructions from the given module with the given opcode.
static std::vector<HloInstruction*> FindInstructions(HloModule* module,
HloOpcode opcode);

bool verifier_layout_sensitive() const { return verifier_layout_sensitive_; }
void set_verifier_layout_sensitive(bool verifier_layout_sensitive) {
Expand Down

0 comments on commit f221555

Please sign in to comment.