Skip to content

Commit

Permalink
fix: using macro to print location correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jul 25, 2024
1 parent 6bc016a commit db135f5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
6 changes: 3 additions & 3 deletions common/src/KokkosFFT_Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ auto get_shift(const ViewType& inout, axis_type<DIM> _axes, int direction = 1) {

// Assert if the elements are overlapped
constexpr int rank = ViewType::rank();
check_precondition(!KokkosFFT::Impl::has_duplicate_values(axes),
"axes are overlapped");
check_precondition(
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(axes),
"axes are overlapped");
KOKKOSFFT_EXPECTS(
!KokkosFFT::Impl::is_out_of_range_value_included(axes, rank),
"axes include out of range index."
"axes should be in the range of [-rank, rank-1].");
Expand Down
4 changes: 2 additions & 2 deletions common/src/KokkosFFT_layouts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ auto get_extents(const InViewType& in, const OutViewType& out,
if (is_real_v<in_value_type>) {
// Then R2C
if (is_complex_v<out_value_type>) {
check_precondition(
KOKKOSFFT_EXPECTS(
_out_extents.at(inner_most_axis) ==
_in_extents.at(inner_most_axis) / 2 + 1,
"For R2C, the output extent of transform should be input extent / "
Expand All @@ -81,7 +81,7 @@ auto get_extents(const InViewType& in, const OutViewType& out,
if (is_real_v<out_value_type>) {
// Then C2R
if (is_complex_v<in_value_type>) {
check_precondition(
KOKKOSFFT_EXPECTS(
_in_extents.at(inner_most_axis) ==
_out_extents.at(inner_most_axis) / 2 + 1,
"For C2R, the input extent of transform should be output extent / "
Expand Down
6 changes: 3 additions & 3 deletions common/src/KokkosFFT_padding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ auto get_modified_shape(const InViewType in, const OutViewType /* out */,
}

// Assert if the elements are overlapped
check_precondition(!KokkosFFT::Impl::has_duplicate_values(positive_axes),
"axes are overlapped");
check_precondition(
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(positive_axes),
"axes are overlapped");
KOKKOSFFT_EXPECTS(
!KokkosFFT::Impl::is_out_of_range_value_included(positive_axes, rank),
"axes include out of range index."
"axes should be in the range of [-rank, rank-1].");
Expand Down
24 changes: 19 additions & 5 deletions common/src/KokkosFFT_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,51 @@

#ifndef KOKKOS_ENABLE_CXX17
#include <source_location>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition(expression, msg)
#else
#include <cstdlib>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition(expression, msg, __FILE__, __LINE__, \
__FUNCTION__)
#endif

namespace KokkosFFT {
namespace Impl {

#ifndef KOKKOS_ENABLE_CXX17
inline void check_precondition(const bool expression, const std::string& msg) {
std::stringstream ss("file: ");
#ifndef KOKKOS_ENABLE_CXX17
std::source_location location = std::source_location::current();
ss << location.file_name() << '(' << location.line() << ':'
<< location.column() << ") `" << location.function_name() << "`: " << msg
<< '\n';

if (!expression) {
throw std::runtime_error(ss.str());
}
}
#else
ss << __FILE__ << '(' << __LINE__ << ") `" << __FUNCTION__ << "`: " << msg
inline void check_precondition(const bool expression, const std::string& msg,
const char* file_name, int line,
const char* function_name) {
std::stringstream ss("file: ");
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
<< '\n';
#endif
if (!expression) {
throw std::runtime_error(ss.str());
}
}
#endif

template <typename ViewType>
auto convert_negative_axis(ViewType, int _axis = -1) {
static_assert(Kokkos::is_view<ViewType>::value,
"convert_negative_axis: ViewType is not a Kokkos::View.");
int rank = static_cast<int>(ViewType::rank());

check_precondition(_axis >= -rank && _axis < rank,
"axis should be in [-rank, rank-1]");
KOKKOSFFT_EXPECTS(_axis >= -rank && _axis < rank,
"axis should be in [-rank, rank-1]");

int axis = _axis < 0 ? rank + _axis : _axis;
return axis;
Expand Down

0 comments on commit db135f5

Please sign in to comment.