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

Rescale to int cpu/gpu agnostic #157

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Rescale to int cpu/gpu agnostic #157

wants to merge 8 commits into from

Conversation

dkazanc
Copy link
Collaborator

@dkazanc dkazanc commented Sep 20, 2024

CPU-GPU rescale_to_int function. All tests modified to compare the results of CPU with GPU results.

I discovered that the GPU function accepts only float32 array as an input yet the CPU one can accept any data type (because of the cast to float64). The GPU implementation is significantly more memory efficient because of the elementwise loop and casting scalars instead of arrays compared to Python one-liners.

So far I don't see the reason to satisfy other data type inputs, however, in future we might work with uint16 then this code must be adapted accordingly.

I'll modify image saver in here accordingly, we need to remove redundant parameters.

@dkazanc dkazanc changed the title Rescale cpu/gpu agnostic Rescale to int cpu/gpu agnostic Sep 20, 2024
Comment on lines +80 to +84
if cupy_run:
xp = cp.get_array_module(data)
else:
import numpy as xp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that cp.get_array_module() is intended to return either the cupy or numpy module depending on if any of the given args require cupy, I would have thought that doing simply

xp = cp.get_array_module(data)

would work.

If I do that locally and run the tests they all pass, which suggests that it does work without the if/else.

I do understand though that the CPU/GPU agnostic stuff can be tricky and that there may be other factors at play here, so I wanted to ask: is there some reason I'm unaware of that the if/else is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the true GPU-less case, so then cp.get_array_module(data) won't be possible without the condition. This makes sure that this can be run on the CPU arch alone.

@yousefmoazzam
Copy link
Contributor

Apologies for the broken IRIS CI job, it looks like maybe IRIS isn't happy, the conda env failed to be created... https://github.com/DiamondLightSource/httomolibgpu/actions/runs/11052312862/job/30704122840?pr=157

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

Successfully merging this pull request may close these issues.

2 participants