Skip to content

Commit

Permalink
Ensure managed memory is supported in cudf.pandas.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Aug 13, 2024
1 parent cf3fabf commit 60e0621
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/cudf/cudf/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
import warnings

from cuda import cudart

import rmm.mr

from cudf._lib import pylibcudf
Expand All @@ -26,6 +28,27 @@
}


def _ensure_managed_memory_is_supported(rmm_mode):
# WSL does not support managed memory. We raise if the user requests
# managed memory on a system that does not support it.
if "managed" in rmm_mode:
# Ensure CUDA is initialized before checking cudaDevAttrConcurrentManagedAccess
cudart.cudaFree(0)

device_id = 0
err, supports_managed_access = cudart.cudaDeviceGetAttribute(
cudart.cudaDeviceAttr.cudaDevAttrConcurrentManagedAccess, device_id
)
if err != cudart.cudaError_t.cudaSuccess:
raise RuntimeError(
f"Failed to check cudaDevAttrConcurrentManagedAccess with error {err}"
)
if supports_managed_access == 0:
raise ValueError(
f"Managed memory is unsupported on this system, so {rmm_mode=} is not allowed."
)


def _enable_managed_prefetching(rmm_mode):
if "managed" in rmm_mode:
for key in _SUPPORTED_PREFETCHES:
Expand All @@ -50,6 +73,8 @@ def install():
)
return

_ensure_managed_memory_is_supported(rmm_mode)

free_memory, _ = rmm.mr.available_device_memory()
free_memory = int(round(float(free_memory) * 0.80 / 256) * 256)
new_mr = current_mr
Expand Down

0 comments on commit 60e0621

Please sign in to comment.