Skip to content

Commit

Permalink
add trait IsKernelTriviallyCopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraPerego committed Jun 25, 2024
1 parent 7b06ada commit 9e78818
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions include/alpaka/kernel/Traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T, typename = void>
struct IsKernelTriviallyCopyable
#if BOOST_COMP_NVCC
: std::bool_constant<
std::is_trivially_copyable_v<T> || __nv_is_extended_device_lambda_closure_type(T)
|| __nv_is_extended_host_device_lambda_closure_type(T)>
#else
: std::bool_constant<std::is_trivially_copyable_v<T>>
#endif
{
};

template<typename T>
inline constexpr bool isKernelTriviallyCopyable = IsKernelTriviallyCopyable<T>::value;

//! @}

//! Creates a kernel execution task.
//!
//! \tparam TAcc The accelerator type.
Expand All @@ -266,11 +293,10 @@ namespace alpaka

#if BOOST_COMP_NVCC
static_assert(
std::is_trivially_copyable_v<TKernelFnObj> || __nv_is_extended_device_lambda_closure_type(TKernelFnObj)
|| __nv_is_extended_host_device_lambda_closure_type(TKernelFnObj),
isKernelTriviallyCopyable<TKernelFnObj>,
"Kernels must be trivially copyable or an extended CUDA lambda expression!");
#else
static_assert(std::is_trivially_copyable_v<TKernelFnObj>, "Kernels must be trivially copyable!");
static_assert(isKernelTriviallyCopyable<TKernelFnObj>, "Kernels must be trivially copyable!");
#endif
(detail::assertKernelArgIsTriviallyCopyable<std::decay_t<TArgs>>(), ...);
static_assert(
Expand Down

0 comments on commit 9e78818

Please sign in to comment.