Skip to content

Commit b5509ab

Browse files
dalg24Rombur
andauthored
Medley of (hopefully) uncontroversial fixups towards building with no exceptions (kokkos#7337)
* Abort on TeamPolicy::set_scratch_team() precondition violation Call abort for invalid level argument instead of throwing * Prefer GTetst native support to report failure * Avoid ASSERT_NO_THROW in range policy tests * Drop EXPECT_NO_THROW in reduce test * Abort on the host-side as well on subview precondition violation * Abort instead of throwing if parsing tools settings failed * Fix warning comparison of integers of different signs * Get rid of all *_NO_THROW in algorithms tests * Get rid of a few more *_NO_THROW in core tests * Abort on error in shared allocation instead of throwing * Per review adding comments that code w/o assertions is meant to check that it does not throw Co-Authored-By: Bruno Turcksin <[email protected]> --------- Co-authored-by: Bruno Turcksin <[email protected]>
1 parent 827e7da commit b5509ab

14 files changed

+62
-65
lines changed

algorithms/unit_tests/TestBinSortA.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ TEST(TEST_CATEGORY, BinSortEmptyView) {
246246
// does not matter if we use int or something else
247247
Kokkos::View<int*, ExecutionSpace> v("v", 0);
248248

249-
// test all exposed public sort methods
250-
ASSERT_NO_THROW(Sorter.sort(ExecutionSpace(), v, 0, 0));
251-
ASSERT_NO_THROW(Sorter.sort(v, 0, 0));
252-
ASSERT_NO_THROW(Sorter.sort(ExecutionSpace(), v));
253-
ASSERT_NO_THROW(Sorter.sort(v));
249+
// test all exposed public sort methods are callable and do not throw
250+
Sorter.sort(ExecutionSpace(), v, 0, 0);
251+
Sorter.sort(v, 0, 0);
252+
Sorter.sort(ExecutionSpace(), v);
253+
Sorter.sort(v);
254254
}
255255

256256
TEST(TEST_CATEGORY, BinSortEmptyKeysView) {
@@ -263,7 +263,7 @@ TEST(TEST_CATEGORY, BinSortEmptyKeysView) {
263263
BinOp_t binOp(5, 0, 10);
264264
Kokkos::BinSort<KeyViewType, BinOp_t> Sorter(ExecutionSpace{}, kv, binOp);
265265

266-
ASSERT_NO_THROW(Sorter.create_permute_vector(ExecutionSpace{}));
266+
Sorter.create_permute_vector(ExecutionSpace{}); // does not throw
267267
}
268268

269269
// BinSort may delegate sorting within bins to std::sort when running on host
@@ -282,7 +282,7 @@ TEST(TEST_CATEGORY, BinSort_issue_7221) {
282282
Kokkos::BinSort<KeyViewType, BinOp_t> Sorter(ExecutionSpace{}, kv, binOp,
283283
/*sort_within_bins*/ true);
284284

285-
ASSERT_NO_THROW(Sorter.create_permute_vector(ExecutionSpace{}));
285+
Sorter.create_permute_vector(ExecutionSpace{}); // does not throw
286286
}
287287

288288
} // namespace Test

algorithms/unit_tests/TestSort.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,10 @@ TEST(TEST_CATEGORY, SortEmptyView) {
229229
// does not matter if we use int or something else
230230
Kokkos::View<int*, ExecutionSpace> v("v", 0);
231231

232+
// checking that it does not throw
232233
// TODO check the synchronous behavior of the calls below
233-
ASSERT_NO_THROW(Kokkos::sort(ExecutionSpace(), v));
234-
ASSERT_NO_THROW(Kokkos::sort(v));
234+
Kokkos::sort(ExecutionSpace(), v);
235+
Kokkos::sort(v);
235236
}
236237

237238
} // namespace Test

algorithms/unit_tests/TestSortByKey.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ TEST(TEST_CATEGORY, SortByKeyEmptyView) {
8383
Kokkos::View<int *, ExecutionSpace> keys("keys", 0);
8484
Kokkos::View<float *, ExecutionSpace> values("values", 0);
8585

86-
ASSERT_NO_THROW(
87-
Kokkos::Experimental::sort_by_key(ExecutionSpace(), keys, values));
86+
// checking that it does not throw
87+
Kokkos::Experimental::sort_by_key(ExecutionSpace(), keys, values);
8888
}
8989

9090
// Test #7036
@@ -95,8 +95,8 @@ TEST(TEST_CATEGORY, SortByKeyEmptyViewHost) {
9595
Kokkos::View<int *, ExecutionSpace> keys("keys", 0);
9696
Kokkos::View<float *, ExecutionSpace> values("values", 0);
9797

98-
ASSERT_NO_THROW(
99-
Kokkos::Experimental::sort_by_key(ExecutionSpace(), keys, values));
98+
// checking that it does not throw
99+
Kokkos::Experimental::sort_by_key(ExecutionSpace(), keys, values);
100100
}
101101

102102
TEST(TEST_CATEGORY, SortByKey) {
@@ -183,12 +183,12 @@ TEST(TEST_CATEGORY, SortByKeyStaticExtents) {
183183
Kokkos::View<int[10], ExecutionSpace> keys("keys");
184184

185185
Kokkos::View<int[10], ExecutionSpace> values_static("values_static");
186-
ASSERT_NO_THROW(
187-
Kokkos::Experimental::sort_by_key(space, keys, values_static));
186+
// checking that it does not throw
187+
Kokkos::Experimental::sort_by_key(space, keys, values_static);
188188

189189
Kokkos::View<int *, ExecutionSpace> values_dynamic("values_dynamic", 10);
190-
ASSERT_NO_THROW(
191-
Kokkos::Experimental::sort_by_key(space, keys, values_dynamic));
190+
// checking that it does not throw
191+
Kokkos::Experimental::sort_by_key(space, keys, values_dynamic);
192192
}
193193

194194
template <typename ExecutionSpace, typename Keys, typename Values>

algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ TEST(std_algorithms, expect_no_overlap) {
148148
auto last_st0 = first_st0 + strided_view_1d_0.extent(0);
149149
auto first_st1 = KE::begin(strided_view_1d_1); // [3, 15)
150150
// Does not overlap since offset (=3) is not divisible by stride (=2)
151-
EXPECT_NO_THROW(
152-
{ KE::Impl::expect_no_overlap(first_st0, last_st0, first_st1); });
151+
KE::Impl::expect_no_overlap(first_st0, last_st0, first_st1);
153152

154153
// Iterating over the same range without overlapping
155154
Kokkos::View<value_type[2][extent0], Kokkos::LayoutLeft> static_view_2d{
@@ -160,9 +159,7 @@ TEST(std_algorithms, expect_no_overlap) {
160159
auto sub_last_s0 = sub_first_s0 + sub_static_view_1d_0.extent(0);
161160
auto sub_first_s1 = KE::begin(sub_static_view_1d_1); // 1, 3, 5, ...
162161

163-
EXPECT_NO_THROW({
164-
KE::Impl::expect_no_overlap(sub_first_s0, sub_last_s0, sub_first_s1);
165-
});
162+
KE::Impl::expect_no_overlap(sub_first_s0, sub_last_s0, sub_first_s1);
166163

167164
Kokkos::View<value_type**, Kokkos::LayoutLeft> dynamic_view_2d{
168165
"std-algo-test-2d-contiguous-view-dynamic", 2, extent0};
@@ -172,9 +169,7 @@ TEST(std_algorithms, expect_no_overlap) {
172169
auto sub_last_d0 = sub_first_d0 + sub_dynamic_view_1d_0.extent(0);
173170
auto sub_first_d1 = KE::begin(sub_dynamic_view_1d_1); // 1, 3, 5, ...
174171

175-
EXPECT_NO_THROW({
176-
KE::Impl::expect_no_overlap(sub_first_d0, sub_last_d0, sub_first_d1);
177-
});
172+
KE::Impl::expect_no_overlap(sub_first_d0, sub_last_d0, sub_first_d1);
178173

179174
Kokkos::LayoutStride layout2d{2, 3, extent0, 2 * 3};
180175
Kokkos::View<value_type**, Kokkos::LayoutStride> strided_view_2d{
@@ -185,9 +180,7 @@ TEST(std_algorithms, expect_no_overlap) {
185180
auto sub_last_st0 = sub_first_st0 + sub_strided_view_1d_0.extent(0);
186181
auto sub_first_st1 = KE::begin(sub_strided_view_1d_1); // 1, 7, 13, ...
187182

188-
EXPECT_NO_THROW({
189-
KE::Impl::expect_no_overlap(sub_first_st0, sub_last_st0, sub_first_st1);
190-
});
183+
KE::Impl::expect_no_overlap(sub_first_st0, sub_last_st0, sub_first_st1);
191184
}
192185

193186
} // namespace stdalgos

core/src/Kokkos_ExecPolicy.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ struct ScratchRequest {
582582
}
583583
};
584584

585-
// Throws a runtime exception if level is not `0` or `1`
585+
// Causes abnormal program termination if level is not `0` or `1`
586586
void team_policy_check_valid_storage_level_argument(int level);
587587

588588
/** \brief Execution policy for parallel work over a league of teams of

core/src/View/Kokkos_ViewMapping.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ struct SubviewExtents {
370370
const int n = snprintf(buffer, LEN, "Kokkos::subview bounds error (");
371371
error(buffer + n, LEN - n, 0, 0, dim, args...);
372372

373-
Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
373+
Kokkos::abort(buffer);))
374374

375375
KOKKOS_IF_ON_DEVICE(((void)dim;
376376
Kokkos::abort("Kokkos::subview bounds error");

core/src/impl/Kokkos_Core.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ void Kokkos::Impl::parse_environment_variables(
979979
Tools::Impl::parse_environment_variables(tools_init_arguments);
980980
if (init_result.result ==
981981
Tools::Impl::InitializationStatus::environment_argument_mismatch) {
982-
Impl::throw_runtime_exception(init_result.error_message);
982+
Kokkos::abort(init_result.error_message.c_str());
983983
}
984984
combine(settings, tools_init_arguments);
985985

core/src/impl/Kokkos_ExecPolicy.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void team_policy_check_valid_storage_level_argument(int level) {
4141
std::stringstream ss;
4242
ss << "TeamPolicy::set_scratch_size(/*level*/ " << level
4343
<< ", ...) storage level argument must be 0 or 1 to be valid\n";
44-
Impl::throw_runtime_exception(ss.str());
44+
abort(ss.str().c_str());
4545
}
4646
}
4747

core/src/impl/Kokkos_SharedAlloc.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool SharedAllocationRecord<void, void>::is_sane(
8686
}
8787

8888
if (nullptr != Kokkos::atomic_exchange(&root->m_next, root_next)) {
89-
Kokkos::Impl::throw_runtime_exception(
89+
Kokkos::abort(
9090
"Kokkos::Impl::SharedAllocationRecord failed is_sane unlocking");
9191
}
9292
}
@@ -97,7 +97,7 @@ bool SharedAllocationRecord<void, void>::is_sane(
9797

9898
bool SharedAllocationRecord<void, void>::is_sane(
9999
SharedAllocationRecord<void, void>*) {
100-
Kokkos::Impl::throw_runtime_exception(
100+
Kokkos::abort(
101101
"Kokkos::Impl::SharedAllocationRecord::is_sane only works with "
102102
"KOKKOS_ENABLE_DEBUG enabled");
103103
return false;
@@ -129,18 +129,17 @@ SharedAllocationRecord<void, void>* SharedAllocationRecord<void, void>::find(
129129
}
130130

131131
if (nullptr != Kokkos::atomic_exchange(&arg_root->m_next, root_next)) {
132-
Kokkos::Impl::throw_runtime_exception(
132+
Kokkos::abort(
133133
"Kokkos::Impl::SharedAllocationRecord failed locking/unlocking");
134134
}
135135
return r;
136136
}
137137
#else
138138
SharedAllocationRecord<void, void>* SharedAllocationRecord<void, void>::find(
139139
SharedAllocationRecord<void, void>* const, void* const) {
140-
Kokkos::Impl::throw_runtime_exception(
140+
Kokkos::abort(
141141
"Kokkos::Impl::SharedAllocationRecord::find only works with "
142-
"KOKKOS_ENABLE_DEBUG "
143-
"enabled");
142+
"KOKKOS_ENABLE_DEBUG enabled");
144143
return nullptr;
145144
}
146145
#endif
@@ -188,13 +187,13 @@ SharedAllocationRecord<void, void>::SharedAllocationRecord(
188187
Kokkos::memory_fence();
189188

190189
if (nullptr != Kokkos::atomic_exchange(&m_root->m_next, this)) {
191-
Kokkos::Impl::throw_runtime_exception(
190+
Kokkos::abort(
192191
"Kokkos::Impl::SharedAllocationRecord failed locking/unlocking");
193192
}
194193
#endif
195194

196195
} else {
197-
Kokkos::Impl::throw_runtime_exception(
196+
Kokkos::abort(
198197
"Kokkos::Impl::SharedAllocationRecord given nullptr allocation");
199198
}
200199
}
@@ -204,8 +203,7 @@ void SharedAllocationRecord<void, void>::increment(
204203
const int old_count = Kokkos::atomic_fetch_add(&arg_record->m_count, 1);
205204

206205
if (old_count < 0) { // Error
207-
Kokkos::Impl::throw_runtime_exception(
208-
"Kokkos::Impl::SharedAllocationRecord failed increment");
206+
Kokkos::abort("Kokkos::Impl::SharedAllocationRecord failed increment");
209207
}
210208
}
211209

@@ -219,8 +217,7 @@ SharedAllocationRecord<void, void>* SharedAllocationRecord<
219217
ss << "Kokkos allocation \"";
220218
ss << arg_record->get_label();
221219
ss << "\" is being deallocated after Kokkos::finalize was called\n";
222-
auto s = ss.str();
223-
Kokkos::Impl::throw_runtime_exception(s);
220+
Kokkos::abort(ss.str().c_str());
224221
}
225222

226223
#ifdef KOKKOS_ENABLE_DEBUG
@@ -256,7 +253,7 @@ SharedAllocationRecord<void, void>* SharedAllocationRecord<
256253
// Unlock the list:
257254
if (nullptr !=
258255
Kokkos::atomic_exchange(&arg_record->m_root->m_next, root_next)) {
259-
Kokkos::Impl::throw_runtime_exception(
256+
Kokkos::abort(
260257
"Kokkos::Impl::SharedAllocationRecord failed decrement unlocking");
261258
}
262259

@@ -273,7 +270,7 @@ SharedAllocationRecord<void, void>* SharedAllocationRecord<
273270
"= %d\n",
274271
arg_record->m_alloc_ptr->m_label, old_count);
275272
fflush(stderr);
276-
Kokkos::Impl::throw_runtime_exception(
273+
Kokkos::abort(
277274
"Kokkos::Impl::SharedAllocationRecord failed decrement count");
278275
}
279276

@@ -317,7 +314,7 @@ void SharedAllocationRecord<void, void>::print_host_accessible_records(
317314
void SharedAllocationRecord<void, void>::print_host_accessible_records(
318315
std::ostream&, const char* const, const SharedAllocationRecord* const,
319316
const bool) {
320-
Kokkos::Impl::throw_runtime_exception(
317+
Kokkos::abort(
321318
"Kokkos::Impl::SharedAllocationRecord::print_host_accessible_records"
322319
" only works with KOKKOS_ENABLE_DEBUG enabled");
323320
}

core/unit_test/TestGraph.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,8 @@ TEST_F(TEST_CATEGORY_FIXTURE(graph), zero_work_reduce) {
393393
// Ensure that an empty graph can be submitted.
394394
TEST_F(TEST_CATEGORY_FIXTURE(graph), empty_graph) {
395395
auto graph = Kokkos::Experimental::create_graph(ex, [](auto) {});
396-
ASSERT_NO_THROW({
397-
graph.instantiate();
398-
graph.submit(ex);
399-
});
396+
graph.instantiate();
397+
graph.submit(ex);
400398
ex.fence();
401399
}
402400

core/unit_test/TestRangePolicyConstructors.hpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ TEST(TEST_CATEGORY, range_policy_round_trip_conversion_fires) {
145145
ASSERT_DEATH((void)Policy(0, W(&n)), msg);
146146
#else
147147
::testing::internal::CaptureStderr();
148-
ASSERT_NO_THROW((void)Policy(0, W(&n)));
148+
(void)Policy(0, W(&n));
149149
auto s = std::string(::testing::internal::GetCapturedStderr());
150150
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
151151
if (Kokkos::show_warnings()) {
@@ -164,13 +164,16 @@ struct B { // round-trip conversion would not compile
164164
};
165165

166166
TEST(TEST_CATEGORY, range_policy_one_way_convertible_bounds) {
167-
using Policy = Kokkos::RangePolicy<>;
167+
using Policy = Kokkos::RangePolicy<>;
168+
using IndexType = Policy::index_type;
168169

169-
static_assert(std::is_convertible_v<B, Policy::index_type>);
170-
static_assert(!std::is_convertible_v<Policy::index_type, B>);
170+
static_assert(std::is_convertible_v<B, IndexType>);
171+
static_assert(!std::is_convertible_v<IndexType, B>);
171172

172173
int const n = 1;
173-
ASSERT_NO_THROW((void)Policy(0, B(&n)));
174+
Policy policy(0, B(&n));
175+
EXPECT_EQ(policy.begin(), static_cast<IndexType>(0));
176+
EXPECT_EQ(policy.end(), static_cast<IndexType>(1));
174177
}
175178

176179
TEST(TEST_CATEGORY, range_policy_check_sign_changes) {
@@ -193,7 +196,7 @@ TEST(TEST_CATEGORY, range_policy_check_sign_changes) {
193196
{
194197
::testing::internal::CaptureStderr();
195198
std::int64_t n = std::numeric_limits<std::int64_t>::max();
196-
ASSERT_NO_THROW((void)UInt32Policy(0, n));
199+
(void)UInt32Policy(0, n);
197200
auto s = std::string(::testing::internal::GetCapturedStderr());
198201
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
199202
if (Kokkos::show_warnings()) {
@@ -204,7 +207,7 @@ TEST(TEST_CATEGORY, range_policy_check_sign_changes) {
204207
{
205208
::testing::internal::CaptureStderr();
206209
std::int64_t n = std::numeric_limits<std::int64_t>::min();
207-
ASSERT_NO_THROW((void)UInt32Policy(n, 0));
210+
(void)UInt32Policy(n, 0);
208211
auto s = std::string(::testing::internal::GetCapturedStderr());
209212
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
210213
if (Kokkos::show_warnings()) {

core/unit_test/TestReduce.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ TEST(TEST_CATEGORY, reduction_with_large_iteration_count) {
645645
const int64_t N = pow(2LL, 39LL) - pow(2LL, 8LL) + 1;
646646
Kokkos::RangePolicy<TEST_EXECSPACE, Kokkos::IndexType<int64_t>> p(0, N);
647647
double nu = 0;
648-
EXPECT_NO_THROW(Kokkos::parallel_reduce(
649-
"sample reduction", p, FunctorReductionWithLargeIterationCount(), nu));
648+
Kokkos::parallel_reduce("sample reduction", p,
649+
FunctorReductionWithLargeIterationCount(), nu);
650650
ASSERT_DOUBLE_EQ(nu, double(N));
651651
}
652652
#endif

core/unit_test/TestViewCtorDimMatch.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ void test_matching_arguments_rank_helper(std::index_sequence<Is...>) {
2424
constexpr int nargs = sizeof...(Is);
2525
using view_type = Kokkos::View<RankType>;
2626
if (nargs == rank || nargs == dynrank) {
27-
EXPECT_NO_THROW({ view_type v("v", ((Is * 0) + 1)...); });
28-
EXPECT_NO_THROW({ view_type v(nullptr, ((Is * 0) + 1)...); });
27+
{ // does not throw
28+
view_type v("v", ((Is * 0) + 1)...);
29+
}
30+
{ // does not throw
31+
view_type v(nullptr, ((Is * 0) + 1)...);
32+
}
2933
} else {
3034
ASSERT_DEATH(
3135
{ view_type v("v", ((Is * 0) + 1)...); },

core/unit_test/TestViewIsAssignable.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <Kokkos_Core.hpp>
1818

19+
#include <gtest/gtest.h>
20+
1921
namespace Test {
2022
namespace Impl {
2123
template <class ViewTypeDst, class ViewTypeSrc>
@@ -36,8 +38,7 @@ struct TestAssignability {
3638
static void try_assign(
3739
ViewTypeDst&, ViewTypeSrc&,
3840
std::enable_if_t<!MappingType::is_assignable>* = nullptr) {
39-
Kokkos::Impl::throw_runtime_exception(
40-
"TestAssignability::try_assign: Unexpected call path");
41+
FAIL() << "TestAssignability::try_assign: Unexpected call path";
4142
}
4243

4344
template <class... Dimensions>
@@ -50,7 +51,7 @@ struct TestAssignability {
5051
bool is_assignable = Kokkos::is_assignable(dst, src);
5152

5253
if (sometimes) {
53-
ASSERT_NO_THROW(try_assign<mapping_type>(dst, src));
54+
try_assign<mapping_type>(dst, src);
5455
}
5556
ASSERT_EQ(always, is_always_assignable)
5657
<< Kokkos::Impl::TypeInfo<ViewTypeSrc>::name() << " to "

0 commit comments

Comments
 (0)