-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,11 @@ | |
#ifndef ARBORX_SPACE_FILLING_CURVES_HPP | ||
#define ARBORX_SPACE_FILLING_CURVES_HPP | ||
|
||
#include <ArborX_Box.hpp> | ||
#include <ArborX_Point.hpp> | ||
#include <ArborX_GeometryTraits.hpp> | ||
#include <algorithms/ArborX_Centroid.hpp> | ||
#include <algorithms/ArborX_TranslateAndScale.hpp> | ||
#include <detail/ArborX_MortonCode.hpp> | ||
#include <misc/ArborX_SortUtils.hpp> | ||
|
||
#include <Kokkos_DetectionIdiom.hpp> | ||
#include <Kokkos_Macros.hpp> | ||
|
@@ -30,20 +30,11 @@ namespace Experimental | |
|
||
struct Morton32 | ||
{ | ||
template <typename Box, typename Point, | ||
std::enable_if_t<GeometryTraits::is_box_v<Box> && | ||
GeometryTraits::is_point_v<Point>> * = nullptr> | ||
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Point p) const | ||
{ | ||
Details::translateAndScale(p, p, scene_bounding_box); | ||
return Details::morton32(p); | ||
} | ||
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> | ||
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, | ||
Geometry const &geometry) const | ||
{ | ||
static_assert(GeometryTraits::is_box_v<Box>); | ||
using Details::returnCentroid; | ||
auto p = returnCentroid(geometry); | ||
Details::translateAndScale(p, p, scene_bounding_box); | ||
|
@@ -53,20 +44,11 @@ struct Morton32 | |
|
||
struct Morton64 | ||
{ | ||
template <typename Box, typename Point, | ||
std::enable_if_t<GeometryTraits::is_box_v<Box> && | ||
GeometryTraits::is_point_v<Point>> * = nullptr> | ||
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Point p) const | ||
{ | ||
Details::translateAndScale(p, p, scene_bounding_box); | ||
return Details::morton64(p); | ||
} | ||
template <typename Box, class Geometry, | ||
std::enable_if_t<GeometryTraits::is_box_v<Box> && | ||
!GeometryTraits::is_point_v<Geometry>> * = nullptr> | ||
template <typename Box, class Geometry> | ||
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, | ||
Geometry const &geometry) const | ||
{ | ||
static_assert(GeometryTraits::is_box_v<Box>); | ||
using Details::returnCentroid; | ||
auto p = returnCentroid(geometry); | ||
Details::translateAndScale(p, p, scene_bounding_box); | ||
|
@@ -79,6 +61,50 @@ struct Morton64 | |
namespace Details | ||
{ | ||
|
||
template <typename ExecutionSpace, typename Values, typename SpaceFillingCurve, | ||
typename Box> | ||
inline Kokkos::View<std::invoke_result_t<SpaceFillingCurve, Box, | ||
std::decay_t<decltype(returnCentroid( | ||
std::declval<Values>()(0)))>> *, | ||
typename Values::memory_space> | ||
projectOntoSpaceFillingCurve(ExecutionSpace const &space, Values const &values, | ||
SpaceFillingCurve const &curve, | ||
Box const &scene_bounding_box) | ||
{ | ||
using Point = std::decay_t<decltype(returnCentroid(values(0)))>; | ||
static_assert(GeometryTraits::is_point_v<Point>); | ||
static_assert(GeometryTraits::is_box_v<Box>); | ||
|
||
auto const n = values.size(); | ||
|
||
using LinearOrderingValueType = | ||
std::invoke_result_t<SpaceFillingCurve, Box, Point>; | ||
Kokkos::View<LinearOrderingValueType *, typename Values::memory_space> | ||
linear_ordering_indices( | ||
Kokkos::view_alloc(space, Kokkos::WithoutInitializing, | ||
"ArborX::SpaceFillingCurve::linear_ordering"), | ||
n); | ||
Comment on lines
+82
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
Kokkos::parallel_for( | ||
"ArborX::SpaceFillingCurve::project_onto_space_filling_curve", | ||
Kokkos::RangePolicy(space, 0, n), KOKKOS_LAMBDA(int i) { | ||
linear_ordering_indices(i) = curve(scene_bounding_box, values(i)); | ||
}); | ||
|
||
return linear_ordering_indices; | ||
} | ||
|
||
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); | ||
} | ||
Comment on lines
+96
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saves little code to bundle two distinct operations. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
template <int DIM, class SpaceFillingCurve> | ||
void check_valid_space_filling_curve(SpaceFillingCurve const &) | ||
{ | ||
|
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.
Do not mix
typename
andclass