question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow single precision operation in the cupyx.scipy.ndimage module

See original GitHub issue

allow single-precision computations in cupyx.scipy.ndimage

I opened this PR to discuss the potential for performing computations in single precision in cupyx.scipy.ndimage functions when the input is single precision. Currently, the internal weights arrays used in the convolution function, etc. are always np.float64, which does match the internal use of double precision in scipy.ndimage. However, to improve performance and reduce memory usage, it would be preferable to use single precision for the computations when possible.

A similar exception was made previously for cupy.fft where inputs are NOT automatically promoted to double precision as in NumPy.

I see three ways this can potentially be done (I am willing to make the necessary changes, but need to know what approach would be preferred).

  • automatically promote types to at least float32 via: cp.promote_types(image, cupy.float32) instead of just using cupy.float64 everywhere (e.g. for the weights arrays in convolution)
  • leave the default internal floating point type float64, unless a boolean keyword-only argument (e.g. allow_float32) is specified
  • add a global cupy configuration variable to control whether single-precision computation is allowed within the cupyx.scipy.ndimage module

related issue: complex dtype support

A separate consideration is adding support for complex-valued inputs. I have open PRs for this in SciPy for the filtering and interpolation functions (scipy/scipy#12725 and scipy/scipy#12812). Hopefully those will be merged for SciPy 1.6.0 and then we can revisit adding complex support here.

cc: @jakirkham, @quasiben

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jakirkhamcommented, Nov 11, 2020

I don’t think there is an equivalent issue related to single-precision open on SciPy. For SciPy itself, I think the argument is less compelling because the amount of work required would be substantial and the performance benefits of single precision may not be substantial.

Ah right. Sorry forgot this.

It may still be worth adding an issue even if it is closed out as unfeasible or lingerings for time. At least that will make this issue more visible to others who may care about the performance improvement.

1reaction
grlee77commented, Nov 27, 2020

~I don’t think there is an equivalent issue related to single-precision open on SciPy.~ There is an issue scipy/scipy#8495. For SciPy itself, I think the argument is less compelling because the amount of work required would be substantial and the performance benefits of single precision may not be substantial.

As an example, many C functions copy lines to buffers that are double precision and the temporary variable holding the convolution result is double, etc. Adding templating would make the source C code harder to read and a rewrite to templated C++ would be a lot of work.

On the CuPy side the kernel C++ code is generated on the fly, so it is minimal effort to support single and/or complex dtypes as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CuPy Documentation - Read the Docs
Multidimensional Image Processing (cupyx.scipy.ndimage.*) ... Kernel Fusion: Fuse multiple CuPy operations into a single CUDA kernel.
Read more >
Multidimensional image processing (cupyx.scipy.ndimage)
One -dimensional Gaussian filter along the given axis. ... Generate a binary structure for binary morphological operations.
Read more >
Accelerating Scikit-Image API with cuCIM: n-Dimensional ...
cuCIM is a new RAPIDS library for accelerated n-dimensional image processing and image I/O. The project is now publicly available under a ...
Read more >
Using the Single-Precision Floating-Point Data Type - NI
This conversion is useful in situations where you want to operate on data from multiple inputs that return different fixed-point data types. The ......
Read more >
GPU Programming - The Carpentries Incubator
Using NumPy, we first need to create an array of random single precision ... Now on the GPU from cupyx.scipy.ndimage import center_of_mass as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found