alpaka-group / cupla

C++ User interface for the Platform independent Library Alpaka :arrows_clockwise:
Other
37 stars 18 forks source link

cudaGetLastError() results in infinite loop #138

Closed fwyzard closed 4 years ago

fwyzard commented 4 years ago

Calling cudaGetLastError() results while using Cupla in header-only mode in an infinite loop.

test.cc

#include <iostream>

#include <cupla/config/GpuCudaRt.hpp>

int main(void) {
  auto status = cudaGetLastError();

  std::cout << "status: " << status << std::endl;

  return 0;
}

Build and run with

nvcc -x cu -std=c++11 -O2 -g -I/usr/local/alpaka/alpaka/include -I/usr/local/alpaka/cupla/include -w test.cc -o test
./test

The program gets stuck on line 6, and it never reaches the std::cout statement.

Removing the #include <cupla/config/GpuCudaRt.hpp> and running with CUDA natively works, as expected.

fwyzard commented 4 years ago

I forgot to add that I am using the devel branch of Alpaka and the dev branch of Cupla.

fwyzard commented 4 years ago

From a quick look at the code, I guess the reason is that in include/cupla/cudaToCupla/runtime.hpp cudaGetLastError() is #defined to cuplaGetLastError():

#define cudaGetLastError(...) cuplaGetLastError(__VA_ARGS__)

and in src/common.cpp cuplaGetLastError() calls cudaGetLastError():

CUPLA_HEADER_ONLY_FUNC_SPEC
cuplaError_t
cuplaGetLastError()
{
#if( ALPAKA_ACC_GPU_CUDA_ENABLED == 1 )
    // reset the last cuda error
    return (cuplaError_t)cudaGetLastError();
#elif( ALPAKA_ACC_GPU_HIP_ENABLED == 1 )
    return (cuplaError_t)hipGetLastError();
#else
    return cuplaSuccess;
#endif
}

which means it calls itself indefinitely.

fwyzard commented 4 years ago

@waredjeb FYI

psychocoderHPC commented 4 years ago

thanks for the report, the bug is fixed with #139.

ax3l commented 4 years ago

Confirmed here, thank you for the detailed report! :)