Skip to content

Commit 351e03a

Browse files
authored
Use KOKKOS_ASSERT in KOKKOS_FUNCTION annotated functions (#968)
* Use KOKKOS_ASSERT in KOKKOS_FUNCTION annotated functions * Remove trailing semicolon
1 parent dfd5d82 commit 351e03a

File tree

10 files changed

+63
-64
lines changed

10 files changed

+63
-64
lines changed

include/ddc/chunk_common.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include <array>
8-
#include <cassert>
98
#include <cstddef>
109
#include <type_traits>
1110
#include <utility>
@@ -221,7 +220,7 @@ class ChunkCommon
221220
, m_domain(domain)
222221
{
223222
// Handle the case where an allocation of size 0 returns a nullptr.
224-
assert(domain.empty() || ((ptr != nullptr) && !domain.empty()));
223+
KOKKOS_ASSERT(domain.empty() || ((ptr != nullptr) && !domain.empty()))
225224
}
226225

227226
/** Constructs a new ChunkCommon by copy, yields a new view to the same data

include/ddc/chunk_span.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include <array>
8-
#include <cassert>
98
#include <cstddef>
109
#include <type_traits>
1110
#include <utility>
@@ -233,8 +232,9 @@ class ChunkSpan : public ChunkCommon<ElementType, SupportType, LayoutStridedPoli
233232
: base_type(allocation_mdspan, domain)
234233
{
235234
for (std::size_t i = 0; i < SupportType::rank(); ++i) {
236-
assert(allocation_mdspan.extent(i)
237-
== static_cast<std::size_t>(detail::array(domain.extents())[i]));
235+
KOKKOS_ASSERT(
236+
allocation_mdspan.extent(i)
237+
== static_cast<std::size_t>(detail::array(domain.extents())[i]))
238238
}
239239
}
240240

@@ -272,7 +272,7 @@ class ChunkSpan : public ChunkCommon<ElementType, SupportType, LayoutStridedPoli
272272
{
273273
using detail::TypeSeq;
274274
using QueryDDom = typename detail::RebindDomain<SupportType, TypeSeq<QueryDDims...>>::type;
275-
assert(QueryDDom(this->m_domain).contains(slice_spec));
275+
KOKKOS_ASSERT((QueryDDom(this->m_domain).contains(slice_spec)))
276276
slicer<to_type_seq_t<SupportType>> const slicer;
277277
auto subview = slicer(
278278
this->allocation_mdspan(),
@@ -310,9 +310,10 @@ class ChunkSpan : public ChunkCommon<ElementType, SupportType, LayoutStridedPoli
310310
std::enable_if_t<is_discrete_domain_v<SFINAESupportType>, std::nullptr_t> = nullptr>
311311
KOKKOS_FUNCTION constexpr auto operator[](DiscreteDomain<QueryDDims...> const& odomain) const
312312
{
313-
assert(odomain.empty()
314-
|| (DiscreteDomain<QueryDDims...>(this->m_domain).contains(odomain.front())
315-
&& DiscreteDomain<QueryDDims...>(this->m_domain).contains(odomain.back())));
313+
KOKKOS_ASSERT(
314+
odomain.empty()
315+
|| (DiscreteDomain<QueryDDims...>(this->m_domain).contains(odomain.front())
316+
&& DiscreteDomain<QueryDDims...>(this->m_domain).contains(odomain.back())))
316317
slicer<to_type_seq_t<SupportType>> const slicer;
317318
auto subview = slicer(this->allocation_mdspan(), odomain, this->m_domain);
318319
using layout_type = typename decltype(subview)::layout_type;
@@ -349,7 +350,7 @@ class ChunkSpan : public ChunkCommon<ElementType, SupportType, LayoutStridedPoli
349350
static_assert(
350351
SupportType::rank() == (0 + ... + DElems::size()),
351352
"Invalid number of dimensions");
352-
assert(this->m_domain.contains(delems...));
353+
KOKKOS_ASSERT((this->m_domain.contains(delems...)))
353354
return DDC_MDSPAN_ACCESS_OP(
354355
this->m_allocation_mdspan,
355356
detail::array(this->m_domain.distance_from_front(delems...)));

include/ddc/detail/kokkos.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ KOKKOS_FUNCTION auto build_mdspan(
175175
Kokkos::View<DataType, Properties...> const view,
176176
std::index_sequence<Is...>)
177177
{
178-
assert(is_kokkos_layout_compatible(view));
178+
KOKKOS_ASSERT((is_kokkos_layout_compatible(view)))
179179
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
180180
using element_type = kokkos_to_mdspan_element_t<DataType>;
181181
using extents_type = Kokkos::dextents<std::size_t, Kokkos::View<DataType, Properties...>::rank>;

include/ddc/discrete_domain.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <cassert>
87
#include <cstddef>
98
#include <iterator>
109
#include <tuple>
@@ -193,12 +192,14 @@ class DiscreteDomain
193192
template <class... ODDims>
194193
KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain<ODDims...> const& odomain) const
195194
{
196-
assert(((DiscreteElement<ODDims>(m_element_begin)
197-
<= DiscreteElement<ODDims>(odomain.m_element_begin))
198-
&& ...));
199-
assert(((DiscreteElement<ODDims>(m_element_end)
200-
>= DiscreteElement<ODDims>(odomain.m_element_end))
201-
&& ...));
195+
KOKKOS_ASSERT(
196+
((DiscreteElement<ODDims>(m_element_begin)
197+
<= DiscreteElement<ODDims>(odomain.m_element_begin))
198+
&& ...))
199+
KOKKOS_ASSERT(
200+
((DiscreteElement<ODDims>(m_element_end)
201+
>= DiscreteElement<ODDims>(odomain.m_element_end))
202+
&& ...))
202203
DiscreteVector<DDims...> const myextents = extents();
203204
DiscreteVector<ODDims...> const oextents = odomain.extents();
204205
return DiscreteDomain(

include/ddc/discrete_space.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include <cassert>
78
#include <cstddef>
89
#include <functional>
910
#include <map>
@@ -234,7 +235,7 @@ KOKKOS_FUNCTION detail::ddim_impl_t<DDim, MemorySpace> const& discrete_space()
234235
{
235236
// This function requires that `ddc::init_discrete_space<DDim>(...);` be called first
236237
if constexpr (std::is_same_v<MemorySpace, Kokkos::HostSpace>) {
237-
assert(is_discrete_space_initialized<DDim>());
238+
KOKKOS_ASSERT((is_discrete_space_initialized<DDim>()))
238239
return detail::g_discrete_space_dual<DDim>->get_host();
239240
}
240241
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)

include/ddc/kernels/splines/bsplines_non_uniform.hpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -450,22 +450,22 @@ template <class DDim, class MemorySpace>
450450
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
451451
Impl<DDim, MemorySpace>::eval_basis(DSpan1D values, ddc::Coordinate<CDim> const& x) const
452452
{
453-
assert(values.size() == D + 1);
453+
KOKKOS_ASSERT((values.size() == D + 1))
454454

455455
std::array<double, degree()> left;
456456
std::array<double, degree()> right;
457457

458-
assert(x - rmin() >= -length() * 1e-14);
459-
assert(rmax() - x >= -length() * 1e-14);
460-
assert(values.size() == degree() + 1);
458+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
459+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
460+
KOKKOS_ASSERT((values.size() == degree() + 1))
461461

462462
// 1. Compute cell index 'icell'
463463
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);
464464

465-
assert(icell >= m_break_point_domain.front());
466-
assert(icell <= m_break_point_domain.back());
467-
assert(ddc::coordinate(icell) - x <= length() * 1e-14);
468-
assert(x - ddc::coordinate(icell + 1) <= length() * 1e-14);
465+
KOKKOS_ASSERT((icell >= m_break_point_domain.front()))
466+
KOKKOS_ASSERT((icell <= m_break_point_domain.back()))
467+
KOKKOS_ASSERT((ddc::coordinate(icell) - x <= length() * 1e-14))
468+
KOKKOS_ASSERT((x - ddc::coordinate(icell + 1) <= length() * 1e-14))
469469

470470
// 2. Compute values of B-splines with support over cell 'icell'
471471
double temp;
@@ -493,17 +493,17 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
493493
std::array<double, degree()> left;
494494
std::array<double, degree()> right;
495495

496-
assert(x - rmin() >= -length() * 1e-14);
497-
assert(rmax() - x >= -length() * 1e-14);
498-
assert(derivs.size() == degree() + 1);
496+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
497+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
498+
KOKKOS_ASSERT((derivs.size() == degree() + 1))
499499

500500
// 1. Compute cell index 'icell'
501501
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);
502502

503-
assert(icell >= m_break_point_domain.front());
504-
assert(icell <= m_break_point_domain.back());
505-
assert(ddc::coordinate(icell) <= x);
506-
assert(ddc::coordinate(icell + 1) >= x);
503+
KOKKOS_ASSERT((icell >= m_break_point_domain.front()))
504+
KOKKOS_ASSERT((icell <= m_break_point_domain.back()))
505+
KOKKOS_ASSERT((ddc::coordinate(icell) <= x))
506+
KOKKOS_ASSERT((ddc::coordinate(icell + 1) >= x))
507507

508508
// 2. Compute values of derivatives of B-splines with support over cell 'icell'
509509

@@ -563,20 +563,20 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> NonUniformBSplines<CDim, D>::
563563
Kokkos::mdspan<double, Kokkos::extents<std::size_t, degree() + 1, degree() + 1>> const ndu(
564564
ndu_ptr.data());
565565

566-
assert(x - rmin() >= -length() * 1e-14);
567-
assert(rmax() - x >= -length() * 1e-14);
568-
// assert(n >= 0); as long as n is unsigned
569-
assert(n <= degree());
570-
assert(derivs.extent(0) == 1 + degree());
571-
assert(derivs.extent(1) == 1 + n);
566+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
567+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
568+
// KOKKOS_ASSERT((n >= 0)) as long as n is unsigned
569+
KOKKOS_ASSERT((n <= degree()))
570+
KOKKOS_ASSERT((derivs.extent(0) == 1 + degree()))
571+
KOKKOS_ASSERT((derivs.extent(1) == 1 + n))
572572

573573
// 1. Compute cell index 'icell' and x_offset
574574
ddc::DiscreteElement<knot_discrete_dimension_type> const icell = find_cell_start(x);
575575

576-
assert(icell >= m_break_point_domain.front());
577-
assert(icell <= m_break_point_domain.back());
578-
assert(ddc::coordinate(icell) <= x);
579-
assert(ddc::coordinate(icell + 1) >= x);
576+
KOKKOS_ASSERT((icell >= m_break_point_domain.front()))
577+
KOKKOS_ASSERT((icell <= m_break_point_domain.back()))
578+
KOKKOS_ASSERT((ddc::coordinate(icell) <= x))
579+
KOKKOS_ASSERT((ddc::coordinate(icell + 1) >= x))
580580

581581
// 2. Compute nonzero basis functions and knot differences for splines
582582
// up to degree (degree-1) which are needed to compute derivative
@@ -658,8 +658,8 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<NonUniformBsplinesKnots<DDim>> NonUn
658658
CDim,
659659
D>::Impl<DDim, MemorySpace>::find_cell_start(ddc::Coordinate<CDim> const& x) const
660660
{
661-
assert(x - rmin() >= -length() * 1e-14);
662-
assert(rmax() - x >= -length() * 1e-14);
661+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
662+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
663663

664664
if (x <= rmin()) {
665665
return m_break_point_domain.front();

include/ddc/kernels/splines/bsplines_uniform.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class UniformBSplines : detail::UniformBSplinesBase
201201
KOKKOS_INLINE_FUNCTION discrete_element_type
202202
eval_basis(DSpan1D values, ddc::Coordinate<CDim> const& x) const
203203
{
204-
assert(values.size() == degree() + 1);
204+
KOKKOS_ASSERT((values.size() == degree() + 1))
205205
return eval_basis(values, x, degree());
206206
}
207207

@@ -388,7 +388,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> UniformBSplines<CDim, D>::
388388
ddc::Coordinate<CDim> const& x,
389389
[[maybe_unused]] std::size_t const degree) const
390390
{
391-
assert(values.size() == degree + 1);
391+
KOKKOS_ASSERT((values.size() == degree + 1))
392392

393393
double offset;
394394
int jmin;
@@ -421,7 +421,7 @@ template <class DDim, class MemorySpace>
421421
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> UniformBSplines<CDim, D>::
422422
Impl<DDim, MemorySpace>::eval_deriv(DSpan1D derivs, ddc::Coordinate<CDim> const& x) const
423423
{
424-
assert(derivs.size() == degree() + 1);
424+
KOKKOS_ASSERT((derivs.size() == degree() + 1))
425425

426426
double offset;
427427
int jmin;
@@ -477,12 +477,12 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<DDim> UniformBSplines<CDim, D>::
477477
double offset;
478478
int jmin;
479479

480-
assert(x - rmin() >= -length() * 1e-14);
481-
assert(rmax() - x >= -length() * 1e-14);
482-
// assert(n >= 0); as long as n is unsigned
483-
assert(n <= degree());
484-
assert(derivs.extent(0) == 1 + degree());
485-
assert(derivs.extent(1) == 1 + n);
480+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
481+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
482+
// KOKKOS_ASSERT((n >= 0)) as long as n is unsigned
483+
KOKKOS_ASSERT((n <= degree()))
484+
KOKKOS_ASSERT((derivs.extent(0) == 1 + degree()))
485+
KOKKOS_ASSERT((derivs.extent(1) == 1 + n))
486486

487487
// 1. Compute cell index 'icell' and x_offset
488488
// 2. Compute index range of B-splines with support over cell 'icell'
@@ -561,8 +561,8 @@ KOKKOS_INLINE_FUNCTION void UniformBSplines<CDim, D>::Impl<DDim, MemorySpace>::g
561561
double& offset,
562562
ddc::Coordinate<CDim> const& x) const
563563
{
564-
assert(x - rmin() >= -length() * 1e-14);
565-
assert(rmax() - x >= -length() * 1e-14);
564+
KOKKOS_ASSERT((x - rmin() >= -length() * 1e-14))
565+
KOKKOS_ASSERT((rmax() - x >= -length() * 1e-14))
566566

567567
double const inv_dx = inv_step();
568568
if (x <= rmin()) {

include/ddc/kernels/splines/periodic_extrapolation_rule.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#pragma once
66

7-
#include <cassert>
8-
7+
#include <Kokkos_Assert.hpp>
98
#include <Kokkos_Macros.hpp>
109

1110
namespace ddc {
@@ -18,7 +17,7 @@ struct PeriodicExtrapolationRule
1817
template <class CoordType, class ChunkSpan>
1918
KOKKOS_FUNCTION double operator()(CoordType, ChunkSpan) const
2019
{
21-
assert("PeriodicExtrapolationRule::operator() should never be called");
20+
KOKKOS_ASSERT(("PeriodicExtrapolationRule::operator() should never be called"))
2221

2322
return 0.;
2423
}

include/ddc/sparse_discrete_domain.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <cassert>
87
#include <cstddef>
98
#include <iterator>
109
#include <tuple>
@@ -296,7 +295,7 @@ class SparseDiscreteDomain
296295
sizeof...(DDims) == (0 + ... + DElems::size()),
297296
"Invalid number of dimensions");
298297
static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
299-
assert(contains(delems...));
298+
KOKKOS_ASSERT((contains(delems...)))
300299
return DiscreteVector<DDims...>(
301300
(detail::lower_bound(
302301
get<DDims>(m_views).data(),

include/ddc/strided_discrete_domain.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <cassert>
87
#include <cstddef>
98
#include <iterator>
109
#include <tuple>
@@ -247,7 +246,7 @@ class StridedDiscreteDomain
247246
sizeof...(DDims) == (0 + ... + DElems::size()),
248247
"Invalid number of dimensions");
249248
static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
250-
assert(contains(delems...));
249+
KOKKOS_ASSERT((contains(delems...)))
251250
return DiscreteVector<DDims...>(
252251
((DiscreteElement<DDims>(take<DDims>(delems...))
253252
- DiscreteElement<DDims>(m_element_begin))

0 commit comments

Comments
 (0)