Skip to content
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

Add available_device_memory to fetch free amount of memory on a GPU #1567

Merged
merged 11 commits into from
Jun 4, 2024
9 changes: 8 additions & 1 deletion python/rmm/rmm/_lib/memory_resource.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1188,3 +1188,10 @@ def get_log_filenames():
else None
for i, each_mr in _per_device_mrs.items()
}


def get_free_device_memory():
"""
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
Return the number of bytes of available device memory.
"""
return percent_of_free_device_memory(percent)
4 changes: 3 additions & 1 deletion python/rmm/rmm/mr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@
enable_logging,
get_current_device_resource,
get_current_device_resource_type,
get_free_device_memory,
get_log_filenames,
get_per_device_resource,
get_per_device_resource_type,
Expand Down Expand Up @@ -65,6 +66,7 @@
"get_current_device_resource",
"get_per_device_resource_type",
"get_current_device_resource_type",
"get_free_device_memory",
"get_log_filenames",
"is_initialized",
]
7 changes: 7 additions & 0 deletions python/rmm/rmm/tests/test_rmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,3 +1002,10 @@ def test_invalid_logging_level(level):
rmm.set_flush_level(level)
with pytest.raises(TypeError):
rmm.should_log(level)


def test_get_free_device_memory():
from rmm._lib.memory_resource import get_free_device_memory

memory = get_free_device_memory()
assert memory != 0
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
Loading