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

Reuse dpnp.nan_to_num in dpnp.nansum and dpnp.nanprod #2339

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ndgrigorian
Copy link
Collaborator

@ndgrigorian ndgrigorian commented Feb 25, 2025

This PR proposes the use of nan_to_num over _replace_nan in nansum, nanprod, nancumsum, and nancumprod using new internal function _replace_nan_no_mask.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you filing the PR as a draft?

Copy link
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2339/index.html

@coveralls
Copy link
Collaborator

coveralls commented Feb 25, 2025

Coverage Status

coverage: 71.919% (+0.002%) from 71.917%
when pulling 40af29a on reuse-nan-to-num-nan-fns
into 2bb1e8b on master.

Copy link
Contributor

github-actions bot commented Feb 25, 2025

Array API standard conformance tests for dpnp=0.18.0dev0=py312he4f9c94_10 ran successfully.
Passed: 1006
Failed: 0
Skipped: 16

@ndgrigorian
Copy link
Collaborator Author

This relatively simple and non-invasive change improves performance significantly. On Max GPU

before:

In [1]: import dpnp

In [2]: x = dpnp.ones(3*10**8, dtype="f4")

In [3]: q = x.sycl_queue

In [4]: %timeit r = dpnp.nansum(x); q.wait()
9.37 ms ± 33.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [5]: %timeit r = dpnp.nansum(x); q.wait()
9.42 ms ± 18.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [6]: x = dpnp.ones(10**8, dtype="f4")

In [7]: %timeit r = dpnp.nansum(x); q.wait()
4.5 ms ± 8.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [8]: %timeit r = dpnp.nansum(x); q.wait()
4.51 ms ± 11 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

after:

In [1]: import dpnp

In [2]: x = dpnp.ones(3*10**8, dtype="f4")

In [3]: q = x.sycl_queue

In [4]: %timeit r = dpnp.nansum(x); q.wait()
6.5 ms ± 24.5 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [5]: %timeit r = dpnp.nansum(x); q.wait()
6.47 ms ± 35.7 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [6]: x = dpnp.ones(10**8, dtype="f4")

In [7]: %timeit r = dpnp.nansum(x); q.wait()
2.78 ms ± 14.3 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [8]: %timeit r = dpnp.nansum(x); q.wait()
2.78 ms ± 14 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

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.

3 participants