Possible feature: add GPU Direct Storage Support for Nibabel
Hi Nibabel maintainers,
This is Yiheng Wang from NVIDIA, I did some research on how to use Kvikio + Nibabel to load .nii images into GPU directly, it helps accelerate the loading time especially on large (100MB+) images.
A solution is confirmed work:
- using kvikio to load .nii file as bytes from disk into gpu
- using nibabel to load headers of the file from disk into cpu
- parse bytes according to headers.
Related discussion: https://github.com/nipy/nibabel/discussions/1385
In the Kvikio side, I already added a related tutorial: https://github.com/rapidsai/kvikio/blob/branch-25.04/notebooks/medical_nifti_image_loading_example.ipynb
I'm wondering if it can be a feature directly in nibabel repo. What do you think?
cc @effigies
What would your proposed API be?
What would your proposed API be?
Hi @effigies , thanks for the question!
My simple thought is to add an arg for nibabel.loadsave.load, like:
load(filename: FileSpec, to_gpu: bool = False, **kwargs)
For gpu loading cases, if calling .get_fdata(), the achieved data will be a cupy array:
img = nib.load('path/to/your/file.nii', to_gpu=True)
data = img.get_fdata()
What do you think?