Skip to content

Commit

Permalink
use GKO_ASSERT in device code
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Aug 8, 2024
1 parent 374e32e commit 9fbbbba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 3 additions & 1 deletion core/base/index_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <iterator>
#include <type_traits>

#include <ginkgo/core/base/types.hpp>

#include "core/base/iterator_range.hpp"


Expand Down Expand Up @@ -188,7 +190,7 @@ class irange : public iterator_range<index_iterator<IndexType>> {
constexpr explicit irange(index_type begin, index_type end)
: iterator_range<iterator>{iterator{begin}, iterator{end}}
{
assert(begin <= end);
GKO_ASSERT(begin <= end);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/base/segmented_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct device_segmented_array {

constexpr segment get_segment(size_type segment_id)
{
assert(segment_id < (offsets_end - offsets_begin));
GKO_ASSERT(segment_id < (offsets_end - offsets_begin));
return {flat_begin + offsets_begin[segment_id],
flat_begin + offsets_begin[segment_id + 1]};
}
Expand Down
40 changes: 20 additions & 20 deletions core/base/segmented_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class segmented_index_range {

constexpr enumerated_segment operator*() const
{
assert(segment_ >= 0);
assert(segment_ < range_.num_segments());
GKO_ASSERT(segment_ >= 0);
GKO_ASSERT(segment_ < range_.num_segments());
return enumerated_segment{segment_,
segment_type{range_.begin_index(segment_),
range_.end_index(segment_)}};
Expand All @@ -61,7 +61,7 @@ class segmented_index_range {

constexpr friend bool operator==(iterator lhs, iterator rhs)
{
assert(lhs.range_ == rhs.range_);
GKO_ASSERT(lhs.range_ == rhs.range_);
return lhs.segment_ == rhs.segment_;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ class segmented_index_range {
index_type num_segments)
: begins_{begins}, ends_{ends}, num_segments_{num_segments}
{
assert(num_segments_ >= 0);
GKO_ASSERT(num_segments_ >= 0);
}

/**
Expand All @@ -113,8 +113,8 @@ class segmented_index_range {
*/
constexpr segment_type operator[](index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return (*iterator{*this, segment}).segment;
}

Expand Down Expand Up @@ -142,16 +142,16 @@ class segmented_index_range {
/** @return the beginning index of the given segment. */
constexpr index_type begin_index(index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return begin_indices()[segment];
}

/** @return the end index of the given segment. */
constexpr index_type end_index(index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return end_indices()[segment];
}

Expand Down Expand Up @@ -214,8 +214,8 @@ class segmented_value_range {

constexpr enumerated_segment operator*() const
{
assert(segment_ >= 0);
assert(segment_ < range_.num_segments());
GKO_ASSERT(segment_ >= 0);
GKO_ASSERT(segment_ < range_.num_segments());
return enumerated_segment{
segment_,
segment_type{range_.values() + range_.begin_index(segment_),
Expand All @@ -230,7 +230,7 @@ class segmented_value_range {

constexpr friend bool operator==(iterator lhs, iterator rhs)
{
assert(lhs.range_ == rhs.range_);
GKO_ASSERT(lhs.range_ == rhs.range_);
return lhs.segment_ == rhs.segment_;
}

Expand Down Expand Up @@ -264,7 +264,7 @@ class segmented_value_range {
values_{values},
num_segments_{num_segments}
{
assert(num_segments_ >= 0);
GKO_ASSERT(num_segments_ >= 0);
}

/**
Expand All @@ -291,8 +291,8 @@ class segmented_value_range {
*/
constexpr segment_type operator[](index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return (*iterator{*this, segment}).segment;
}

Expand Down Expand Up @@ -328,16 +328,16 @@ class segmented_value_range {
/** @return the beginning index of the given segment. */
constexpr index_type begin_index(index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return begin_indices()[segment];
}

/** @return the end index of the given segment. */
constexpr index_type end_index(index_type segment) const
{
assert(segment >= 0);
assert(segment < num_segments());
GKO_ASSERT(segment >= 0);
GKO_ASSERT(segment < num_segments());
return end_indices()[segment];
}

Expand Down

0 comments on commit 9fbbbba

Please sign in to comment.