-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
Conversation
In particular, the reassignment of `res_cpu` made things a bit confusing.
if cupy_run: | ||
xp = cp.get_array_module(data) | ||
else: | ||
import numpy as xp | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
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.