gputools - OpenCL accelerated volume processing in Python
GPU accelerated 2D/3D image processing, e.g. for microscopy, via OpenCL (i.e. works on both NVIDIA and non-NVIDIA devices).
- convolutions
- denoising
- synthetic noise
- ffts (simple wrapper around reikna)
- affine transforms
Built on the excellent pyopencl bindings.
Some examples of processing tasks and their respective runtime (tests/benchmark/benchmark.py):
| Task | Image Size/type | CPU[1] | GPU[2] | GPU (w/o transfer) |
|---|---|---|---|---|
| Mean filter 7x7x7 | (128, 1024, 1024) uint8 | 1708 ms | 22 ms | 5 ms |
| Median filter 3x3x3 | (128, 1024, 1024) uint8 | 37591 ms | 49 ms | 31 ms |
| Gaussian filter 5x5x5 | (128, 1024, 1024) float32 | 4536 ms | 86 ms | 19 ms |
| Zoom/Scale 2x2x2 | (128, 1024, 1024) uint8 | 18433 ms | 133 ms | - |
| NLM denoising | (64, 256, 256) float32 | 21109 ms | 105 ms | - |
| FFT (pow2) | (128, 1024, 1024) complex64 | 3418 ms | 156 ms | 21 ms |
[1] AMD Ryzen Threadripper PRO 9965WX
[2] NVIDIA GeForce RTX 5090
Requirements
- Python 3.9+
- a working OpenCL environment (check with
clinfo).
Installation
pip install gputools
Or the development version:
pip install git+https://github.com/maweigert/gputools
Check if basic stuff is working:
python -m gputools
Troubleshooting
If you experience installation issues, this might be due to pyopencl not
being properly installed. The easiest way to get a working pyopencl is via conda:
conda install -c conda-forge pyopencl
Usage
Docs are still to be done ;)
Most of the methods work on both numpy arrays or GPU memory objects (gputools.OCLArrays/OCLImage). The latter saving the memory transfer (which e.g. for simple convolutions accounts for the main run time)
Convolutions
- 2D-3D convolutions
- separable convolutions
- fft based convolution
- spatially varying convolutions
import gputools
d = np.zeros((128,128), np.float32)
d[64,64] = 1.
h = np.ones((17,17))
res = gputools.convolve(d,h)
d = np.zeros((128,128,128), np.float32)
d[64,64,64] = 1.
hx,hy,hz = np.ones(7),np.ones(9),np.ones(11)
res = gputools.convolve_sep3(d,hx,hy,hz)
Denoising
bilateral filter, non local means
...
d = np.zeros((128,128,128), np.float32)
d[50:78,50:78,50:78:2] = 4.
d = d+np.random.normal(0,1,d.shape)
res_nlm = gputools.denoise.nlm3(d,2.,2,3)
res_bilat = gputools.denoise.bilateral3(d,3,4.)
Perlin noise
fast 2d and 3d perlin noise calculations
gputools.perlin3(size = (256,256,256), scale = (10.,10.,10.))
Transforms
scaling, translate, rotate, affine...
gputools.transforms.scale(d,.2)
gputools.transforms.rotate(d,axis = (64,64,64),angle = .3)
gputools.transforms.shift(d,(10,20,30))
...
fft
wraps around reikna
gputools.fft(d)
gputools.fft(d, inverse = True)
Configuration
Some configuration data (e.g. the default OpenCL platform and devic) can be changed in the config file "~/.gputools" (create it if necessary)
#~/.gputools
id_platform = 0
id_device = 1
See
gputools.config.defaults
for available keys and their defaults.
Alternatively, the used OpenCL Device can be set via the environment variables gputools_id_device, gputools_id_platform, and gputools_use_gpu (variables present in the config file will take precendence, however).
Metadata
Release files for gputools 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gputools-0.3.1.tar.gz | 89.3 kB | Without provenance | Details for gputools-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gputools-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for gputools-0.3.1-py3-none-any.whl |
Total release size: 206.6 kB
Release files / gputools-0.3.1.tar.gz
| Download URL | gputools-0.3.1.tar.gz |
|---|---|
| Size | 89.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc01a320dbecb022bddf75749467b61ff5bf7abeef50b93de2e06ccd84fe2c02
|
|
BLAKE2b-256 checksum How to use checksums |
4d76a10eb303f8a35fe2a117e260a5d129279f0d18e6fd3eb759500b41b26994
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / gputools-0.3.1-py3-none-any.whl
| Download URL | gputools-0.3.1-py3-none-any.whl |
|---|---|
| Size | 117.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
030534191cf6ed8c012403edf1702f797696f0a4b067d8bb19358d8fd2385a8d
|
|
BLAKE2b-256 checksum How to use checksums |
2cd2d7e5db97007b741ab9207ae953f93be3968ee7cf9acd61e033728c821a22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for gputools 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.