Skip to content

Commit

Permalink
Use cupy to measure memory leak (#777)
Browse files Browse the repository at this point in the history
While adding support for Python 3.12 in #773, we found a problem where `GPUtil` does not support Python 3.12 (#775).

This PR removes the dependency on `GPUtil` and replaces it with `cupy`, which is already a dependency.

Closes #775. Closes #776.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - James Lamb (https://github.com/jameslamb)
  - Gregory Lee (https://github.com/grlee77)
  - Gigon Bae (https://github.com/gigony)

URL: #777
  • Loading branch information
bdice committed Sep 6, 2024
1 parent 1584885 commit 73e6d93
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ channels:
- conda-forge
- nvidia
dependencies:
- GPUtil>=1.4.0
- c-compiler
- click
- cmake>=3.26.4,!=3.30.0
Expand Down
1 change: 0 additions & 1 deletion conda/environments/all_cuda-125_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ channels:
- conda-forge
- nvidia
dependencies:
- GPUtil>=1.4.0
- c-compiler
- click
- cmake>=3.26.4,!=3.30.0
Expand Down
1 change: 0 additions & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ dependencies:
common:
- output_types: [conda, requirements, pyproject]
packages:
- GPUtil>=1.4.0
- psutil>=5.8.0
- pytest>=6.2.4,<8.0.0a0
- pytest-cov>=2.12.1
Expand Down
1 change: 0 additions & 1 deletion python/cucim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Tracker = "https://github.com/rapidsai/cucim/issues"

[project.optional-dependencies]
test = [
"GPUtil>=1.4.0",
"imagecodecs>=2021.6.8; platform_machine=='x86_64'",
"matplotlib",
"numpydoc>=1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
#

import cupy as cp
import pytest

from ...util.io import open_image_cucim
Expand All @@ -22,23 +23,24 @@


def test_read_region_cuda_memleak(testimg_tiff_stripe_4096x4096_256_jpeg):
import GPUtil

gpus = GPUtil.getGPUs()

if len(gpus) == 0:
def get_used_gpu_memory_mib():
"""Get the used GPU memory in MiB."""
dev = cp.cuda.Device()
free, total = dev.mem_info
memory_used = (total - free) / (2**20)
return memory_used

num_gpus = cp.cuda.runtime.getDeviceCount()
if num_gpus == 0:
pytest.skip("No gpu available")

img = open_image_cucim(testimg_tiff_stripe_4096x4096_256_jpeg)

gpu = gpus[0]
mem_usage_history = [gpu.memoryUsed]
mem_usage_history = [get_used_gpu_memory_mib()]

for i in range(10):
_ = img.read_region(device="cuda")
gpus = GPUtil.getGPUs()
gpu = gpus[0]
mem_usage_history.append(gpu.memoryUsed)
mem_usage_history.append(get_used_gpu_memory_mib())

print(mem_usage_history)

Expand Down

0 comments on commit 73e6d93

Please sign in to comment.