I am having issues with compiling my CUDA code with CMake. I am using CUDA 7 and the version information from nvcc is as follows:
nvcc: NVIDIA (R) Cuda compiler
This worked for me using CUDA 7, gcc 4.8.2 and CMake 3.0.2.
I updated the code and added a simple thrust-based example to make it clear that you can use C++11 in CUDA code
CMakeLists.txt
project(cpp11)
find_package(CUDA)
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_20;-std=c++11;-O2;-DVERBOSE")
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)
CUDA_ADD_EXECUTABLE(cpp11 main.cpp test.h test.cu)
test.h
#ifndef TEST_H
#define TEST_H
int run();
#endif
test.cu
#include "test.h"
#include
#include
#include
template
struct Fun
{
__device__ T operator()(T t1, T t2)
{
auto result = t1+t2;
return result;
}
};
int run()
{
const int N = 100;
thrust::device_vector vec(N);
thrust::sequence(vec.begin(),vec.end());
auto op = Fun();
return thrust::reduce(vec.begin(),vec.end(),0,op);
}
main.cpp
#include
#include "test.h"
int main()
{
std::cout << run() << std::endl;
return 0;
}