-
Notifications
You must be signed in to change notification settings - Fork 207
Add missing memory estimates #2255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huuanhhuyn
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
huuanhhuyn:add_heuristic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20
−3
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eada0c5
Add ivf_pq extend and debug sizes
huuanhhuyn e914251
Add device memory estimate when attaching graph to index on GPU
huuanhhuyn 45ce85e
Add missing trainset tmp large workspace allocation when dtype != float
huuanhhuyn 677f67e
Apply suggestion from @achirkin
huuanhhuyn 7440e5b
Run formatting
huuanhhuyn b966399
Merge branch 'main' into add_heuristic
huuanhhuyn dca1308
Remove redundant estimates
huuanhhuyn db54ffc
Remove redundant params
huuanhhuyn 54f806f
Add guarantee_connectivity back
huuanhhuyn 1f86a58
Merge branch 'main' into add_heuristic
huuanhhuyn 7ab8d26
Include graph size to the estimate
huuanhhuyn 5111fed
Merge branch 'main' into add_heuristic
huuanhhuyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
@@ -84,7 +84,16 @@ std::tuple<size_t, size_t, size_t, size_t> optimize_workspace_size(size_t n_rows | |
| } | ||
| size_t combine_dev = combine_dev_fixed; | ||
|
|
||
| size_t total_host = mst_host + combine_host; | ||
| size_t debug_host_size = 0; | ||
| if (raft::default_logger().should_log(rapids_logger::level_enum::debug)) { | ||
| // cagra::detail::graph::optimize() allocates extra memory to calculate | ||
| // graph metrics when debug logging is enabled | ||
| debug_host_size = n_rows * graph_degree * sizeof(uint32_t) // host_copy_output_graph | ||
| + n_rows * sizeof(uint32_t) // in_edge_count | ||
| + graph_degree * sizeof(uint32_t); // hist | ||
| } | ||
|
|
||
| size_t total_host = mst_host + combine_host + debug_host_size; | ||
| size_t total_host_fixed = mst_host_fixed + combine_host_fixed; | ||
| size_t total_dev = std::max(prune_dev, rev_dev + combine_dev); | ||
| size_t total_dev_fixed = std::max(prune_dev_fixed, combine_dev_fixed); | ||
|
|
@@ -125,6 +134,10 @@ inline std::pair<size_t, size_t> ivf_pq_build_mem_usage( | |
| params.build_params.n_lists)); | ||
| size_t kmeans_n_rows = n_rows / kmeans_trainset_ratio; | ||
| size_t kmeans_gpu_mem = kmeans_n_rows * dim * sizeof(float); | ||
| if (dtype != CUDA_R_32F) { | ||
| // kmeans trainset tmp allocation | ||
| kmeans_gpu_mem += kmeans_n_rows * dim * dtype_size; | ||
| } | ||
|
|
||
| // For non-float input, ivf_pq::build first samples into a temporary trainset of type T | ||
| if (!input_is_float) { kmeans_gpu_mem += kmeans_n_rows * dim * dtype_size; } | ||
|
|
@@ -137,6 +150,9 @@ inline std::pair<size_t, size_t> ivf_pq_build_mem_usage( | |
| size_t kmeans_pinned_host = 2 * pinned_rows * dim * dtype_size; // two staging double-buffers | ||
| size_t kmeans_host_mem = kmeans_indices_host + kmeans_pinned_host; | ||
|
|
||
| // Add graph to index on GPU | ||
| size_t create_index_gpu_mem = n_rows * graph_degree * sizeof(uint32_t); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment explaining why we intentionally ignore attached dataset size (fallback path when insufficient memory) |
||
| // Search phase (build_knn_graph): | ||
| constexpr size_t kWorkspaceRatio = 5; | ||
| size_t top_k = intermediate_graph_degree + 1; | ||
|
|
@@ -155,7 +171,8 @@ inline std::pair<size_t, size_t> ivf_pq_build_mem_usage( | |
| + (sizeof(float) + sizeof(int64_t)) * top_k); // refined_* | ||
|
|
||
| // Phases run sequentially (train/extend -> search -> optimize) | ||
| size_t total_dev = std::max({kmeans_gpu_mem, search_phase_dev, gpu_workspace_size}); | ||
| size_t total_dev = | ||
| std::max({kmeans_gpu_mem, search_phase_dev, gpu_workspace_size, create_index_gpu_mem}); | ||
|
|
||
| // The graph (and its optimize workspace) stays resident across phases | ||
| size_t total_host = | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.