Alpaka: On 0.4.0 arrays can't be passed to kernels

Created on 20 Sep 2019  路  6Comments  路  Source: alpaka-group/alpaka

Something like this:

double data[4] = { };
alpaka::queue::enqueue(stream, alpaka::kernel::createTaskKernel<Accelerator>(workDiv, kernel, data));

doesn't work in 0.4.0 anymore, since data is converted to a const pointer (actually std::ref creates a std::reference_wrapper

Bug

All 6 comments

@krzikalla to clarify, does your kernel take this array by reference, as double (&data)[4] ?

As pointer template like this:

template<typename Acc, typename T>
ALPAKA_FN_ACC void operator()(const Acc& acc, T* data) const

Worked with 0.3.5, with 0.4.0 T becomes a const double.

Ah, sorry, I first thought the issue is with array decaying to pointers, not with const being incorrectly deduced. Thanks for explaining further.

I updated the hello world:

diff --git a/example/helloWorld/src/helloWorld.cpp b/example/helloWorld/src/helloWorld.cpp
index 49d6b4f3..2b7a3f6b 100644
--- a/example/helloWorld/src/helloWorld.cpp
+++ b/example/helloWorld/src/helloWorld.cpp
@@ -27,9 +27,10 @@ struct HelloWorldKernel
 {
     //-----------------------------------------------------------------------------
     template<
-        typename TAcc>
+        typename TAcc,
+        typename T>
     ALPAKA_FN_ACC auto operator()(
-        TAcc const & acc) const
+        TAcc const & acc, T* data) const
     -> void
     {
         using Dim = alpaka::dim::Dim<TAcc>;
@@ -192,10 +193,12 @@ auto main()
     // The queue can be blocking or non-blocking
     // depending on the choosen queue type (see type definitions above).
     // Here it is synchronous which means that the kernel is directly executed.
+    double data[4] = { };
     alpaka::kernel::exec<Acc>(
         queue,
         workDiv,
-        helloWorldKernel
+        helloWorldKernel,
+        data
         /* put kernel arguments here */);

     return EXIT_SUCCESS;

The error is:

/bigdata/hplsim/scratch/widera/alpaka/include/alpaka/kernel/TaskKernelCpuSerial.hpp(60): error: no instance of constructor "std::tuple<_Elements...>::tuple [with _Elements=<double [4]>]" matches the argument list
            argument types are: (const double [4])
          detected during:
            instantiation of "alpaka::kernel::TaskKernelCpuSerial<TDim, TIdx, TKernelFnObj, TArgs...>::TaskKernelCpuSerial(TWorkDiv &&, const TKernelFnObj &, const TArgs &...) [with TDim=alpaka::dim::DimInt<3UL>, TIdx=std::size_t, TKernelFnObj=HelloWorldKernel, TArgs=<double [4]>, TWorkDiv=const alpaka::workdiv::WorkDivMembers<alpaka::dim::DimInt<3UL>, std::size_t> &]" 
/bigdata/hplsim/scratch/widera/alpaka/include/alpaka/acc/AccCpuSerial.hpp(264): here
            instantiation of "auto alpaka::kernel::traits::CreateTaskKernel<alpaka::acc::AccCpuSerial<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>::createTaskKernel(const TWorkDiv &, const TKernelFnObj &, const TArgs &...)->alpaka::kernel::TaskKernelCpuSerial<TDim, TIdx, TKernelFnObj, TArgs...> [with TDim=alpaka::dim::DimInt<3UL>, TIdx=std::size_t, TWorkDiv=alpaka::workdiv::WorkDivMembers<alpaka::dim::DimInt<3UL>, std::size_t>, TKernelFnObj=HelloWorldKernel, TArgs=<double [4]>]" 
/bigdata/hplsim/scratch/widera/alpaka/include/alpaka/kernel/Traits.hpp(213): here
            instantiation of "auto alpaka::kernel::createTaskKernel<TAcc,TWorkDiv,TKernelFnObj,TArgs...>(const TWorkDiv &, const TKernelFnObj &, const TArgs &...)->decltype((<expression>)) [with TAcc=alpaka::acc::AccCpuSerial<alpaka::dim::DimInt<3UL>, std::size_t>, TWorkDiv=alpaka::workdiv::WorkDivMembers<alpaka::dim::DimInt<3UL>, std::size_t>, TKernelFnObj=HelloWorldKernel, TArgs=<double [4]>]" 
/bigdata/hplsim/scratch/widera/alpaka/include/alpaka/kernel/Traits.hpp(257): here
            instantiation of "auto alpaka::kernel::exec<TAcc,TQueue,TWorkDiv,TKernelFnObj,TArgs...>(TQueue &, const TWorkDiv &, const TKernelFnObj &, const TArgs &...)->void [with TAcc=alpaka::acc::AccCpuSerial<alpaka::dim::DimInt<3UL>, std::size_t>, TQueue=alpaka::queue::QueueCpuBlocking, TWorkDiv=alpaka::workdiv::WorkDivMembers<alpaka::dim::DimInt<3UL>, std::size_t>, TKernelFnObj=HelloWorldKernel, TArgs=<double [4]>]" 
/bigdata/hplsim/scratch/widera/alpaka/example/helloWorld/src//helloWorld.cpp(197): here
...

Just as thinking out loud, since kernel arguments are logically kind of passed by value, we might want to use (at an appropriate place) std::decay that cppreference describes as These conversions model the type conversion applied to all function arguments when passed by value.

@krzikalla This should be fixed now. Would be really helpful if you could verify that it solves your issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psychocoderHPC picture psychocoderHPC  路  5Comments

tdd11235813 picture tdd11235813  路  4Comments

ax3l picture ax3l  路  4Comments

BenjaminW3 picture BenjaminW3  路  6Comments

jkelling picture jkelling  路  4Comments