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

Move interpolation routines to pxd #2849

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

matthewturk
Copy link
Member

PR Summary

This moves some functions that are in C into a pxd file, and marks them as inline.

Why do this, you might ask? Good question! It turns out that on some compiler combinations, we got into a situation where marking the grid_traversal.pyx file as c++ resulted in a propagation of C++ that ended up with cross-C/C++ calls that were disallowed. Anyway, this fixes it!

What we should definitely keep an eye on is performance regressions.

PR Checklist

  • pass black --check yt/
  • pass isort . --check --diff
  • pass flake8 yt/
  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

@matthewturk matthewturk added refactor improve readability, maintainability, modularity viz: volume rendering labels Aug 12, 2020
@neutrinoceros
Copy link
Member

What's the reason for the line count diff ?

@matthewturk
Copy link
Member Author

I deleted the old .h and .c files.

Will have to figure out what's up with the grid traversal build failure on fido.

Xarthisius and others added 2 commits August 13, 2020 09:22
We need to have this be inside, and use pointers, so that we aren't
implicitly *executing* code or using *python* code in the pxd file.
@matthewturk
Copy link
Member Author

Real errors! Probably a mistake I made in my code, which I will address.

@cphyc
Copy link
Member

cphyc commented Sep 2, 2020

There doesn't seem to be significant performance implication, at least regarding isocontours extraction (we should double check the cost for volume rendering as well).
For reference:

With this PR:

[success] 62.27% yt.data_objects.tests.test_data_containers.TestDataContainers.test_extract_isocontours: 10.9075s
[success] 9.59% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_frb: 1.6794s
[success] 9.29% yt.data_objects.tests.test_data_containers.TestDataContainers.test_derived_field: 1.6276s
[success] 5.33% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_astropy_table: 0.9341s
[success] 3.53% yt.data_objects.tests.test_data_containers.TestDataContainers.test_std: 0.6182s
[success] 3.37% yt.data_objects.tests.test_data_containers.TestDataContainers.test_write_out: 0.5897s
[success] 3.35% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_dataframe: 0.5863s
[success] 3.27% yt.data_objects.tests.test_data_containers.TestDataContainers.test_yt_data_container: 0.5737s

With master:

[success] 61.75% yt.data_objects.tests.test_data_containers.TestDataContainers.test_extract_isocontours: 11.3581s
[success] 9.35% yt.data_objects.tests.test_data_containers.TestDataContainers.test_derived_field: 1.7190s
[success] 9.21% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_frb: 1.6935s
[success] 6.55% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_astropy_table: 1.2046s
[success] 3.35% yt.data_objects.tests.test_data_containers.TestDataContainers.test_std: 0.6161s
[success] 3.29% yt.data_objects.tests.test_data_containers.TestDataContainers.test_write_out: 0.6059s
[success] 3.26% yt.data_objects.tests.test_data_containers.TestDataContainers.test_to_dataframe: 0.6002s
[success] 3.24% yt.data_objects.tests.test_data_containers.TestDataContainers.test_yt_data_container: 0.5959s

cphyc
cphyc previously approved these changes Sep 2, 2020
Copy link
Member

@cphyc cphyc left a comment

Choose a reason for hiding this comment

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

Assuming we check that the perf were not degraded, I'm all in!

@matthewturk
Copy link
Member Author

@cphyc thanks for the fix!

I'm game for this going in; the perf does not seem to be a big deal, and is likely swallowed up by perf implications of other things that could be improved.

@cphyc
Copy link
Member

cphyc commented Sep 2, 2020

@cphyc thanks for the fix!

I'm game for this going in; the perf does not seem to be a big deal, and is likely swallowed up by perf implications of other things that could be improved.

Have you tried volume rendering?

@matthewturk
Copy link
Member Author

Yes, but I did not write down the numbers. Will attempt to do some perf comparisons asap.

@cphyc
Copy link
Member

cphyc commented Sep 2, 2020

Yes, but I did not write down the numbers. Will attempt to do some perf comparisons asap.

yt.visualization.volume_rendering.tests.test_mesh_render.test_surface_mesh_render goes from 3.8746s to 7.9495s with this PR!

@matthewturk
Copy link
Member Author

matthewturk commented Sep 2, 2020 via email

@cphyc
Copy link
Member

cphyc commented Sep 2, 2020

Yes, but I did not write down the numbers. Will attempt to do some perf comparisons asap.

yt.visualization.volume_rendering.tests.test_mesh_render.test_surface_mesh_render goes from 3.8746s to 7.9495s with this PR!

Ignore this comment, I just reran it with completely different results.

@matthewturk
Copy link
Member Author

So maybe it's OK to go?

@cphyc
Copy link
Member

cphyc commented Sep 11, 2020

I'm ok in principle, but I would like to have some robust performance test (esp. for volume rendering) before merging.

@matthewturk
Copy link
Member Author

@cphyc fair! OK I'll work on that.

@matthewturk
Copy link
Member Author

@cphyc I'm looking at this again and I'm not 100% convinced I still want it with the changes you made, but I'm going to add the perf anyway.

@neutrinoceros
Copy link
Member

@yt-fido test this please

@matthewturk
Copy link
Member Author

I had to commit this before I completed it; I'm also finding some strange memory things that I need to convince myself are not real before I proceed.

Comment on lines +13 to +14
for i in range(3):
random_index[:, i] = np.random.randint(0, shape[i], size=M, dtype="u8")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for i in range(3):
random_index[:, i] = np.random.randint(0, shape[i], size=M, dtype="u8")
for i, s in enumerate(shape):
random_index[:, i] = np.random.randint(0, s, size=M, dtype="u8")

random_index = np.random.randint((0, 0, 0), shape, size=(M, 3), dtype="u8")
random_index = np.empty((M, 3), dtype="u8")
for i in range(3):
random_index[:, i] = np.random.randint(0, shape[i], size=M, dtype="u8")
random_offset = np.random.random((M, 3))
# import time
Copy link
Member

Choose a reason for hiding this comment

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

@matthewturk could we clean up the commented code here while we're at it ?

@matthewturk
Copy link
Member Author

matthewturk commented Sep 25, 2020 via email

@neutrinoceros
Copy link
Member

@matthewturk I'm waiting for your answer but I'm ready to approve+merge this !

@matthewturk
Copy link
Member Author

I actually spent some trying to compare, and then I forget what happened. I will attempt again.

@neutrinoceros
Copy link
Member

This is starting to drift into the conflict realm.

@matthewturk
Copy link
Member Author

Yes, it is, but I'm still struggling to get the micro-benchmarks. Won't be too hard to harmonize...

Base automatically changed from master to main January 20, 2021 15:27
@matthewturk matthewturk marked this pull request as draft May 18, 2021 19:35
@matthewturk
Copy link
Member Author

I'm converting this to draft until after 4.0 goes out so that it won't show up in my filters. The performance tests are harder than I expected.

@neutrinoceros
Copy link
Member

@matthewturk do you want to pick this up again for the 4.1 release or should we take it out of the milestone ?

@matthewturk
Copy link
Member Author

Let's take it out.

@neutrinoceros neutrinoceros removed this from the 4.1.0 milestone Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor improve readability, maintainability, modularity viz: volume rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants