I am trying to compile and run a simple Cuda/thrust program, it works when the extension is .cu but it fails when the extension of source is .cpp.
I already applied the required changes for cpp file in cmake but I am getting
error: static assertion failed: unimplemented for this system THRUST_STATIC_ASSERT_MSG
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(thrust_test LANGUAGES CXX CUDA)
find_package(CUDA 10.0 REQUIRED)
message(STATUS "CUDA ${CUDA_VERSION_STRING} at ${CUDA_TOOLKIT_ROOT_DIR}")
set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC)
include_directories(${CUDA_INCLUDE_DIRS})
link_directories(${CUDA_LIBRARY_DIRS})
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CUDA_SEPARABLE_COMPILATION ON)
set_source_files_properties(
main.cpp
PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT
OBJ)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES})
and the main.cpp:
__host__
__device__
int foo() {
// generate random data serially
thrust::host_vector<int> h_vec(100);
std::generate(h_vec.begin(), h_vec.end(), rand);
// transfer to device and compute sum
thrust::device_vector<int> d_vec = h_vec;
return thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());
}
int main(void) {
std::cout << "Thrust v" << THRUST_MAJOR_VERSION << "." << THRUST_MINOR_VERSION << std::endl;
std::cout << foo() << std::endl;
return 0;
}