From 188361be72cf8815f89b9535ad65edfabe37409d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Widera?= Date: Fri, 1 Dec 2023 11:30:16 +0100 Subject: [PATCH] add trait `IsKernelArgumentTriviallyCopyable` fix #2195 Provide an alpaka specific trait to validate kernel argument conditions which can be specialized by the user for their own types and at their own risk. --- include/alpaka/kernel/Traits.hpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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.