Skip to content

MCS graph construction utils - #230

Merged
scal444 merged 3 commits into
mainfrom
mcs-split-01-foundations
Jul 28, 2026
Merged

MCS graph construction utils#230
scal444 merged 3 commits into
mainfrom
mcs-split-01-foundations

Conversation

@scal444

@scal444 scal444 commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

We use a simpler graph representation than substruct, since we don't need repeated label/recurse cycles and the scope of matching is typically more limited.

PR 3 towards #221

@scal444
scal444 requested a review from evasnow1992 July 24, 2026 17:35
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds the CSR graph construction utility (buildGraphFromEdges) and GPU-side packed bitmap match tables (MatchTableHost/MatchTableDevice/uploadPairMatchTables) that form the foundational data structures for the FMCS CUDA pipeline.

  • mcs_graph.cpp: Builds a sorted, symmetric CSR adjacency list from an undirected edge list with validation for out-of-range vertices and self-loops. Two concerns (silent size_t→int truncation in numVertices/numEdges and no duplicate-edge detection) were raised in the prior review cycle.
  • fmcs_match_tables.cuh/.cu: Defines host and device bitset tables for atom/bond compatibility and packs all pairs into a single contiguous AsyncDeviceVector<uint32_t> in one upload, with device pointers pre-computed from sequential packing offsets.
  • Tests: Covers sorted symmetry, empty/disconnected graphs, error paths, word-boundary bit packing, and contiguous buffer layout — good breadth for a foundations layer.

Confidence Score: 5/5

Safe to merge — the new graph-building and match-table upload code is well-scoped and the test suite validates the key invariants.

The graph construction and bitset-table upload are straightforward additions with no shared mutable state or complex ownership. The two open concerns from the prior round (int truncation on vertex/edge counts and no duplicate-edge guard in buildGraphFromEdges) are known and tracked — neither affects correctness for real molecule sizes — and no new defects are introduced here.

Files Needing Attention: No files require special attention beyond the previously noted items in src/mcs/mcs_graph.cpp.

Important Files Changed

Filename Overview
src/mcs/mcs_graph.cpp New CSR graph builder with validation; duplicate-edge and int-overflow concerns flagged in prior review threads
src/mcs/fmcs_cuda/fmcs_match_tables.cuh Defines host/device bitmap match-table types and upload interface; clean struct layout, well-typed bit arithmetic
src/mcs/fmcs_cuda/fmcs_match_tables.cu Implements contiguous device-side packing of match tables; offset accounting and stream usage are correct
tests/test_fmcs_foundations.cu Good coverage of graph construction and table upload; tests sort order, symmetry, error paths, word-boundary packing, and empty cases
src/mcs/CMakeLists.txt New CMake target wiring mcs_graph.cpp and fmcs_match_tables.cu into mcs_fmcs_foundations; include dirs and link deps look correct

Reviews (4): Last reviewed commit: "Use project-rooted includes in fMCS foun..." | Re-trigger Greptile

Comment thread src/mcs/mcs_graph.cpp
Comment thread src/mcs/mcs_graph.cpp
Comment on lines +28 to +29
graph.numVertices = static_cast<int>(numVertices);
graph.numEdges = static_cast<int>(edges.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 numVertices and edges.size() are size_t, but the Graph struct stores int numVertices and int numEdges. The silent static_cast<int> truncates without any guard for values above INT_MAX. In practice molecule graphs are tiny, but an explicit check would make the expectation clear and catch misuse early.

Suggested change
graph.numVertices = static_cast<int>(numVertices);
graph.numEdges = static_cast<int>(edges.size());
if (numVertices > static_cast<size_t>(std::numeric_limits<int>::max()) ||
edges.size() > static_cast<size_t>(std::numeric_limits<int>::max())) {
throw std::runtime_error("MCS graph vertex/edge count exceeds int capacity");
}
graph.numVertices = static_cast<int>(numVertices);
graph.numEdges = static_cast<int>(edges.size());

@scal444
scal444 force-pushed the mcs-split-01-foundations branch from 8f2d628 to feb29f2 Compare July 27, 2026 13:56

@evasnow1992 evasnow1992 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes look good to me. Thanks!

@scal444

scal444 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

As discussed I'll wait until CI is green and rebase before merging.

@scal444
scal444 force-pushed the mcs-split-01-foundations branch from feb29f2 to 52a0e9b Compare July 28, 2026 15:28
@scal444
scal444 merged commit 68625d7 into main Jul 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants