Skip to content

Commit 47e3c13

Browse files
yasahi-hpcYuuichi Asahi
andauthored
Replace KOKKOSFFT_EXPECTS with KOKKOSFFT_THROW_IF (#131)
Co-authored-by: Yuuichi Asahi <y.asahi@nr.titech.ac.jp>
1 parent be5919c commit 47e3c13

14 files changed

+152
-152
lines changed

common/src/KokkosFFT_Helpers.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ auto get_shift(const ViewType& inout, axis_type<DIM> _axes, int direction = 1) {
2323

2424
// Assert if the elements are overlapped
2525
constexpr int rank = ViewType::rank();
26-
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(axes),
27-
"Axes overlap");
28-
KOKKOSFFT_EXPECTS(
29-
!KokkosFFT::Impl::is_out_of_range_value_included(axes, rank),
26+
KOKKOSFFT_THROW_IF(KokkosFFT::Impl::has_duplicate_values(axes),
27+
"Axes overlap");
28+
KOKKOSFFT_THROW_IF(
29+
KokkosFFT::Impl::is_out_of_range_value_included(axes, rank),
3030
"Axes include an out-of-range index."
3131
"Axes must be in the range of [-rank, rank-1].");
3232

common/src/KokkosFFT_asserts.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
1313
#include <source_location>
14-
#define KOKKOSFFT_EXPECTS(expression, msg) \
14+
#define KOKKOSFFT_THROW_IF(expression, msg) \
1515
KokkosFFT::Impl::check_precondition( \
1616
(expression), msg, std::source_location::current().file_name(), \
1717
std::source_location::current().line(), \
1818
std::source_location::current().function_name(), \
1919
std::source_location::current().column())
2020
#else
2121
#include <cstdlib>
22-
#define KOKKOSFFT_EXPECTS(expression, msg) \
22+
#define KOKKOSFFT_THROW_IF(expression, msg) \
2323
KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \
2424
__FUNCTION__)
2525
#endif
@@ -33,7 +33,7 @@ inline void check_precondition(const bool expression,
3333
const char* function_name,
3434
const int column = -1) {
3535
// Quick return if possible
36-
if (expression) return;
36+
if (!expression) return;
3737

3838
std::stringstream ss("file: ");
3939
if (column == -1) {

common/src/KokkosFFT_layouts.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ auto get_extents(const InViewType& in, const OutViewType& out,
2626
using out_value_type = typename OutViewType::non_const_value_type;
2727
using array_layout_type = typename InViewType::array_layout;
2828

29-
KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(in, axes),
30-
"input axes are not valid for the view");
29+
KOKKOSFFT_THROW_IF(!KokkosFFT::Impl::are_valid_axes(in, axes),
30+
"input axes are not valid for the view");
3131

3232
constexpr std::size_t rank = InViewType::rank;
3333
[[maybe_unused]] int inner_most_axis =
@@ -65,17 +65,17 @@ auto get_extents(const InViewType& in, const OutViewType& out,
6565

6666
if (is_real_v<in_value_type>) {
6767
// Then R2C
68-
KOKKOSFFT_EXPECTS(
69-
_out_extents.at(inner_most_axis) ==
68+
KOKKOSFFT_THROW_IF(
69+
_out_extents.at(inner_most_axis) !=
7070
_in_extents.at(inner_most_axis) / 2 + 1,
7171
"For R2C, the 'output extent' of transform must be equal to "
7272
"'input extent'/2 + 1");
7373
}
7474

7575
if (is_real_v<out_value_type>) {
7676
// Then C2R
77-
KOKKOSFFT_EXPECTS(
78-
_in_extents.at(inner_most_axis) ==
77+
KOKKOSFFT_THROW_IF(
78+
_in_extents.at(inner_most_axis) !=
7979
_out_extents.at(inner_most_axis) / 2 + 1,
8080
"For C2R, the 'input extent' of transform must be equal to "
8181
"'output extent' / 2 + 1");

common/src/KokkosFFT_padding.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ auto get_modified_shape(const InViewType in, const OutViewType /* out */,
3030
static_assert(
3131
KokkosFFT::Impl::have_same_rank_v<InViewType, OutViewType>,
3232
"get_modified_shape: Input View and Output View must have the same rank");
33-
KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(in, axes),
34-
"input axes are not valid for the view");
33+
KOKKOSFFT_THROW_IF(!KokkosFFT::Impl::are_valid_axes(in, axes),
34+
"input axes are not valid for the view");
3535

3636
shape_type<DIM> zeros = {0}; // default shape means no crop or pad
3737
if (shape == zeros) {

common/src/KokkosFFT_transpose.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace KokkosFFT {
1414
namespace Impl {
1515
template <typename ViewType, std::size_t DIM>
1616
auto get_map_axes(const ViewType& view, axis_type<DIM> _axes) {
17-
KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(view, _axes),
18-
"get_map_axes: input axes are not valid for the view");
17+
KOKKOSFFT_THROW_IF(!KokkosFFT::Impl::are_valid_axes(view, _axes),
18+
"get_map_axes: input axes are not valid for the view");
1919

2020
// Convert the input axes to be in the range of [0, rank-1]
2121
std::vector<int> axes;
@@ -400,8 +400,8 @@ void transpose(const ExecutionSpace& exec_space, InViewType& in,
400400
"transpose: Rank of View must be equal to Rank of "
401401
"transpose axes.");
402402

403-
KOKKOSFFT_EXPECTS(KokkosFFT::Impl::is_transpose_needed(map),
404-
"transpose: transpose not necessary");
403+
KOKKOSFFT_THROW_IF(!KokkosFFT::Impl::is_transpose_needed(map),
404+
"transpose: transpose not necessary");
405405

406406
// in order not to call transpose_impl for 1D case
407407
if constexpr (DIM > 1) {

common/src/KokkosFFT_utils.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ auto convert_negative_axis(ViewType, int _axis = -1) {
2323
"convert_negative_axis: ViewType must be a Kokkos::View.");
2424
int rank = static_cast<int>(ViewType::rank());
2525

26-
KOKKOSFFT_EXPECTS(_axis >= -rank && _axis < rank,
27-
"Axis must be in [-rank, rank-1]");
26+
KOKKOSFFT_THROW_IF(_axis < -rank || _axis >= rank,
27+
"Axis must be in [-rank, rank-1]");
2828

2929
int axis = _axis < 0 ? rank + _axis : _axis;
3030
return axis;
@@ -130,7 +130,7 @@ std::size_t get_index(ContainerType& values, const ValueType& value) {
130130
static_assert(std::is_same_v<value_type, ValueType>,
131131
"get_index: Container value type must match ValueType");
132132
auto it = std::find(values.begin(), values.end(), value);
133-
KOKKOSFFT_EXPECTS(it != values.end(), "value is not included in values");
133+
KOKKOSFFT_THROW_IF(it == values.end(), "value is not included in values");
134134
return it - values.begin();
135135
}
136136

@@ -256,44 +256,44 @@ void create_view(ViewType& out, const Label& label,
256256

257257
template <typename ViewType>
258258
void reshape_view(ViewType& out, const std::array<int, 1>& extents) {
259-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
260-
ViewType::required_allocation_size(extents[0]),
261-
"reshape_view: insufficient memory");
259+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
260+
ViewType::required_allocation_size(extents[0]),
261+
"reshape_view: insufficient memory");
262262
out = ViewType(out.data(), extents[0]);
263263
}
264264

265265
template <typename ViewType>
266266
void reshape_view(ViewType& out, const std::array<int, 2>& extents) {
267-
KOKKOSFFT_EXPECTS(
268-
ViewType::required_allocation_size(out.layout()) >=
267+
KOKKOSFFT_THROW_IF(
268+
ViewType::required_allocation_size(out.layout()) <
269269
ViewType::required_allocation_size(extents[0], extents[1]),
270270
"reshape_view: insufficient memory");
271271
out = ViewType(out.data(), extents[0], extents[1]);
272272
}
273273

274274
template <typename ViewType>
275275
void reshape_view(ViewType& out, const std::array<int, 3>& extents) {
276-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
277-
ViewType::required_allocation_size(
278-
extents[0], extents[1], extents[2]),
279-
"reshape_view: insufficient memory");
276+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
277+
ViewType::required_allocation_size(
278+
extents[0], extents[1], extents[2]),
279+
"reshape_view: insufficient memory");
280280
out = ViewType(out.data(), extents[0], extents[1], extents[2]);
281281
}
282282

283283
template <typename ViewType>
284284
void reshape_view(ViewType& out, const std::array<int, 4>& extents) {
285-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
286-
ViewType::required_allocation_size(
287-
extents[0], extents[1], extents[2], extents[3]),
288-
"reshape_view: insufficient memory");
285+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
286+
ViewType::required_allocation_size(
287+
extents[0], extents[1], extents[2], extents[3]),
288+
"reshape_view: insufficient memory");
289289

290290
out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3]);
291291
}
292292

293293
template <typename ViewType>
294294
void reshape_view(ViewType& out, const std::array<int, 5>& extents) {
295-
KOKKOSFFT_EXPECTS(
296-
ViewType::required_allocation_size(out.layout()) >=
295+
KOKKOSFFT_THROW_IF(
296+
ViewType::required_allocation_size(out.layout()) <
297297
ViewType::required_allocation_size(extents[0], extents[1], extents[2],
298298
extents[3], extents[4]),
299299
"reshape_view: insufficient memory");
@@ -303,33 +303,33 @@ void reshape_view(ViewType& out, const std::array<int, 5>& extents) {
303303

304304
template <typename ViewType>
305305
void reshape_view(ViewType& out, const std::array<int, 6>& extents) {
306-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
307-
ViewType::required_allocation_size(
308-
extents[0], extents[1], extents[2], extents[3],
309-
extents[4], extents[5]),
310-
"reshape_view: insufficient memory");
306+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
307+
ViewType::required_allocation_size(
308+
extents[0], extents[1], extents[2], extents[3],
309+
extents[4], extents[5]),
310+
"reshape_view: insufficient memory");
311311
out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3],
312312
extents[4], extents[5]);
313313
}
314314

315315
template <typename ViewType>
316316
void reshape_view(ViewType& out, const std::array<int, 7>& extents) {
317-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
318-
ViewType::required_allocation_size(
319-
extents[0], extents[1], extents[2], extents[3],
320-
extents[4], extents[5], extents[6]),
321-
"reshape_view: insufficient memory");
317+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
318+
ViewType::required_allocation_size(
319+
extents[0], extents[1], extents[2], extents[3],
320+
extents[4], extents[5], extents[6]),
321+
"reshape_view: insufficient memory");
322322
out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3],
323323
extents[4], extents[5], extents[6]);
324324
}
325325

326326
template <typename ViewType>
327327
void reshape_view(ViewType& out, const std::array<int, 8>& extents) {
328-
KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >=
329-
ViewType::required_allocation_size(
330-
extents[0], extents[1], extents[2], extents[3],
331-
extents[4], extents[5], extents[6], extents[7]),
332-
"reshape_view: insufficient memory");
328+
KOKKOSFFT_THROW_IF(ViewType::required_allocation_size(out.layout()) <
329+
ViewType::required_allocation_size(
330+
extents[0], extents[1], extents[2], extents[3],
331+
extents[4], extents[5], extents[6], extents[7]),
332+
"reshape_view: insufficient memory");
333333
out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3],
334334
extents[4], extents[5], extents[6], extents[7]);
335335
}

fft/src/KokkosFFT_Cuda_plans.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ auto create_plan(const ExecutionSpace& exec_space,
3131

3232
plan = std::make_unique<PlanType>();
3333
cufftResult cufft_rt = cufftCreate(&(*plan));
34-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftCreate failed");
34+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
3535

3636
cudaStream_t stream = exec_space.cuda_stream();
3737
cufftSetStream((*plan), stream);
@@ -45,7 +45,7 @@ auto create_plan(const ExecutionSpace& exec_space,
4545
std::multiplies<>());
4646

4747
cufft_rt = cufftPlan1d(&(*plan), nx, type, howmany);
48-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftPlan1d failed");
48+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftPlan1d failed");
4949

5050
return fft_size;
5151
}
@@ -69,7 +69,7 @@ auto create_plan(const ExecutionSpace& exec_space,
6969

7070
plan = std::make_unique<PlanType>();
7171
cufftResult cufft_rt = cufftCreate(&(*plan));
72-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftCreate failed");
72+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
7373

7474
cudaStream_t stream = exec_space.cuda_stream();
7575
cufftSetStream((*plan), stream);
@@ -83,7 +83,7 @@ auto create_plan(const ExecutionSpace& exec_space,
8383
std::multiplies<>());
8484

8585
cufft_rt = cufftPlan2d(&(*plan), nx, ny, type);
86-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftPlan2d failed");
86+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftPlan2d failed");
8787

8888
return fft_size;
8989
}
@@ -107,7 +107,7 @@ auto create_plan(const ExecutionSpace& exec_space,
107107

108108
plan = std::make_unique<PlanType>();
109109
cufftResult cufft_rt = cufftCreate(&(*plan));
110-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftCreate failed");
110+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
111111

112112
cudaStream_t stream = exec_space.cuda_stream();
113113
cufftSetStream((*plan), stream);
@@ -123,7 +123,7 @@ auto create_plan(const ExecutionSpace& exec_space,
123123
std::multiplies<>());
124124

125125
cufft_rt = cufftPlan3d(&(*plan), nx, ny, nz, type);
126-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftPlan3d failed");
126+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftPlan3d failed");
127127

128128
return fft_size;
129129
}
@@ -167,7 +167,7 @@ auto create_plan(const ExecutionSpace& exec_space,
167167

168168
plan = std::make_unique<PlanType>();
169169
cufftResult cufft_rt = cufftCreate(&(*plan));
170-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftCreate failed");
170+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
171171

172172
cudaStream_t stream = exec_space.cuda_stream();
173173
cufftSetStream((*plan), stream);
@@ -176,7 +176,7 @@ auto create_plan(const ExecutionSpace& exec_space,
176176
in_extents.data(), istride, idist,
177177
out_extents.data(), ostride, odist, type, howmany);
178178

179-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftPlanMany failed");
179+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftPlanMany failed");
180180

181181
return fft_size;
182182
}

fft/src/KokkosFFT_Cuda_transform.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,42 @@ template <typename... Args>
1414
inline void exec_plan(cufftHandle& plan, cufftReal* idata, cufftComplex* odata,
1515
int /*direction*/, Args...) {
1616
cufftResult cufft_rt = cufftExecR2C(plan, idata, odata);
17-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecR2C failed");
17+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecR2C failed");
1818
}
1919

2020
template <typename... Args>
2121
inline void exec_plan(cufftHandle& plan, cufftDoubleReal* idata,
2222
cufftDoubleComplex* odata, int /*direction*/, Args...) {
2323
cufftResult cufft_rt = cufftExecD2Z(plan, idata, odata);
24-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecD2Z failed");
24+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecD2Z failed");
2525
}
2626

2727
template <typename... Args>
2828
inline void exec_plan(cufftHandle& plan, cufftComplex* idata, cufftReal* odata,
2929
int /*direction*/, Args...) {
3030
cufftResult cufft_rt = cufftExecC2R(plan, idata, odata);
31-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecC2R failed");
31+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecC2R failed");
3232
}
3333

3434
template <typename... Args>
3535
inline void exec_plan(cufftHandle& plan, cufftDoubleComplex* idata,
3636
cufftDoubleReal* odata, int /*direction*/, Args...) {
3737
cufftResult cufft_rt = cufftExecZ2D(plan, idata, odata);
38-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecZ2D failed");
38+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecZ2D failed");
3939
}
4040

4141
template <typename... Args>
4242
inline void exec_plan(cufftHandle& plan, cufftComplex* idata,
4343
cufftComplex* odata, int direction, Args...) {
4444
cufftResult cufft_rt = cufftExecC2C(plan, idata, odata, direction);
45-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecC2C failed");
45+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecC2C failed");
4646
}
4747

4848
template <typename... Args>
4949
inline void exec_plan(cufftHandle& plan, cufftDoubleComplex* idata,
5050
cufftDoubleComplex* odata, int direction, Args...) {
5151
cufftResult cufft_rt = cufftExecZ2Z(plan, idata, odata, direction);
52-
KOKKOSFFT_EXPECTS(cufft_rt == CUFFT_SUCCESS, "cufftExecZ2Z failed");
52+
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftExecZ2Z failed");
5353
}
5454
} // namespace Impl
5555
} // namespace KokkosFFT

0 commit comments

Comments
 (0)