Skip to content

Flatten hierarchical collective payloads#7370

Closed
iemAnshuman wants to merge 1 commit into
TheHPXProject:masterfrom
iemAnshuman:feat/flatten-hierarchical-collectives
Closed

Flatten hierarchical collective payloads#7370
iemAnshuman wants to merge 1 commit into
TheHPXProject:masterfrom
iemAnshuman:feat/flatten-hierarchical-collectives

Conversation

@iemAnshuman

@iemAnshuman iemAnshuman commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #

Proposed Changes

  • Replace nested intermediate vectors with serializable flat buffers and offset tables for hierarchical gather, scatter, and all_to_all
  • Keep all-to-all diagonal blocks local during packing (empty segment for the local group) so they skip the inter-group round trip
  • Extend unit coverage for uneven trees, bool/string payloads, serialization, non-default-constructible values, flat fallback, and flattened-data helpers

Any background context you want to provide?

Hierarchical gather/scatter/all-to-all previously shuttled nested vector payloads between tree levels. Flattening to a contiguous buffer plus offset table reduces allocation churn and simplifies serialization across the communicator tree while preserving existing hierarchical generation semantics.

This PR is based directly on current master and does not include the collectives hardening work from #7359.

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@iemAnshuman iemAnshuman requested a review from hkaiser as a code owner July 11, 2026 19:01
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56d4598b-9465-44ba-93c4-dbea72665144

📥 Commits

Reviewing files that changed from the base of the PR and between c69e7cb and b77a379.

📒 Files selected for processing (11)
  • libs/full/collectives/CMakeLists.txt
  • libs/full/collectives/include/hpx/collectives/all_to_all.hpp
  • libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp
  • libs/full/collectives/include/hpx/collectives/detail/hierarchical_all_to_all_helpers.hpp
  • libs/full/collectives/include/hpx/collectives/gather.hpp
  • libs/full/collectives/include/hpx/collectives/scatter.hpp
  • libs/full/collectives/tests/unit/CMakeLists.txt
  • libs/full/collectives/tests/unit/gather_hierarchical.cpp
  • libs/full/collectives/tests/unit/hierarchical_flat_fallback.cpp
  • libs/full/collectives/tests/unit/hierarchical_helpers.cpp
  • libs/full/collectives/tests/unit/subtree_gather_scatter.cpp

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Improved hierarchical gather, scatter, and all-to-all operations with more efficient flattened payload handling.
    • Added support for complex, variable-sized, boolean, string, and non-default-constructible payloads.
    • Enhanced validation and serialization for collective data exchanges.
  • Tests

    • Expanded coverage for hierarchical communication, flattened payloads, uneven trees, and multi-locality scenarios.
    • Added verification for slicing, merging, transposition, and serialization behavior.

Walkthrough

The collectives module introduces flattened payload storage and utilities, extends gather, scatter, and all-to-all communication paths, refactors hierarchical subtree exchanges, and adds coverage for flattened data, payload types, and uneven locality topologies.

Changes

Flattened hierarchical collectives

Layer / File(s) Summary
Flattened data primitives
libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp
Adds flattened payload storage, offset validation, construction, merging, slicing, column selection, serialization, and unwrapping utilities.
Flattened gather and scatter transport
libs/full/collectives/include/hpx/collectives/gather.hpp, libs/full/collectives/include/hpx/collectives/scatter.hpp
Adds flattened communication-operation overloads and updates direct and hierarchical gather/scatter paths to transport flattened payloads.
Hierarchical all-to-all exchange
libs/full/collectives/include/hpx/collectives/all_to_all.hpp, libs/full/collectives/include/hpx/collectives/detail/hierarchical_all_to_all_helpers.hpp
Reworks representative all-to-all exchange and subtree gather/scatter operations around flattened blocks and selected columns.
Build wiring and behavioral coverage
libs/full/collectives/CMakeLists.txt, libs/full/collectives/tests/unit/*
Registers the new header and tests flattened helpers, non-default-constructible payloads, boolean and string payloads, hierarchical paths, and subtree result layouts.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LocalSite
  participant SubtreeRepresentative
  participant CollectiveCommunicator
  LocalSite->>SubtreeRepresentative: gather or scatter flattened payload
  SubtreeRepresentative->>CollectiveCommunicator: exchange flattened blocks
  CollectiveCommunicator-->>SubtreeRepresentative: gathered or selected flattened data
  SubtreeRepresentative-->>LocalSite: scatter and unwrap row
Loading

Suggested labels: category: algorithms, category: components

Suggested reviewers: hkaiser

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: flattening hierarchical collective payloads.
Description check ✅ Passed The description is related to the changeset and explains the flattening work, tests, and dependency stack.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@StellarBot

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

Replace nested intermediate vectors with serializable flat buffers and offset tables for hierarchical gather, scatter, and all-to-all. Keep all-to-all diagonal blocks local and add coverage for uneven trees, bool payloads, strings, serialization, and non-default-constructible values.

Signed-off-by: iemAnshuman <asquare567@gmail.com>
@iemAnshuman iemAnshuman force-pushed the feat/flatten-hierarchical-collectives branch from c69e7cb to b77a379 Compare July 11, 2026 19:05
@hkaiser hkaiser added this to the 2.0.0 milestone Jul 11, 2026
@iemAnshuman

iemAnshuman commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@hkaiser sorry I ran into a git conflict...will resolve it soon.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
libs/full/collectives/tests/unit/hierarchical_flat_fallback.cpp (1)

120-161: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting a generic payload-verification helper to avoid triplicated blocks.

The uint32/string/bool verification blocks (fb_clients and tree_clients legs) are structurally identical aside from the payload type and generation number. A small templated helper (e.g., verify_all_to_all<T>(clients, send, expected, generation)) would remove the duplication and make adding a 4th payload type (or extending coverage) less error-prone.

Also applies to: 187-207

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/full/collectives/tests/unit/hierarchical_flat_fallback.cpp` around lines
120 - 161, Extract the repeated all_to_all result-size and element verification
logic into a templated helper such as verify_all_to_all, parameterized by
payload type, clients, send data, expected data, and generation. Replace the
duplicated uint32, string, and bool checks in both fb_clients and tree_clients
sections with this helper while preserving each payload’s generation value and
expected ordering.
libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp (1)

189-304: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the destructive move semantics of merge_flattened_data/slice_flattened_data/select_flattened_column.

These take mutable references (flattened_data<T>& / std::vector<flattened_data<T>>&) and, for non-bool T, move-construct elements out of the source via append_flattened_range's move-iterator branch (Line 139-141). This leaves the caller's input in a moved-from (unspecified but valid) state, e.g. strings become empty. Callers within this PR are safe today (disjoint-segment access pattern and single-use inputs), but the API doesn't signal this destructive behavior, which is a foot-gun for future maintainers reusing an input after calling one of these.

Consider documenting this explicitly (e.g., a // NOTE: moves elements out of value/values comment), or making it explicit at the type level (accept &&).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp`
around lines 189 - 304, Document that merge_flattened_data,
slice_flattened_data, and select_flattened_column destructively move non-bool
elements from their mutable input value or values, leaving sources valid but
unspecified. Add clear comments at these APIs, or change their parameters to
rvalue references if the surrounding callers support that contract; preserve the
existing behavior and avoid implying inputs remain reusable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp`:
- Around line 189-304: Document that merge_flattened_data, slice_flattened_data,
and select_flattened_column destructively move non-bool elements from their
mutable input value or values, leaving sources valid but unspecified. Add clear
comments at these APIs, or change their parameters to rvalue references if the
surrounding callers support that contract; preserve the existing behavior and
avoid implying inputs remain reusable.

In `@libs/full/collectives/tests/unit/hierarchical_flat_fallback.cpp`:
- Around line 120-161: Extract the repeated all_to_all result-size and element
verification logic into a templated helper such as verify_all_to_all,
parameterized by payload type, clients, send data, expected data, and
generation. Replace the duplicated uint32, string, and bool checks in both
fb_clients and tree_clients sections with this helper while preserving each
payload’s generation value and expected ordering.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c368f2fa-3009-4b3b-a121-0b617facf702

📥 Commits

Reviewing files that changed from the base of the PR and between f360e03 and c69e7cb.

📒 Files selected for processing (26)
  • libs/full/collectives/CMakeLists.txt
  • libs/full/collectives/include/hpx/collectives/all_gather.hpp
  • libs/full/collectives/include/hpx/collectives/all_reduce.hpp
  • libs/full/collectives/include/hpx/collectives/all_to_all.hpp
  • libs/full/collectives/include/hpx/collectives/barrier.hpp
  • libs/full/collectives/include/hpx/collectives/broadcast.hpp
  • libs/full/collectives/include/hpx/collectives/create_communicator.hpp
  • libs/full/collectives/include/hpx/collectives/detail/communicator.hpp
  • libs/full/collectives/include/hpx/collectives/detail/flattened_data.hpp
  • libs/full/collectives/include/hpx/collectives/detail/hierarchical_all_to_all_helpers.hpp
  • libs/full/collectives/include/hpx/collectives/detail/hierarchical_helpers.hpp
  • libs/full/collectives/include/hpx/collectives/detail/hierarchical_scan_helpers.hpp
  • libs/full/collectives/include/hpx/collectives/gather.hpp
  • libs/full/collectives/include/hpx/collectives/reduce.hpp
  • libs/full/collectives/include/hpx/collectives/scatter.hpp
  • libs/full/collectives/src/barrier.cpp
  • libs/full/collectives/src/create_communicator.cpp
  • libs/full/collectives/src/detail/hierarchical_helpers.cpp
  • libs/full/collectives/tests/unit/CMakeLists.txt
  • libs/full/collectives/tests/unit/barrier.cpp
  • libs/full/collectives/tests/unit/barrier_hierarchical.cpp
  • libs/full/collectives/tests/unit/gather_hierarchical.cpp
  • libs/full/collectives/tests/unit/hierarchical_flat_fallback.cpp
  • libs/full/collectives/tests/unit/hierarchical_helpers.cpp
  • libs/full/collectives/tests/unit/inclusive_scan_hierarchical.cpp
  • libs/full/collectives/tests/unit/subtree_gather_scatter.cpp

@iemAnshuman iemAnshuman deleted the feat/flatten-hierarchical-collectives branch July 11, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants