Skip to content

Commit

Permalink
show better error message if kernel argument is not trivially copyable
Browse files Browse the repository at this point in the history
fix alpaka-group#1922

Currently, alpaka is checking all kernel arguments with the fold expression that all arguments are trivially copyable. The problem is if one argument is not trivially copyable the user does not know which.

By checking each argument separately and providing the index to the validator class the user gets the information on which argument produces issues.
This simplifies the debugging a lot.
  • Loading branch information
psychocoderHPC committed Jun 28, 2023
1 parent 375f4f0 commit 902a50b
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions include/alpaka/kernel/Traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,41 @@ namespace alpaka
static_assert(std::is_same_v<Result, void>, "The TKernelFnObj is required to return void!");
}
};

//! Check that all types are trivially copyable.
template<size_t TIdx, typename THead, typename... TTail>
struct AssertTriviallyCopyable
: AssertTriviallyCopyable<TIdx, THead>
, AssertTriviallyCopyable<TIdx + 1, TTail...>
{
};

template<size_t TIdx, typename THead>
struct AssertTriviallyCopyable<TIdx, THead>
{
static_assert(std::is_trivially_copyable_v<THead>, "Kernels N-th argument must be trivially copyable!");
};

//! Check that each argument type is trivially copyable
//
// \tparam TArgs types to be checked
template<typename... TArgs>
inline void assertArgsTriviallyCopyable()
{
if constexpr(sizeof...(TArgs))
{
[[maybe_unused]] auto check = AssertTriviallyCopyable<0, TArgs...>{};
}
}

} // namespace detail
//! Creates a kernel execution task.
//!
//! \tparam TAcc The accelerator type.
//! \param workDiv The index domain work division.
//! \param kernelFnObj The kernel function object which should be executed.
//! \param args,... The kernel invocation arguments.
//! \return The kernel execution task.
//! Creates a kernel execution task.
//!
//! \tparam TAcc The accelerator type.
//! \param workDiv The index domain work division.
//! \param kernelFnObj The kernel function object which should be executed.
//! \param args,... The kernel invocation arguments.
//! \return The kernel execution task.
#if BOOST_COMP_CLANG
# pragma clang diagnostic pop
#endif
Expand All @@ -224,9 +251,7 @@ namespace alpaka
#else
static_assert(std::is_trivially_copyable_v<TKernelFnObj>, "Kernels must be trivially copyable!");
#endif
static_assert(
(std::is_trivially_copyable_v<std::decay_t<TArgs>> && ...),
"Kernel arguments must be trivially copyable!");
detail::assertArgsTriviallyCopyable<std::decay_t<TArgs>...>();
static_assert(
Dim<std::decay_t<TWorkDiv>>::value == Dim<TAcc>::value,
"The dimensions of TAcc and TWorkDiv have to be identical!");
Expand All @@ -249,13 +274,13 @@ namespace alpaka
# pragma clang diagnostic ignored \
"-Wdocumentation" // clang does not support the syntax for variadic template arguments "args,..."
#endif
//! Executes the given kernel in the given queue.
//!
//! \tparam TAcc The accelerator type.
//! \param queue The queue to enqueue the view copy task into.
//! \param workDiv The index domain work division.
//! \param kernelFnObj The kernel function object which should be executed.
//! \param args,... The kernel invocation arguments.
//! Executes the given kernel in the given queue.
//!
//! \tparam TAcc The accelerator type.
//! \param queue The queue to enqueue the view copy task into.
//! \param workDiv The index domain work division.
//! \param kernelFnObj The kernel function object which should be executed.
//! \param args,... The kernel invocation arguments.
#if BOOST_COMP_CLANG
# pragma clang diagnostic pop
#endif
Expand Down

0 comments on commit 902a50b

Please sign in to comment.