diff --git a/include/alpaka/kernel/Traits.hpp b/include/alpaka/kernel/Traits.hpp index c49e05da24e9..44b6476aa4f7 100644 --- a/include/alpaka/kernel/Traits.hpp +++ b/include/alpaka/kernel/Traits.hpp @@ -202,6 +202,29 @@ namespace alpaka "-Wdocumentation" // clang does not support the syntax for variadic template arguments "args,..." #endif + + //! Check if a type used as kernel argument is trivially copyable + //! + //! \attention In case this trait is specialized for a user type the user should be sure that the result of calling + //! the copy constructor is equal to use memcpy to duplicate the object. An existing destructor should be free + //! of side effects. + //! + //! It's implementation defined whether the closure type of a lambda is trivially copyable. + //! Therefor the default implementation is true for trivially copyable or empty (stateless) types. + //! + //! @tparam T type to check + //! @{ + template + struct IsKernelArgumentTriviallyCopyable + : std::bool_constant || std::is_trivially_copyable_v> + { + }; + + template + inline constexpr bool isKernelArgumentTriviallyCopyable = IsKernelArgumentTriviallyCopyable::value; + + //! @} + namespace detail { //! Check that the return of TKernelFnObj is void @@ -221,13 +244,8 @@ namespace alpaka template inline void assertKernelArgIsTriviallyCopyable() { - static_assert( - // it's implementation defined whether the closure type of a lambda is trivially copyable. But they - // should be at least empty then (stateless). - std::is_empty_v || std::is_trivially_copyable_v, - "The kernel argument T must be trivially copyable!"); + static_assert(isKernelArgumentTriviallyCopyable, "The kernel argument T must be trivially copyable!"); } - } // namespace detail //! Creates a kernel execution task.