Skip to content

Commit

Permalink
Updated RangePolicy to have the same precondition as MDRangePolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
ldh4 committed Jan 11, 2024
1 parent 909c91a commit 208bbfb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
22 changes: 18 additions & 4 deletions core/src/Kokkos_ExecPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,18 @@ class RangePolicy : public Impl::PolicyTraits<Properties...> {
inline RangePolicy(const typename traits::execution_space& work_space,
const member_type work_begin, const member_type work_end)
: m_space(work_space),
m_begin(work_begin < work_end ? work_begin : 0),
m_end(work_begin < work_end ? work_end : 0),
m_begin(work_begin),
m_end(work_end),
m_granularity(0),
m_granularity_mask(0) {
check_bounds_validity();
set_auto_chunk_size();
}

/** \brief Total range */
inline RangePolicy(const member_type work_begin, const member_type work_end)
: RangePolicy(typename traits::execution_space(), work_begin, work_end) {
check_bounds_validity();
set_auto_chunk_size();
}

Expand All @@ -136,10 +138,11 @@ class RangePolicy : public Impl::PolicyTraits<Properties...> {
const member_type work_begin, const member_type work_end,
Args... args)
: m_space(work_space),
m_begin(work_begin < work_end ? work_begin : 0),
m_end(work_begin < work_end ? work_end : 0),
m_begin(work_begin),
m_end(work_end),
m_granularity(0),
m_granularity_mask(0) {
check_bounds_validity();
set_auto_chunk_size();
set(args...);
}
Expand All @@ -149,6 +152,7 @@ class RangePolicy : public Impl::PolicyTraits<Properties...> {
inline RangePolicy(const member_type work_begin, const member_type work_end,
Args... args)
: RangePolicy(typename traits::execution_space(), work_begin, work_end) {
check_bounds_validity();
set_auto_chunk_size();
set(args...);
}
Expand Down Expand Up @@ -218,6 +222,16 @@ class RangePolicy : public Impl::PolicyTraits<Properties...> {
m_granularity_mask = m_granularity - 1;
}

inline void check_bounds_validity() {
if (m_end < m_begin) {
std::string msg = "Kokkos::RangePolicy bounds error: The lower bound (" +
std::to_string(m_begin) +
") is greater than the upper bound (" +
std::to_string(m_end) + ").";
Kokkos::abort(msg.c_str());
}
}

public:
/** \brief Subrange for a partition's rank and size.
*
Expand Down
13 changes: 13 additions & 0 deletions core/unit_test/TestRangePolicyConstructors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,17 @@ TEST(TEST_CATEGORY, range_policy_runtime_parameters) {
}
}

TEST(TEST_CATEGORY_DEATH, range_policy_invalid_bounds) {
using Policy = Kokkos::RangePolicy<TEST_EXECSPACE>;
using ChunkSize = Kokkos::ChunkSize;

ASSERT_DEATH({ (void)Policy(100, 90); },
"Kokkos::RangePolicy bounds error: The lower bound \\(100\\) is "
"greater than the upper bound \\(90\\)\\.");

ASSERT_DEATH({ (void)Policy(TEST_EXECSPACE(), 100, 90, ChunkSize(10)); },
"Kokkos::RangePolicy bounds error: The lower bound \\(100\\) is "
"greater than the upper bound \\(90\\)\\.");
}

} // namespace

0 comments on commit 208bbfb

Please sign in to comment.