Skip to content

Commit

Permalink
[XLA:GPU] Remove IsForwardCycle and IsBackwardCycle as they are not u…
Browse files Browse the repository at this point in the history
…sed.

PiperOrigin-RevId: 719420695
  • Loading branch information
Google-ML-Automation committed Jan 24, 2025
1 parent 14ba309 commit 758b56e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 73 deletions.
32 changes: 0 additions & 32 deletions xla/service/collective_ops_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,38 +803,6 @@ bool IsSyncCollective(const HloInstruction* instr) {
using SourceTargetPair = std::pair<int64_t, int64_t>;
using SourceTargetPairs = std::vector<SourceTargetPair>;

bool IsForwardCycle(const SourceTargetPairs& pairs) {
int64_t size = pairs.size();
if (size <= 1) return false; // self reference is not a cycle.
const SourceTargetPair& last_pair = pairs[size - 1];
if (last_pair.first != size - 1 || last_pair.second != 0) {
return false;
}
for (int64_t i = 0; i < size - 1; ++i) {
const SourceTargetPair& pair = pairs[i];
if (pair.first != i || pair.second != i + 1) {
return false;
}
}
return true;
}

bool IsBackwardCycle(const SourceTargetPairs& pairs) {
int64_t size = pairs.size();
if (size <= 1) return false; // self reference is not a cycle.
const SourceTargetPair& first_pair = pairs[0];
if (first_pair.first != 0 || first_pair.second != size - 1) {
return false;
}
for (int64_t i = 1; i < size; ++i) {
const SourceTargetPair& pair = pairs[i];
if (pair.first != i || pair.second != i - 1) {
return false;
}
}
return true;
}

std::pair<CycleType, std::set<int>> GetCycleTypeAndIndices(
const SourceTargetPairs& pairs) {
std::set<int> seen_replica_ids;
Expand Down
10 changes: 0 additions & 10 deletions xla/service/collective_ops_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,6 @@ HloInstruction* IsOrHasCollectiveWithChannelId(HloInstruction* instruction);
// Returns true if instruction is a synchronous collective op.
bool IsSyncCollective(const HloInstruction* instr);

// Returns true if the (a, b) pairs form a forward cycle with all participants
// in the cycle, such as {{0,1},{1,2},{2,3},{3,0}}. We assume that the (a, b)
// pairs are ordered as they are generated by SPMD partitioning.
bool IsForwardCycle(const std::vector<std::pair<int64_t, int64_t>>& pairs);

// Returns true if the (a, b) pairs form a backward cycle with all participants
// in the cycle, such as {{0,3},{1,0},{2,1},{3,2}}. We assume that the (a, b)
// pairs are ordered as they are generated by SPMD partitioning.
bool IsBackwardCycle(const std::vector<std::pair<int64_t, int64_t>>& pairs);

// Returns the cycle type and indices of the vertices that form cycles. For
// example, GetCycleTypeAndIndices({{0,3},{1,0},{2,1},{3,2}}) returns
// {kBackward, {0}}, since the communication pattern contains a backward cycle
Expand Down
31 changes: 0 additions & 31 deletions xla/service/collective_ops_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,37 +149,6 @@ TEST(CollectiveOpsUtilsTest, CollectiveWithChannelId2) {
EXPECT_EQ(IsOrHasCollectiveWithChannelId(fusion2.get()), nullptr);
}

TEST(CollectiveOpsUtilsTest, IsForwardCycle) {
EXPECT_TRUE(IsForwardCycle({{0, 1}, {1, 0}}));
EXPECT_TRUE(IsForwardCycle({{0, 1}, {1, 2}, {2, 3}, {3, 0}}));
EXPECT_FALSE(IsForwardCycle({{0, 0}})) << "Self link is not a cycle!";
EXPECT_FALSE(IsForwardCycle({{}})) << "Self link due to initialization to 0";

EXPECT_FALSE(IsForwardCycle({}));
EXPECT_FALSE(IsForwardCycle({{0, 1}}));
EXPECT_FALSE(IsForwardCycle({{0, 1}, {2, 0}})) << "No link between 1 and 2";
EXPECT_FALSE(IsForwardCycle({{1, 0}, {0, 1}})) << "Backward cycle";
EXPECT_FALSE(IsForwardCycle({{3, 0}, {0, 1}, {1, 2}, {2, 3}}))
<< "Unordered pairs are not a cycle";
EXPECT_FALSE(IsForwardCycle({{0, 1}, {1, 2}, {2, 3}, {4, 5}, {3, 0}}))
<< "Out of order pairs are not a cycle";
}

TEST(CollectiveOpsUtilsTest, IsBackwardCycle) {
EXPECT_TRUE(IsBackwardCycle({{0, 1}, {1, 0}}));
EXPECT_TRUE(IsBackwardCycle({{0, 3}, {1, 0}, {2, 1}, {3, 2}}));
EXPECT_FALSE(IsBackwardCycle({{0, 0}})) << "Self link is a backward cycle!";
EXPECT_FALSE(IsBackwardCycle({{}})) << "Self link due to initialization to 0";

EXPECT_FALSE(IsForwardCycle({}));
EXPECT_FALSE(IsForwardCycle({{1, 0}}));
EXPECT_FALSE(IsForwardCycle({{2, 1}, {0, 2}})) << "No link between 1 and 2";
EXPECT_FALSE(IsBackwardCycle({{3, 2}, {0, 3}, {1, 0}, {2, 1}}))
<< "Unordered pairs are not a cycle";
EXPECT_FALSE(IsForwardCycle({{0, 1}, {1, 2}, {4, 5}, {3, 0}}))
<< "Out of order pairs are not a cycle";
}

TEST(CollectiveOpsUtilsTest, GetForwardCycleIndices) {
auto res_one_cycle = GetCycleTypeAndIndices({{0, 1}, {1, 2}, {2, 3}, {3, 0}});
EXPECT_EQ(res_one_cycle.first, CycleType::kForward);
Expand Down

0 comments on commit 758b56e

Please sign in to comment.