Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cpp/src/utilities/cuda_helpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

#include <utilities/macros.cuh>

#include <cuda/memory_resource>

#include <thrust/host_vector.h>
#include <thrust/tuple.h>
#include <algorithm>
#include <mutex>
#include <raft/core/device_span.hpp>
#include <raft/util/cuda_utils.cuh>
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>
#include <rmm/mr/limiting_resource_adaptor.hpp>
#include <rmm/mr/per_device_resource.hpp>
#include <shared_mutex>
#include <unordered_map>

Expand Down Expand Up @@ -242,7 +247,19 @@ inline size_t get_device_memory_size()
{
size_t free_mem, total_mem;
RAFT_CUDA_TRY(cudaMemGetInfo(&free_mem, &total_mem));
// TODO (bdice): Restore limiting adaptor check after updating CCCL to support resource_cast

auto res = rmm::mr::get_current_device_resource_ref();
auto limiting_adaptor = cuda::mr::resource_cast<rmm::mr::limiting_resource_adaptor>(&res);
if (limiting_adaptor) {
printf("limiting_adaptor->get_allocation_limit(): %fMiB\n",
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.

Remove the printf

limiting_adaptor->get_allocation_limit() / (double)1e6);
printf("used_mem: %fMiB\n", limiting_adaptor->get_allocated_bytes() / (double)1e6);
printf("free_mem: %fMiB\n",
(limiting_adaptor->get_allocation_limit() - limiting_adaptor->get_allocated_bytes()) /
(double)1e6);
Comment on lines +254 to +259
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix unit mismatch in memory diagnostics.

Line 254, Line 256, and Line 257 label values as MiB but divide by 1e6 (MB). Use 1024.0 * 1024.0 or relabel to MB.

Suggested patch
-    printf("limiting_adaptor->get_allocation_limit(): %fMiB\n",
-           limiting_adaptor->get_allocation_limit() / (double)1e6);
-    printf("used_mem: %fMiB\n", limiting_adaptor->get_allocated_bytes() / (double)1e6);
+    constexpr double bytes_per_mib = 1024.0 * 1024.0;
+    printf("limiting_adaptor->get_allocation_limit(): %fMiB\n",
+           limiting_adaptor->get_allocation_limit() / bytes_per_mib);
+    printf("used_mem: %fMiB\n", limiting_adaptor->get_allocated_bytes() / bytes_per_mib);
     printf("free_mem: %fMiB\n",
-           (limiting_adaptor->get_allocation_limit() - limiting_adaptor->get_allocated_bytes()) /
-             (double)1e6);
+           (limiting_adaptor->get_allocation_limit() - limiting_adaptor->get_allocated_bytes()) /
+             bytes_per_mib);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
printf("limiting_adaptor->get_allocation_limit(): %fMiB\n",
limiting_adaptor->get_allocation_limit() / (double)1e6);
printf("used_mem: %fMiB\n", limiting_adaptor->get_allocated_bytes() / (double)1e6);
printf("free_mem: %fMiB\n",
(limiting_adaptor->get_allocation_limit() - limiting_adaptor->get_allocated_bytes()) /
(double)1e6);
constexpr double bytes_per_mib = 1024.0 * 1024.0;
printf("limiting_adaptor->get_allocation_limit(): %fMiB\n",
limiting_adaptor->get_allocation_limit() / bytes_per_mib);
printf("used_mem: %fMiB\n", limiting_adaptor->get_allocated_bytes() / bytes_per_mib);
printf("free_mem: %fMiB\n",
(limiting_adaptor->get_allocation_limit() - limiting_adaptor->get_allocated_bytes()) /
bytes_per_mib);
🤖 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/utilities/cuda_helpers.cuh` around lines 254 - 259, The printed
memory diagnostics use the label "MiB" but divide by 1e6 (decimal MB); update
the three printf calls that reference limiting_adaptor->get_allocation_limit()
and limiting_adaptor->get_allocated_bytes() to divide by 1024.0 * 1024.0 (or use
a named constant like BYTES_PER_MIB) so the units correctly reflect mebibytes,
and keep the "MiB" labels unchanged.

return std::min(total_mem, limiting_adaptor->get_allocation_limit());
}

return total_mem;
}

Expand Down
Loading