-
Notifications
You must be signed in to change notification settings - Fork 231
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
builtins: Add devito version of NumPy's count_nonzero, nonzero #1815
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1815 +/- ##
==========================================
- Coverage 89.56% 89.54% -0.02%
==========================================
Files 209 209
Lines 34381 34440 +59
Branches 5198 5201 +3
==========================================
+ Hits 30793 30841 +48
- Misses 3098 3107 +9
- Partials 490 492 +2
Continue to review full report at Codecov.
|
00f0294
to
eb752c9
Compare
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.
Numpy's version is faster unless we change to collapse(1)
you may use the par-collapse
opt-option also
But anyway, if you write it as a built-in, I don't see how you can glue it with a compiler pass, unless you copy-paste the equation definition?
727fb1e
to
ebcadf3
Compare
Yes, though I am still thinking about the best way for doing that. |
ebcadf3
to
b9f62f6
Compare
b7abe2a
to
e3aac66
Compare
Yes, since it will be added as part of the pass, we will need to use the equations of it. However, are we opposed to having devito versions of this? |
e3aac66
to
908166c
Compare
devito/builtins/arithmetic.py
Outdated
eqi = dv.Eq(i, 0) | ||
|
||
eq0 = dv.Inc(g[i], 1, implicit_dims=(f.dimensions + (ci,))) | ||
op0 = dv.Operator([eqi, eq0], opt=('openmp', {'par-collapse-ncores': 30})) |
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.
Is this really the most efficient way to compute this?
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.
wrt par-collpase?
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.
No I mean the equation + conditional but I guess not really simpler way.
908166c
to
87695b4
Compare
Where would this be used? And when you say faster does it count the code-generation overhead because it would re-generate the operator at each call so numpy is still probably more efficient. |
Sorry to reply late Mathias. With regards to the use, maybe it is not needed anymore for the time-tiling work, since I can use this: https://github.com/devitocodes/devito/pull/1817/files#diff-2da23b1e569f0f2b184634790719bca628a15fdd92739ddf6e9f0452e5b9bc6eR614 wrt to efficiency I admit I did not check the operator generation. The question is: Since we probably do not need this functionality, I am thinking of whether this can be an enhancement/tutorial of how to use conditional dimension? Thoughts @FabioLuporini ? |
@georgebisbas perhaps you can extend the existing notebook about ConditionalDimensions with one/two/three cells showing this additional example? probably this PR can be closed though? |
I agree. |
Add a Devito version of NumPy's count_nonzero, nonzero:
https://numpy.org/doc/stable/reference/generated/numpy.count_nonzero.html
This PR is needed towards implementing steps 1,2 of p4 in https://arxiv.org/pdf/2010.10248.pdf.
In the paper, I was using NumPy, but now to automate through Devito, I would like to generate it through Devito.
Numpy's version is faster unless we change to collapse(1). Then Devito is faster for like int32 (20000, 20000) sized functions.
If reviewers require more benchmarking, happy to do so.
Generated code is like: