From 902a50bba13c1dc7f840165e259b399589d290c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Widera?= Date: Wed, 28 Jun 2023 15:01:35 +0200 Subject: [PATCH] show better error message if kernel argument is not trivially copyable fix #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. --- include/alpaka/kernel/Traits.hpp | 59 +++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/include/alpaka/kernel/Traits.hpp b/include/alpaka/kernel/Traits.hpp index 33032cdb5c57..fc8df4f49c72 100644 --- a/include/alpaka/kernel/Traits.hpp +++ b/include/alpaka/kernel/Traits.hpp @@ -199,14 +199,41 @@ namespace alpaka static_assert(std::is_same_v, "The TKernelFnObj is required to return void!"); } }; + + //! Check that all types are trivially copyable. + template + struct AssertTriviallyCopyable + : AssertTriviallyCopyable + , AssertTriviallyCopyable + { + }; + + template + struct AssertTriviallyCopyable + { + static_assert(std::is_trivially_copyable_v, "Kernels N-th argument must be trivially copyable!"); + }; + + //! Check that each argument type is trivially copyable + // + // \tparam TArgs types to be checked + template + 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 @@ -224,9 +251,7 @@ namespace alpaka #else static_assert(std::is_trivially_copyable_v, "Kernels must be trivially copyable!"); #endif - static_assert( - (std::is_trivially_copyable_v> && ...), - "Kernel arguments must be trivially copyable!"); + detail::assertArgsTriviallyCopyable...>(); static_assert( Dim>::value == Dim::value, "The dimensions of TAcc and TWorkDiv have to be identical!"); @@ -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