alpaka-group / vikunja

Vikunja is a performance portable algorithm library that defines functions operating on ranges of elements for a variety of purposes . It supports the execution on multi-core CPUs and various GPUs. Vikunja uses alpaka to implement platform-independent primitives such as reduce or transform.
https://vikunja.readthedocs.io/en/latest/
Mozilla Public License 2.0
14 stars 5 forks source link

Normal annotated functions are not working with vikunja::reduce and the CUDA backend #41

Closed SimeonEhrig closed 2 years ago

SimeonEhrig commented 2 years ago

If I use an annotated function together with vikunja::reduce it is only working with CPU backends but not the CUDA backend (HIP not testet). It compiles, but I get an runtime error.

template<typename TData>
ALPAKA_FN_HOST_ACC TData sum(TData const i, TData const j)
{
    return i + j;
}

//...

P::m_result = vikunja::reduce::deviceReduce<typename P::Acc>(
                        P::devAcc,
                        P::devHost,
                        P::P::queue,
                        P::m_size,
                        alpaka::getPtrNative(P::m_device_mem),
                        sum<Data>);
terminate called after throwing an instance of 'std::runtime_error'
  what():  /home/sehrig/application/miniconda3/envs/vikunja-dev/include/alpaka/mem/buf/BufUniformCudaHipRt.hpp(101) 'cudaFree(reinterpret_cast<void*>(memPtr))' returned error  : 'cudaErrorInvalidPc': 'invalid program counter'!

If I replace the function with a lambda, everything is fine.

SimeonEhrig commented 2 years ago

I found the reason, see here: https://github.com/alpaka-group/vikunja/pull/40#issuecomment-951825425

If it should work, it needs some extra work. At the moment, lambdas and structs with operator() function are fine. Therefore I will not support plain functions for the moment.