Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trait IsKernelTriviallyCopyable #2302

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::is_trivially_copyable<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
Loading