TomographicImaging / CCPi-Regularisation-Toolkit

The set of CPU/GPU optimised regularisation modules for iterative image reconstruction and other image processing tasks
Apache License 2.0
49 stars 25 forks source link

Remove the Cython layer and use ctypes #183

Closed paskino closed 5 months ago

paskino commented 5 months ago

Removes the Cython layer in favour of ctypes. My aim has been to generally maintain the user experience however, this change is backward incompatible.

New functionality

In python it is possible now to pass to each function an out parameter for the regulariser to store the result. This was earlier not possible and the output was always allocated in the Cython layer. The output is also always returned, remaining backward compatible.

Backward incompatibilities

infovector

The infovector, a vector of 2 floats with information on whether the algorithm stopped having reached a certain tolerance, is never returned. To access the infovector the user needs to pass the function a preallocated vector with the key-worded parameter infovector.

device

Most of the functions have a OpenMP and CUDA version (CPU and GPU). The user could earlier specify which one to use with the positional parameter device. To remove lots of boilerplate code, device is now a key-worded argument because the C functions are wrapped in Python by the function below and, the positional parameters of each function are different, so I am never sure where device really is.

At any rate I believe this change adds clarity and the default is device="cpu".

https://github.com/vais-ral/CCPi-Regularisation-Toolkit/blob/739e52af5542b2debb94ddfab0bce0901e7f2aae/src/Python/ccpi/filters/regularisers.py#L19-L32

PD_TV positional parameter order

I changed the parameter order of the PD_TV to reflect the underlying C/CUDA implementation.

dkazanc commented 5 months ago

thanks @paskino for looking into this. I think dropping Cython in favour of Ctypes is probably for the best here. Happy to contribute at some point, I was thinking of integrating more rigorous unit testing as well.

We are planning to use some CuPy wrapped functions in production from the toolkit, so it is worth looking into how both cupy and cuda parts can be added in one conda build. I can do that later when the build is actually works. cheers