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

Refactor space filling curves surrounding code #1180

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

Conversation

aprokop
Copy link
Contributor

@aprokop aprokop commented Oct 11, 2024

  • Fix getGeometry for prvalues
    If a passed function argument is a prvalue, it will be destroyed once we return, as returning a reference to its member does not extend its lifetime.
  • Move projectOntoSpaceFillingCurve from ArborX_TreeConstruction.hpp to ArborX_SpaceFillingCurve.hpp
    It will also be used by the tree traversal now
  • Change signature of projectOntoSpaceFillingCurve to return linear ordering
    This avoids a lot of boilerplate code to determine the type. We currently have zero benefit from passing indices as the last argument.
  • Add computeSpaceFillingCurvePermutation that combines projectOntoSpaceFillingCurve with sorting to further reduce the amount of code
  • Added PredicateIndexables to easily iterate over predicate geometries

If a passed function argument is a prvalue, it will be destroyed once we
return, as returning a reference to its member does not extend its
lifetime.
@aprokop aprokop added the refactoring Code reorganization label Oct 11, 2024
template <typename Box, typename Geometry,
std::enable_if_t<GeometryTraits::is_box_v<Box> &&
!GeometryTraits::is_point_v<Geometry>> * = nullptr>
template <typename Box, class Geometry>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not mix typename and class

Comment on lines +82 to +86
Kokkos::View<LinearOrderingValueType *, typename Values::memory_space>
linear_ordering_indices(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::SpaceFillingCurve::linear_ordering"),
n);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that moving the allocation into that function and returning the Morton codes is a good change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like it much either. However, our boilerplate code for determining the type of indices is really several lines at every call site.

Alternatively, we could introduce a requirement for a space filling curve to provide index_type that it will return. It would simplify things a lot.

Comment on lines +96 to +106
template <typename ExecutionSpace, typename Values, typename SpaceFillingCurve,
typename Box>
inline auto computeSpaceFillingCurvePermutation(ExecutionSpace const &space,
Values const &values,
SpaceFillingCurve const &curve,
Box const &scene_bounding_box)
{
auto linear_ordering_indices =
projectOntoSpaceFillingCurve(space, values, curve, scene_bounding_box);
return sortObjects(space, linear_ordering_indices);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Saves little code to bundle two distinct operations.
I am not convinced it is a good idea to introduce it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair. It does a bit more than that in that it also reduces the amount of used memory as linear_ordering_indices are deallocated automatically once this function returns. This behavior is similar to the original sortPredicatesAlongSpaceFillingCurve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code reorganization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants