kokkos/kokkos-tutorials

Problem compiling Exercices with CUDA

thelfer opened this issue · 3 comments

Dear developpers,
I am very new to Kokkos, so I beg you pardon in advance if this issue is a trivial error on my side.
I compiled Kokkos with CUDA support and tries to compile the exercies from kokkos-tutorials.
They all fail with the same kind of error:

$ cmake ../ -DKokkos_DIR=/home/th202608/codes/kokkos/master/install/lib/cmake/Kokkos/
$ make
[ 50%] Building CXX object CMakeFiles/03_Exercise.dir/exercise_3_solution.cpp.o
/home/th202608/codes/kokkos/master/install/include/Cuda/Kokkos_Cuda_Parallel.hpp(909): error: calling a __host__ function("main::[lambda(int, double &) (instance 1)]::operator ()(int, double &) const") from a __device__ function("Kokkos::Impl::ParallelReduce<    ::main   ::[lambda(int, double &) (instance 1)],  ::Kokkos::RangePolicy< ::Kokkos::Cuda > ,  ::Kokkos::InvalidType,  ::Kokkos::Cuda> ::exec_range<void>  const") is not allowed

/home/th202608/codes/kokkos/master/install/include/Cuda/Kokkos_Cuda_Parallel.hpp(909): error: identifier "main::[lambda(int, double &) (instance 1)]::operator () const" is undefined in device code

2 errors detected in the compilation of "/home/th202608/codes/kokkos/tutorials/master/src/kokkos-tutorials/Exercises/03/Solution/exercise_3_solution.cpp".
make[2]: *** [CMakeFiles/03_Exercise.dir/build.make:76: CMakeFiles/03_Exercise.dir/exercise_3_solution.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/03_Exercise.dir/all] Error 2

For the sake of completness, I am on Debian stretch, gcc 8.3.0, cuda 11.4, cmake 3.20.3
Thanks for any help.

How did you compile Kokkos? Did you specify cmake -DKokkos_ENABLE_CUDA_LAMBDA=ON?

@masterleinad Seems like I did not. I only specified -DKokkos_ENABLE_CUDA=ON. Now it can compile the first exercise, but it fails with error:

 ./01_Exercise 
  Total size S = 4194304 N = 4096 M = 1024
terminate called after throwing an instance of 'std::runtime_error'
  what():  cudaStreamSynchronize(m_stream) error( cudaErrorIllegalAddress): an illegal memory access was encountered /home/th202608/codes/kokkos/master/src/kokkos/core/src/Cuda/Kokkos_Cuda_Instance.cpp:314
Traceback functionality not available

Abandon

Ok, solution was on slide 51 of the Kokkos lectures.... (replace std::malloc and std::free by Kokkos counterparts)