-
Notifications
You must be signed in to change notification settings - Fork 22
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
Improve performance of dnp.nan_to_num
#2228
Merged
antonwolfy
merged 18 commits into
IntelPython:master
from
ndgrigorian:improve-nan-to-num-performance
Feb 5, 2025
Merged
Improve performance of dnp.nan_to_num
#2228
antonwolfy
merged 18 commits into
IntelPython:master
from
ndgrigorian:improve-nan-to-num-performance
Feb 5, 2025
+770
−19
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
antonwolfy
reviewed
Dec 10, 2024
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
antonwolfy
reviewed
Dec 10, 2024
48f623b
to
0693c0b
Compare
0693c0b
to
50c28f7
Compare
0c6d3f8
to
54dfaf5
Compare
5d19afb
to
d1fb595
Compare
1ac1288
to
3c66551
Compare
antonwolfy
reviewed
Feb 5, 2025
antonwolfy
reviewed
Feb 5, 2025
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
Use std::conditional and value_type_of_t struct to avoid constexpr branches with redundant code
* nan_to_num_call -> nan_to_num_strided_call * add missing const markers on converted Python scalar objects
3c66551
to
99fd28b
Compare
antonwolfy
reviewed
Feb 5, 2025
dpnp/backend/extensions/ufunc/elementwise_functions/nan_to_num.cpp
Outdated
Show resolved
Hide resolved
antonwolfy
approved these changes
Feb 5, 2025
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.
Thank you @ndgrigorian, no more comments from me
Great, feel free to merge at your convenience |
Also, for posterity, the tests all pass on CUDA |
github-actions bot
added a commit
that referenced
this pull request
Feb 5, 2025
This PR adds a dedicated kernel for `dnp.nan_to_num` to improve its performance. This reduces the number of kernel calls to at most one in all cases. A kernel for both strided and contiguous inputs have been added, to avoid additional allocation of device memory for trivial strides when input is fully C- or F-contiguous. For example of performance gains, using Max GPU master: ```python In [1]: import dpnp as dnp In [2]: import numpy as np In [3]: x_np = np.random.randn(10**9) In [4]: x_np[np.random.choice(x_np.size, 200, replace=False)] = np.nan In [5]: x = dnp.asarray(x_np) In [6]: q = x.sycl_queue In [7]: %time r = dnp.nan_to_num(x); q.wait() CPU times: user 394 ms, sys: 43.8 ms, total: 438 ms Wall time: 304 ms In [8]: %time r = dnp.nan_to_num(x); q.wait() CPU times: user 333 ms, sys: 31.8 ms, total: 364 ms Wall time: 134 ms ``` on branch: ```python In [8]: %time r = dnp.nan_to_num(x); q.wait() CPU times: user 49.6 ms, sys: 8.1 ms, total: 57.7 ms Wall time: 60.9 ms In [9]: %time r = dnp.nan_to_num(x); q.wait() CPU times: user 22.9 ms, sys: 16 ms, total: 38.9 ms Wall time: 19.7 ms ``` 77702b3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a dedicated kernel for
dnp.nan_to_num
to improve its performance. This reduces the number of kernel calls to at most one in all cases.A kernel for both strided and contiguous inputs have been added, to avoid additional allocation of device memory for trivial strides when input is fully C- or F-contiguous.
For example of performance gains, using Max GPU
master:
on branch: