Skip to content

Add missing memory estimates#2255

Open
huuanhhuyn wants to merge 2 commits into
NVIDIA:mainfrom
huuanhhuyn:add_heuristic
Open

Add missing memory estimates#2255
huuanhhuyn wants to merge 2 commits into
NVIDIA:mainfrom
huuanhhuyn:add_heuristic

Conversation

@huuanhhuyn

@huuanhhuyn huuanhhuyn commented Jun 23, 2026

Copy link
Copy Markdown

Add missing memory usage estimates:

  • IVF-PQ extend phase takes more memory than search phase for OpenAI 5M dataset
  • Graph optimization debuging allocates large host memory when raft debug mode is enabled
image
  • Cagra params might enable option "attach_dataset_on_build" which allocates large device memory for the graph
image

@copy-pr-bot

copy-pr-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

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.

@huuanhhuyn huuanhhuyn changed the title Add missing allocations Add missing memory estimates Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bc35defb-589c-41c3-a16d-be008f45229e

📥 Commits

Reviewing files that changed from the base of the PR and between 3e27c6e and 8cfd600.

📒 Files selected for processing (1)
  • cpp/src/neighbors/detail/cagra/cagra_helpers.cpp

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory estimation for builds that add or attach data during indexing, helping prevent under-allocation on GPU.
    • Debug-enabled runs now account for additional host-side workspace in total memory estimates.
    • Overall memory calculations now better reflect the full cost of extended build and graph-attachment workflows.

Walkthrough

Memory estimation in cagra_helpers.cpp now includes debug logging overhead in optimize_workspace_size and additional IVF-PQ device memory terms for extend and attach-dataset build paths.

Changes

CAGRA and IVF-PQ memory estimation updates

Layer / File(s) Summary
CAGRA optimize workspace debug logging memory
cpp/src/neighbors/detail/cagra/cagra_helpers.cpp
optimize_workspace_size conditionally computes debug_host_size when debug logging is enabled and includes it in total_host.
IVF-PQ extend and attach memory estimation
cpp/src/neighbors/detail/cagra/cagra_helpers.cpp
Adds ivf_pq_extend_mem_usage, updates ivf_pq_build_mem_usage to accept attach_dataset_on_build, computes conditional extend and attach GPU memory terms, includes them in total_dev, and passes the new flag from cagra_build_mem_usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

feature request

Suggested reviewers

  • tfeher
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 matches the main change: adding missing memory estimates.
Description check ✅ Passed The description is directly related and accurately summarizes the added memory estimates.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
cpp/src/neighbors/detail/cagra/cagra_helpers.cpp

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.21][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


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

@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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@cpp/src/neighbors/detail/cagra/cagra_helpers.cpp`:
- Around line 184-208: The extend_gpu_mem variable is being calculated when
add_data_on_build is true but is not being included in the total_dev
calculation. Fix this by adding extend_gpu_mem to the std::max initializer list
that computes total_dev alongside kmeans_gpu_mem, search_phase_dev, and
gpu_workspace_size to ensure the extend-phase GPU memory requirement is properly
accounted for in the final device memory estimate.
- Around line 159-239: The `ivf_pq_build_mem_usage` function has a broken
control flow where the return statement is inside the debug logging condition
block, causing a compile error when debug logging is disabled. Additionally, the
code references an undefined variable `pq_params` when the actual parameter is
`params`. To fix this, move the return statement that returns
`std::make_pair(total_host, total_dev)` to the end of the function after the
closing brace of the debug logging if-block, change
`pq_params.build_params.add_data_on_build` to
`params.build_params.add_data_on_build`, and ensure all code after the if-block
has correct indentation so the function properly exits regardless of whether
debug logging is enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b7aa4e21-abed-421b-b84f-0824ce932a43

📥 Commits

Reviewing files that changed from the base of the PR and between 71306ec and bbc7e02.

📒 Files selected for processing (1)
  • cpp/src/neighbors/detail/cagra/cagra_helpers.cpp

Comment thread cpp/src/neighbors/detail/cagra/cagra_helpers.cpp Outdated
Comment thread cpp/src/neighbors/detail/cagra/cagra_helpers.cpp Outdated

@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.

Actionable comments posted: 2

♻️ Duplicate comments (1)
cpp/src/neighbors/detail/cagra/cagra_helpers.cpp (1)

185-185: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

CRITICAL: pq_params is undefined in this scope; use params.

The function parameter is params (Line 143); pq_params does not exist here, so this won't compile.

🐛 Proposed fix
-  if (pq_params.build_params.add_data_on_build) {
+  if (params.build_params.add_data_on_build) {
     extend_gpu_mem = ivf_pq_extend_mem_usage(dataset, params, dtype_size);
   }
🤖 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 `@cpp/src/neighbors/detail/cagra/cagra_helpers.cpp` at line 185, Replace the
undefined variable `pq_params` with the correct parameter name `params` in the
condition at line 185 where `pq_params.build_params.add_data_on_build` is being
accessed. The function parameter is named `params` (defined on line 143), not
`pq_params`, so update the reference to use the correct variable name to ensure
the code compiles.
🤖 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.

Inline comments:
In `@cpp/src/neighbors/detail/cagra/cagra_helpers.cpp`:
- Around line 87-99: The if block in the optimize_workspace_size function that
checks raft::default_logger().should_log(rapids_logger::level_enum::debug) is
opened with a brace but never closed, causing the total_host, total_host_fixed,
total_dev, total_dev_fixed variable declarations and the return statement to be
incorrectly nested inside the if block. Add a closing brace immediately after
the debug_host_size calculation (after the hist comment) and before the size_t
total_host declaration to properly close the if block and allow the function to
execute correctly in both debug and non-debug code paths.
- Around line 101-136: The ivf_pq_extend_mem_usage function lacks validation for
the pq_dim parameter, which can default to 0 when using the default constructor
and will cause division by zero when used in raft::round_up_safe and in the
code_bytes_per_vec calculation. Add a RAFT_EXPECTS check at the beginning of the
function to ensure params.build_params.pq_dim is non-zero before it is used in
the rot_dim assignment and the code_bytes_per_vec calculation.

---

Duplicate comments:
In `@cpp/src/neighbors/detail/cagra/cagra_helpers.cpp`:
- Line 185: Replace the undefined variable `pq_params` with the correct
parameter name `params` in the condition at line 185 where
`pq_params.build_params.add_data_on_build` is being accessed. The function
parameter is named `params` (defined on line 143), not `pq_params`, so update
the reference to use the correct variable name to ensure the code compiles.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d30ab270-2969-474d-8d34-226155d494b2

📥 Commits

Reviewing files that changed from the base of the PR and between 7c200d4 and 3e27c6e.

📒 Files selected for processing (1)
  • cpp/src/neighbors/detail/cagra/cagra_helpers.cpp

Comment thread cpp/src/neighbors/detail/cagra/cagra_helpers.cpp
Comment thread cpp/src/neighbors/detail/cagra/cagra_helpers.cpp
@cjnolet cjnolet added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jun 23, 2026
@cjnolet cjnolet moved this to In Progress in Unstructured Data Processing Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants