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

Use memoryviews and allow nogil in gradient search #455

Merged
merged 2 commits into from
Nov 7, 2022

Conversation

mraspaud
Copy link
Member

@mraspaud mraspaud commented Sep 21, 2022

This PR uses moryviews and allows nogil in gradient search

@mraspaud mraspaud self-assigned this Sep 21, 2022
@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Merging #455 (8ba117b) into main (8da4081) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #455   +/-   ##
=======================================
  Coverage   94.28%   94.28%           
=======================================
  Files          69       69           
  Lines       12388    12388           
=======================================
  Hits        11680    11680           
  Misses        708      708           
Flag Coverage Δ
unittests 94.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.13% when pulling 8ba117b on mraspaud:feature-nogil-gradient into 8da4081 on pytroll:main.

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment, but otherwise if it compiles and works then 👍

Might be nice in the future to not have to do np.full everywhere or if they are intermediate arrays use C-level buffers/arrays, but that's in the future.

Comment on lines +122 to +123
image = np.full([z_size, y_size, x_size], np.nan, dtype=DTYPE)
cdef DTYPE_t [:, :, :] image_view = image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may benefit from defining these as [:, :, ::1] when you know they are C contiguous. This does (from my experience) require all arguments where this is passed to also define their arguments as [:, :, ::1] which seems dumb to me but anyway...

My understanding is that cython can make better indexing and for looping choices when it knows that everything is contiguous (makes sense).

@djhoese
Copy link
Member

djhoese commented Sep 21, 2022

Do you have a plot of the differences? Dask diagnostics plot if you can

@mraspaud
Copy link
Member Author

TBH, I can't see any difference. My guess is that somehow the gil was already released...
before the change (so not releasing the gil?)
withgil
after the change (releasing the gil?)
nogil

@djhoese
Copy link
Member

djhoese commented Sep 26, 2022

It might be easier to see if you do multiple datasets at the same time? Like running a satpy Scene with multiple bands loaded and all being resampled at the same time. Actually yeah, if the nogil sections you have now are all run serially for the most part then dask may be making it look like high CPU usage. You could also try passing 0.2 to your ResourceProfiler to get more data points on the CPU/memory graph since it looks like it is only every half second and your total processing time isn't that long.

...or you forgot to recompile between tests.

@mraspaud
Copy link
Member Author

I did recompile! Checking now with other settings

@mraspaud
Copy link
Member Author

Tried with 3 composites, a bigger destination area, the setting was already to dt=0.25. The results are marginally better without gil.
before this PR
withgil
after this PR
nogil

Next, I'm going to try with bigger data (was testing with seviri 3km0

@djhoese
Copy link
Member

djhoese commented Sep 26, 2022

Yeah that CPU line definitely looks better. The amount that it drops down still makes me think the chunk size could be larger (if the files are a good size for it).

@mraspaud
Copy link
Member Author

chunk size is 1024 in the previous examples

@pnuu
Copy link
Member

pnuu commented Sep 26, 2022

I guess the flat 100 % in the beginning is the Satpy file handler creation we've already discussed in pytroll/satpy#2186 ?

@mraspaud
Copy link
Member Author

I guess the flat 100 % in the beginning is the Satpy file handler creation we've already discussed in pytroll/satpy#2186 ?

yes, that looks like it. Far to long imo, we should look a that.

@djhoese
Copy link
Member

djhoese commented Oct 28, 2022

@mraspaud can you give more details on what your code and target AreaDefinition looked like for your last comment's plots? I'm wondering if we can come up with a case that shows a little more improvement.

@mraspaud
Copy link
Member Author

@djhoese that was seviri data full disk resampled onto a full earth mollweide:

moll:
  description: moll
  projection:
    ellps: WGS84
    lon_0: 0.0
    proj: moll
    lat_0: 0.0
  shape:
    height: 4500
    width: 9000
  area_extent:
    lower_left_xy: [-18040095.696147293, -9020047.848073646]
    upper_right_xy: [18040095.696147293, 9020047.848073646]
    units: m

then I tried with fci but got my computer to crash..

@djhoese
Copy link
Member

djhoese commented Oct 31, 2022

Trying it with ABI to a latlong projection (not the full data region). Before this PR:

image

After:

image

So I see better CPU usage and a faster run time by almost 30 seconds. This was generating a fully corrected true_color.

Note: This is using my "pass through" profiling where I just compute the chunks and throw them away (no saving to disk).

@djhoese
Copy link
Member

djhoese commented Oct 31, 2022

And for the record, here is the same thing with nearest:

image

But I also see "PerformanceWarning"s in the kd_tree.py module. But it took 3x as much memory and took longer than the before this PR case of gradient_search.

@djhoese
Copy link
Member

djhoese commented Oct 31, 2022

Pretty:

image

@mraspaud
Copy link
Member Author

mraspaud commented Nov 7, 2022

Thanks for trying it out @djhoese ! Should we merge?

@djhoese djhoese merged commit 5f53ecd into pytroll:main Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Release GIL in gradient search resampling
4 participants