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

Replace assert with KOKKOS_ASSERT in kernel code #951

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/details/ArborX_DetailsCartesianGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct CartesianGrid
KOKKOS_FUNCTION
auto extent(int d) const
{
assert(0 <= d && d < DIM);
KOKKOS_ASSERT(0 <= d && d < DIM);
return _n[d];
}

Expand Down
43 changes: 21 additions & 22 deletions src/details/ArborX_DetailsContainers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <Kokkos_Macros.hpp>

#include <cassert> // assert
#include <cstddef> // size_t, ptrdiff_t
#include <utility> // move, forward

Expand All @@ -40,17 +39,17 @@ class StaticVector
KOKKOS_INLINE_FUNCTION size_type size() const { return _size; }
KOKKOS_INLINE_FUNCTION constexpr size_type maxSize() const { return N; }
KOKKOS_INLINE_FUNCTION constexpr size_type capacity() const { return N; }
KOKKOS_INLINE_FUNCTION reference operator[]( size_type pos ) { assert(pos < size()); return _data[pos]; }
KOKKOS_INLINE_FUNCTION const_reference operator[]( size_type pos ) const { assert(pos < size()); return _data[pos]; }
KOKKOS_INLINE_FUNCTION reference back() { assert(size() > 0 ); return _data[_size - 1]; }
KOKKOS_INLINE_FUNCTION const_reference back() const { assert(size() > 0); return _data[_size - 1]; }
KOKKOS_INLINE_FUNCTION void pushBack(T const &value) { assert(size() < maxSize()); _data[_size++] = value; }
KOKKOS_INLINE_FUNCTION void pushBack(T &&value) { assert(size() < maxSize()); _data[_size++] = std::move(value); }
KOKKOS_INLINE_FUNCTION reference operator[]( size_type pos ) { KOKKOS_ASSERT(pos < size()); return _data[pos]; }
KOKKOS_INLINE_FUNCTION const_reference operator[]( size_type pos ) const { KOKKOS_ASSERT(pos < size()); return _data[pos]; }
KOKKOS_INLINE_FUNCTION reference back() { KOKKOS_ASSERT(size() > 0 ); return _data[_size - 1]; }
KOKKOS_INLINE_FUNCTION const_reference back() const { KOKKOS_ASSERT(size() > 0); return _data[_size - 1]; }
KOKKOS_INLINE_FUNCTION void pushBack(T const &value) { KOKKOS_ASSERT(size() < maxSize()); _data[_size++] = value; }
KOKKOS_INLINE_FUNCTION void pushBack(T &&value) { KOKKOS_ASSERT(size() < maxSize()); _data[_size++] = std::move(value); }
template<class... Args>
KOKKOS_INLINE_FUNCTION void emplaceBack(Args&&... args) { assert(size() < maxSize()); ::new (static_cast<void*>(_data + _size++)) T(std::forward<Args>(args)...); }
KOKKOS_INLINE_FUNCTION void popBack() { assert(size() > 0); _size--; }
KOKKOS_INLINE_FUNCTION reference front() { assert(size() > 0); return _data[0]; }
KOKKOS_INLINE_FUNCTION const_reference front() const { assert(size() > 0); return _data[0]; }
KOKKOS_INLINE_FUNCTION void emplaceBack(Args&&... args) { KOKKOS_ASSERT(size() < maxSize()); ::new (static_cast<void*>(_data + _size++)) T(std::forward<Args>(args)...); }
KOKKOS_INLINE_FUNCTION void popBack() { KOKKOS_ASSERT(size() > 0); _size--; }
KOKKOS_INLINE_FUNCTION reference front() { KOKKOS_ASSERT(size() > 0); return _data[0]; }
KOKKOS_INLINE_FUNCTION const_reference front() const { KOKKOS_ASSERT(size() > 0); return _data[0]; }
KOKKOS_INLINE_FUNCTION void clear() { _size = 0; }
KOKKOS_INLINE_FUNCTION pointer data() { return _data; }
KOKKOS_INLINE_FUNCTION constexpr const_pointer data() const { return _data; }
Expand All @@ -73,22 +72,22 @@ class UnmanagedStaticVector
using const_reference = value_type const &;
using pointer = value_type *;
using const_pointer = value_type const *;
KOKKOS_FUNCTION UnmanagedStaticVector( pointer ptr, size_type max_size ) : _ptr(ptr) , _max_size(max_size) { assert(ptr != nullptr); }
KOKKOS_FUNCTION UnmanagedStaticVector( pointer ptr, size_type max_size ) : _ptr(ptr) , _max_size(max_size) { KOKKOS_ASSERT(ptr != nullptr); }
KOKKOS_INLINE_FUNCTION bool empty() const { return _size == 0; }
KOKKOS_INLINE_FUNCTION size_type size() const { return _size; }
KOKKOS_INLINE_FUNCTION constexpr size_type maxSize() const { return _max_size; }
KOKKOS_INLINE_FUNCTION constexpr size_type capacity() const { return _max_size; }
KOKKOS_INLINE_FUNCTION reference operator[]( size_type pos ) { assert(pos < size()); return *(_ptr + pos); }
KOKKOS_INLINE_FUNCTION const_reference operator[]( size_type pos ) const { assert(pos < size()); return *(_ptr + pos); }
KOKKOS_INLINE_FUNCTION reference back() { assert(size() > 0); return *(_ptr + _size - 1); }
KOKKOS_INLINE_FUNCTION const_reference back() const { assert(size() > 0); return *(_ptr + _size - 1); }
KOKKOS_INLINE_FUNCTION void pushBack(T const &value) { assert(size() < maxSize()); *(_ptr + _size++) = value; }
KOKKOS_INLINE_FUNCTION void pushBack(T &&value) { assert(size() < maxSize()); *(_ptr + _size++) = std::move(value); }
KOKKOS_INLINE_FUNCTION reference operator[]( size_type pos ) { KOKKOS_ASSERT(pos < size()); return *(_ptr + pos); }
KOKKOS_INLINE_FUNCTION const_reference operator[]( size_type pos ) const { KOKKOS_ASSERT(pos < size()); return *(_ptr + pos); }
KOKKOS_INLINE_FUNCTION reference back() { KOKKOS_ASSERT(size() > 0); return *(_ptr + _size - 1); }
KOKKOS_INLINE_FUNCTION const_reference back() const { KOKKOS_ASSERT(size() > 0); return *(_ptr + _size - 1); }
KOKKOS_INLINE_FUNCTION void pushBack(T const &value) { KOKKOS_ASSERT(size() < maxSize()); *(_ptr + _size++) = value; }
KOKKOS_INLINE_FUNCTION void pushBack(T &&value) { KOKKOS_ASSERT(size() < maxSize()); *(_ptr + _size++) = std::move(value); }
template<class... Args>
KOKKOS_INLINE_FUNCTION void emplaceBack(Args&&... args) { assert(size() < maxSize()); ::new (static_cast<void*>(_ptr + _size++)) T(std::forward<Args>(args)...); }
KOKKOS_INLINE_FUNCTION void popBack() { assert(size() > 0); _size--; }
KOKKOS_INLINE_FUNCTION reference front() { assert(size() > 0); return *(_ptr + 0); }
KOKKOS_INLINE_FUNCTION const_reference front() const { assert(size() > 0); return *(_ptr + 0); }
KOKKOS_INLINE_FUNCTION void emplaceBack(Args&&... args) { KOKKOS_ASSERT(size() < maxSize()); ::new (static_cast<void*>(_ptr + _size++)) T(std::forward<Args>(args)...); }
KOKKOS_INLINE_FUNCTION void popBack() { KOKKOS_ASSERT(size() > 0); _size--; }
KOKKOS_INLINE_FUNCTION reference front() { KOKKOS_ASSERT(size() > 0); return *(_ptr + 0); }
KOKKOS_INLINE_FUNCTION const_reference front() const { KOKKOS_ASSERT(size() > 0); return *(_ptr + 0); }
KOKKOS_INLINE_FUNCTION void clear() { _size = 0; }
KOKKOS_INLINE_FUNCTION pointer data() { return _ptr; }
KOKKOS_INLINE_FUNCTION const_pointer data() const { return _ptr; }
Expand Down
12 changes: 6 additions & 6 deletions src/details/ArborX_DetailsHappyTreeFriends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ struct HappyTreeFriends
template <class BVH>
static KOKKOS_FUNCTION int getRoot(BVH const &bvh)
{
assert(bvh.size() > 1);
KOKKOS_ASSERT(bvh.size() > 1);
return bvh.size();
}

template <class BVH>
static KOKKOS_FUNCTION bool isLeaf(BVH const &bvh, int i)
{
assert(bvh.size() > 1);
assert(i >= 0 && i < 2 * (int)bvh.size() - 1);
KOKKOS_ASSERT(bvh.size() > 1);
KOKKOS_ASSERT(i >= 0 && i < 2 * (int)bvh.size() - 1);
return i < (int)bvh.size();
}

Expand Down Expand Up @@ -74,21 +74,21 @@ struct HappyTreeFriends
template <class BVH>
static KOKKOS_FUNCTION auto const &getValue(BVH const &bvh, int i)
{
assert(i >= 0 && i < (int)bvh.size());
KOKKOS_ASSERT(i >= 0 && i < (int)bvh.size());
return bvh._leaf_nodes(i).value;
}

template <class BVH>
static KOKKOS_FUNCTION auto getLeftChild(BVH const &bvh, int i)
{
assert(!isLeaf(bvh, i));
KOKKOS_ASSERT(!isLeaf(bvh, i));
return bvh._internal_nodes(internalIndex(bvh, i)).left_child;
}

template <class BVH>
static KOKKOS_FUNCTION auto getRightChild(BVH const &bvh, int i)
{
assert(!isLeaf(bvh, i));
KOKKOS_ASSERT(!isLeaf(bvh, i));
return getRope(bvh, getLeftChild(bvh, i));
}

Expand Down
5 changes: 3 additions & 2 deletions src/details/ArborX_DetailsPriorityQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class PriorityQueue
KOKKOS_FUNCTION PriorityQueue(Container const &c)
: _c(c)
{
assert(_c.empty() || isHeap(_c.data(), _c.data() + _c.size(), _compare));
KOKKOS_ASSERT(_c.empty() ||
isHeap(_c.data(), _c.data() + _c.size(), _compare));
}

// Capacity
Expand Down Expand Up @@ -86,7 +87,7 @@ class PriorityQueue
template <typename... Args>
KOKKOS_INLINE_FUNCTION void popPush(Args &&...args)
{
assert(!_c.empty());
KOKKOS_ASSERT(!_c.empty());
bubbleDown(_c.data(), std::ptrdiff_t(0), std::ptrdiff_t(_c.size()),
T{std::forward<Args>(args)...}, _compare);
}
Expand Down
6 changes: 3 additions & 3 deletions src/details/ArborX_DetailsTreeNodeLabeling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ void reduceLabels(ExecutionSpace const &exec_space, Parents const &parents,
"ArborX::reduce_internal_node_labels",
Kokkos::RangePolicy<ExecutionSpace>(exec_space, 0, n),
KOKKOS_LAMBDA(int i) {
assert(labels(i) != indeterminate);
assert(labels(i) != untouched);
assert(parents(i) >= 0);
KOKKOS_ASSERT(labels(i) != indeterminate);
KOKKOS_ASSERT(labels(i) != untouched);
KOKKOS_ASSERT(parents(i) >= 0);

// TODO consider asserting the precondition below holds at call site or
// taking root as an input argument
Expand Down
2 changes: 1 addition & 1 deletion src/details/ArborX_DetailsTreeTraversal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct TreeTraversal<BVH, Predicates, Callback, NearestPredicateTag>
// preserve the heap structure internally at all time. There is no
// memory allocation, elements are stored in the buffer passed as an
// argument. The farthest leaf node is on top.
assert(k == (int)buffer.size());
KOKKOS_ASSERT(k == (int)buffer.size());
PriorityQueue<PairIndexDistance, CompareDistance,
UnmanagedStaticVector<PairIndexDistance>>
heap(UnmanagedStaticVector<PairIndexDistance>(buffer.data(),
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/ArborX_DetailsAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ struct intersects<PointTag, TriangleTag, Point, Triangle>
Float u[] = {b[0] - a[0], b[1] - a[1]};
Float v[] = {c[0] - a[0], c[1] - a[1]};
Float const det = v[1] * u[0] - v[0] * u[1];
assert(det != 0);
KOKKOS_ASSERT(det != 0);
Float const inv_det = 1 / det;

Float alpha[] = {v[1] * inv_det, -v[0] * inv_det};
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/ArborX_Ray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct Ray
KOKKOS_FUNCTION static void normalize(Vector &v)
{
auto const magv = norm(v);
assert(magv > 0);
KOKKOS_ASSERT(magv > 0);
for (int d = 0; d < 3; ++d)
v[d] /= magv;
}
Expand Down Expand Up @@ -475,7 +475,7 @@ float distance(Ray const &ray, Box const &box)
KOKKOS_INLINE_FUNCTION bool solveQuadratic(float const a, float const b,
float const c, float &x1, float &x2)
{
assert(a != 0);
KOKKOS_ASSERT(a != 0);

auto const discriminant = b * b - 4 * a * c;
if (discriminant < 0)
Expand Down
Loading