From f18b1967e5534cf99cdb2bf180fd558fcd31245b Mon Sep 17 00:00:00 2001 From: AuroraPerego Date: Sun, 23 Jun 2024 01:52:22 +0200 Subject: [PATCH] add trait IsKernelTriviallyCopyable --- include/alpaka/kernel/Traits.hpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/include/alpaka/kernel/Traits.hpp b/include/alpaka/kernel/Traits.hpp index 44b6476aa4f7..9227afbd368a 100644 --- a/include/alpaka/kernel/Traits.hpp +++ b/include/alpaka/kernel/Traits.hpp @@ -248,6 +248,33 @@ namespace alpaka } } // namespace detail + //! Check if the kernel type 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. + //! + //! The default implementation is true for trivially copyable types (or for extended lambda expressions for CUDA). + //! + //! @tparam T type to check + //! @{ + template + struct IsKernelTriviallyCopyable +#if BOOST_COMP_NVCC + : std::bool_constant< + std::is_trivially_copyable_v || __nv_is_extended_device_lambda_closure_type(T) + || __nv_is_extended_host_device_lambda_closure_type(T)> +#else + : std::is_trivially_copyable +#endif + { + }; + + template + inline constexpr bool isKernelTriviallyCopyable = IsKernelTriviallyCopyable::value; + + //! @} + //! Creates a kernel execution task. //! //! \tparam TAcc The accelerator type. @@ -266,11 +293,10 @@ namespace alpaka #if BOOST_COMP_NVCC static_assert( - std::is_trivially_copyable_v || __nv_is_extended_device_lambda_closure_type(TKernelFnObj) - || __nv_is_extended_host_device_lambda_closure_type(TKernelFnObj), + isKernelTriviallyCopyable, "Kernels must be trivially copyable or an extended CUDA lambda expression!"); #else - static_assert(std::is_trivially_copyable_v, "Kernels must be trivially copyable!"); + static_assert(isKernelTriviallyCopyable, "Kernels must be trivially copyable!"); #endif (detail::assertKernelArgIsTriviallyCopyable>(), ...); static_assert(