Files
pytorch/test/cpp/c10d/ProcessGroupUCCTest.cpp
Tristan Rice b4d3913dc2 Move backend-specific c10d files into per-backend subfolders (#187083) (#187083)
Summary:

Reorganizes `torch/csrc/distributed/c10d` by moving non-public, backend-specific implementation files and the TCPStore backend files into per-backend subfolders, while leaving the public-facing classes at the top level (the `ProcessGroupGloo`/`NCCL`/`MPI`/`UCC` backends and the `Store`/`TCPStore`/`FileStore`/`HashStore`/`PrefixStore` classes all stay put).

The moves are: `store/` gets `TCPStoreBackend.{cpp,hpp}` and `TCPStoreLibUvBackend.cpp`; `gloo/` gets `ProcessGroupGlooCuda.cpp`, `ProcessGroupGlooDetail.hpp`, and `GlooDeviceFactory.{cpp,hpp}`; `ucc/` gets `UCCTracing.{cpp,hpp}` and `UCCUtils.{cpp,hpp}`; `nccl/` gets `NCCLXStub.hpp`.

`NCCLUtils.{cpp,hpp}` was deliberately kept at the top level even though it is backend-specific: it is included by several call sites outside `caffe2` (in `gen_ai`, `ads_mkl`, and `fbgemm_gpu`), so relocating it would be a wider, riskier change better done on its own. As a result the new `nccl/` folder currently holds only `NCCLXStub.hpp`.

All include sites were updated, covering both the canonical `torch/csrc/distributed/c10d/...` include form and the legacy short `c10d/...` form (used by `fb/GlooDeviceFactory.cpp`). Build wiring was updated in `build_variables.bzl` -- the canonical source list consumed by CMake (via `append_filelist` in `cmake/Codegen.cmake`), OSS Bazel, and OSS Buck -- and in the internal `fb/fbcode/target_definitions.bzl` for `ProcessGroupGlooCuda.cpp`. Headers are picked up by recursive globs, so no header-list edits were needed.

This is a pure file move: contents are unchanged apart from the relocated `#include` paths, so correctness is established by a clean build rather than by behavioral tests.

Authored with the assistance of an AI coding assistant (Claude Code).

Test Plan:
Confirmed no references to the old paths remain anywhere in `fbcode`, then ran the fbcode lint and build tooling:

```
arc f
arc lint
arc lint --take AUTODEPS --apply-patches
buck2 build fbcode//caffe2:_libtorch fbcode//caffe2:_libtorch_cuda
```

`arc f` and `arc lint` reported no issues; AUTODEPS produced no dependency changes (the moves stayed within existing Buck targets); both the CPU (`_libtorch`) and CUDA (`_libtorch_cuda`) libraries built successfully (exit 0).

Reviewed By: kapilsh

Pull Request resolved: https://github.com/pytorch/pytorch/pull/187083
Approved by: https://github.com/kapilsh
2026-06-12 11:40:30 +00:00

35 lines
946 B
C++

#ifdef USE_C10D_UCC
#include <gtest/gtest.h>
#include <torch/csrc/distributed/c10d/ucc/UCCUtils.hpp>
#include <utility>
#include <vector>
TEST(ProcessGroupUCCTest, testTrim) {
std::vector<std::pair<std::string, std::string>> tests = {
{" allreduce ", "allreduce"},
{"\tallgather", "allgather"},
{"send\n", "send"},
};
for (auto entry : tests) {
ASSERT_EQ(c10d::trim(entry.first), entry.second);
}
}
TEST(ProcessGroupUCCTest, testToLower) {
std::vector<std::pair<std::string, std::string>> tests = {
{"AllReduce", "allreduce"},
{"ALLGATHER", "allgather"},
{"send", "send"},
};
for (auto entry : tests) {
ASSERT_EQ(c10d::tolower(entry.first), entry.second);
}
}
TEST(ProcessGroupUCCTest, testParseList) {
std::string input = "\tAllReduce, ALLGATHER, send\n";
std::vector<std::string> expect{"allreduce", "allgather", "send"};
ASSERT_EQ(c10d::parse_list(input), expect);
}
#endif