Skip to content

Commit

Permalink
Migrate MinMax
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Dec 26, 2023
1 parent 835ab9a commit f5f469f
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/details/ArborX_DetailsBruteForceImpl.hpp
Expand Up @@ -13,6 +13,7 @@
#define ARBORX_DETAILS_BRUTE_FORCE_IMPL_HPP

#include <ArborX_DetailsAlgorithms.hpp> // expand
#include <ArborX_DetailsKokkosExtMinMaxOperations.hpp>
#include <ArborX_Exception.hpp>

#include <Kokkos_Core.hpp>
Expand Down Expand Up @@ -95,9 +96,9 @@ struct BruteForceImpl
int indexable_start = indexables_per_team *
(teamMember.league_rank() % n_indexable_tiles);

int predicates_in_this_team = KokkosBlah::min(
int predicates_in_this_team = KokkosExt::min(
predicates_per_team, n_predicates - predicate_start);
int indexables_in_this_team = KokkosBlah::min(
int indexables_in_this_team = KokkosExt::min(
indexables_per_team, n_indexables - indexable_start);

ScratchPredicateType scratch_predicates(teamMember.team_scratch(0),
Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsDistributedTreeImpl.hpp
Expand Up @@ -398,7 +398,7 @@ void DistributedTreeImpl<DeviceType>::reassessStrategy(
"ArborX::DistributedTree::query::most_distant_neighbor_so_far",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, n_queries),
KOKKOS_LAMBDA(int i) {
using KokkosBlah::max;
using KokkosExt::max;
farthest_distances(i) = 0.;
for (int j = offset(i); j < offset(i + 1); ++j)
farthest_distances(i) = max(farthest_distances(i), distances(j));
Expand Down Expand Up @@ -888,7 +888,7 @@ void DistributedTreeImpl<DeviceType>::filterResults(
"ArborX::DistributedTree::query::discard_results",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, n_queries),
KOKKOS_LAMBDA(int q) {
using KokkosBlah::min;
using KokkosExt::min;
new_offset(q) = min(offset(q + 1) - offset(q), getK(queries(q)));
});

Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsMinimumSpanningTree.hpp
Expand Up @@ -357,7 +357,7 @@ void updateLowerBounds(ExecutionSpace const &space, Labels const &labels,
Kokkos::parallel_for(
"ArborX::MST::update_lower_bounds",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, n), KOKKOS_LAMBDA(int i) {
using KokkosBlah::max;
using KokkosExt::max;
auto component = labels(i);
auto const &edge = component_out_edges(component);
lower_bounds(i) = max(lower_bounds(i), edge.weight);
Expand Down Expand Up @@ -429,7 +429,7 @@ struct UpdateComponentsAndEdges
}
// The component's edge is bidirectional, uniquely resolve the bidirectional
// edge
return KokkosBlah::min(component, next_component);
return KokkosExt::min(component, next_component);
}

KOKKOS_FUNCTION auto computeFinalComponent(int component) const
Expand Down
12 changes: 6 additions & 6 deletions src/details/ArborX_DetailsMortonCode.hpp
Expand Up @@ -289,8 +289,8 @@ KOKKOS_INLINE_FUNCTION unsigned int morton32(Point const &p)
constexpr int DIM = GeometryTraits::dimension_v<Point>;
constexpr unsigned N = 1u << (DIM == 1 ? 31 : 32 / DIM);

using KokkosBlah::max;
using KokkosBlah::min;
using KokkosExt::max;
using KokkosExt::min;

unsigned int r = 0;
for (int d = 0; d < DIM; ++d)
Expand All @@ -310,8 +310,8 @@ KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p)
constexpr int DIM = GeometryTraits::dimension_v<Point>;
constexpr unsigned long long N = (1llu << (63 / DIM));

using KokkosBlah::max;
using KokkosBlah::min;
using KokkosExt::max;
using KokkosExt::min;

unsigned long long r = 0;
for (int d = 0; d < DIM; ++d)
Expand All @@ -334,8 +334,8 @@ KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p)
// direction).
constexpr unsigned N = (1u << 31);

using KokkosBlah::max;
using KokkosBlah::min;
using KokkosExt::max;
using KokkosExt::min;

// Have to use double as float is not sufficient to represent large
// integers, which would result in some missing bins.
Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsMutualReachabilityDistance.hpp
Expand Up @@ -38,7 +38,7 @@ struct MaxDistance
{
size_type const i = value.index;
size_type const j = getData(predicate);
using KokkosBlah::max;
using KokkosExt::max;
auto const distance_ij = distance(_primitives(i), _primitives(j));
// NOTE using knowledge that each nearest predicate traversal is performed
// by a single thread. The distance update below would need to be atomic
Expand Down Expand Up @@ -85,7 +85,7 @@ struct MutualReachability
KOKKOS_FUNCTION value_type operator()(size_type i, size_type j,
value_type distance_ij) const
{
using KokkosBlah::max;
using KokkosExt::max;
return max({_core_distances(i), _core_distances(j), distance_ij});
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsWeightedEdge.hpp
Expand Up @@ -35,14 +35,14 @@ struct WeightedEdge
{
return (lhs.weight < rhs.weight);
}
using KokkosBlah::min;
using KokkosExt::min;
auto const lhs_min = min(lhs.source, lhs.target);
auto const rhs_min = min(rhs.source, rhs.target);
if (lhs_min != rhs_min)
{
return (lhs_min < rhs_min);
}
using KokkosBlah::max;
using KokkosExt::max;
auto const lhs_max = max(lhs.source, lhs.target);
auto const rhs_max = max(rhs.source, rhs.target);
return (lhs_max < rhs_max);
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/ArborX_Box.hpp
Expand Up @@ -61,8 +61,8 @@ struct Box

KOKKOS_FUNCTION Box &operator+=(Box const &other)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;

for (int d = 0; d < 3; ++d)
{
Expand All @@ -74,8 +74,8 @@ struct Box

KOKKOS_FUNCTION Box &operator+=(Point const &point)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;

for (int d = 0; d < 3; ++d)
{
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/ArborX_DetailsAlgorithms.hpp
Expand Up @@ -241,7 +241,7 @@ struct distance<PointTag, SphereTag, Point, Sphere>
{
KOKKOS_FUNCTION static auto apply(Point const &point, Sphere const &sphere)
{
using KokkosBlah::max;
using KokkosExt::max;
return max(Details::distance(point, sphere.centroid()) - sphere.radius(),
0.f);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ struct distance<SphereTag, BoxTag, Sphere, Box>
{
KOKKOS_FUNCTION static auto apply(Sphere const &sphere, Box const &box)
{
using KokkosBlah::max;
using KokkosExt::max;

auto distance_center_box = Details::distance(sphere.centroid(), box);
return max(distance_center_box - sphere.radius(), 0.f);
Expand Down Expand Up @@ -335,8 +335,8 @@ struct expand<BoxTag, SphereTag, Box, Sphere>
{
KOKKOS_FUNCTION static void apply(Box &box, Sphere const &sphere)
{
using KokkosBlah::max;
using KokkosBlah::min;
using KokkosExt::max;
using KokkosExt::min;

constexpr int DIM = GeometryTraits::dimension_v<Box>;
for (int d = 0; d < DIM; ++d)
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/ArborX_HyperBox.hpp
Expand Up @@ -68,8 +68,8 @@ struct Box
std::enable_if_t<GeometryTraits::is_box<OtherBox>{}> * = nullptr>
KOKKOS_FUNCTION auto &operator+=(OtherBox const &other)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;

for (int d = 0; d < DIM; ++d)
{
Expand All @@ -83,8 +83,8 @@ struct Box
std::enable_if_t<GeometryTraits::is_point<Point>{}> * = nullptr>
KOKKOS_FUNCTION auto &operator+=(Point const &point)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;

for (int d = 0; d < DIM; ++d)
{
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/ArborX_KDOP.hpp
Expand Up @@ -155,8 +155,8 @@ struct KDOP : private Details::KDOP_Directions<k>
}
KOKKOS_FUNCTION KDOP &operator+=(Point const &p)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;
for (int i = 0; i < n_directions; ++i)
{
auto const proj_i = Details::project(p, this->directions()[i]);
Expand Down Expand Up @@ -203,8 +203,8 @@ struct KDOP : private Details::KDOP_Directions<k>
}
KOKKOS_FUNCTION KDOP &operator+=(KDOP const &other)
{
using KokkosBlah::max;
using KokkosBlah::min;
using Details::KokkosExt::max;
using Details::KokkosExt::min;
for (int i = 0; i < n_directions; ++i)
{
_min_values[i] = min(_min_values[i], other._min_values[i]);
Expand Down
10 changes: 5 additions & 5 deletions src/geometry/ArborX_Ray.hpp
Expand Up @@ -414,15 +414,15 @@ bool intersection(Ray const &ray,
bool bc_intersect = rayEdgeIntersect(B_star, C_star, t_bc);
if (bc_intersect)
{
tmin = KokkosBlah::min(tmin, t_bc);
tmax = KokkosBlah::max(tmax, t_bc);
tmin = KokkosExt::min(tmin, t_bc);
tmax = KokkosExt::max(tmax, t_bc);
}
float t_ca = inf;
bool ca_intersect = rayEdgeIntersect(C_star, A_star, t_ca);
if (ca_intersect)
{
tmin = KokkosBlah::min(tmin, t_ca);
tmax = KokkosBlah::max(tmax, t_ca);
tmin = KokkosExt::min(tmin, t_ca);
tmax = KokkosExt::max(tmax, t_ca);
}

if (ab_intersect || bc_intersect || ca_intersect)
Expand Down Expand Up @@ -558,7 +558,7 @@ overlapDistance(Ray const &ray, Geometry const &geometry, float &length,
if (intersection(ray, geometry, tmin, tmax) && (tmin <= tmax && tmax >= 0))
{
// Overlap [tmin, tmax] with [0, +inf)
tmin = KokkosBlah::max(0.f, tmin);
tmin = Details::KokkosExt::max(0.f, tmin);
// As direction is normalized,
// |(o + tmax*d) - (o + tmin*d)| = tmax - tmin
length = tmax - tmin;
Expand Down
4 changes: 2 additions & 2 deletions src/kokkos_ext/ArborX_DetailsKokkosExtMinMaxOperations.hpp
Expand Up @@ -16,7 +16,7 @@

#include <initializer_list>

namespace KokkosBlah
namespace ArborX::Details::KokkosExt
{

//! Compute the maximum of two values.
Expand Down Expand Up @@ -73,6 +73,6 @@ KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist)
return result;
}

} // namespace KokkosBlah
} // namespace ArborX::Details::KokkosExt

#endif

0 comments on commit f5f469f

Please sign in to comment.