-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[xla:collectives] NFC: Extract NcclCommunicators into GpuClique and N…
…cclCliqueImpl PiperOrigin-RevId: 702499628
- Loading branch information
1 parent
cb7ae7c
commit d44da53
Showing
10 changed files
with
241 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* 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/backends/gpu/collectives/gpu_clique.h" | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <utility> | ||
|
||
#include "absl/container/btree_map.h" | ||
#include "xla/backends/gpu/collectives/gpu_clique_key.h" | ||
#include "xla/core/collectives/clique.h" | ||
#include "xla/core/collectives/clique_id.h" | ||
#include "xla/core/collectives/communicator.h" | ||
#include "xla/core/collectives/rank_id.h" | ||
|
||
namespace xla::gpu { | ||
|
||
GpuClique::GpuClique( | ||
GpuCliqueKey clique_key, std::optional<CliqueId> clique_id, | ||
absl::btree_map<RankId, std::unique_ptr<Communicator>> communicators) | ||
: Clique(std::move(communicators)), | ||
clique_key_(clique_key), | ||
clique_id_(clique_id) {} | ||
|
||
} // namespace xla::gpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
==============================================================================*/ | ||
|
||
#ifndef XLA_BACKENDS_GPU_COLLECTIVES_GPU_CLIQUE_H_ | ||
#define XLA_BACKENDS_GPU_COLLECTIVES_GPU_CLIQUE_H_ | ||
|
||
#include <memory> | ||
#include <optional> | ||
|
||
#include "absl/container/btree_map.h" | ||
#include "xla/backends/gpu/collectives/gpu_clique_key.h" | ||
#include "xla/core/collectives/clique.h" | ||
#include "xla/core/collectives/clique_id.h" | ||
#include "xla/core/collectives/communicator.h" | ||
#include "xla/core/collectives/rank_id.h" | ||
|
||
namespace xla::gpu { | ||
|
||
// A group of GPU communicators making up a clique for a given clique key. | ||
class GpuClique : public Clique { | ||
public: | ||
GpuClique( | ||
GpuCliqueKey clique_key, std::optional<CliqueId> clique_id, | ||
absl::btree_map<RankId, std::unique_ptr<Communicator>> communicators); | ||
|
||
// Returns true if clique is local: all communicators belong to current | ||
// process. Non-local cliques spans multiple processes (typically hosts). | ||
bool IsLocal() const { | ||
return num_communicators() == clique_key_.devices().size(); | ||
} | ||
|
||
const GpuCliqueKey& clique_key() const { return clique_key_; } | ||
const std::optional<CliqueId>& clique_id() const { return clique_id_; } | ||
|
||
private: | ||
GpuCliqueKey clique_key_; | ||
std::optional<CliqueId> clique_id_; | ||
}; | ||
|
||
} // namespace xla::gpu | ||
|
||
#endif // XLA_BACKENDS_GPU_COLLECTIVES_GPU_CLIQUE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* 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/backends/gpu/collectives/nccl_clique.h" | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/strings/str_cat.h" | ||
#include "absl/strings/str_format.h" | ||
#include "xla/core/collectives/communicator.h" | ||
#include "xla/core/collectives/rank_id.h" | ||
#include "xla/service/gpu/runtime/nccl_api.h" | ||
#include "tsl/platform/logging.h" | ||
|
||
namespace xla::gpu { | ||
|
||
std::string NcclCliqueImpl::DebugString() const { | ||
std::string out = absl::StrFormat( | ||
"clique_key: %s; fingerprint(id): %d; size: %d; communicators: ", | ||
clique_key().ToString(), | ||
clique_id().has_value() ? clique_id()->fingerprint() : 0, | ||
num_communicators()); | ||
int32_t cnt = 0; | ||
ForEachComm([&](RankId rank, Communicator* comm) { | ||
if (cnt++) absl::StrAppend(&out, ", "); | ||
absl::StrAppendFormat(&out, "[rank=%d, comm=%p]", rank.value(), comm); | ||
}); | ||
return out; | ||
} | ||
|
||
absl::Status NcclCliqueImpl::HealthCheck() const { | ||
absl::Status health_check = absl::OkStatus(); | ||
ForEachComm([&health_check](RankId rank, Communicator* comm) { | ||
// TODO(b/380457503): Move error checking API to communicator base class. | ||
if (auto s = NcclApi::Default()->CommGetAsyncError(comm); !s.ok()) { | ||
LOG(ERROR) << "NCCL async error (rank " << rank << "): " << s; | ||
if (health_check.ok()) health_check = std::move(s); // return first error | ||
} | ||
}); | ||
return health_check; | ||
} | ||
|
||
} // namespace xla::gpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* 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. | ||
==============================================================================*/ | ||
|
||
#ifndef XLA_BACKENDS_GPU_COLLECTIVES_NCCL_CLIQUE_H_ | ||
#define XLA_BACKENDS_GPU_COLLECTIVES_NCCL_CLIQUE_H_ | ||
|
||
#include <string> | ||
|
||
#include "absl/status/status.h" | ||
#include "xla/backends/gpu/collectives/gpu_clique.h" | ||
|
||
namespace xla::gpu { | ||
|
||
// A GPU clique that is implemented on top of NCCL communicators. | ||
// | ||
// TODO(b/380457503): Remove `Impl` suffix once we migrate all users to | ||
// LockableGpuClique. | ||
class NcclCliqueImpl : public GpuClique { | ||
public: | ||
using GpuClique::GpuClique; | ||
|
||
std::string DebugString() const final; | ||
absl::Status HealthCheck() const final; | ||
}; | ||
|
||
} // namespace xla::gpu | ||
|
||
#endif // XLA_BACKENDS_GPU_COLLECTIVES_NCCL_CLIQUE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters