Skip to content

Fix tautological self-comparisons (#4534) - #4534

Open
r-barnes wants to merge 1 commit into
meta-pytorch:mainfrom
r-barnes:export-D126816956
Open

r-barnes wants to merge 1 commit into
meta-pytorch:mainfrom
r-barnes:export-D126816956

Conversation

@r-barnes

@r-barnes r-barnes commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Two macro patterns in RCCL produce comparisons whose result is fixed at compile time once the hipify pipeline expands them, which -Wtautological-compare rejects.

  • NCCL_CONVERT_ORDER tested its argument against each std::memory_order enumerator, so every call site passing a literal became x == x. std::memory_order and the __ATOMIC_* constants share the same underlying values, so the conversion is now a cast, with static_asserts pinning the correspondence. A constexpr helper would not fold at -O0 and would emit a runtime switch on every atomic op; the cast keeps the argument an integer constant expression and generates identical IR.
  • On AMD builds before ROCm 7.12, CU_MEM_LOCATION_TYPE_HOST_NUMA is a sentinel (3) that hipMemLocationType cannot represent, so comparing a memory-location type against it is always false. A new ncclMemLocationIsHostNuma predicate in hip_compat.h is statically false where the sentinel is in use and a plain comparison everywhere else; gin__funcs.h, dev_runtime.cc and dev_runtime_segments.cc call it instead of comparing directly.
  • The development tree and the stable snapshot tree get the same changes.

No warning is suppressed.

Differential Revision: D126816956

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 23, 2026
@meta-codesync

meta-codesync Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@r-barnes has exported this pull request. If you are a Meta employee, you can view the originating Diff in D126816956.

@meta-codesync meta-codesync Bot changed the title Fix tautological self-comparisons Fix tautological self-comparisons (#4534) Oct 23, 2026
r-barnes added a commit to r-barnes/torchcomms that referenced this pull request Oct 23, 2026
Summary:

Two macro patterns in RCCL produce comparisons whose result is fixed at compile time once the hipify pipeline expands them, which `-Wtautological-compare` rejects.

- `NCCL_CONVERT_ORDER` tested its argument against each `std::memory_order` enumerator, so every call site passing a literal became `x == x`. `std::memory_order` and the `__ATOMIC_*` constants share the same underlying values, so the conversion is now a cast, with `static_assert`s pinning the correspondence. A `constexpr` helper would not fold at `-O0` and would emit a runtime switch on every atomic op; the cast keeps the argument an integer constant expression and generates identical IR.
- On AMD builds before ROCm 7.12, `CU_MEM_LOCATION_TYPE_HOST_NUMA` is a sentinel (`3`) that `hipMemLocationType` cannot represent, so comparing a memory-location type against it is always false. A new `ncclMemLocationIsHostNuma` predicate in `hip_compat.h` is statically false where the sentinel is in use and a plain comparison everywhere else; `gin__funcs.h`, `dev_runtime.cc` and `dev_runtime_segments.cc` call it instead of comparing directly.
- The development tree and the stable snapshot tree get the same changes.

No warning is suppressed.

Differential Revision: D126816956
Summary:

Two macro patterns in RCCL produce comparisons whose result is fixed at compile time once the hipify pipeline expands them, which `-Wtautological-compare` rejects.

- `NCCL_CONVERT_ORDER` tested its argument against each `std::memory_order` enumerator, so every call site passing a literal became `x == x`. `std::memory_order` and the `__ATOMIC_*` constants share the same underlying values, so the conversion is now a cast, with `static_assert`s pinning the correspondence. A `constexpr` helper would not fold at `-O0` and would emit a runtime switch on every atomic op; the cast keeps the argument an integer constant expression and generates identical IR.
- On AMD builds before ROCm 7.12, `CU_MEM_LOCATION_TYPE_HOST_NUMA` is a sentinel (`3`) that `hipMemLocationType` cannot represent, so comparing a memory-location type against it is always false. A new `ncclMemLocationIsHostNuma` predicate in `hip_compat.h` is statically false where the sentinel is in use and a plain comparison everywhere else; `gin__funcs.h`, `dev_runtime.cc` and `dev_runtime_segments.cc` call it instead of comparing directly.
- The development tree and the stable snapshot tree get the same changes.

No warning is suppressed.

Differential Revision: D126816956

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant