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

CuPy vs Numpy backends performance question. How to call them properly? #138

Open
XarlesMicro opened this issue Mar 8, 2024 · 0 comments

Comments

@XarlesMicro
Copy link

@JoOkuma I am wondering if this is the proper wayof calling the back ends, as you kindly explained in this issue. I would like to measure the performance of the Numpy vs. Cupy backends. in other words a process based exclusively on CPU vs the boost in performance using the CuPy GPU backend. I am posting the code I used to generate this test. I have a 32x speed increase using the Cupy backend (uhuu!!!). I want to make sure I am not missing something. The results (see below) indicate that I effectively was using Numpy vs Cupy backends "effectively". Nevertheless I observed a spike of function in my GPU using the Numpy backend. I was expecting that the Numpy backend was exclusively CPU based. Did I understood this wrong?

Results:

Yang <<CupyBackend>> Deskewing completed. Execution Time: 0.5733585357666016 seconds
├ Number of free blocks before and after release: 4->0, used: 0.055 GBs -> 0.055 GBs, total:0.055 GBs
Yang <<NumpyBackend>> Deskewing completed. Execution Time: 19.52552628517151 seconds

Code

from dexp.utils.backends import CupyBackend, NumpyBackend
import dexp
from tifffile import imread
import numpy as np
from dexp.processing.deskew import yang_deskew
import time

def main():
    path2img = 'C:\\Python\\Tilt_Calibration_by_Sphere_deskew\\20240207_agoSlide_sphere_8_1_MMStack_Pos0.ome.tif' 
    RawImage = imread(path2img)
    RotatedImage = np.transpose(RawImage, axes=(0, 2, 1)).copy()
    dz_pixel = 1.0
    test_angle = 45
    dz_stage = dz_pixel / np.sin(np.deg2rad(test_angle))

    backends = [CupyBackend, NumpyBackend]
    for backend in backends:
        with backend() as bkd:
            array = bkd.to_backend(RotatedImage)
            start_time = time.time()
            array_out = dexp.processing.deskew.yang_deskew(array,
                depth_axis=0,
                lateral_axis=2,
                flip_depth_axis=0,
                dx=0.175,
                dz=dz_stage,
                angle=45,
                camera_orientation=0,
                num_split=1,
                internal_dtype=None,
                padding=None)
            end_time = time.time()
            print(f"Yang <<{backend.__name__}>> Deskewing completed. Execution Time:", end_time - start_time, "seconds")
            array_out = bkd.to_numpy(array_out)

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant