Skip to content

Commit 7c0b2b4

Browse files
committed
Backport PR rapidsai#6359
1 parent 2e85c91 commit 7c0b2b4

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

python/cuml/cuml/experimental/accel/__init__.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
from .magics import load_ipython_extension
2121

22+
from cuda.bindings import runtime
2223
from cuml.internals import logger
2324
from cuml.internals.global_settings import GlobalSettings
2425
from cuml.internals.memory_utils import set_global_output_type
25-
from cuml.internals.safe_imports import UnavailableError
26+
from cuml.internals.safe_imports import UnavailableError, gpu_only_import
27+
28+
rmm = gpu_only_import("rmm")
2629

2730
__all__ = ["load_ipython_extension", "install"]
2831

@@ -31,11 +34,38 @@ def _install_for_library(library_name):
3134
importlib.import_module(f"._wrappers.{library_name}", __name__)
3235

3336

34-
def install():
37+
def _is_concurrent_managed_access_supported():
38+
"""Check the availability of concurrent managed access (UVM).
39+
Note that WSL2 does not support managed memory.
40+
"""
41+
42+
# Ensure CUDA is initialized before checking cudaDevAttrConcurrentManagedAccess
43+
runtime.cudaFree(0)
44+
45+
device_id = 0
46+
err, supports_managed_access = runtime.cudaDeviceGetAttribute(
47+
runtime.cudaDeviceAttr.cudaDevAttrConcurrentManagedAccess, device_id
48+
)
49+
if err != runtime.cudaError_t.cudaSuccess:
50+
logger.error(
51+
f"Failed to check cudaDevAttrConcurrentManagedAccess with error {err}"
52+
)
53+
return False
54+
return supports_managed_access != 0
55+
56+
57+
def install(disable_uvm=False):
3558
"""Enable cuML Accelerator Mode."""
3659
logger.set_level(logger.level_enum.info)
3760
logger.set_pattern("%v")
3861

62+
if not disable_uvm:
63+
if _is_concurrent_managed_access_supported():
64+
logger.debug("cuML: Enabling managed memory...")
65+
rmm.mr.set_current_device_resource(rmm.mr.ManagedMemoryResource())
66+
else:
67+
logger.warn("cuML: Could not enable managed memory.")
68+
3969
logger.debug("cuML: Installing accelerator...")
4070
libraries_to_accelerate = ["sklearn", "umap", "hdbscan"]
4171
accelerated_libraries = []

python/cuml/cuml/experimental/accel/__main__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,22 @@
5454
default="converted_sklearn_model.pkl",
5555
help="Output path for the converted sklearn estimator file.",
5656
)
57+
@click.option(
58+
"--disable-uvm",
59+
is_flag=True,
60+
default=False,
61+
help="Disable UVM (managed memory) allocations.",
62+
)
5763
@click.option(
5864
"-v",
5965
"--verbose",
6066
count=True,
6167
help="Increase output verbosity (can be used multiple times, e.g. -vv). Default shows warnings only.",
6268
)
6369
@click.argument("args", nargs=-1)
64-
def main(module, strict, convert_to_sklearn, format, output, verbose, args):
70+
def main(
71+
module, convert_to_sklearn, format, output, disable_uvm, verbose, args
72+
):
6573
default_logger_level_index = list(logger.level_enum).index(
6674
logger.level_enum.warn
6775
)
@@ -70,7 +78,7 @@ def main(module, strict, convert_to_sklearn, format, output, verbose, args):
7078
logger.set_level(logger_level)
7179
logger.set_pattern("%v")
7280

73-
install()
81+
install(disable_uvm=disable_uvm)
7482

7583
# If the user requested a conversion, handle it and exit
7684
if convert_to_sklearn:

0 commit comments

Comments
 (0)