Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用推力::max_元素时出现未定义的符号错误 我正在使用一个CUDA C++项目,它使用可分编译,并且我有一些麻烦,需要编译一个推力函数。_Cuda_Cmake_Thrust_Nvcc - Fatal编程技术网

使用推力::max_元素时出现未定义的符号错误 我正在使用一个CUDA C++项目,它使用可分编译,并且我有一些麻烦,需要编译一个推力函数。

使用推力::max_元素时出现未定义的符号错误 我正在使用一个CUDA C++项目,它使用可分编译,并且我有一些麻烦,需要编译一个推力函数。,cuda,cmake,thrust,nvcc,Cuda,Cmake,Thrust,Nvcc,在添加以下函数调用之前,项目构建不会出现问题 thrust::device_ptr<float> max_int = thrust::max_element( thrust::device_ptr<float>(dev_temp_intensity_buffer), thrust::device_ptr<float>(dev_temp_intensity_buffer + INT_BUF_SIZE); 有趣的是,另一个推力函数调用编译得很好:

在添加以下函数调用之前,项目构建不会出现问题

thrust::device_ptr<float> max_int = thrust::max_element(
    thrust::device_ptr<float>(dev_temp_intensity_buffer),
    thrust::device_ptr<float>(dev_temp_intensity_buffer + INT_BUF_SIZE);
有趣的是,另一个推力函数调用编译得很好:

thrust::exclusive_scan(thrust::device_ptr<unsigned int>(dev_ray_alive),
    thrust::device_ptr<unsigned int>(dev_ray_alive + NRAYS),
    thrust::device_ptr<unsigned int>(dev_scanned_alive_rays));

我终于明白了

链接问题是由于缺少
cudadevrt
库造成的。问题是,仅仅将
-lcudadevrt
添加到
CUDA\u NVCC\u标志
是不够的

将CUDA运行时设备库链接到CMake目标时,问题消失,如下所示:

target\u link\u库(project glut glew${CUDA\u cudadevrt\u库})

Obs1:
CUDA\u cudadevrt\u库
变量仅在3.7.2以上的CMake版本上可用。添加行
cmake\u minimum\u required(版本3.7.2)
是一个好主意

Obs2:仅当您使用3.7.2以上的CMake版本时,以下链接到CUDA_库才能解决此问题。在较低版本上,此变量存在,但不包含
cudadevrt


target\u link\u库(project glut glew${CUDA\u libraries})

与此问题类似:@JaredHoberock是的。我已经将-lcudadevrt添加到nvcc标志中,并且还尝试使用
target\u link\u库(可视化utils cuda\u utils glut glew${cuda\u库)
,但没有成功。感谢您的评论。问题是否独立于您的CMake构建而发生?您能够从命令行手动链接程序吗?你能发布一个小的复制程序来演示这个问题,以便其他人可以试用他们的系统吗?@JaredHoberock你的调查本来是有用的,但问题已经解决了。谢谢你的评论。
thrust::exclusive_scan(thrust::device_ptr<unsigned int>(dev_ray_alive),
    thrust::device_ptr<unsigned int>(dev_ray_alive + NRAYS),
    thrust::device_ptr<unsigned int>(dev_scanned_alive_rays));
SET(CUDA_SEPARABLE_COMPILATION ON)

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -rdc=true -D_FORCE_INLINES) 
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=compute_52  -code=sm_52 -lcudart -lcudadevrt -lcuda)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xptxas -v)

cuda_add_executable(
 project 
 file1.cu
  ...)

target_link_libraries (project glut glew)