12#include <initializer_list>
18#if ALPAKA_LANG_CUDA || ALPAKA_LANG_HIP
20namespace alpaka::uniform_cuda_hip::detail
23 template<
typename TApi,
bool TThrow>
25 typename TApi::Error_t
const& error,
28 int const& line)
noexcept(!TThrow)
30 if(error != TApi::success)
34 std::ignore = TApi::getLastError();
38 auto const sError = std::string{
39 std::string(file) +
"(" + std::to_string(line) +
") " + std::string(desc) +
" : '"
40 + TApi::getErrorName(error) +
"': '" + std::string(TApi::getErrorString(error)) +
"'!"};
42 throw std::runtime_error(sError);
48 template<
typename TApi,
bool TThrow>
50 typename TApi::Error_t
const& error,
54 std::initializer_list<typename TApi::Error_t> ignoredErrorCodes)
noexcept(!TThrow)
56 if(error != TApi::success)
59 if(std::find(std::cbegin(ignoredErrorCodes), std::cend(ignoredErrorCodes), error)
60 == std::cend(ignoredErrorCodes))
62 using namespace std::literals;
63 rtCheck<TApi, TThrow>(error, (
"'"s + std::string(cmd) +
"' returned error "s).c_str(), file, line);
69 std::ignore = TApi::getLastError();
75 template<
typename TApi,
bool TThrow>
76 ALPAKA_FN_HOST inline void rtCheckLastError(
char const* desc,
char const* file,
int const& line)
noexcept(!TThrow)
78 typename TApi::Error_t
const error(TApi::getLastError());
79 rtCheck<TApi, TThrow>(error, desc, file, line);
83# define ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IMPL(ApiInterfaceType, cmd, throw, ...) \
86 ::alpaka::uniform_cuda_hip::detail::rtCheckLastError<ApiInterfaceType, throw>( \
87 "'" #cmd "' A previous API call (not this one) set the error ", \
90 ::alpaka::uniform_cuda_hip::detail::rtCheckIgnore<ApiInterfaceType, throw>( \
99# define ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IGNORE(ApiInterfaceType, cmd, ...) \
100 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IMPL(ApiInterfaceType, cmd, true, __VA_ARGS__)
103# define ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(ApiInterfaceType, cmd) \
104 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IMPL(ApiInterfaceType, cmd, true, )
107# define ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IGNORE_NOEXCEPT(ApiInterfaceType, cmd, ...) \
108 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IMPL(ApiInterfaceType, cmd, false, __VA_ARGS__)
111# define ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_NOEXCEPT(ApiInterfaceType, cmd) \
112 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IMPL(ApiInterfaceType, cmd, false, )
#define ALPAKA_FN_HOST
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...