29 template<
typename TFn>
34 template<
typename TAcc,
typename T>
37 static_assert(std::is_invocable_r_v<T, TFn, T> or std::is_invocable_r_v<T, TFn, TAcc const&, T>);
44 if constexpr(std::is_invocable_r_v<T, TFn, T>)
47 out_ptr[i] =
fn(in_ptr[i]);
52 out_ptr[i] =
fn(acc, in_ptr[i]);
58 template<
typename TFn>
63 template<
typename TAcc,
typename T>
72 static_assert(std::is_invocable_r_v<T, TFn, T> or std::is_invocable_r_v<T, TFn, TAcc const&, T>);
80 auto p_in =
reinterpret_cast<T const*
>(
81 reinterpret_cast<uintptr_t
>(in_ptr) +
static_cast<uintptr_t
>((idx * in_pithces).sum()));
82 auto p_out =
reinterpret_cast<T*
>(
83 reinterpret_cast<uintptr_t
>(out_ptr) +
static_cast<uintptr_t
>((idx * out_pitches).sum()));
84 if constexpr(std::is_invocable_r_v<T, TFn, T>)
92 *p_out =
fn(acc, *p_in);
105 template<alpaka::concepts::Tag TTag,
typename TQueue,
typename T,
typename TFn>
106 void transform(TQueue& queue, T* out_begin, T* out_end, TFn&& fn, T* in)
108 using Idx =
typename std::iterator_traits<T*>::difference_type;
112 std::is_invocable_r_v<T, TFn, T> or std::is_invocable_r_v<T, TFn, Acc1D const&, T>,
113 "TFn must accept either one argument (of type T) or two arguments (an accelerator and an argument of type "
114 "T), and return a value of type T.");
116 Idx size = std::distance(out_begin, out_end);
125 alpaka::exec<Acc1D>(queue, grid, kernel, in, out_begin, size);
133 template<alpaka::concepts::Tag TTag,
typename TQueue,
typename TBuf,
typename TFn,
typename TConstBuf>
134 void transform(TQueue& queue, TBuf& out, TFn&& fn, TConstBuf
const& in)
139 std::is_same_v<alpaka::Idx<TBuf>,
Idx>,
140 "The input and output buffers must have the same index type.");
143 std::is_same_v<alpaka::Dim<TBuf>,
Dim>,
144 "The input and output buffers must have the same dimension.");
145 using In = std::remove_const_t<alpaka::Elem<TConstBuf>>;
151 std::is_invocable_r_v<Out, TFn, In const> or std::is_invocable_r_v<Out, TFn, Acc const&, In const>,
152 "TFn must accept either one argument (of the buffer's element type) or two arguments (an accelerator and "
153 "the element type), and return a value of the buffer's element type.");
157 assert(
alpaka::getExtents(out) == size and
"The input and output buffers must have the same extents.");
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto ones() -> Vec< TDim, TVal >
One value constructor.
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
The alpaka accelerator library.
typename trait::IdxType< T >::type Idx
ALPAKA_FN_HOST auto getValidWorkDiv(KernelCfg< TAcc, TGridElemExtent, TThreadElemExtent > const &kernelCfg, TDev const &dev, TKernelFnObj const &kernelFnObj, TArgs &&... args) -> WorkDivMembers< Dim< TAcc >, Idx< TAcc > >
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
ALPAKA_FN_ACC auto uniformElements(TAcc const &acc, TArgs... args)
ALPAKA_FN_ACC auto uniformElementsND(TAcc const &acc)
@ Unrestricted
The block thread extent will not have any restrictions.
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T > >
ALPAKA_FN_HOST auto getDev(T const &t)
void transform(TQueue &queue, T *out_begin, T *out_end, TFn &&fn, T *in)
typename trait::AccType< T >::type Acc
The accelerator type trait alias template to remove the ::type.
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
typename trait::TagToAcc< TTag, TDim, TIdx >::type TagToAcc
maps a tag type to an acc type
Kernel start configuration to determine a valid work division.