Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Yiheng Wang <[email protected]>
  • Loading branch information
yiheng-wang-nv committed Dec 17, 2024
1 parent acf2cba commit e5d7907
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io
import os
import re
import tempfile
import warnings
from abc import ABC, abstractmethod
from collections.abc import Callable, Iterable, Iterator, Sequence
Expand Down Expand Up @@ -909,9 +910,30 @@ def __init__(
)
to_gpu = False

if to_gpu:
self.warmup_kvikio()

self.to_gpu = to_gpu
self.kwargs = kwargs

def warmup_kvikio(self):
"""
Warm up the Kvikio library to initialize the internal buffers, cuFile, GDS, etc.
This can accelerate the data loading process when `to_gpu` is set to True.
"""
if has_cp and has_kvikio:
print("warm up")
a = cp.arange(100)
with tempfile.NamedTemporaryFile() as tmp_file:
tmp_file_name = tmp_file.name
f = kvikio.CuFile(tmp_file_name, "w")
f.write(a)
f.close()

b = cp.empty_like(a)
f = kvikio.CuFile(tmp_file_name, "r")
f.read(b)

def verify_suffix(self, filename: Sequence[PathLike] | PathLike) -> bool:
"""
Verify whether the specified file or files format is supported by Nibabel reader.
Expand Down Expand Up @@ -961,6 +983,9 @@ def get_data(self, img) -> tuple[np.ndarray, dict]:
img: a Nibabel image object loaded from an image file or a list of Nibabel image objects.
"""
# TODO: the actual type is list[np.ndarray | cp.ndarray]
# should figure out how to define correct types without having cupy not found error
# https://github.com/Project-MONAI/MONAI/pull/8188#discussion_r1886645918
img_array: list[np.ndarray] = []
compatible_meta: dict = {}

Expand Down

0 comments on commit e5d7907

Please sign in to comment.