Skip to content

Commit

Permalink
Get rid of ArborX::Exception in favor of KOKKOS_ASSERT and Kokkos::ab…
Browse files Browse the repository at this point in the history
…ort()
  • Loading branch information
aprokop committed Oct 17, 2024
1 parent 116aabd commit 0323146
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 159 deletions.
4 changes: 2 additions & 2 deletions benchmarks/dbscan/ArborX_DBSCANVerification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives,
static_assert(std::is_same<typename LabelsView::value_type, int>{});
static_assert(std::is_same<typename LabelsView::memory_space, MemorySpace>{});

ARBORX_ASSERT(eps > 0);
ARBORX_ASSERT(core_min_size >= 2);
KOKKOS_ASSERT(eps > 0);
KOKKOS_ASSERT(core_min_size >= 2);

Points points{primitives}; // NOLINT

Expand Down
7 changes: 4 additions & 3 deletions benchmarks/dbscan/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define DATA_HPP

#include <ArborX_Point.hpp>
#include <misc/ArborX_Exception.hpp>

#include <iostream>
#include <random>
Expand Down Expand Up @@ -65,7 +64,8 @@ std::vector<Point<DIM>> loadData(std::string const &filename,
input.open(filename);
else
input.open(filename, std::ifstream::binary);
ARBORX_ASSERT(input.good());
if (!input.good())
Kokkos::abort("Could not load data");

std::vector<Point<DIM>> v;

Expand All @@ -82,7 +82,8 @@ std::vector<Point<DIM>> loadData(std::string const &filename,
input.read(reinterpret_cast<char *>(&dim), sizeof(int));
}

ARBORX_ASSERT(dim == DIM);
if (dim != DIM)
Kokkos::abort("Mismatching dimensions");

if (max_num_points > 0 && max_num_points < num_points)
num_points = max_num_points;
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/dbscan/dbscan_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void writeLabelsData(std::string const &filename,
Kokkos::View<int *, MemorySpace> labels)
{
std::ofstream out(filename, std::ofstream::binary);
ARBORX_ASSERT(out.good());
if (!out.good())
Kokkos::abort("Could not open file");

auto labels_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, labels);
Expand Down Expand Up @@ -70,7 +71,7 @@ void sortAndFilterClusters(ExecutionSpace const &exec_space,
static_assert(
std::is_same<typename ClusterOffsetView::memory_space, MemorySpace>{});

ARBORX_ASSERT(cluster_min_size >= 1);
KOKKOS_ASSERT(cluster_min_size >= 1);

int const n = labels.extent_int(0);

Expand Down
2 changes: 1 addition & 1 deletion examples/viz/tree_visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void loadPointCloud(std::string const &filename, Points &random_points)
{
int size = -1;
file >> size;
ARBORX_ASSERT(size > 0);
KOKKOS_ASSERT(size > 0);
Kokkos::realloc(random_points, size);
auto random_points_host = Kokkos::create_mirror_view(random_points);
for (int i = 0; i < size; ++i)
Expand Down
1 change: 0 additions & 1 deletion src/ArborX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <ArborX_Sphere.hpp>
#include <detail/ArborX_PredicateHelpers.hpp>
#include <detail/ArborX_Predicates.hpp>
#include <misc/ArborX_Exception.hpp>
// FIXME: we include ArborX_Utils.hpp only for backward compatibility for
// users using deprecated functions in ArborX namespace (min, max,
// adjacentDifference, ...). This header should be removed when we remove those
Expand Down
15 changes: 13 additions & 2 deletions src/cluster/ArborX_DBSCAN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <misc/ArborX_SortUtils.hpp>
#include <misc/ArborX_Utils.hpp> // sortObjects

#include <Kokkos_Assert.hpp>

namespace ArborX
{

Expand Down Expand Up @@ -217,8 +219,17 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
KokkosExt::is_accessible_from<MemorySpace, ExecutionSpace>::value,
"Primitives must be accessible from the execution space");

ARBORX_ASSERT(eps > 0);
ARBORX_ASSERT(core_min_size >= 2);
if (eps <= 0)
Kokkos::abort((std::string("ArborX: DBSCAN parameter eps must be positive "
"(provided value is ") +
std::to_string(eps) + ")")
.c_str());

if (core_min_size < 2)
Kokkos::abort((std::string("ArborX: DBSCAN parameter core_min_size must be "
"greater than 1 (provided value is ") +
std::to_string(core_min_size) + ")")
.c_str());

#ifdef KOKKOS_ENABLE_SERIAL
using UnionFind = Details::UnionFind<
Expand Down
8 changes: 4 additions & 4 deletions src/cluster/detail/ArborX_BoruvkaHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ struct FindComponentNearestNeighbors
, _lower_bounds(lower_bounds)
{
int const n = bvh.size();
ARBORX_ASSERT(labels.extent_int(0) == 2 * n - 1);
ARBORX_ASSERT(edges.extent_int(0) == n);
ARBORX_ASSERT(radii.extent_int(0) == n);
KOKKOS_ASSERT(labels.extent_int(0) == 2 * n - 1);
KOKKOS_ASSERT(edges.extent_int(0) == n);
KOKKOS_ASSERT(radii.extent_int(0) == n);

#ifdef KOKKOS_ENABLE_SERIAL
if (std::is_same<ExecutionSpace, Kokkos::Serial>{})
Expand Down Expand Up @@ -479,7 +479,7 @@ void finalizeEdges(ExecutionSpace const &space, BVH const &bvh,
Edges const &edges)
{
int const n = bvh.size();
ARBORX_ASSERT(edges.extent_int(0) == n - 1);
KOKKOS_ASSERT(edges.extent_int(0) == n - 1);
Kokkos::parallel_for(
"ArborX::MST::finalize_edges", Kokkos::RangePolicy(space, 0, n - 1),
KOKKOS_LAMBDA(int i) {
Expand Down
15 changes: 9 additions & 6 deletions src/cluster/detail/ArborX_CartesianGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

#include <ArborX_Box.hpp>
#include <ArborX_GeometryTraits.hpp>
#include <misc/ArborX_Exception.hpp>

#include <Kokkos_Assert.hpp> // KOKKOS_ASSERT
#include <Kokkos_Macros.hpp>
#include <Kokkos_MathematicalFunctions.hpp> // floor

#include <string>

namespace ArborX::Details
{

Expand All @@ -32,7 +33,8 @@ struct CartesianGrid
CartesianGrid(Box<DIM> const &bounds, float h)
: _bounds(bounds)
{
ARBORX_ASSERT(h > 0);
KOKKOS_ASSERT(h > 0);

for (int d = 0; d < DIM; ++d)
_h[d] = h;
buildGrid();
Expand All @@ -42,7 +44,7 @@ struct CartesianGrid
{
for (int d = 0; d < DIM; ++d)
{
ARBORX_ASSERT(_h[d] > 0);
KOKKOS_ASSERT(_h[d] > 0);
_h[d] = h[d];
}
buildGrid();
Expand Down Expand Up @@ -101,7 +103,7 @@ struct CartesianGrid
if (delta != 0)
{
_n[d] = std::ceil(delta / _h[d]);
ARBORX_ASSERT(_n[d] > 0);
KOKKOS_ASSERT(_n[d] > 0);
}
else
{
Expand All @@ -117,7 +119,8 @@ struct CartesianGrid
for (int d = 1; d < DIM; ++d)
{
m /= _n[d - 1];
ARBORX_ASSERT(_n[d] < m);
if (_n[d] >= m)
Kokkos::abort("ArborX: potential overflow detected in CartesianGrid");
}

// Catch a potential loss of precision that may happen in cellBox() and can
Expand All @@ -131,7 +134,7 @@ struct CartesianGrid
for (int d = 0; d < DIM; ++d)
{
if (std::abs(_h[d] / min_corner[d]) < eps)
throw std::runtime_error(
Kokkos::abort(
"ArborX exception: FDBSCAN-DenseBox algorithm will experience loss "
"of precision, undetectably producing wrong results. Please switch "
"to using FDBSCAN.");
Expand Down
27 changes: 13 additions & 14 deletions src/distributed/detail/ArborX_Distributor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <kokkos_ext/ArborX_KokkosExtAccessibilityTraits.hpp>
#include <kokkos_ext/ArborX_KokkosExtMinMaxReduce.hpp>
#include <kokkos_ext/ArborX_KokkosExtViewHelpers.hpp>
#include <misc/ArborX_Exception.hpp>
#include <misc/ArborX_SortUtils.hpp>

#include <Kokkos_Core.hpp>
Expand Down Expand Up @@ -44,10 +43,10 @@ determineBufferLayout(ExecutionSpace const &space, InputView batched_ranks,
Kokkos::Profiling::ScopedRegion guard(
"ArborX::Distributor::determineBufferLayout");

ARBORX_ASSERT(unique_ranks.empty());
ARBORX_ASSERT(offsets.empty());
ARBORX_ASSERT(permutation_indices.extent_int(0) == 0);
ARBORX_ASSERT(batched_ranks.size() + 1 == batched_offsets.size());
KOKKOS_ASSERT(unique_ranks.empty());
KOKKOS_ASSERT(offsets.empty());
KOKKOS_ASSERT(permutation_indices.extent_int(0) == 0);
KOKKOS_ASSERT(batched_ranks.size() + 1 == batched_offsets.size());
static_assert(std::is_same_v<typename InputView::non_const_value_type, int>);
static_assert(std::is_same_v<typename OutputView::value_type, int>);

Expand Down Expand Up @@ -140,9 +139,9 @@ static void sortAndDetermineBufferLayout(ExecutionSpace const &space,
Kokkos::Profiling::ScopedRegion guard(
"ArborX::Distributor::sortAndDetermineBufferLayout");

ARBORX_ASSERT(unique_ranks.empty());
ARBORX_ASSERT(offsets.empty());
ARBORX_ASSERT(permutation_indices.extent_int(0) == ranks.extent_int(0));
KOKKOS_ASSERT(unique_ranks.empty());
KOKKOS_ASSERT(offsets.empty());
KOKKOS_ASSERT(permutation_indices.extent_int(0) == ranks.extent_int(0));
static_assert(std::is_same_v<typename InputView::non_const_value_type, int>);
static_assert(std::is_same_v<typename OutputView::value_type, int>);

Expand Down Expand Up @@ -195,7 +194,7 @@ static void sortAndDetermineBufferLayout(ExecutionSpace const &space,
offsets.push_back(offset);
}
Kokkos::deep_copy(space, permutation_indices, device_permutation_indices);
ARBORX_ASSERT(offsets.back() == static_cast<int>(ranks.size()));
KOKKOS_ASSERT(offsets.back() == static_cast<int>(ranks.size()));
}

template <typename DeviceType>
Expand Down Expand Up @@ -307,9 +306,9 @@ class Distributor

bool const permutation_necessary = _permute.size() != 0;

ARBORX_ASSERT(!permutation_necessary || exports.size() == _permute.size());
ARBORX_ASSERT(exports.size() == getTotalSendLength());
ARBORX_ASSERT(imports.size() == getTotalReceiveLength());
KOKKOS_ASSERT(!permutation_necessary || exports.size() == _permute.size());
KOKKOS_ASSERT(exports.size() == getTotalSendLength());
KOKKOS_ASSERT(imports.size() == getTotalReceiveLength());

// Make sure things work even if ExportView is unmanaged
using ExportViewWithoutMemoryTraits =
Expand Down Expand Up @@ -343,7 +342,7 @@ class Distributor
same_rank_destination = it - _destinations.begin();

it = std::find(_sources.begin(), _sources.end(), comm_rank);
ARBORX_ASSERT(it != _sources.end());
KOKKOS_ASSERT(it != _sources.end());
same_rank_source = it - _sources.begin();
}
}
Expand Down Expand Up @@ -410,7 +409,7 @@ class Distributor

if (same_rank_destination != -1)
{
ARBORX_ASSERT((_src_offsets[same_rank_source + 1] -
KOKKOS_ASSERT((_src_offsets[same_rank_source + 1] -
_src_offsets[same_rank_source]) ==
(_dest_offsets[same_rank_destination + 1] -
_dest_offsets[same_rank_destination]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define ARBORX_INTERP_SYMMETRIC_PSEUDO_INVERSE_SVD_HPP

#include <kokkos_ext/ArborX_KokkosExtAccessibilityTraits.hpp>
#include <misc/ArborX_Exception.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_Profiling_ScopedRegion.hpp>
Expand Down
10 changes: 6 additions & 4 deletions src/kokkos_ext/ArborX_KokkosExtMinMaxReduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define ARBORX_KOKKOS_EXT_MIN_MAX_REDUCTIONS_HPP

#include <kokkos_ext/ArborX_KokkosExtAccessibilityTraits.hpp>
#include <misc/ArborX_Exception.hpp>

#include <Kokkos_Core.hpp>

Expand All @@ -34,7 +33,8 @@ minmax_reduce(ExecutionSpace const &space, ViewType const &v)
"minmax_reduce requires a View of rank 1");

auto const n = v.extent(0);
ARBORX_ASSERT(n > 0);
if (n == 0)
Kokkos::abort("ArborX: minmax_reduce: view must be non-empty");

using ValueType = typename ViewType::non_const_value_type;

Expand Down Expand Up @@ -69,7 +69,8 @@ typename ViewType::non_const_value_type min_reduce(ExecutionSpace const &space,
static_assert(ViewType::rank() == 1, "min_reduce requires a View of rank 1");

auto const n = v.extent(0);
ARBORX_ASSERT(n > 0);
if (n == 0)
Kokkos::abort("ArborX: minmax_reduce: view must be non-empty");

using ValueType = typename ViewType::non_const_value_type;

Expand All @@ -96,7 +97,8 @@ typename ViewType::non_const_value_type max_reduce(ExecutionSpace const &space,
static_assert(ViewType::rank() == 1, "max_reduce requires a View of rank 1");

auto const n = v.extent(0);
ARBORX_ASSERT(n > 0);
if (n == 0)
Kokkos::abort("ArborX: minmax_reduce: view must be non-empty");

using ValueType = typename ViewType::non_const_value_type;

Expand Down
12 changes: 9 additions & 3 deletions src/kokkos_ext/ArborX_KokkosExtSort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ void sortByKey(ExecutionSpace const &space, Keys &keys, Values &values)
static_assert(KokkosExt::is_accessible_from<typename Values::memory_space,
ExecutionSpace>::value);
auto const n = keys.size();
ARBORX_ASSERT(values.size() == n);
if (values.size() != n)
Kokkos::abort(
"ArborX: sortByKey: keys and values must be of the same size");

if (n == 0)
return;
Expand Down Expand Up @@ -132,7 +134,9 @@ void sortByKey(
static_assert(KokkosExt::is_accessible_from<typename Values::memory_space,
ExecutionSpace>::value);
auto const n = keys.size();
ARBORX_ASSERT(values.size() == n);
if (values.size() != n)
Kokkos::abort(
"ArborX: sortByKey: keys and values must be of the same size");

if (n == 0)
return;
Expand Down Expand Up @@ -165,7 +169,9 @@ void sortByKey(Kokkos::Experimental::SYCL const &space, Keys &keys,
static_assert(KokkosExt::is_accessible_from<typename Values::memory_space,
ExecutionSpace>::value);
auto const n = keys.size();
ARBORX_ASSERT(values.size() == n);
if (values.size() != n)
Kokkos::abort(
"ArborX: sortByKey: keys and values must be of the same size");

if (n == 0)
return;
Expand Down
4 changes: 1 addition & 3 deletions src/kokkos_ext/ArborX_KokkosExtViewHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#ifndef ARBORX_KOKKOS_EXT_VIEW_HELPERS_HPP
#define ARBORX_KOKKOS_EXT_VIEW_HELPERS_HPP

#include <misc/ArborX_Exception.hpp>

#include <Kokkos_Core.hpp>

namespace ArborX::Details::KokkosExt
Expand All @@ -34,7 +32,7 @@ lastElement(ExecutionSpace const &space, Kokkos::View<T, P...> const &v)
static_assert(unsigned(Kokkos::ViewTraits<T, P...>::rank) == unsigned(1),
"lastElement requires Views of rank 1");
auto const n = v.extent(0);
ARBORX_ASSERT(n > 0);
KOKKOS_ASSERT(n > 0);
auto v_subview = Kokkos::subview(v, n - 1);
typename Kokkos::ViewTraits<T, P...>::non_const_value_type v_host;
Kokkos::deep_copy(space, v_host, v_subview);
Expand Down
Loading

0 comments on commit 0323146

Please sign in to comment.