Skip to content

Commit

Permalink
Use absl::string_view instead of std::string_view as some environment…
Browse files Browse the repository at this point in the history
…s (e.g. Android) don't provide std::string_view.

PiperOrigin-RevId: 706812521
  • Loading branch information
klucke authored and Google-ML-Automation committed Dec 16, 2024
1 parent c5fd482 commit 23907df
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 67 deletions.
7 changes: 1 addition & 6 deletions xla/hlo/transforms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,14 @@ xla_cc_test(
srcs = ["simplifiers/hlo_computation_deduplicator_test.cc"],
deps = [
":hlo_computation_deduplicator",
"//xla:literal",
"//xla:literal_util",
"//xla:shape_util",
"//xla:test",
"//xla:types",
"//xla:xla_data_proto_cc",
"//xla/hlo/ir:hlo",
"//xla/hlo/pass:hlo_pass",
"//xla/hlo/testlib:hlo_hardware_independent_test_base",
"//xla/hlo/utils:hlo_matchers",
"//xla/tsl/lib/core:status_test_util",
"@com_google_absl//absl/strings:string_view",
"@com_google_googletest//:gtest_main",
"@tsl//tsl/platform:statusor",
"@tsl//tsl/platform:test_main",
],
)
Expand Down
1 change: 1 addition & 0 deletions xla/hlo/transforms/collectives/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ xla_cc_test(
"//xla/hlo/ir:hlo",
"//xla/hlo/testlib:hlo_hardware_independent_test_base",
"//xla/hlo/utils:hlo_matchers",
"@com_google_absl//absl/strings:string_view",
"@com_google_googletest//:gtest",
"@tsl//tsl/platform:statusor",
"@tsl//tsl/platform:test_main", # fixdeps: keep
Expand Down
1 change: 0 additions & 1 deletion xla/hlo/transforms/collectives/all_gather_cse_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
#include "xla/hlo/transforms/collectives/all_gather_cse.h"

#include <memory>
#include <string_view>
#include <vector>

#include <gmock/gmock.h>
Expand Down
5 changes: 2 additions & 3 deletions xla/hlo/transforms/collectives/infeed_token_propagation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
#define XLA_HLO_TRANSFORMS_COLLECTIVES_INFEED_TOKEN_PROPAGATION_H_

#include <memory>
#include <string_view>

#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
Expand All @@ -39,11 +38,11 @@ namespace xla {
// This pass assumes the HLO graph is flattened.
class InfeedTokenPropagation : public HloModulePass {
public:
std::string_view name() const override { return "infeed-token-propagation"; }
absl::string_view name() const override { return "infeed-token-propagation"; }
using HloPassInterface::Run;
absl::StatusOr<bool> Run(
HloModule* module,
const absl::flat_hash_set<std::string_view>& execution_threads) override;
const absl::flat_hash_set<absl::string_view>& execution_threads) override;

private:
absl::Status PropagateToken(const HloOrdering& ordering);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ limitations under the License.

#include "xla/hlo/transforms/collectives/while_loop_all_reduce_code_motion_setup.h"

#include <string_view>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/strings/string_view.h"
#include "xla/hlo/ir/hlo_instruction.h"
#include "xla/hlo/testlib/hlo_hardware_independent_test_base.h"
#include "xla/hlo/utils/hlo_matchers.h"
Expand All @@ -35,7 +34,7 @@ class ReorderReduceTransposeTest : public HloHardwareIndependentTestBase {
};

TEST_F(ReorderReduceTransposeTest, SimpleReduceScatterTransposeInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -82,7 +81,7 @@ ENTRY main {

TEST_F(ReorderReduceTransposeTest,
ReduceScatterConvertTransposeNotInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand All @@ -105,7 +104,7 @@ ENTRY main {
}

TEST_F(ReorderReduceTransposeTest, ReduceScatterConvertTransposeInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -153,7 +152,7 @@ ENTRY main {

TEST_F(ReorderReduceTransposeTest,
ReduceScatterTransposeReshapeDynamicUpdateSliceInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -208,7 +207,7 @@ class ReorderConvertReduceAddTest : public HloHardwareIndependentTestBase {
};

TEST_F(ReorderConvertReduceAddTest, SimpleConvertReduceScatterAddInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -255,7 +254,7 @@ ENTRY main {
}

TEST_F(ReorderConvertReduceAddTest, ConvertAllReduceAddNotInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand All @@ -277,7 +276,7 @@ ENTRY main {
}

TEST_F(ReorderConvertReduceAddTest, ConvertReduceScatterAddInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -324,7 +323,7 @@ ENTRY main {
}

TEST_F(ReorderConvertReduceAddTest, DisableReduceScatter) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down Expand Up @@ -361,7 +360,7 @@ ENTRY main {
}

TEST_F(ReorderConvertReduceAddTest, ConvertAllReduceAddInWhileBody) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule main
%reduction {
Expand Down
28 changes: 14 additions & 14 deletions xla/hlo/transforms/simplifiers/hlo_computation_deduplicator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ limitations under the License.
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include <gtest/gtest.h>
#include "absl/strings/string_view.h"
#include "xla/hlo/ir/hlo_computation.h"
#include "xla/hlo/ir/hlo_instruction.h"
#include "xla/hlo/ir/hlo_opcode.h"
Expand All @@ -38,7 +38,7 @@ namespace {

class HloComputationDeduplicatorTest : public HloHardwareIndependentTestBase {
protected:
std::vector<std::string> RunDeduplicatePass(const std::string_view text,
std::vector<std::string> RunDeduplicatePass(const absl::string_view text,
bool expect_true) {
std::unique_ptr<HloModule> module =
ParseAndReturnVerifiedModule(text).value();
Expand All @@ -54,7 +54,7 @@ class HloComputationDeduplicatorTest : public HloHardwareIndependentTestBase {
};

TEST_F(HloComputationDeduplicatorTest, RemoveRegionBandC) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0}, s32[20]{0})->s32[]}
region_A {
Arg_0.6 = s32[] parameter(0)
Expand Down Expand Up @@ -97,7 +97,7 @@ TEST_F(HloComputationDeduplicatorTest, RemoveRegionBandC) {
}

TEST_F(HloComputationDeduplicatorTest, RemoveRegionBExactCopy) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Arg_0.5 = s32[] parameter(0)
Expand Down Expand Up @@ -129,7 +129,7 @@ TEST_F(HloComputationDeduplicatorTest, RemoveRegionBExactCopy) {
}

TEST_F(HloComputationDeduplicatorTest, RemoveRegionsWithSameSubcomp) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_X {
Ag_0 = s32[] parameter(0)
Expand Down Expand Up @@ -193,7 +193,7 @@ TEST_F(HloComputationDeduplicatorTest, RemoveRegionsWithSameSubcomp) {
}

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionsWithDifferentSubcomp) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_X {
Ag_0 = s32[] parameter(0)
Expand Down Expand Up @@ -272,7 +272,7 @@ TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionsWithDifferentSubcomp) {
}

TEST_F(HloComputationDeduplicatorTest, RemoveRegionBVarDifferences) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Arg_0.5 = s32[] parameter(0)
Expand Down Expand Up @@ -306,7 +306,7 @@ TEST_F(HloComputationDeduplicatorTest, RemoveRegionBVarDifferences) {
}

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBCommutative) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Arg_0 = s32[] parameter(0)
Expand Down Expand Up @@ -342,7 +342,7 @@ TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBCommutative) {

TEST_F(HloComputationDeduplicatorTest,
DontRemoveRegionBDifferentExecutionThread) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Expand Down Expand Up @@ -389,7 +389,7 @@ TEST_F(HloComputationDeduplicatorTest,
}

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionLargeConstant) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Arg_00 = s32[] parameter(0)
Expand Down Expand Up @@ -481,7 +481,7 @@ TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionLargeConstant) {
}

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBDifferentcomp) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A {
Arg_0.5 = s32[] parameter(0)
Expand Down Expand Up @@ -516,7 +516,7 @@ TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBDifferentcomp) {
}

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBDifferentType) {
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s16[15]{0})->s16[]}
region_A {
Arg_0.5 = s32[] parameter(0)
Expand Down Expand Up @@ -552,7 +552,7 @@ TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBDifferentType) {

TEST_F(HloComputationDeduplicatorTest, DontRemoveRegionBEntryComp) {
// Note: this test is hypothetical and just to check dedup.
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule DeDupTest, entry_computation_layout={(s32[10]{0},s32[15]{0})->s32[]}
region_A1 {
Arg_0.5 = s32[] parameter(0)
Expand Down Expand Up @@ -637,7 +637,7 @@ TEST_F(HloComputationDeduplicatorTest, LargeSubComputationTest) {

TEST_F(HloComputationDeduplicatorTest, DontDeduplicateReduceAllReduce) {
// Note: this test is hypothetical and just to check dedup.
const std::string_view text = R"(
const absl::string_view text = R"(
HloModule TestModule
add.1 {
Expand Down
3 changes: 1 addition & 2 deletions xla/hlo/transforms/simplifiers/hlo_memory_scheduler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "absl/algorithm/container.h"
Expand Down Expand Up @@ -429,7 +428,7 @@ TEST_F(HloSchedulingTest, BFSScheduler) {
instructions_by_name[instruction->name()] = instruction;
}

auto index = [&](std::string_view name) -> size_t {
auto index = [&](absl::string_view name) -> size_t {
const HloInstruction* instruction = instructions_by_name.at(name);
return std::distance(sequence.begin(), absl::c_find(sequence, instruction));
};
Expand Down
3 changes: 1 addition & 2 deletions xla/hlo/transforms/simplifiers/hlo_rematerialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ limitations under the License.
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -2898,7 +2897,7 @@ absl::StatusOr<bool> HloRematerialization::Run(
// at the same time, as that will cause the asynchronous callee usage to be
// added to the main thread callers usage. The callee's memory is
// preallocated, so the caller doesn't pay for it.
absl::flat_hash_set<std::string_view> async_threads;
absl::flat_hash_set<absl::string_view> async_threads;
for (const auto& [computation, _] :
options_.async_computation_parallelism) {
async_threads.insert(computation->execution_thread());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class AsyncRematerializationTest : public RematerializationTestBase {
};

TEST_F(AsyncRematerializationTest, AsyncComputation) {
constexpr std::string_view hlo = R"(
constexpr absl::string_view hlo = R"(
HloModule async, is_scheduled=true
%offload_computation {
Expand Down
1 change: 1 addition & 0 deletions xla/hlo/translate/mhlo_to_hlo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cc_library(
hdrs = ["stack_frame_index_builder.h"],
deps = [
"//xla/service:hlo_proto_cc",
"@com_google_absl//absl/strings:string_view",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Support",
],
Expand Down
4 changes: 2 additions & 2 deletions xla/hlo/translate/mhlo_to_hlo/stack_frame_index_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ limitations under the License.
#include <map>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>

#include "absl/strings/string_view.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Location.h"
#include "mlir/Support/LLVM.h"
#include "xla/service/hlo.pb.h"

namespace mlir {

int FindId(std::string_view key, std::map<std::string_view, int> &index) {
int FindId(absl::string_view key, std::map<absl::string_view, int> &index) {
auto entry_iterator = index.find(key);
if (entry_iterator == index.end()) {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions xla/hlo/translate/mhlo_to_hlo/stack_frame_index_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License.

#include <map>
#include <string>
#include <string_view>
#include <tuple>

#include "absl/strings/string_view.h"
#include "mlir/IR/Location.h"
#include "xla/service/hlo.pb.h"

Expand All @@ -46,8 +46,8 @@ class StackFrameIndexBuilder {

xla::StackFrameIndexProto indexes_;

std::map<std::string_view, int> function_name_to_id_;
std::map<std::string_view, int> file_name_to_id_;
std::map<absl::string_view, int> function_name_to_id_;
std::map<absl::string_view, int> file_name_to_id_;
std::map<std::tuple<int, int, int, int>, int> file_location_to_id_;
std::map<std::tuple<int, int>, int> frame_to_id_;
};
Expand Down
4 changes: 1 addition & 3 deletions xla/pjrt/c/pjrt_c_api_ffi_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ limitations under the License.

#include "xla/pjrt/c/pjrt_c_api_ffi_internal.h"

#include <string_view>

#include "absl/status/status.h"
#include "xla/ffi/execution_context.h"
#include "xla/ffi/type_id_registry.h"
Expand All @@ -36,7 +34,7 @@ static PJRT_Error* PJRT_FFI_TypeID_Register(
PJRT_ASSIGN_OR_RETURN(
auto type_id,
xla::ffi::TypeIdRegistry::RegisterExternalTypeId(
std::string_view(args->type_name, args->type_name_size)));
absl::string_view(args->type_name, args->type_name_size)));
args->type_id = type_id.value();
return nullptr;
}
Expand Down
Loading

0 comments on commit 23907df

Please sign in to comment.