Skip to content

fix(cuda.core): avoid truncating graph queries - #2587

Open
yimoj wants to merge 4 commits into
NVIDIA:mainfrom
yimoj:fix/6572657-graph-query-truncation
Open

fix(cuda.core): avoid truncating graph queries#2587
yimoj wants to merge 4 commits into
NVIDIA:mainfrom
yimoj:fix/6572657-graph-query-truncation

Conversation

@yimoj

@yimoj yimoj commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

CUDA graph query APIs report the number of entries copied when the supplied buffer is too small. cuda.core used fixed-size buffers and treated that copied count as the total, silently truncating adjacency queries after 16 entries and graph node/edge queries after 128 entries.

This change uses the documented two-call pattern: first query the total count with a NULL output buffer, then allocate the exact capacity and fetch the results. It covers adjacency iteration and membership as well as GraphDefinition.nodes() and GraphDefinition.edges().

NVBug: 6572657

Testing

  • New truncation regression tests: 2 passed
  • cuda_core/tests/graph/test_graph_definition.py: 210 passed, 6 skipped
  • cuda_core/tests/graph: 495 passed, 7 skipped

Implementation choice

This follows the NULL-first two-call pattern discussed in #2529: the first call obtains the true count, then adjacency queries use the existing 16-entry C stack buffer when the result fits and fall back to std::vector for larger sets. This preserves correctness without a new small-vector dependency and avoids heap allocation in the common small-adjacency case.

We compared the plain std::vector, manual stack fallback, and a small-vector wrapper. All variants passed the regression tests; the manual stack variant was the simplest and consistently fastest in the microbenchmark. For adjacency membership at 1/8/16 entries it was approximately 17%/21%/21% faster than always allocating a vector, while iteration improved by approximately 2-7%.

Fixes #2529

@copy-pr-bot

copy-pr-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 10, 2026
@Andy-Jost Andy-Jost self-assigned this Aug 10, 2026
@Andy-Jost Andy-Jost added bug Something isn't working P0 High priority - Must do! labels Aug 10, 2026
@Andy-Jost Andy-Jost added this to the cuda.core 1.2.0 milestone Aug 10, 2026
Verify exact edge identities so graph query regressions cannot pass through count-only checks.
@Andy-Jost
Andy-Jost self-requested a review August 10, 2026 17:29
@Andy-Jost

Copy link
Copy Markdown
Contributor

/ok to test a1ba4ef

@github-actions

Copy link
Copy Markdown

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

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Graph adjacency / nodes / edges silently truncate past fixed buffer sizes (16 / 128)

2 participants